Solved

Create a dialog

Posted on 2004-04-27
12
413 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Host to IP 7 78
List out all word 7 292
Prevent this page from creating additional dialogs. 3 532
maven archtype selection in eclipse 1 57
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

778 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