- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I want to be able to access menu items by pressing a single key on the keyboard - say "M" for a "Move" command, rather than having to select the "Edit" then the "Move" menu items, or instead of using the "Move" button on the tool bar.
How do I trap these keyboard characters in a Windows API project to achieve this?
Thanks,
David
How do I trap these keyboard characters in a Windows API project to achieve this?
Thanks,
David
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It is straightforward to program 'accelerator keys' using Visual Fortran.
Use the Resource Editor to create an 'accelerator table', defining key combinations for frequently-used menu items, and give it a name (e.g.'GENERIC') and then in your WInMain function add
After registering your window class, load your menu and accelerator table resources and create your main window
then start your message loop and include a reference to the TranslateAccelerator function to trap keyboard accelerators
HTH
Use the Resource Editor to create an 'accelerator table', defining key combinations for frequently-used menu items, and give it a name (e.g.'GENERIC') and then in your WInMain function add
character*100 lpszAcceltabname ! lpszAcceltabname="Generic"C
After registering your window class, load your menu and accelerator table resources and create your main window
hmenu = LoadMenu(hInstance, LOC(lpszMenuName)) haccel = LoadAccelerators(hInstance, LOC(lpszAcceltabname)) ghInstance = hInstance hWnd = CreateWindow( lpszClassName, & lpszAppName, & INT(WS_OVERLAPPEDWINDOW), & 50, & 50, & 800, & 575, & NULL, & hmenu, & hInstance, & NULL & ) i = ShowWindow( hWnd, SW_SHOWNORMAL) ghWnd=hWnd
then start your message loop and include a reference to the TranslateAccelerator function to trap keyboard accelerators
! ! Start a message loop do while( GetMessage (mesg, NULL, 0, 0) .NEQV. .FALSE.) ! look for accelerator key-strokes - returns TRUE if key-stroke found and processed ! do not process message further if accelerotor key processed if (TranslateAccelerator( hwnd, haccel, mesg).EQV. .FALSE.) THEN ! process message if accelerator not used i = TranslateMessage( mesg ) i = DispatchMessage( mesg ) ENDIF end do WinMain = mesg.wParam end
HTH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
...just an additional remark -- accelerator IDs from resource accelerator table should be the same as corresponding menu IDs. In this case, a) you don't change any of WM_COMMAND handling code b) Windows automatically disables accelerator when menu item is grayed and vice versa.
Jugoslav
Jugoslav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the reply - I was trying to use WM_KEYUP!
I now have a resource table and have defined lpszAcceltabname - but when I make the call
haccel=LoadAccelerators(hInstance,LOC(lpszAcceltabname))
I get the error -
The specified resource name cannot be found in the image file.
I have not mistyped the accelerator name. Is there something I have missed?
Thanks, David
I now have a resource table and have defined lpszAcceltabname - but when I make the call
haccel=LoadAccelerators(hInstance,LOC(lpszAcceltabname))
I get the error -
The specified resource name cannot be found in the image file.
I have not mistyped the accelerator name. Is there something I have missed?
Thanks, David
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I managed to fix it myself by forcing the resource ID number rather than the resource name:-
haccel= LoadAccelerators(hInstance,MakeIntResource(127))
Thanks, David
haccel= LoadAccelerators(hInstance,MakeIntResource(127))
Thanks, David
![](/skins/images/318B71AC6E18CAB8E2CA944B2397E849/responsive_peak/images/icon_anonymous_message.png)
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page