Solved

Dropdown combobox return problem II

Posted on 1999-01-27
11
397 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I need some code and a little more explaining.  I am not that familiar with windows programming. thanks
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:atsac
Comment Utility
Adjusted points to 400
0
 

Expert Comment

by:kralubo
Comment Utility
Overwtite CmOK event.
0
 

Author Comment

by:atsac
Comment Utility
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
Comment Utility
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
Comment Utility
O atsas, sorry, text begins with TTable i include by mistake.
Reply: all texts before that!
Best Regards, Alex
0
 

Author Comment

by:atsac
Comment Utility
The code works, thanks for your help.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
XSLT 5 36
wordpress limitations 4 91
use of cookies and regulations 1 50
Stupid git question 2 17
There are two main kinds of selectors in CSS: One is base selector like h1, h2, body, table or any existing HTML tags.  For instance, the following rule sets all paragraphs (<p> elements) to red: (CODE) CSS also allows us to define our own custom …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

763 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

7 Experts available now in Live!

Get 1:1 Help Now