Solved

Dropdown combobox return problem II

Posted on 1999-01-27
11
412 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
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.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying 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

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

809 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