A frequently asked question is: how can I captrue the F10 key or capture clicking on the X-button. Those things can be done by adding a user-event to your Window and map it to pbm_syscommand. A WM_SYSCOMMAND message is sent to your WIndow whenever the user chooses a command from the window menu (or systemmenu) or when the user chooses the maximize button, minimize button, restore button or close button.
You can check for these messages in your user-event or sent them yourself by sending a WM_SYSCOMMAND (= 274) message to your WIndow. This would look like:
Send( Handle( yourWindow ), WM_SYSCOMMAND, SC_CLOSE, 0 )
The values for the different messages are as follows:
|SC_SIZE||61440||Sizes the Window.|
|SC_MOVE||61456||Moves the Window.|
|SC_MINIMIZE||61472||User clicked the Minimize-button|
|SC_MAXIMIZE||61488||User clicked the Maximize-button|
|SC_CLOSE||61536||User clicked the Close-button|
|SC_KEYMENU||61696||Contains the character code of the key that is used with the Alt key. When pressing F10 or just Alt this value is 0.||User pressed F10, Alt or another menu-shortkey.|
|SC_RESTORE||61728||User clicked the Restore-button|
|SC_TASKLIST||61744||Activates the Start menu.|
|SC_SCREENSAVE||61760||Executes the screensaver application specified in the [boot] section of the system.ini file.|
1 = the display is going to low power
2 = the display is being shut off
|Sets the state of the display.|
A point of attention here: the four low-order bits of the wparam value (which gives you your commandtype value) are used internally by the system and make the value of wparam vary between the values mentioned above plus 15 (so, SC_SIZE has values within the range from 61440 uptil and including 61455). To obtain the correct result when testing the value of wparam you have to combine the wparam value with the value 0xFFF0 (65520). You can do this by using the bitwise AND operator (see the of_BitwiseAnd function within the PFC object pfc_n_cst_numerical how to do this).
By using the SC_MOVE message you can move a Window without a Titlebar. Add one line of code to the mousedown-event:
Send( Handle( yourWindow ), WM_SYSCOMMAND, SC_MOVE + 2, 0 )
You have to add two to fake that your mouse is on the TitleBar.
When you want to capture the F10 systemkey, you can code something like this:
Declare an instance variable:
In the systemkey-event of your Window (this is a predefined Window-event) add:
If key = KeyAlt! Then
ib_AltPressed = True
ib_AltPressed = False
In the userevent for pbm_syscommand code (this example makes use of the PFC function of_BitwiseAnd):
Constant Long ll_Mask = 65520
If lnv_Numerical.of_BitwiseAnd( commandtype, ll_Mask ) = SC_KEYMENU Then
If Message.LongParm = 0 And not ib_AltPressed Then
Return 1 // .. do not process this message any further
Before the wm_syscommand message is sent to your Window, a wm_syskeydown message is sent. This message is mapped to the PowerBuilder systemkey Window event. Because you can't know within the wm_syscommand message if the user pressed F10 or Alt, you can receive this information within the systemkey event. One drawback of this approach is: the systemkey event isn't triggered when the focus is on a editable DataWindow-column. In this case, you don't know what key was pressed to fire the wm_syscommand message.
There are some other messages. You can check them out at: