Is there any way to SendMessage to a Button control
-
Just SendMessge to the Button IDC_BUTTON1 and make sure the button will be clicked what's the code ? thanks for help!
If you're not using MFC, the following would be the code, where
hDlg
is the handle to the dialog hosting the button -::SendMessage(hDlg, WM_COMMAND, (BN_CLICKED << 16) | IDC_BUTTON1, ::GetDlgItem(hDlg, IDC_BUTTON1);
If you're using MFC, the following would be the version if you're calling it from within the dialog class -
SendMessage(WM_COMMAND, (BN_CLICKED << 16) | IDC_BUTTON1, GetDlgItem(IDC_BUTTON1));
«_Superman_» _I love work. It gives me something to do between weekends.
-
If you're not using MFC, the following would be the code, where
hDlg
is the handle to the dialog hosting the button -::SendMessage(hDlg, WM_COMMAND, (BN_CLICKED << 16) | IDC_BUTTON1, ::GetDlgItem(hDlg, IDC_BUTTON1);
If you're using MFC, the following would be the version if you're calling it from within the dialog class -
SendMessage(WM_COMMAND, (BN_CLICKED << 16) | IDC_BUTTON1, GetDlgItem(IDC_BUTTON1));
«_Superman_» _I love work. It gives me something to do between weekends.
-
ERROR,parameter 3... SendMessage(WM_COMMAND, ((WPARAM)BN_CLICKED)<<8|(WPARAM)IDC_BUTTON, 0L); is that right? I want the Button will be clicked down when the Message send,but there's nothing happened with the Button while the Message sent ,why
If you want to emulate a human pressing a button, then you will have to perform the actions a human performs: 1. Press button: send WM_LBUTTONDOWN 2. Hold button down a while: use SetTimer() or similar to implement delay. 3. Release button: send WM_LBUTTONUP.
Best wishes, Hans
-
ERROR,parameter 3... SendMessage(WM_COMMAND, ((WPARAM)BN_CLICKED)<<8|(WPARAM)IDC_BUTTON, 0L); is that right? I want the Button will be clicked down when the Message send,but there's nothing happened with the Button while the Message sent ,why
-
Why did you not use the code that Superman posted? Re-read his answer and select the appropriate one (MFC or non-MFC) and use copy & paste to add to your project.
The best things in life are not things.
-
I got a error with it in my MFC app Error 1 error C2664: 'CWnd::SendMessageW' : cannot convert parameter 3 from 'CWnd *' to 'LPARAM'
-
Just use a cast thus:
SendMessage(p1, p2, (LPARAM)p3 ...
You should really study and understand these basics of C++ before embarking on advanced projects such as you describe.
The best things in life are not things.
yea,I use
SendMessage(WM_COMMAND,(BN_CLICKED)<<16|IDC_BUTTON1,(LPARAM)GetDlgItem(IDC_BUTTON1));
it's passed in Compiling but pop up a Assertion Failded when running
> mfc100ud.dll!CWnd::OnCommand(unsigned int wParam, long lParam) Line 2708 + 0x27 bytes C++
so I changed it in Release Configuration,no Assertion Failed pop up ,why?
-
yea,I use
SendMessage(WM_COMMAND,(BN_CLICKED)<<16|IDC_BUTTON1,(LPARAM)GetDlgItem(IDC_BUTTON1));
it's passed in Compiling but pop up a Assertion Failded when running
> mfc100ud.dll!CWnd::OnCommand(unsigned int wParam, long lParam) Line 2708 + 0x27 bytes C++
so I changed it in Release Configuration,no Assertion Failed pop up ,why?
asserts don't get compiled in release code - they are a debugging tool and have little value in release code - i.e. the problem is still there in release code, you just didn't get a popup In that code nugget the assert could be caused by an invalid window, are your sure that the window you are in is the immediate parent of the button you'd normally be in a CDialog... class for this to work
-
yea,I use
SendMessage(WM_COMMAND,(BN_CLICKED)<<16|IDC_BUTTON1,(LPARAM)GetDlgItem(IDC_BUTTON1));
it's passed in Compiling but pop up a Assertion Failded when running
> mfc100ud.dll!CWnd::OnCommand(unsigned int wParam, long lParam) Line 2708 + 0x27 bytes C++
so I changed it in Release Configuration,no Assertion Failed pop up ,why?
-
If you're not using MFC, the following would be the code, where
hDlg
is the handle to the dialog hosting the button -::SendMessage(hDlg, WM_COMMAND, (BN_CLICKED << 16) | IDC_BUTTON1, ::GetDlgItem(hDlg, IDC_BUTTON1);
If you're using MFC, the following would be the version if you're calling it from within the dialog class -
SendMessage(WM_COMMAND, (BN_CLICKED << 16) | IDC_BUTTON1, GetDlgItem(IDC_BUTTON1));
«_Superman_» _I love work. It gives me something to do between weekends.