Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

Simulating a button click?

michael_green
Beginner
854 Views
Hi,
In a certain situation I would like to be able to simulate the click of a button without actually having to click it. For example, when a user clicks a particular radio button, I would like the program to behave as though the user had then immediately clicked the OK button as well. Can this be done?
With many thanks in advance,
Mike
0 Kudos
4 Replies
anthonyrichards
New Contributor III
854 Views
Here is how I send such a message to a button control, ID=IDC_DISPLAY_FILE. gDlg is type T_DIALOG
and gDlg%hWnd is the handle to the dialog containing the control. IOR combines the BN_CLICKED 
and the control ID into high and low order parts of the first argument of the WM_COMMAND. 
GetDlgItem supplies the handle to the control with ID IDC_DISPLAY_FILE as
the second argument required by WM_COMMAND (See below)
 	retlog = SendMessage(gdlg%hWnd,WM_COMMAND, IOR(BN_CLICKED,IDC_DISPLAY_FILE),    &
	                                          GetDlgItem(gdlg%hWnd,IDC_DISPLAY_FILE))
WM_COMMAND takes two arguments (see CVF HELP) as shown below
Code:
WM_COMMAND 
wNotifyCode = HIWORD(wParam); // notification code 
wID = LOWORD(wParam);         // item, control, or accelerator identifier 
hwndCtl = (HWND) lParam;      // handle of control 
 
Parameters
wNotifyCode 
Value of the high-order word of wParam. Specifies the notification code if the message is from a control. If the message is from an accelerator, this parameter is 1. If the message is from a menu, this parameter is 0. 
wID 
Value of the low-order word of wParam. Specifies the identifier of the menu item, control, or accelerator. 
hwndCtl 
Value of lParam. Handle to the control sending the message if the message is from a control. Otherwise, this parameter is NULL. 

Message Edited by anthonyrichards on 08-23-2004 02:41 AM

Message Edited by anthonyrichards on 08-23-2004 02:47 AM

0 Kudos
aliho
Beginner
854 Views
The BM_CLICK message has exactly that purpose.

Send it to the control with sendmessage(hctrl,BM_CLICK,0,0)

See :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/buttons/buttonreference/buttonmessages/bm_click.asp
0 Kudos
anthonyrichards
New Contributor III
854 Views
Another method is possible, if you have assigned a callback routine, MyButtonSub say,
to the button, by just calling the callback directly as
call MyButtonSub( ButtonDlg, IDC_MYBUTTON, dlg_clicked)
where ButtonDlg is type T_Dialog and is the dialog containing the button whose ID is defined to be IDC_MYBUTTON. The ID is normally listed in RESOURCE.FD that is generated by the Resource compiler when it builds your dialog, so INCLUDE RESOURCE.FD must be added to
the routine from which you call the callback routine, and the dialog ButtonDlg must be available
(possibly via a global variable) to the same routine. 'Dlg_Clicked' is defined in DFLOGM.F90 in Module DFLOGM ( integer, parameter, public :: dlg_clicked = -4), so USE DFLOGM must also be added to the code for the calling routine. HTH
0 Kudos
michael_green
Beginner
854 Views
Hi Anthony,
The first method you suggested works very well and I am using it to great effect. However, I will note your second suggestion for the future.
With many thanks
Mike
0 Kudos
Reply