Hello. How can i use SendMessage to "press" other program's button? I don't know other program's button's ID but there is only one button in that program. I searched MSDN and found something. I tried this piece of code:

HWND hWnd;
hWnd = HWND(FindWindow(NULL, "WindowName"));
SendMessageW(hWnd, BM_CLICK, NULL, NULL);

At MSDN says that wParm and lParm has to be NULL. Can you help me?
Thank you.

Hi,

AutoIt

After installing autoit, there is a file named "AutoIt window info". That should help you get the button ID.

Hi,

AutoIt

After installing autoit, there is a file named "AutoIt window info". That should help you get the button ID.

Thank you. This seems to be useful. But how can i send BM_CLICK to specific button? Maybe i should add button ID to wParam or lParam?

Here, this code demonstrates sending click to a calculator:
Open a calculator, input any value then executing the code below will reset the value:

int main(int argc, char *argv[])
{
LPARAM ID = 81;
LRESULT res;
HWND hWnd;
HWND hWnd1; //handle to the Button 'C'
hWnd = HWND(FindWindow("SciCalc", "Calculator"));
hWnd1 = HWND(GetDlgItem(hWnd, 81));
res = SendMessage(hWnd1, BM_CLICK, NULL, NULL);
cout << "\nResult: " << res;
getchar();
return 0;
}

What headers do i need to include?

Line 8: error C2664: 'void CWnd::GetDlgItem(int,HWND *) const' : cannot convert parameter 1 from 'HWND' to 'int'
Line 8: error C2514: 'HWND' : class has no constructors
Line 9: error C2660: 'CWnd:: SendMessageA' : function does not take 4 arguments

HWND hWnd;
    HWND *p_hWnd = &hWnd;
    HWND hButton;
    hWnd = HWND(FindWindow(NULL, "Dialog"));
    hButton = HWND(GetDlgItem(1001, p_hWnd));
    SendMessageW(hButton, BM_CLICK, NULL, NULL);

Line 5: error C2440: '<function-style-cast>' : cannot convert from 'void' to 'HWND'
So how am i supposed to get button handle to HWND variable if GetDlgItem isn't returning anything??? :( any advice?

P.S I'm using MFC. Does that change anything?

Never mind. I found the answer...

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.