?
Solved

Borland OWL, hotkeys in a Dialog menu

Posted on 1997-03-14
11
Medium Priority
?
595 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.
Suggested Courses

649 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