Good day!

I just want to know on how to correctly use SendMessage API. When the save as dialog box popsup, Save button will be automatically click.
Let say I have hwnd and classname value. Please see below

Public Declare Function SendMessage Lib "user32" Alias "SendMessageW" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Public DialogHWND As Long
Public ClassNameX as string

DialogHWND=1115400
classname="#31786"

Private Sun Command1_Click()
Dim lret As Long
lret = SendMessage(DialogHWND, BN_CLICKED, ClassNameX, Null)
End Sub

Thank you fe helping..!

Presumably the Save button will already have the focus, so why not just use SendKeys

SendKeys "{Enter}"

HTH,
Rob

I haven't used VB for years so I won't try to write actual code but maybe I can give some clues. Taking the SendMessage parameters one by one:

hwnd : I assume you show DialogHWND as a hard coded value for simplicity. In practise you should determine the value at run time. A common approach is to use the FindWindow API but there are other possibilities.

wMsg : BN_CLICKED is not a message, it is a notification code that is to be sent as part of the wParam. BN_CLICKED should not be used in the wMsg parameter. The wMsg should be WM_COMMAND.

wParam : MSDB says: "The LOWORD contains the button's control identifier. The HIWORD specifies the notification code." So you need to combine the button's ID with BN_CLICKED. For example if you wanted to click an OK button you would combine IDC_OK and BN_CLICKED. You can use MAKELONG(IDC_OK, BN_CLICKED)

lParam : I think this needs to be the handle of the button you want to click. You should be able to get that handle using GetDlgItem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.