I forgot how to disable a button with API for another APP, how can i enable and disable a button? I think u use the SendMessage API but i don't have my API viewer, can someone give me an example how to enable a disabed button in nother APP?
Printable View
I forgot how to disable a button with API for another APP, how can i enable and disable a button? I think u use the SendMessage API but i don't have my API viewer, can someone give me an example how to enable a disabed button in nother APP?
Use SendDlgItemMessage, which allows you to send it to a specific item in a dialogue box.
yes....... but what is the message i send? huh? that was the question...
I am not sure what you are looking for, but here is my sample.
Code:Option Explicit
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) 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
Private Declare Function SendMessageByNum Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_LBUTTONUP = &H202
Private Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Private Const WM_CLOSE = &H10
Sub p_Close_Dialog()
Dim lng_Dialog As Long
Dim lng_Button As Long
'PURPOSE: Get the handle of an application by the classname
lng_Dialog = Findwindow("#32770", vbNullString)
'lng_Dialog = Findwindow("XLMAIN", vbNullString)
'PURPOSE: Get extra information of that application
lng_Button = FindWindowEx(lng_Dialog, 0&, "Button", vbNullString)
'PURPOSE: Press the Buttons - Method #1
Call SendMessageByNum(lng_Button, WM_LBUTTONDOWN, 0, 0&)
Call SendMessageByNum(lng_Button, WM_LBUTTONUP, 0, 0&)
'PURPOSE: Press the Buttons - Method #2
Call SendMessage(lng_Button, WM_LBUTTONDOWN, 0, 0&)
Call SendMessage(lng_Button, WM_LBUTTONUP, 0, 0&)
'PURPOSE: Close the button
Call SendMessageByString(lng_Button, WM_CLOSE, 0, 0&)
'PURPOSE: Close the message box
Call SendMessageByString(lng_Dialog, WM_CLOSE, 0, 0&)
End Sub
Nice code, try putting WM_ENABLE and you should be fine.
You are right Parksie! Forgot to change WM_CLOSE to WM_ENABLE.