?
Solved

Accelerators

Posted on 1999-01-16
11
Medium Priority
?
202 Views
Last Modified: 2013-12-03
My win main goes like this:

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR lpszCmdLine, int cmdShow)
{
      InitCommonControls() ;

      DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG), NULL, DlgProc) ;

      return FALSE ;
}


Because I have a modal box and I have any message loop, I'm not able to catch my accelerators.

What am I suppose to do??
0
Comment
Question by:asimov_
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 

Author Comment

by:asimov_
ID: 1418854
Moreover, I'm not able to have a modeless box because I'm not able to dispatch my message...
0
 
LVL 22

Accepted Solution

by:
nietod earned 280 total points
ID: 1418855
In the dialog procedure, call TranslateAccelerator on WM_KEYDOWN and WM_SYSKEYDOWN messages.  (You will have to "make" a MSG structure out of the message and parameters passed to the dialgo procedure.  

Let me know if you have any questions.
0
 

Author Comment

by:asimov_
ID: 1418856
Hello,
 Your answer is good, but maybe my own question wasn't clear enough! Sorry, it's my fault. I'll give to you an entire program code from Petzold book. Goes like this :

/*----------------------------------------
   HEXCALC.C -- Hexadecimal Calculator
                (c) Charles Petzold, 1996
  ----------------------------------------*/

#include <windows.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PSTR szCmdLine, int iCmdShow)
     {
     static char  szAppName[] = "HexCalc" ;
     HWND         hwnd ;
     MSG          msg ;
     WNDCLASSEX   wndclass ;

     wndclass.cbSize        = sizeof (wndclass) ;
     wndclass.style         = CS_HREDRAW | CS_VREDRAW;
     wndclass.lpfnWndProc   = WndProc ;
     wndclass.cbClsExtra    = 0 ;
     wndclass.cbWndExtra    = DLGWINDOWEXTRA ;
     wndclass.hInstance     = hInstance ;
     wndclass.hIcon         = LoadIcon (hInstance, szAppName) ;
     wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
     wndclass.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1) ;
     wndclass.lpszMenuName  = NULL ;
     wndclass.lpszClassName = szAppName ;
     wndclass.hIconSm       = LoadIcon (hInstance, szAppName) ;

     RegisterClassEx (&wndclass) ;

     hwnd = CreateDialog (hInstance, szAppName, 0, NULL) ;

     ShowWindow (hwnd, iCmdShow) ;

     while (GetMessage (&msg, NULL, 0, 0))
          {
          TranslateMessage (&msg) ;
          DispatchMessage (&msg) ;
          }
     return msg.wParam ;
     }

void ShowNumber (HWND hwnd, UINT iNumber)
     {
     char szBuffer[20] ;

     SetDlgItemText (hwnd, VK_ESCAPE, strupr (ltoa (iNumber, szBuffer, 16))) ;
     }

DWORD CalcIt (UINT iFirstNum, int iOperation, UINT iNum)
     {
     switch (iOperation)
          {
          case '=' : return iNum ;
          case '+' : return iFirstNum +  iNum ;
          case '-' : return iFirstNum -  iNum ;
          case '*' : return iFirstNum *  iNum ;
          case '&' : return iFirstNum &  iNum ;
          case '|' : return iFirstNum |  iNum ;
          case '^' : return iFirstNum ^  iNum ;
          case '<' : return iFirstNum << iNum ;
          case '>' : return iFirstNum >> iNum ;
          case '/' : return iNum ? iFirstNum / iNum : UINT_MAX ;
          case '%' : return iNum ? iFirstNum % iNum : UINT_MAX ;
          default  : return 0 ;
          }
     }

LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
     {
     static BOOL  bNewNumber = TRUE ;
     static int   iOperation = '=' ;
     static UINT  iNumber, iFirstNum ;
     HWND         hButton ;

     switch (iMsg)
          {
          case WM_KEYDOWN :                   // left arrow --> backspace
               if (wParam != VK_LEFT)
                    break ;
               wParam = VK_BACK ;
                                             // fall through
          case WM_CHAR :
               if ((wParam = toupper (wParam)) == VK_RETURN)
                    wParam = '=' ;

               hButton = GetDlgItem (hwnd, wParam) ;

               if (hButton != NULL)
                    {
                    SendMessage (hButton, BM_SETSTATE, 1, 0) ;
                    SendMessage (hButton, BM_SETSTATE, 0, 0) ;
                    }
               else
                    {
                    MessageBeep (0) ;
                    break ;
                    }
                                             // fall through
          case WM_COMMAND :
               SetFocus (hwnd) ;

               if (LOWORD (wParam) == VK_BACK)         // backspace
                    ShowNumber (hwnd, iNumber /= 16) ;

               else if (LOWORD (wParam) == VK_ESCAPE)  // escape
                    ShowNumber (hwnd, iNumber = 0) ;

               else if (isxdigit (LOWORD (wParam)))    // hex digit
                    {
                    if (bNewNumber)
                         {
                         iFirstNum = iNumber ;
                         iNumber = 0 ;
                         }
                    bNewNumber = FALSE ;

                    if (iNumber <= UINT_MAX >> 4)
                         ShowNumber (hwnd, iNumber = 16 * iNumber + wParam -
                              (isdigit (wParam) ? '0' : 'A' - 10)) ;
                    else
                         MessageBeep (0) ;
                    }
               else                                    // operation
                    {
                    if (!bNewNumber)
                         ShowNumber (hwnd, iNumber =
                              CalcIt (iFirstNum, iOperation, iNumber)) ;
                    bNewNumber = TRUE ;
                    iOperation = LOWORD (wParam) ;
                    }
               return 0 ;

          case WM_DESTROY :
               PostQuitMessage (0) ;
               return 0 ;
          }
     return DefWindowProc (hwnd, iMsg, wParam, lParam) ;
     }


