VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



This code finds a window and sends message to the window.

by Raj Diwate (4 Submissions)
Category: Windows API Call/Explanation
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Tue 20th February 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)

This code finds a window and sends message to the window.

API Declarations


'Anybody can make suitable changes and reuse it.
'For Furthur querries please do not hesitate to contact [email protected]
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long


Rate This code finds a window and sends message to the window.



'This program will send a message sc_close to the window to close it.
    Dim handle As Long
    Const NILL = 0&
    Const WM_SYSCOMMAND = &H112
    Const SC_CLOSE = &HF060
    lpClassName$ = "SciCalc"
    lpCaption$ = "Calculator"
    handle = FindWindow(lpClassName$, lpCaption$)
    X = SendMessage(handle, WM_SYSCOMMAND, SC_CLOSE, NILL)
End Sub
Private Sub Form_Load()
'Open the calculator exe say for instance then run this program it will find the instance of calculator exe.
    Dim sStr As String
    Dim lRet As Long
    Dim szTitle As String
    Dim lBret As Long
    szTitle = String(512, 0)
    lBret = GetWindowText(Me.hwnd, szTitle, 512)
    sStr = String(512, 0)
    lRet = FindWindow(sStr, "Calculator")
End Sub

Download this snippet    Add to My Saved Code

This code finds a window and sends message to the window. Comments

No comments have been posted about This code finds a window and sends message to the window.. Why not be the first to post a comment about This code finds a window and sends message to the window..

Post your comment

Subject:
Message:
0/1000 characters