Solved

Borland OWL, hotkeys in a Dialog menu

Posted on 1997-03-14
11
588 Views
Last Modified: 2006-11-17
I am using Borland C++ v. 4.5 OWL. I have a dialog (TDialog)
which have a menu, all this is maded in the resource workshop. Now I need to add (or activate) some hot keys I have defined, eg. CTRL+O for open file. How to do this ?
0
Comment
Question by:tovergaard
11 Comments
 
LVL 3

Expert Comment

by:gaohong
ID: 1162047
Pretty Easy, just Add accelerator key in menu like this

 MENUITEM SEPARATOR
 POPUP "&Edit"
 {
  MENUITEM "&Undo\tCtrl+Z", CM_EDITUNDO, GRAYED
  MENUITEM SEPARATOR
  MENUITEM "Cu&t\tCtrl+X", CM_EDITCUT, GRAYED
  MENUITEM "&Copy\tCtrl+C", CM_EDITCOPY, GRAYED
  MENUITEM "&Paste\tCtrl+V", CM_EDITPASTE, GRAYED
  MENUITEM SEPARATOR
  MENUITEM "Select &All\tCtrl+A", CM_EDITSELALL, GRAYED
  MENUITEM "&Delete\tDel", CM_EDITDELETE, GRAYED
 }

// Accelerator table for short-cut to menu commands. (include\owl\editfile.rc)
MDI_MENU ACCELERATORS
BEGIN
  VK_DELETE, CM_EDITDELETE, VIRTKEY
  VK_DELETE, CM_EDITCUT, VIRTKEY, SHIFT
  VK_INSERT, CM_EDITCOPY, VIRTKEY, CONTROL
  VK_INSERT, CM_EDITPASTE, VIRTKEY, SHIFT
  VK_BACK,   CM_EDITUNDO, VIRTKEY, ALT
  VK_F3,     CM_EDITFINDNEXT, VIRTKEY
  VK_F2,     CM_EDITFIND, VIRTKEY
END

good luck
0
 
LVL 2

Author Comment

by:tovergaard
ID: 1162048
Thank for your answer, but the hot keys are not active!

The menu is display in the TDialog and the menu works when I select the menu items, but no hot keys works.

What must I do to activate the hot keys in the TDialog ?


0
 
LVL 3

Expert Comment

by:gaohong
ID: 1162049
Thank for your answer, but the hot keys are not active!

The answer is correct !!!

The menu is display in the TDialog and the menu works when I select the menu items, but no hot keys works.

Have Assigned the accelerator to Attr.AccelTable ?  Just post
your code before make any judgement.

What must I do to activate the hot keys in the TDialog ?
Do nothing.

 
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 2

Author Comment

by:tovergaard
ID: 1162050
Sorry, but I still have the problem.


> Have Assigned the accelerator to Attr.AccelTable ?    

Attr.AccelTable is not accessable in TDialog, so I do this (in the TDialog EvInitDialog):

TWindow::Attr.AccelTable = MENU_ENCODE;

--
A part from my RC file

MENU_ENCODE MENU
{
 POPUP "&File"
 {
  MENUITEM "&Open type definition file\tCtrl+O", IDM_EN_OPEN, INACTIVE
  MENUITEM "&Close dialog\tALT+F4", IDM_QUIT
 }

 POPUP "&Tools"
 {
  MENUITEM "Editor", CM_ENC_TOOL_EDITOR
 }

}
MENU_ENCODE ACCELERATORS
{
VK_F3, IDM_EN_OPEN, VIRTKEY
}



IDD_CREATE_DATA DIALOG 10, 37, 298, 223
STYLE WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "ENCODE DATA"
MENU MENU_ENCODE
FONT 8, "MS Sans Serif"
{
......
0
 
LVL 2

Author Comment

by:tovergaard
ID: 1162051
I know the menu text says CTRL+O, and the accelerator table
define F3, but it is not the problem, none of the keys works.

It seems as the menu hotkeys is not active (the accelerator table not loaded)



0
 
LVL 2

Author Comment

by:tovergaard
ID: 1162052
Adjusted points to 75
0
 
LVL 23

Expert Comment

by:chensu
ID: 1162053
I am familiar with MFC rather than OWL. But they are similar and I think you can match them.

It should work fine if you use a window instead of a dialog box.

CTRL+O doesn't work. What about ALT+F+O? If this doesn't work too, try SetFocus to the dialog box.

There is an alternative way. Override the OnKeyDown member function of the dialog box and send the menu command message in the function what you catch CTRL+O.

0
 
LVL 2

Author Comment

by:tovergaard
ID: 1162054
> It should work fine if you use a window instead of a dialog
> box.

Yes it works fine if I use a Window, but it is not a solution
to the problem. I need menus AND hot keys in a Dialog.

There must be a way to activate they, so they are handled automatically.

Okay, I can overwrite the onKey method, but it is not a nice (and probably not the easiest) way to do it.

Hope some of the experts have tried some similar.
0
 
LVL 5

Expert Comment

by:pitonyak
ID: 1162055

It is my understanding (I have not used OWL) that dialogs typically use callback functions rather than processing commands. If you have something like winsite, open the dialog and hit the hotkey that you want and see who gets it.

We had to modify the base dialog class to get this processing in zApp.

Andy

0
 

Accepted Solution

by:
Bauer earned 70 total points
ID: 1162056
The reason for your problems is, that in a modal dialog the message loop
is suspended. Try the following solution, it works very well.

good luck

Frank


class MenuDialog : public TDialog
      {
       public:
       MenuDialog(TWindow* parent,TResId resid);
       bool Create();
       int Execute();
       void Destroy(int retVal);
       ....

       private:
       bool isModal;
       ..OpenFile(...);
       ....

       DECLARE_RESPONSE_TABLE(MenuDialog);

     };

DEFINE_RESPONSE_TABLE1(MenuDialog,TDialog)
EV_COMMAND(CM_OPEN_FILE,OpenFile),
....
END_RESPONSE_TABLE;

MenuDialog::MenuDialog(TWindow* parent,TResId resid):
                     TDialog(parent, resid)
       {
        TWindow::Attr.AccelTable=ID_MENU_XXX;
        ....
       }

... MenuDialog::OpenFile(...)
       {
        ...
       {

// modification for accelerators

bool MenuDialog::Create()
     {
      isModal=false;
      return TDialog::Create();
     }

int MenuDialog::Execute()
     {
      isModal=true;
      if(TDialog::Create()==true)
         return GetApplication()->BeginModal(this, MB_TASKMODAL);
      else
         return -1;
     }

void MenuDialog::Destroy(int retVal)
     {
      if(isModal==true)
      GetApplication()->EndModal(IDCANCEL);
      TDialog::Destroy(retVal);
     }
// End modification


0
 
LVL 2

Author Comment

by:tovergaard
ID: 1162057
I have not tried the code yet, but it looks good. Thank for your help.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

808 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