Solved

Dropdown combobox return problem II

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

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
create wsdl for check policy price 32 32
HTML Video won't Autoplay on site 6 25
Read XML Response From ASP Classic 9 66
Animated .jpg? 13 59
Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
It's sometimes a bit tricky to use date functions in Oracle BPEL. I'll explain quickly how you can add N days to the current date. In a BPEL process this can be useful, and you can adapt it to fit your needs. First of all, let's see how to add 1 …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now