Solved

Create a dialog

Posted on 2004-04-27
12
418 Views
Last Modified: 2013-11-20
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
Comment
Question by:jasoncpp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
12 Comments
 
LVL 3

Expert Comment

by:akalmani
ID: 10928133
Here is a step by step have a look at it
http://www.codeproject.com/dialog/dialogapptute.asp
0
 
LVL 3

Accepted Solution

by:
akalmani earned 500 total points
ID: 10928209
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
 
LVL 14

Expert Comment

by:wayside
ID: 10928215
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
Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

 
LVL 3

Expert Comment

by:akalmani
ID: 10928223
Usage wherever you need, include the header file MyDialog.h

CMyDialog dlg;
dlg.DoModal();
0
 

Author Comment

by:jasoncpp
ID: 10928350
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
 
LVL 3

Expert Comment

by:akalmani
ID: 10928412
Are u using visual studio ? Which version of it ?
Are you working on windows ?
0
 

Author Comment

by:jasoncpp
ID: 10928435
windows xp, using visual c++ 6.0 sp5.
0
 
LVL 3

Expert Comment

by:akalmani
ID: 10928473
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
 

Author Comment

by:jasoncpp
ID: 10928529
It is a single document frame.  I want to display a dialog on a certain condition.
0
 
LVL 3

Expert Comment

by:akalmani
ID: 10928540
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
 
LVL 3

Expert Comment

by:akalmani
ID: 10928605
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
 

Author Comment

by:jasoncpp
ID: 10928614
Thanks for your help.
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

623 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