Solved

Borland OWL, hotkeys in a Dialog menu

Posted on 1997-03-14
11
586 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

911 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now