Method for realizing hotkeys in PB

xiaoxiao2021-03-06  111

If you can add some hot keys in your application, you can speed up the user's operating speed, especially for those skilled operators, and specially welcome shortcuts. In a lot of large-scale applications, users can easily switch and handle functional switching and processing by using a combined key such as Ctrl Alt F5. So, how do we implement the required hotkey function when developing an app with PowerBuilder? The author introduces two practical methods according to its own experience.

The first method: This method can be implemented: Whenever the user presses the hotkey, it will trigger an event in the window. External API function FUNCTION Integer 1. Statement of GlobalAddAtom (ref string lpString) LIBRARY "kernel32.dll" ALIAS FOR "GlobalAddAtomA" FUNCTION ulong RegisterHotKey (ulong hwnd, ulong id, ulong fsModifiers, ulong vk) LIBRARY "user32.dll" // The HWND parameter is used to specify the window handle using this hotkey, the ID parameter is used to specify a unique id, the FSMODIFIERS parameter indicates the auxiliary key value (ALT, CTRL, SHIFT, etc.), the VK parameter indicates the ASCII code of the virtual key. 2. Assigning initial values ​​for constants: constant integer mod-alt = 1Constant Integer mod-control = 2constant integer mod-shift = 43. Using the code to register the hotkey you want to use in the system = "=" my atom ID "atomid = globaladdatom (ls-str) // gets the only ID in the OPEN event of the window Do not conflict with other applications LL-RC = registerhotKey (Handle (this), atomid, mod-alt mod-control, 65) // 65 is 'a', registered hotkey is Ctrl Alt a if ll-rc = 0 The MessageBox ("Error", "Error Message") End IF 4. Write the handler when pressing the hotkey // In the Other event of the window, if wparam = atomid dam / / Here to write a handler end if

转载请注明原文地址:https://www.9cbs.com/read-126285.html

New Post(0)