[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Dropdown combobox return problem II

Posted on 1999-01-27
11
Medium Priority
?
442 Views
Last Modified: 2013-12-26
I have a dialog box that closes when the return key is pressed while the cursor is in the combobox.  The code below works for a combobox dropdown list, but not for a dropdown combobox.  The editbox portion of the dropdown combobox doesn't execute the EV_WM_KEYDOWN like the dropdown list.  Does anyone know why?  What else do I need to add to make the dropdown combobox work?

class TMy1ComboBox : public TComboBox
{
  public:
    TMy1ComboBox(TWindow* parent, uint ResourceId , uint textLen = 0, TModule* module = 0);
    uint EvGetDlgCode(MSG far*);
    void EvKeyDown(UINT key, UINT, UINT);
  protected:
    friend class TQuickTimingGui;
    TQuickTimingGui *owner;

DECLARE_RESPONSE_TABLE(TMy1ComboBox);
};

DEFINE_RESPONSE_TABLE1 (TMy1ComboBox, TComboBox)
   EV_WM_KEYDOWN,
         EV_WM_GETDLGCODE,
END_RESPONSE_TABLE;

TMy1ComboBox::TMy1ComboBox (TWindow *parent, uint resourceID, uint textLen, TModule *module)
            : TComboBox (parent, resourceID, textLen, module)
{
      owner = dynamic_cast<TQuickTimingGui *>(parent);
}

uint TMy1ComboBox::EvGetDlgCode(MSG far*)
{
  UINT retVal = (UINT)DefaultProcessing();
  retVal |= (DLGC_WANTMESSAGE | DLGC_WANTTAB | DLGC_WANTALLKEYS);
  return retVal;
}

void TMy1ComboBox::EvKeyDown (UINT key, UINT count, UINT flags)
{
   if (key==VK_RETURN) {
     owner-> Test();
   }
}

0
Comment
Question by:atsac
11 Comments
 

Expert Comment

by:gmarston
ID: 1299869
This might be a simple answer to the problem.  I have found that if you do not have a designated default button in your dialog (resouce file), then ENTER from most controls will close the dialog.
0
 

Author Comment

by:atsac
ID: 1299870
I tried it but it still closes the dialog box.  I have 3 dropdown boxes and a OK, CANCEL, and HELP button, plus some other stuff in my dialog box.  Any other suggestions? I tried making the OK button default, but it didn't work.
0
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1299871
You need to subclass the edit control in the combobox and catch the WM_KEYDOWN message for a return code. You also need to respond to the WM_GETDLGCODE for the edit control in the combobox. To get the HWND for the edit control, use GetChild(). The combobox has only one child.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:atsac
ID: 1299872
Could you please provide some sample code.  I'm not sure how to subclass the edit control of the combobox.  I'm still a beginner in this OWL stuff.  Thanks.
0
 

Author Comment

by:atsac
ID: 1299873
I need some code and a little more explaining.  I am not that familiar with windows programming. thanks
0
 

Author Comment

by:atsac
ID: 1299874
Adjusted points to 400
0
 

Expert Comment

by:kralubo
ID: 1299875
Overwtite CmOK event.
0
 

Author Comment

by:atsac
ID: 1299876
What do I put in the CmOK() function?  I need some code please.  How do I capture the different events from different comboboxes and when someone hits the OK button?
0
 
LVL 14

Accepted Solution

by:
AlexVirochovsky earned 1600 total points
ID: 1299877
I don't understand, too, whay you code don't works(may be
some problem in BorlandC 5.0?)
But i send you common way, that i use for trap ENTER message.
Main idea: we must to know, in what contol we are, and by that
make some action with ENTER.
 Details : Dialog with 2 Edit and 1 ComboBox
H file:
#define IDC_EDIT1            100
#define IDC_EDIT2            101
#define IDC_PUSHBUTTON1            102
#define IDC_PUSHBUTTON1            103
#define IDC_OK                    200
....

in RC:
ID_DIALOGMONEY DIALOG 74, 145, 213, 66
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CLASS "bordlg"
CAPTION "caption"
FONT 8, "MS Sans Serif"
{
 LTEXT ":text1", -1, 114, 6, 23, 8
 EDITTEXT IDC_EDIT1, 75, 3, 35, 12
 LTEXT ":text2", -1, 185, 23, 20, 8
 COMBOBOX IDC_COMBOBOX1, 93, 21, 86, 43, CBS_DROPDOWN | WS_TABSTOP
 LTEXT ":text3", -1, 47, 22, 23, 8
 EDITTEXT IDC_EDIT2, 7, 20, 36, 12
 CTEXT ":ctext", IDC_TEXT01, 63, 43, 100, 8
 PUSHBUTTON "OK", IDC_OK, 165, 11, 35, 14
 PUSHBUTTON "Cancel", IDCANCEL, 165, 39, 35, 14
}
C++ file:
//
// DialogBox Class about Money
//
class TDialogMoney: public TDialog {
public:
  TDialogMoney(TWindow* parent, char *szKrtisI,long iNumRecI);
  void SetupWindow(void);
protected:
  void EvSetFocusComboBox1(void){uID = IDC_COMBOBOX1;}
  void EvSetFocusEdit1(void) {uID = IDC_EDIT1;}
  void EvSetFocusEdit2(void) {uID = IDC_EDIT2;}
  void EvSetFocusButton1(void) {uID = IDC_OK;}
  void EvSetFocusButton2(void) {uID = IDCANCEL;}

  void CmEnter(void);
  void CmOk(void);
  TComboBox *tCombo;
  TEdit *tEditSumm;
  TEdit *tEditDate;
  TStatic *tDateRishum;
  TButton *tButton[2];
.....
  UINT uID;
DECLARE_RESPONSE_TABLE(TDialogMoney);
};
// define Main Table Event Handler of Appication class
DEFINE_RESPONSE_TABLE1(TDialogMoney, TDialog)

   EV_CBN_SETFOCUS(IDC_COMBOBOX1, EvSetFocusComboBox1),
   EV_EN_SETFOCUS(IDC_EDIT1,      EvSetFocusEdit1),
   EV_EN_SETFOCUS(IDC_EDIT2,      EvSetFocusEdit2),
   EV_COMMAND(IDOK, CmEnter),
   EV_COMMAND(IDC_OK, CmOk),
   EV_BN_HILITE(IDC_OK, EvSetFocusButton1),
   EV_BN_HILITE(IDCANCEL, EvSetFocusButton2),
.....
END_RESPONSE_TABLE;
//constructor:
TDialogMoney::TDialogMoney(TWindow* parent,......)
  : TDialog(parent, ID_DIALOGMONEY),
    TWindow(parent)
{
  tCombo = new TComboBox(this, IDC_COMBOBOX1,30);
  tEditSumm   = new TEdit(this, IDC_EDIT1,12);
  tEditDate   = new TEdit(this, IDC_EDIT2,11);
  tDateRishum = new TStatic(this, IDC_TEXT01,23);
  tButton[0] = new TButton(this, IDC_OK);
  tButton[1] = new TButton(this, IDCANCEL);
.....
}
void TDialogMoney::SetupWindow()
{
  TDialog::SetupWindow();
//  tCombo->SendMessage(WM_SETFONT, (WPARAM)hfFont);//set Fixed Font
  tEditDate->Insert("  /  /    ");

  char buff[40];
  for (int i = 0; i < 40;; i++)
    {
.....
      tCombo->AddString(buff);
    }
  uID = IDC_EDIT1;  //1-st EDIT1!
.....
}
void TDialogMoney::CmEnter(void)
{
  int iTest = 0;
  char sz[81];
  switch (uID)
    {
      case IDC_EDIT1:
         tEditSumm->GetLine(sz,12,0);
         if (atof(sz) == 0)
           iTest = 1;
         break;
      case IDC_EDIT2:
         tEditDate->GetLine(sz,11,0);
         IsValidDate(sz, iTest, 0);
         break;
    }
  if (iTest)                  //error!
    {
      MessageBeep(-1);
      ::SetFocus(GetDlgItem(uID));
    }
  else  
   switch (uID)
    {
      case IDC_EDIT1:
         uID = IDC_COMBOBOX1; tCombo->SetFocus();
         break;
      case IDC_COMBOBOX1:
         uID = IDC_EDIT2; tEditDate->SetFocus();
         break;
      case IDC_EDIT2:
         uID = IDC_OK; tButton[0]->SetFocus();
         break;
      case IDC_OK:
         CmOk();
         break;
      case IDCANCEL:
         CmCancel();
         break;
    }
}
void TDialogMoney::CmOk(void)
{                  //save (if no errors)
  char sz[81],szOld[81];
  tEditSumm->GetLine(sz,12,0);
  tCombo->GetText(sz,40);
  CloseWindow(IDOK);
}
void TDialogMoney::CmOk(void)
{
  CloseWindow(IDCANCEL);
 
}
void TTestUser::CmDialogMoney(void)
{
  TDialogMoney* dp = new TDialogMoney(this,...);
  if (dp->Execute() == IDOK)            //change data
    {
  ......
    }
}




Class definition
class TTable: public TDialog {
....

protected:
  UINT uID;                  //ID of Control
...
DEFINE_RESPONSE_TABLE1(TStopCass, TDialog)
   EV_COMMAND(IDOK, CmEnter),
   EV_COMMAND(IDC_OK, CmOk),
   EV_CBN_SETFOCUS(IDC_COMBOBOX1, EvSetFocusComboBox1),
   EV_CBN_SETFOCUS(IDC_COMBOBOX2, EvSetFocusComboBox2),
   EV_CBN_SETFOCUS(IDC_COMBOBOX3, EvSetFocusComboBox3),
   EV_CBN_SETFOCUS(IDC_COMBOBOX4, EvSetFocusComboBox4),
   EV_CBN_SETFOCUS(IDC_COMBOBOX5, EvSetFocusComboBox5),

   EV_CBN_SELCHANGE(IDC_COMBOBOX1,EvSelChangeComboBox1),
   EV_CBN_SELCHANGE(IDC_COMBOBOX2,EvSelChangeComboBox2),
   EV_CBN_SELCHANGE(IDC_COMBOBOX3,EvSelChangeComboBox3),
   EV_CBN_SELCHANGE(IDC_COMBOBOX4,EvSelChangeComboBox4),
   EV_CBN_SELCHANGE(IDC_COMBOBOX5,EvSelChangeComboBox5),

   EV_CBN_KILLFOCUS(IDC_COMBOBOX1, EvKillFocus),
   EV_CBN_KILLFOCUS(IDC_COMBOBOX2, EvKillFocus),
   EV_CBN_KILLFOCUS(IDC_COMBOBOX3, EvKillFocus),
   EV_CBN_KILLFOCUS(IDC_COMBOBOX4, EvKillFocus),
   EV_CBN_KILLFOCUS(IDC_COMBOBOX5, EvKillFocus),

0
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 1299878
O atsas, sorry, text begins with TTable i include by mistake.
Reply: all texts before that!
Best Regards, Alex
0
 

Author Comment

by:atsac
ID: 1299879
The code works, thanks for your help.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

831 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