And now, the .rc file :
/*----------------------------
   HEXCALC.RC resource script
  ----------------------------*/

#include <windows.h>

HexCalc ICON hexcalc.ico

HexCalc DIALOG 32768, 0, 102, 122
     STYLE WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX
     CLASS "HexCalc"
     CAPTION "Hex Calculator"
     {
     PUSHBUTTON "D",       68,  8,  24, 14, 14
     PUSHBUTTON "A",       65,  8,  40, 14, 14
     PUSHBUTTON "7",       55,  8,  56, 14, 14
     PUSHBUTTON "4",       52,  8,  72, 14, 14
     PUSHBUTTON "1",       49,  8,  88, 14, 14
     PUSHBUTTON "0",       48,  8, 104, 14, 14
     PUSHBUTTON "0",       27, 26,   4, 50, 14
     PUSHBUTTON "E",       69, 26,  24, 14, 14
     PUSHBUTTON "B",       66, 26,  40, 14, 14
     PUSHBUTTON "8",       56, 26,  56, 14, 14
     PUSHBUTTON "5",       53, 26,  72, 14, 14
     PUSHBUTTON "2",       50, 26,  88, 14, 14
     PUSHBUTTON "Back",     8, 26, 104, 32, 14
     PUSHBUTTON "C",       67, 44,  40, 14, 14
     PUSHBUTTON "F",       70, 44,  24, 14, 14
     PUSHBUTTON "9",       57, 44,  56, 14, 14
     PUSHBUTTON "6",       54, 44,  72, 14, 14
     PUSHBUTTON "3",       51, 44,  88, 14, 14
     PUSHBUTTON "+",       43, 62,  24, 14, 14
     PUSHBUTTON "-",       45, 62,  40, 14, 14
     PUSHBUTTON "*",       42, 62,  56, 14, 14
     PUSHBUTTON "/",       47, 62,  72, 14, 14
     PUSHBUTTON "%",       37, 62,  88, 14, 14
     PUSHBUTTON "Equals",  61, 62, 104, 32, 14
     PUSHBUTTON "&&",      38, 80,  24, 14, 14
     PUSHBUTTON "|",      124, 80,  40, 14, 14
     PUSHBUTTON "^",       94, 80,  56, 14, 14
     PUSHBUTTON "<",       60, 80,  72, 14, 14
     PUSHBUTTON ">",       62, 80,  88, 14, 14
     }




My question is : I would like to use a dialog box like in this example. I want a class definition because I need a message loop. However, with this technic gave by Petzold, I'm not able to insert a menu and an accelerators table to my programm. I would like that you give me the example above with the code to insert menu and accelerators. Test it, because, those solutions aren't good:
wndclass.lpszMenuName = "menu" ;
LoadMenu... ;
Give the menu name to dialog ressource ;

If you're able to give me an answer, I'll consider you like the most famous et bright programmer on earth!!!

LAst two months, I tried to have a program with a window defined in vc's ressource, a menu, and accelerators!

Please help me,

Asimov_

0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
LVL 22

Expert Comment

by:nietod
ID: 1418857
I can not follow you.  Are you saying you want your program to be a dialog box program (just one top-level window that is a dialog box) or do you want your program to be a regular window program  (one with a mesage loop.)
0
 

Author Comment

by:asimov_
ID: 1418858
I want a program to be a regular window program (one qith message loop). But, my window program must be design into vc's resources (insert dialog box). Moreover, I want to use menu and accelerators. And I don't know how to match those three caracteristics.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1418859
I don't think there is any way to use VC's dialgo box editing features to create a regular window.   They are used to create a "dialog template resource" which consists of information use to construct the dialog window and its child windows (controls).   Unfortunately windows does not provide any means for you to use that type of resource to build a regular window.

However, you could write a procedure that interprets this resource and builds the main window and its child windows for you.   If you want to go that route, look at the documentation for DLGTEMPLATE and DLGITEMTEMPLATE these define the structure of the resource.
0
 

Author Comment

by:asimov_
ID: 1418860
k, thanks for your answer but if you're looking for the example I gave you. Those dialog template ressource are used for the principal window. Take a look at this and give me your comments.


0
 
LVL 22

Expert Comment

by:nietod
ID: 1418861
>>Those dialog template ressource are used for the principal window.
They ARE used?  or you WANT to use them?  
0
 

Author Comment

by:asimov_
ID: 1418862
I would like to do exactly like this example, but with a menu  and accelerators. (Sorry, if you don't understand all i'm saying, because english is not my firts language).

I'll try to explain myself: in this example, we can see that a principal window is created with createdialog(). To be created, all childs windows is defined in the .rc file. Then, with a unique call of createdialog(), the window and all childs windows are created.

That's what I want to do. I want to describe another window and another childs (in the .rc file) for a new program. Moreover, to create my principal window and all childs windows, I want to use createdialog(). Then, that's what i'm not able to: I would like to put in my program a menu and accelerators.

Thanks for your patience.
0
 

Author Comment

by:asimov_
ID: 1418863
I'll ask my question differently!
Take the example that i gave you and you only add the code to insert a menu and accelerators (please test it to be sure that's ok). It's all i want to do.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1418864
What you are talking about doing is a lot of work.  I do not have that sort of time.  Windows provides no mechansim for what you want, you will have to create it yourself, or give up on this approach.  Take a look at my 2nd paragraph of comments on Jan 18th at 1:22.  You will have to write a procedure that will  parse the dialog template resources and build the windows from the information in the resource.  Windows does this for you when it creates a dialog, but does not do it for you for a regular window.  You will have to do it yourself, or give up.
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question