Solved

Create a dialog

Posted on 2004-04-27
12
415 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
  • 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.NET how to use the Vertical ScrollBar 5 114
Separate into files by filename 12 87
fix34  challenge 9 140
Problem to open Excel file 15 174
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

839 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