Dropdown combobox return problem II

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();
   }
}

atsacAsked:
Who is Participating?
 
AlexVirochovskyConnect With a Mentor Commented:
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
 
gmarstonCommented:
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
 
atsacAuthor Commented:
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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
Tommy HuiEngineerCommented:
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
 
atsacAuthor Commented:
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
 
atsacAuthor Commented:
I need some code and a little more explaining.  I am not that familiar with windows programming. thanks
0
 
atsacAuthor Commented:
Adjusted points to 400
0
 
kraluboCommented:
Overwtite CmOK event.
0
 
atsacAuthor Commented:
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
 
AlexVirochovskyCommented:
O atsas, sorry, text begins with TTable i include by mistake.
Reply: all texts before that!
Best Regards, Alex
0
 
atsacAuthor Commented:
The code works, thanks for your help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.