Solved

Borland OWL, hotkeys in a Dialog menu

Posted on 1997-03-14
11
584 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 2

Author Comment

by:tovergaard
Comment Utility
Adjusted points to 75
0
 
LVL 23

Expert Comment

by:chensu
Comment Utility
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
Comment Utility
> 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
Comment Utility

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
Comment Utility
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
Comment Utility
I have not tried the code yet, but it looks good. Thank for your help.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

763 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

10 Experts available now in Live!

Get 1:1 Help Now