Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 424
  • Last Modified:

Create a dialog

Hi,

I want to create a modal dialog with a combobox on it.  I do not want to use a class wizard, just code a small window as described.  A simple example of doing this sort of thing would be great.

Thanks.
0
jasoncpp
Asked:
jasoncpp
  • 7
  • 4
1 Solution
 
akalmaniCommented:
Here is a step by step have a look at it
http://www.codeproject.com/dialog/dialogapptute.asp
0
 
akalmaniCommented:
If you intend not to use class wizard. Then may be you can follow these steps.

1) Insert a dialog via the resource editor. Give IDD_MYDIALOG as its resource ID by right clicking and then go to properties.
2) Place combo box control over that dialog which is created and name IDC_MYCOMBO as its resource ID

3) Create a new class which is derived from CDialog name it CMyDialog
sample code here
//MyDialog.h
class CMyDialog: public CDialog
{
public:
CMyDialog(CWnd* pParent = NULL);      // standard constructor
enum { IDD = IDD_MYDIALOG };
virtual void DoDataExchange(CDataExchange* pDX);      // DDX/DDV support
virtual BOOL OnInitDialog();
}

4)//MyDialog.cpp

#include <MyDialog.h>
CMyDialog::CMyDialog(CWnd* pParent /*=NULL*/)
      : CDialog(CMyDialog::IDD, pParent)
{
}

void CMyDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CMyDialog, CDialog)
END_MESSAGE_MAP()

BOOL CMyDialog::OnInitDialog()
{
CDialog::OnInitDialog();

CComboBox *pCombo = (CComboBox *)GetDlgItem(IDC_MYCOMBO);
//Change or add combo box details here
return TRUE;
}

These are the mimimum steps which are mentioned.
0
 
waysideCommented:
Do you want your dialog to use the MFC framework? I assume so since you psoted this in the MFC TA...

If so, even for a simple dialog with one control on it, there's no reason not to use ClassWizard to hook up the plumbing. You can do it by hand, but you'll have to do exactly the same thing the class wizard does anyway.

- create a resource for the dialog
- create a class inheriting from CDialog
- add event handler functions to the class definition
- override DoDataExchange if you want to hook up values or control variables to the dialog controls
- Use the DECLARE_MESSAGEMAP/ BEGIN_MESSAGE_MAP/ END_MESSAGE_MAP macros to set up the message map
- Add messages to the message map
- Implement the message handlers in your class

I probably left a few things out.

The easiest way to learn how to do this would be to create a simple dialog using ClassWizard and examine the code it produces in detail, and then try to do it yourself by hand.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
akalmaniCommented:
Usage wherever you need, include the header file MyDialog.h

CMyDialog dlg;
dlg.DoModal();
0
 
jasoncppAuthor Commented:
akalmani:

1) Insert a dialog via the resource editor. Give IDD_MYDIALOG as its resource ID by right clicking and then go to properties.
2) Place combo box control over that dialog which is created and name IDC_MYCOMBO as its resource ID

Sorry, but this bit is confusing me.  Taking my lead from a book I created a resource file before with resource definitions in it such as for the menu:

General MENU {
POPUP "File" {
  MENUITEM "New...", IDM_NEW
  MENUITEM "Exit", IDM_EXIT
}
//... and so on

How would I define a combo box, dialog in here?
0
 
akalmaniCommented:
Are u using visual studio ? Which version of it ?
Are you working on windows ?
0
 
jasoncppAuthor Commented:
windows xp, using visual c++ 6.0 sp5.
0
 
akalmaniCommented:
what type of application you want to have ? Dialog based ? Single document where in you want to display a dialog or Multiple document where in you want to display a dialog ?

0
 
jasoncppAuthor Commented:
It is a single document frame.  I want to display a dialog on a certain condition.
0
 
akalmaniCommented:
Just insert these lines into your .rc file. Make sure you define IDD_MYDIALOG and IDC_MYCOMBO in resource.h file with appropriate ID's.

IDD_MYDIALOG DIALOGEX 0, 0, 268, 111  
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Test Dialog with combo box"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
    DEFPUSHBUTTON   "OK",IDOK,211,7,50,14
    PUSHBUTTON      "Cancel",IDCANCEL,211,24,50,14
    COMBOBOX        IDC_MYCOMBO,63,37,103,12,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP
END
0
 
akalmaniCommented:
Slight correction forgot to increase the data height in the combo box. See IDC_MYCOMBO 63,37,103,48 The co-ordinates are changed.

IDD_MYDIALOG DIALOGEX 0, 0, 268, 111  
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Test Dialog with combo box"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
    DEFPUSHBUTTON   "OK",IDOK,211,7,50,14
    PUSHBUTTON      "Cancel",IDCANCEL,211,24,50,14
    COMBOBOX        IDC_MYCOMBO,63,37,103,48,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP
END

But i do not understand why do you want to all this manually. You can always do as wayside said.
0
 
jasoncppAuthor Commented:
Thanks for your help.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 7
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now