?
Solved

Borland OWL, hotkeys in a Dialog menu

Posted on 1997-03-14
11
Medium Priority
?
593 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
[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
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 140 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses
Course of the Month13 days, 12 hours left to enroll

800 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