Solved

Create a dialog

Posted on 2004-04-27
12
410 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
 
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
repeatEnd java challenge 42 83
Looking for a specific application/software 2 91
Doc'in system (example?) BA 7 78
sumHeights  challenge 17 61
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seveā€¦
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.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

705 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

18 Experts available now in Live!

Get 1:1 Help Now