Let's first check what we will achieve with winx: change the background color, intercept and process command messages, and customize controls. Have you noticed that we cannot do anything for keyboard input. Today, we will discuss how to use winx to process the acceleration key (shortcut keys, accel, which may be mixed below ).
In the previous article, the bug in the example I used was a superclassized button control, which will be maximized after double-clicking ,:).
The shortcut key is specified in the resource file. You can use the shortcut key resource in the resource file to match a keyboard message with a command ID, in this way, we can process keyboard shortcuts like the previous methods used to process command messages.
Officially started!
In this winx tutorial, we provide two examples: accel and focusmsg, for example:
After reading this Tutorial example (don't tell me that you didn't read the winx tutorial instance when reading this blog), we can easily see that the shortcut keys in winx are mainly handled through the following two macros:
-
Winx_accel
-
Winx_dlg_accel
And a message processing function:
.
Winx_accel
Load the shortcut key resource. The winx_accel macro contains a parameter that specifies the ID of the shortcut resource in the resource file. The usage is as follows:
Winx_accel (idr_accel1 );
Idr_accel1 indicates the ID of the acceleration key resource.
Winx_dlg_accel
In winx, the shortcut keys are not supported by default in the dialog box. You can use the winx_dlg_accel macro to change the settings and make them supported. That is to say, winx_dlg_accel is a switch. Winx_dlg_accel does not contain parameters, but has parentheses. The usage is as follows:
Winx_dlg_accel ();
Testtranslateaccel
This is a message processing function. The message to be processed is a custom winx shortcut for sending messages. It provides an opportunity for us to modify the shortcut key for message processing.
Why? /
Because you don't know when the dialog box will intercept messages that should have been processed by your control, such as the shortcut message here. Once processed by the dialog box, the control cannot be processed. This is obviously not your intention.
How to fix it?
Define the testtranslateaccel function in the dialog box class. Its prototype is as follows:
Bool testtranslateaccel (hwnd, lpmsg );
Cannottranslateaccel is returned for messages not processed by the dialog box. Besides, cantranslateaccel is returned when the dialog box is processed. Usage in a focusmsg instance:
Bool testtranslateaccel (hwnd, lpmsg)
{
If (: getdlgctrlid (: getfocus () = idc_richedit1)
{
If (lpmsg-> message = wm_keydown & lpmsg-> wparam = 'Z ')
Return cannottranslateaccel;
}
Return cantranslateaccel;
}
This gives the control idc_richedit1 the opportunity to process Z-related shortcuts ,.
But don't worry. testtranslateaccel mainly appears when the dialog box and the sub-control display the common shortcut key. There are few such opportunities.
Several Notes
-
Winx_cmds_begin_ex/winx_cmds_end_ex
In the focusmsg tutorial instance, we use this pair of macros (not a pair of red). In fact, we have previously said that the difference between these macros and those without the ex suffix is, this macro sends messages that are not processed to the view for processing. It should be noted that the "View" here is not like the view in MFC, and the "View" here is a more general concept, any window or control that is in charge of display can be called a view. Therefore, in the instance, messages that are not processed in the dialog box are sent to the control for processing. The usage is the same as winx_cmds_begin/winx_cmds_end.
-
Initcommoncontrols/initricheditcontrol
When a general control is used, we need to call initcommoncontrols, use the RichEdit control, and call initricheditcontrol again. Both of them have no parameters.
-
Winx_cmd/winx_cmd_ex
This pair of macros didn't appear in this actual instance. You can leave it alone, but because they and "enclose" their winx_cmds_begin_ex/winx_cmds_end_ex
Or the close relationship between winx_cmds_begin/winx_cmds_end, which must be briefly described here.
Winx_cmd_ex does not have to be paired with winx_cmds_begin_ex/winx_cmds_end_ex. Similarly, winx_cmd does not necessarily match winx_cmds_begin/winx_cmds_end. We have been using winx_cmd. winx_cmd_ex has one more parameter than it. We will review the usage of winx_cmd:
Winx_cmd (idc_button1, onbutton1 );
The program calls the onbutton1 message processing function when it receives the command message with the ID of idc_button1. The usage of winx_cmd_ex is as follows:
Winx_cmd_ex (id_button1, bn_click, onbutton1click );
The same effect can be achieved. Some people will say, what is the purpose of this form? When you need to process other messages with buttons (this button is in the dialog box, but you need to process it in the dialog box!
End
The examples and content of this practical tutorial are relatively simple. As long as the acceleration key resources are added, there should be no problems with caution. Here is no example. In the next article, we will discuss more interesting content. Use the layout control on the winx control dialog box.
End