Click here to Skip to main content
Click here to Skip to main content

Beginners Guide to Dialog Based Applications - Part Two

By , 29 Jun 2000
 

Introduction

Dialog boxes are one of the primary methods that Windows programs use to display information and receive input from users. Therefore, in this tutorial, we are going to use a dialog based application to collect some information from the user. In the real life project, you will use this information somewhere else in the program or it will be stored in a database. But for this tutorial, we are only going to display information in a Message Box.

In this project, the user has to give his/her name and choose their favorite operating system and programming language. The user selects some of their favorite programming technologies and then submits the information by clicking on the Submit Button.

The information will be displayed in a Message Box, see below:

Creating a new Project and designing the dialog

Create a new dialog based application project called Dialog2, accepting the default settings in each step as we did in the last tutorial.

Delete the Cancel button and the text (TODO: Place dialog controls here), and change the Caption of the OK button to Close.

Drop a Button, Combo Box, two Edit Box controls, two List Box controls, six Static text controls and two Group Box into the dialog box, and arrange the controls as shown below.

Drop four Radio Buttons inside the first Group Box. Make sure to drop the Radio Button in sequence, one after another, and don't drop any other controls in between.

Drop three Check Boxes inside the second Group Box as shown below:

Customize the properties of controls

Change the Caption for each control as shown below. Check the Beginners Guide to Dialog Base Applications - Part One (previous tutorial) for full details on changing the ID and Caption for each control.

In the case of new controls Group Boxes, Radio Buttons and Check Boxes, the process of changing the captions and ID is similar to other controls (right click the mouse on the control and select Properties from the context menu).

Change the ID in Edit Properties for first Edit Box control to IDC_FIRSTNAME and the second Edit Box control to IDC_LASTNAME.

Change the ID in Combo Box Properties to IDC_TITLE. Click on Data in Combo Box Properties and populate the Data as shown below:

On Styles tab, change the Combo Box's Type to Drop List to stop the user from adding new titles. Position your mouse over the Combo Box button, then click. Another rectangle will appear. Use this rectangle to specify the size of the open Combo Box's List.

For the List Box on the left of the dialog box, change the ID to IDC_PROG_TECH and for the List Box on the right, change the ID to IDC_YOUR_FAVOURITE_TECH.

Check the Tab Stop option in Properties of the group box with Radio Buttons (Specifies that the user can move to this control with the TAB key)

Change the first Radio Button with caption Windows 95/98 Properties ID to IDC_WIN98 and check Group option (Specifies the first control of the group).

Make sure to check the Group option in the properties of the first control you drop into the dialog, after the last radio button. This implicitly marks the previous control (the last radio button) as the final one in the group.

Change the ID for the Windows NT/2000 Radio Button to IDC_WINNT. Change Unix ID to IDC_UNIX and Linux to IDC_LINUX.

For the second Group Box, change the ID for the Check Box with Caption Java to IDC_JAVA. Change the ID of Visual Basic Check Box to IDC_VISUAL_BASIC and change the ID of Visual CPP Check Box to IDC_VISUAL_CPP.

Change the ID for the Submit button to IDC_SUBMIT and the ID of the button with the Caption >> to IDC_SELECT and the ID of << button to IDC_DESELECT.

Assigning Member variables to Controls

Press Ctrl + W to start ClassWizard, or from the View menu, select ClassWizard. Select the Member Variables tab. Select the dialog class in the Class name: combo box; select CDialog2Dlg.

Assign m_strFirstName of type CString to IDC_FIRSTNAME, m_strLastName of type CString to IDC_LASTNAME, m_nTitle of type int to IDC_TITLE.

Assign m_bJava of type BOOL IDC_JAVA, m_bVisualBasic of type BOOL to IDC_VISUAL_BASIC, m_bVisualCpp of type BOOL to IDC_VISUAL_CPP.

Assign m_Win98 of type int to IDC_WIN98.

You will note that we only assign a variable to the first Radio Button. That is because Radio Buttons work in groups. Therefore, we can access the rest of the Radio Buttons through the first one. Each Radio Button represents one in a list of mutually exclusive options. When clicked, a Radio Button checks itself and un-checks the other Radio Button in the group. That is, of course, assuming that the Auto option has been checked in the Style tab in the properties of the Radio Button. The Auto option is checked by default.

Assign m_YourFavouriteTech of type CListBox to IDC_YOUR_FAVOURITE_TECH and m_ProgTech of type CListBox to IDC_PROG_TEACH.

In Class View tab, right click CDialog2Dlg class and select Add Member Variable. An Add Member Variable dialog box will appear. Add three member variables of type CString: m_strFullInfo, m_strOpertingSystem, m_strProgLanguage. Make sure to choose the Protected Access option.

Initializing Variables

Now that the variables are added, they must each be initialized. The ClassWizard has created code in the program that initializes the variables in the class constructor.

But in the case of m_nWin98 and m_nTitle, these values are initialized to -1, which means that if the program is built and run at this point, none of the radio buttons will be selected and the Title Combo Box will show an empty selection when the dialog box is first displayed.

Therefore, we need to change the values to 0 to select the first Radio Button and the first title. To do this, we need to edit the initialization code created by the ClassWizard in CDialog2Dlg class constructor. Double-click on the class constructor, the constructor function is displayed as shown below. Comment out m_nTitle and m_nWin98 which is generated by the ClassWizard and assign new values to the variables at the end of the constructor as shown below:

CDialog2Dlg::CDialog2Dlg(CWnd* pParent /*=NULL*/)
    : CDialog(CDialog2Dlg::IDD, pParent)
{
    //{{AFX_DATA_INIT(CDialog2Dlg)
    m_strFirstName = _T("");
    m_strLastName = _T("");
    m_bJava = FALSE;
    //m_nTitle = -1;
    m_bVisualBasic = FALSE;
    m_bVisualCpp = FALSE;
    //m_nWin98 = -1;
    //}}AFX_DATA_INIT
    // Note that LoadIcon does not require a subsequent 
    // DestroyIcon in Win32
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
    
    m_nWin98 = 0;
    m_nTitle = 0;
    
}

Adding Member Functions

Right click CDialog2Dlg class and add member function for the Function Type.

Enter void and for the Function Declaration, type PopulateProgTech(). Make sure to choose Public option in Access as shown below.

We are going to use this function to populate the Programming Technologies List Box.

Type the code below:

void CDialog2Dlg::PopulateProgTech()
{
//Populate Programming Technologies List Box
    m_Prog_Tech.AddString("MFC");
    m_Prog_Tech.AddString("COM/DCOM");
    m_Prog_Tech.AddString("ADO");
    m_Prog_Tech.AddString("OLE DB");
    m_Prog_Tech.AddString("ASP");
    m_Prog_Tech.AddString("ATL");
}

Remember we used AddString() which is CListBox member function to add new text to List Box in the last tutorial.

Double click on the OnInitDialog() function in CDialog2Dlg class and call PopulateProgTech() member function just above the return statement as shown below.

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

    // Add "About..." menu item to system menu.

    // IDM_ABOUTBOX must be in the system command range.
    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
    ASSERT(IDM_ABOUTBOX < 0xF000);

    CMenu* pSysMenu = GetSystemMenu(FALSE);
    if (pSysMenu != NULL)
    {
        CString strAboutMenu;
        strAboutMenu.LoadString(IDS_ABOUTBOX);
        if (!strAboutMenu.IsEmpty())
        {
            pSysMenu->AppendMenu(MF_SEPARATOR);
            pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
        }
    }

    // Set the icon for this dialog.  The framework does this automatically
    //  when the application's main window is not a dialog
    SetIcon(m_hIcon, TRUE);            // Set big icon
    SetIcon(m_hIcon, FALSE);        // Set small icon
    
    // TODO: Add extra initialization here

    //Populate Programming Technologies List Box
    PopulateProgTech();  
    
    return TRUE;  // return TRUE  unless you set the focus to a control
}

Open ClassWizard, select Message Maps tab.

In Class name, select CDialog2Dlg, on Object IDs. Select IDC_SELECT, then choose BN_CLICKED from the Messages list, click on Add Function. Click OK, then click Edit Code. Add the code below to OnSelect() function.

void CDialog2Dlg::OnSelect() 
{
    // TODO: Add your control notification handler code here

    //Get the index of the selected item
    int nSelectted=m_ProgTech.GetCurSel();
        
    if (nSelectted != LB_ERR)       //Check for Selection
    {
        CString Sel;

        //Get the Selectted Text
        m_ProgTech.GetText(nSelectted,Sel);      

        //Add string to list to Favourite Technology
        m_YourFavouriteTech.AddString(Sel);      

        //Delete the Selectted item from the list of Techologies
        m_ProgTech.DeleteString(nSelectted); 
    }

}

Assuming you selected an item from the Technologies List Box, clicking on the >> Button will transfer the selected item to the Your Favorite Technologies List Box. OnSelect() function checks for selection first. Copy the text of the selected item into local variable Sel. Add this text to Your Favorite Technologies List Box and then delete the selected item from Technologies List Box.

Double click on >> Button. As soon as you do this, the Add Member Function dialog box will open as shown below.

Accept the default name OnDeselect() and type the code below.

void CDialog2Dlg::OnDeselect()
{
    // TODO: Add your control notification handler code here
    
    //Get the index of the selected item
    int nSelectted=m_YourFavouriteTech.GetCurSel(); 
    
    if (nSelectted != LB_ERR) //Check for Selection
    {
    CString Sel;
    
    //Get the Selectted Text    
    m_YourFavouriteTech.GetText(nSelectted,Sel);   

    //Add the deselectted technology to list to back Technology
    m_ProgTech.AddString(Sel);        
        
    //Delete the Selectted item from the list of Favourite Techologies
    m_YourFavouriteTech.DeleteString(nSelectted);  
    }

}

The function above transfers the selected item from Your Favorite Technologies List Box back to Technologies List Box (Deselected the item).

Double click on the Submit Button. Accept the default name OnSubmit() for new function and add the code below.

void CDialog2Dlg::OnSubmit() 
{
    // TODO: Add your control notification handler code here
    CString strTitle;
    int nReturnValue;
    
    m_strProgLanguage="Programming Languages your prefer \n" ;

    UpdateData(); //Transfer data from controls to variables
    
    //Get the text of the selected radio button
    GetDlgItem(IDC_WIN98+m_nWin98)->GetWindowText(m_strOpertingSystem);
    
    //Get the text of the checked Check Boxes
    
    if(m_bJava)
        m_strProgLanguage+="Java\n "  ;
    
    if(m_bVisualBasic)
        m_strProgLanguage+="Visual Basic\n "  ;
    
    if(m_bVisualCpp)
        m_strProgLanguage+="C++/Visual C++\n "  ;
    
    //get currently selected text of the Combo Box
    
    nReturnValue=GetDlgItemText(IDC_TITLE, strTitle);
    
    m_strFullInfo = "You are "+strTitle + " "+m_strFirstName + 
                    " "+ m_strLastName;
    
    UpdateData(FALSE);  //Transfer data from variables to controls
    
    CString Sel;
    m_strSelectedTech="";

    //Get number of items in the list box
    int nCount = m_YourFavouriteTech.GetCount();  
    
    if(nCount > 0) //Check for empty list box
    {
        for(int i=0; i<nCount; i++) 
        {

            m_YourFavouriteTech.GetText(i, Sel);
    
            m_strSelectedTech+=Sel + "\n";
        }
    }

    m_strFullInfo=m_strFullInfo+"\n"+ m_strProgLanguage +"\n" 
        + "favourite technology\n "+m_strSelectedTech+
        "\nand your favourite operating System is \n"
        +m_strOpertingSystem;

    MessageBox(m_strFullInfo);   //Show the information in Message Box
    
    
}

OnSubmit() collects all user information and puts them into Message Box.

Build and run your program

So far you have learned how to:

  • Add, edit and customize Button, Edit Box Control, Combo Box, List Box, Group Box, Check Box, Radio Buttons.
  • Use a ClassWizard to assign member variables to controls.
  • Add member variables.
  • Add member functions.
  • Use item data,
  • Select items.
  • Determine which item has been selected.
  • Get item information.
  • Handle CButton notification.

Multi-Internet Search Engine

Introduction

For this part of the tutorial, we are going to build a simple but very useful program: a Multi-Internet Search Engine. Realistically, it is only a program which enables the user to access a number of Internet search engines like Altavista, Yahoo, ... without the hassle of remembering the address of each search engine. All the user has to do is select a search engine and type what s/he is trying to find out about, then click Search Button. Below, the user tries to use Altavista to find some information about Physics.

Creating a new Project, designing and customizing the dialog

Start by creating a new Dialog based application called Search_me as we did before.

Delete the Cancel button and the text (TODO: Place dialog controls here). Resize your dialog box to about 300 x 70, change the caption of OK button to Close.

Drop Button, Edit Box, Combo Box and two Static text controls into the dialog box. Change the static text Caption to Search Engine and Search for: Change the ID for the Combo Box to IDC_ENGINE.

Click on Data in Combo Box Properties and populate the data as shown below. Remember to press Ctrl + Enter after each entry.

On the Styles tab, change the Combo Box's Type to Drop List to make sure that the user can't add new search engine.

Position your mouse over the Combo Box button, then click. Another rectangle will appear. Use this rectangle to specify the size of the open Combo Box's List.

Change ID for Edit Box to IDC_SEARCHFOR.

Change the Caption for button to Search and the ID to IDC_SEARCH. Use the ClassWizard to assign member variables m_strSearchFor of type CString for Edit Box and m_nEngine of type int for the Combo Box.

Add member variable of type CString named m_strSearch to CSearch_meDlg class.

Press Ctrl + W to start the ClassWizard, select Message Maps tabs. In Class name, select CSearch_meDlg, on Object IDs select IDC_ENGINE, then choose BN_CLICKED from Messages list. Click on Add function, accepting the default name OnSearch(), then click Edit Code. Then type the code below.

void CSearch_meDlg::OnSearch() 
{
    // TODO: Add your control notification handler code here
    CString strEngine;
    int nReturnValue;

    UpdateData();         //Transfer data from controls to variables
    
    m_strSearch = m_strSearchFor;
    //get currently selected text
    nReturnValue=GetDlgItemText(IDC_ENGINE, strEngine); 
    
    UpdateData(FALSE);      //Transfer data from variables to controls
    
    if(nReturnValue>0)      //Check for Search engine selection
    {
        if(strEngine=="Yahoo")
        {
            m_strSearch = "http://search.yahoo.com/search?p=" 
                                + m_strSearch;
            ShellExecute(NULL, "open", m_strSearch, 
                        NULL,NULL,SW_SHOWDEFAULT);
        }

        else if(strEngine=="Altavista")
        {
            m_strSearch = 
                "http://www.altavista.digital.com/cgi-bin/query?" + "
                pg=q&what=web&fmt=.&q=" + m_strSearch;
            ShellExecute(NULL, "open", m_strSearch,
                NULL,NULL,SW_SHOWDEFAULT);
        }

        else if(strEngine=="Excite")
        {
            m_strSearch = "http://www.excite.com/search.gw?trace=a&search="
                                +m_strSearch;
            ShellExecute(NULL, "open", m_strSearch,
                NULL,NULL,SW_SHOWDEFAULT);
        }

        else if(strEngine=="Askjeeves")
        {
            m_strSearch = "http://www.askjeeves.com/AskJeeves.asp?ask="
                                +m_strSearch;
            ShellExecute(NULL, "open", m_strSearch,
                NULL,NULL,SW_SHOWDEFAULT);
        }


    }

}

We used the ShellExecute() function to open the Internet Client Internet Explorer or any other default Internet client program. Check MSDN Library file for more information on ShellExecute().

Edit the constructor of CSearch_meDlg class and change the value of m_nEngine from -1 to 0 as we did previously, to make sure that when the Search_me dialog box is first displayed, Altavista will be selected on Combo Box.

Build and run your program

If you like the idea of this program, you could add more search engines to Search_me program. The best way of adding new search engines is to use Internet Explorer or any Internet Client to access the particular search engine you wish to add to do a simple search. Then copy the address from Explorer's Combo Box which is a query string (information that is passed to the server in the form of a name/value pair) appended to URL with a question mark, '?'. Use the address from the Explorer's Combo Box which you just copied into the program.

For example, if you do a search for Books using excite search engine, the result page will have address of http://search.excite.com/search.gw?search=Physics which is a URL ( http://search.excite.com/search.gw), '?' and query string (search=Books). All you need to do is replace Physics with m_strSearch.

I hope you found this tutorial enjoyable.

Further Reading

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Dr. Asad Altimeemy
Web Developer
United Kingdom United Kingdom
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionCan Search be alteredmemberTodd91124 Mar '08 - 2:09 
In the Search project, can the Search be changed from an internet source to a Access Data base?
If so how?? thanks for any assistance you can provide..
GeneralText on the menu barmemberMember 463255327 Feb '08 - 0:37 
Hi all,
I am working on the remote console management(REMOTE SERVER MANAGEMENT).
In one situation i need to display a message on the MENU BAR( i.e Like text lable) Is it possible to display text on the menu bar. As of now I am using appendmenu() to display that text. But it is not a better way. Could u please help me with this.
 
Puli

GeneralCombo Box weird and does not searchmemberluckiestdice11 Oct '07 - 7:40 
Hello:
 
I'm using VB 7 and I followed your tutorial part 2 to make a search Engine. However, there are two problems: 1. The drop list only displays "Altavista". 2. When the search button is clicked, nothing happens.
 
I'm quite new to programming with MFC and I'm not sure where the problem is Dead | X| .
 
Thanks,
 
Rita
Questionm_strSelectedTech,where is it?memberthankall15 Jul '07 - 22:47 
i've made this study step by step,bu when i was building my pro,an error "m_strSelectedTech was not defined " occured, i've searched in your article for 10m, but still cant find it.Smile | :)
AnswerRe: m_strSelectedTech,where is it?memberPrriya19 Jul '07 - 3:50 
hi,
 
You can declare it in
void CMFCSample3Dlg::OnSubmit() function.
Just replace the code line
m_strSelectedTech="";
with
CString m_strSelectedTech="";
 
regards,
QuestionMember variable arraymemberKritsie10 Jan '07 - 21:30 
I have 8 check boxes on a dialog, and i want to connect variables to them. Is it possible to make those variables an array and how?
AnswerRe: Member variable arraymemberbishbosh0219 May '07 - 21:59 
Yes you can, but dont put them in the
 
//{{AFX_DATA_MAP
//}}AFX_DATA_MAP
 
Do Them Outside IE
 
void CPropertyPageConfig::DoDataExchange(CDataExchange* pDX)
{
CDialogResize::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPropertyPageConfig)
//}}AFX_DATA_MAP
 
DDX_Check(pDX, IDC_VALID_IMP1, m_Valid_Imp[0]);
DDX_Check(pDX, IDC_VALID_IMP2, m_Valid_Imp[1]);
}
 
OKSmile | :)
GeneralGreat articlemembercristitomi7 Dec '06 - 5:44 
Great article you all.
I have three years of experience in MFC programming and yet I learned many useful things from this.
Best wishes.
 
Cristian Tomescu
Questionpublic, private , protected dialog member variables [modified]memberMGmalvern3 Aug '06 - 2:26 
I have just started with MFC programming.
 
I don't understand why most of the dialog variables are public rather than private. Is there something going on behind the scenes that implies this choice?
 
Why are the following variables protected: m_strFullInfo, m_strOpertingSystem, m_strProgLanguage?
 
I would be grateful if someone could help me out on this.
 
Thanks
 
maxg
 

-- modified at 8:27 Thursday 3rd August, 2006
QuestionHow can i change the caption of a static which will be populated from database itemsmemberman_jee12 Jul '06 - 20:28 
I want to make an application for technical test in MFC.In which in one dialog there will be question and for each question there will be four radio buttons.The questions and and answers will be populated from the data base.On next button click of that page another question with four radio buttons will appear on that same page.So how can I change the captions of that question(Static text) and answers(radio buttons)fetching data from a database table containning questions and answers?
 
Man Jee
Generalhi!!!memberAinJheL_mi28 Jun '06 - 0:15 
helow.. im a computer science student.,., can u help me how to understand or to make code in visual basic? because we have a project that we wiLL make our own software to design.,. but i dont have any idea.,., because im only a beginner.,., and i want also to proved to my classmates., that eventhough im a girl Sniff | :^) i can also make a better software.,., thanx a lot.,., i hope that you can gave me a simple design.,.,as soon as possible.. thanx;)
GeneralDoes not executesusspradeep paul10 Jun '05 - 4:32 
My code compiles without errors. Everything seems fine. But when i try to execute nothing happens.No windows, nothing at all. Cud anyone help me with this. I tried commenting out the CDialog::OnInitDialog() and tried executing it to see if it throws out the error. Nothing happens. Seems like the during execution the code just exits. Please advise.
Generaldifferent in Visual Studio 7.1memberfilius31 May '05 - 2:08 
the assignment of member variables to controls seems to be very different in VS 7.1 (visual studio .net 2003).
especially if you look at the radio buttons and the surrounding groupbox.
 
i'd very much appreciate if you could update this article to match the latest studio version Smile | :) .
 
thanks, filius
General7.1: checkboxmemberfilius7 Jun '05 - 2:32 
"7.1 style" checkboxes seem to require int variables - instead of BOOLs?
 
filius
Generalquestion for beginners guide to dialog based applications-part twomemberjinshi23 Jan '05 - 5:01 
y the search engine program just can run for 1 time only , when i wamt to run for second time , it cant work already . the same thing happend to the source code i dl from the page. y is tat happend?
Generaluse button to link a combo box to another dialogmemberjinshi22 Jan '05 - 20:35 
problem face is like this :
 
1. i creat a combo box with data - main
- profile
each of main n profile is another dialog
 
2. when user choose main in the combo box , then click the "go" button beside the combo box , it will show the user the main dialog tat i already created.
 
3. how i going to link the data in the combo box in a dialog to open another dialog.
 
basically the function is like our web browser that we can choose the web site address from the address combo box then click go to go to the web site we choose from the combo box.
 

hope tat anyone who know it can help me in this cos very urgent
GeneralStatic Framesmemberbamamojo12 May '04 - 12:07 
I'm trying to place a grand total of 416 static frames (so that I can use the static LED control given on this site) on a dialog app. I've placed 208 of these frames. It will only allow me to place 2 more of these frames. Help!
 
Confused | :confused:
 
Bamamojo
GeneralCombo BoxsussAnonymous28 Mar '04 - 21:27 
Hi,
I would use a Combo box Control in a modal Dialog Window. After I call the Dialog with:
SMemo.DoModal();
from the Main Window,
the second Dialog appears, but th Combo box haven't the choices visible, even if I press the
scrollbar.
I have put in the init of the Dialog the following:
CB = (CComboBox*)GetDlgItem (IDC_GROUP);
CB->AddString ("P1");
CB->AddString ("P2");
GeneralRe: Combo Boxmemberallmer1 Apr '04 - 10:56 
Hi,
I have the same problem and if anyone knows
the answer I would be glad to know.
GeneralRe: Combo Boxmemberjinshi22 Jan '05 - 20:40 
hi there, are u using the visual basicC++ 6? if yes , maybe u can try to add ur combo value just right click ur combo box then click the data tab ,start type in the value u want each line with only 1 value ,to type another value at the second line u have to press Cltr+Enter to go to next line
 
hope this will help u
GeneralReflecting dialog box values in the object which called itmembermymauve2110 Mar '04 - 0:40 
I am i novice in vc++. I have a button on the right click of which I open a dialog box. When the dialog box closes I want to get the values in the edit box and manipulate my button object accordingly. How do I do it ? Can somebody guide me.

 
mymauve21
Generalvoice conferencingmembersaechi17 Feb '04 - 0:01 
Now i'm doing project in vc++,the title is "voice conferencing" .i need some idea about the project
& also some codings for chatting client to server and viseversa.
Questionhttp://latina.ceroline.info/susshttp://latina.ceroline.info/4 Dec '07 - 1:06 
http://latina.ceroline.info/
http://latina.ceroline.info/
QuestionHow to know that dialog window is openedmemberVladimir S10 Dec '03 - 21:57 
I have a dialog window "A" with a button
which opens a new dialog "B".
If I press on this button while dialog "B" being active I get an error.
what check should I do to see if dialog "B" is opened already.
GeneralNeed help with multiple dialogsmemberHybridLlama24 Oct '03 - 17:47 
i am writing an app that is broken into a main window and 4 sub windows. When you click on a button for the first window it creates the new dialog. My question is what is the easiest way to take the information that is recieved in the sub dialog and store it for use in the main program. Also terminating the subwindow on an button click. I'm new at this any help would be greatly appreciated.
Generalhelp&#161;&#161; my modal dialog not showedsussremius28 Sep '03 - 4:29 
My main class is CmyApp and I want the dialog CmyAppDlg to be showed once the aplication is started. In CmyApp i do:
 

CmyAppDlg dlg;
m_pMainWnd = &dlg;
dlg.DoModal();
 
but the dialog is not showed. The dialog has an ActiveX Control to show cgm pictures.
Please need help
GeneralMember variablesmemberDetectorElec25 Aug '03 - 9:49 
How do I transfer a variable in a thread to a listbox on dialog based program.
 
Bob Anderson
GeneralMultiple modal dialog boxes.memberDeepak Samuel21 Jul '03 - 5:05 
Hi,
I need to create about three to four modal dialog boxes such that when a button is pressed in the first one it leads to the next and again when a button is pressed in this it leads to the next one and so on..I am a novice in this field and I need some help in this. I tried this:
 
void CNewoneDlg::OnOK()
{
CDialog aboutDlg(IDD_DIALOG1);
 
INT_PTR pRet=-1;
 
aboutDlg.DoModal();

//CDialog::OnOK(); (I tried taking this off...but didnt work either)
}
 
This works..it leads to the next dialog box on pressing ok..
but..
 
void CDialog1Dlg::OnOK()
{
CDialog aboutDlg(IDD_DIALOG2);
 
INT_PTR pRet=-1;
 
aboutDlg.DoModal();

//CDialog::OnOK();
 


}
This doesnt lead to the next dialog box on pressing ok..I am confused, since I have used the method in the earlier function..when that can work, why cant (isnt) this?
 
I desperately need a help..
 
THANKS

 
Deepak Samuel
GeneralRe: Multiple modal dialog boxes.memberCambalindo25 Aug '03 - 10:50 
You can try this:
call every Dialog box from your main window:
suppose this is a message handler or menu hadler:
 
OnFirstDialogOpen()
{
 CDialog1 dialog1;
 CDialog2 dialog2;
 CDialogn dialogn;
 if(dialog1.DoModal()==IDOK)
 {
  //open de the next dialog
  if(dialog2.DoModal()==IDOK)
  {
   //open dialogn
   if(dialogn.DoModal()==IDOK)
   {
    //and so on
    do something
   }
  }
 }
}

 
Daniel Cespedes
 
"There are 10 types of people, those who understand binary and those who do not"
"Santa Cruz de la Sierra Paraiso Terrenal!"
 
daniel.cespedes@ieee.org
GeneralAdding to a CListbox before showmemberJamie Kenyon21 May '03 - 1:50 
Hi,
 
I'm trying to add items to a Clistbox before I show the window. It's in a dialog resource in MFC. I can add to the window once it's visible but I can't fill it before?
 
Any ideas?
GeneralRe: Adding to a CListbox before showsussAnonymous20 Jul '05 - 3:25 
Please Come to My bed I will Show u how to ADD IT
GeneralMonitoring variables in dialog boxmemberalrobin30 Apr '03 - 11:04 
I am a Visual C++ beginner. I have figured out how to bring up modal dialog window from a main-form menu, and add "text" and "edit boxes" and functions, etc., to the dialog windows and files.
 
However, I would like to use a dialog window to view values of string variables used throughout the rest of the project (particularly as controlled in the "View.cpp" file.
 
However, when I debug the program, these string variables are 'empty' when I try to use them to update edit boxes in the "Dialog.cpp" file.
 
I have classified them as "Public", defined them as "CString", but nothing I do seems to make them accessible in "Dialog.cpp".
 
What am I missing? Any tips would be greatly appreciated.
 
Ciao,
Al
GeneralRe: Monitoring variables in dialog boxmemberdigitalmythology10 Dec '06 - 16:45 
// These lines of code are all you need
UpdateData(TRUE);
GetDlgItemText(IDC_EDIT_ITEMNAME, m_newitemname);
 
// In the above, UpdateData is set to 
// TRUE, which gathers the current info from ALL of your 
// controls. It really isn't needed for this to function, 
// it is just a way for you to make sure that the DATA is 
// both current and correct.
//
// IDC_EDIT_ITEMNAME is the name of an 
// EditBox control.  Replace this with the name of 
// your own control.
//
// m_newitemname is the name of my CString, which is
// a member variable of the aforementioned EditBox.
// again, replace this with the name of your own CString.
//
// Now the CString will contain the value of the EditBox.
//
// Test it by adding a button to the dialog; name it 
// IDC_BUTOON_TEST.  Add a function for the button and 
// call it something like OnButtonTest. In this empty 
// function, put in this line of code
//
// MessageBox(m_newitemname)
//
// Please replace m_newitemname with your own CString.
// that should do it.  Once testing is done, you can 
// remove the button, test function, etc.
 
I sure hope this helps. I still remember what it is like to be a newbie. Don't put up with all the know-it-all jerks who have no intention of helping you. You'll get there, just don't trust anyone with the title of "Microsoft MVP" cause they expect you to know everything. They don't explain squat because it seems to be such a burden on them, and when they do have to explain something, they make it blatenly clear that the person who asked the question is a complete moron for not understanding their cryptic answer[s].
 
For further info, contact me using Y! M-digitalmythology -dm

QuestionHow can I change color of dialog boxmemberedv23 Apr '03 - 2:34 
The dialog boxes are uniformly gray. How can I change the color so that the background is, say, white or light blue and maybe the text colors other than black?Suspicious | :suss:
Generalwhy I have to use nReturnValue as fellowing nReturnValue=GetDlgItemText(IDC_ENGINE, strEngine);membergoldust9 Apr '03 - 13:54 
I tried to use
GetDlgItemText(IDC_ENGINE, strEngine);
also can make it work.I confused why use nReturnValue=GetDlgItemText(IDC_ENGINE, strEngine); ??
 

GeneralPlease explain GetItemDlg() in getting value from radiobutton groupmembergoldust9 Apr '03 - 12:35 
In this code,I couldn't understand
GetItemDlg(IDC_WIN98+m_win98)->getwindowtext(m_strOpertingSystem);
I can't find out the information about how to use GetItemDlg to get value from radiobutton group.Please give me some detail.Thanks a lot.
GeneralRe: Please explain GetItemDlg() in getting value from radiobutton groupmembervikas amin27 Aug '05 - 21:22 
I also have the same question
 
Vikas Amin
Embin Technology
Bombay
vikas.amin@embin.com
GeneralRe: Please explain GetItemDlg() in getting value from radiobutton groupsussAnonymous8 Sep '05 - 4:32 
Count me in.
 
I added a member variable for each radio button and check if they are selected by using GetCheck() function instead.
 

GeneralUpdate Menu items in Dialog-based applicationmembergameover29 Jan '03 - 2:32 
I am Yin Xiang. I wrote a dialog-based application with a menu. However, the menu state didnt change accordingly after I implemented the UPDATE_COMMAND_UI message handler.
 
For example, I have the following code in my program:
 
void CFYPDlg::OnUpdateKflannPause(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(started);
}
 
And I tried to debug my program. I noticed that the message handler was not called immediately after the menu was dropped down. It would only be called after I clicked the menu item.
 
Does this mean CDialog can not handle this message properly? Thanks a lot!Eek! | :eek:
Generaltwo modal dialogsmemberLuis Reina3 Sep '02 - 23:29 
Hi everybody:
 
I want to display two modal dialogs, one first and the other when user clicks ok button on first dialog.
I try this:
 
CDialog1 dlg1;
m_pMainWnd = &dlg1;
int nResponse = dlg1.DoModal();
if (nResponse == IDOK)
{
CDialog2 dlg2;
m_pMainWnd = &dlg2;
nResponse = dlg2.DoModal();
...
}
in InitInstance function of my app but doesn't work (first dialog is ok but other dialog is showed and killed inmediately without user interaction)
 
Anybody can help me?
GeneralRe: two modal dialogsmemberLuis Reina4 Sep '02 - 1:09 
Tomasz Sowinski solved my problem.
"Remove lines assigning pointers to m_pMainWnd."
 
Thanxs. Smile | :)

GeneralError with m_strSelectedTech=""memberAnonymous2 Jul '02 - 12:46 
Hi.
After compiling, I have error shown below:
m_strSelectedTech="" 'CButton' : 'operator =' function is unavailable
 
Does anyone know how to fix this error?
Thanks,Laugh | :laugh:
GeneralRe: Error with m_strSelectedTech=""memberGean4 Sep '02 - 2:48 
I have the same problem, and fix that creating another member variable type CString and protected named m_strSelectedTech.
 
Big Grin | :-D
GeneralTHankyoumemberAnonymous20 Jun '02 - 6:10 
Very good tutorial. Noticed that m_strSelectedTech declaration is missing, but rectified easily enough.
GeneralOverriding OnCancel()memberJoeSox14 Jun '02 - 3:32 
What is the proper way to close a Dialog when overriding OnCancel()? the below code is crashing on me.
 
void CMyDlg::OnCancel()
{
// TODO: Add extra cleanup here

// Ensure that you reset all the values back to the
// ones before modification. This handler is called
// when the user doesn't want to save the changes.

if ( AfxMessageBox("Are you sure you want to abort the changes?",
MB_YESNO) == IDNO )
return; // Give the user a chance if he has unknowingly hit the
// Cancel button. If he says No, return. Don't reset. If
// Yes, go ahead and reset the values and close the dialog.
return; // Dialog closed and DoModal returns only here!
CDialog::OnCancel();
}
Cry | :((
Questionis there an unwritten law that all tutorials must be incorrect?memberspoongirl6 May '02 - 8:08 
because i've noticed, there are very few tutorials in existence that actually work "out of the box".
 
such as this one, for instance, which although it has fewer errors than the first tutorial written by the same person, still would definitely not work w/out some fudging.
 
it was certainly helpful to me, and i appreciate the work that went into it, but for somebody who is a true "beginner" i suspect the frustration of not having the code compile would be a real stumbling block.
 
so, here's my little rant for the day, WHY oh WHY don't people who write tutorials ever actually COMPILE and RUN their source before they post it?
 
if anyone who reads this knows of a place where one can find tutorials that ACTUALLY work with no fixing, i'd be interested in knowing about it. thnxOMG | :OMG:
AnswerRe: is there an unwritten law that all tutorials must be incorrect?sussAnonymous31 Oct '03 - 8:19 
the first tutorial did work for me directly "out of the box"
 
i had no problems.
 
-steve
GeneralVC++memberSumesh27 Mar '02 - 6:50 

I would like to know about exported function in a dll.
Just I want to find out the names of the functions that are exported from dll through code...
my input is corresphonding dll
(that is, the functionality of quick view..How I can Implement it?)
Serious
 
sumeshvr@htomail.com
QuestionHow to Open a Window and display a bitmap?memberSMer19 Mar '02 - 4:02 
I have a dialog-based app that parses a satellite data stream. I would like to show the image in a pop up window after the parsing is finished. How do I add a window to be displayed after clicking a button and how do I get the data into a bitmap to display in that window?
 
Thanks,
SMer
QuestionHow to set Windows texts align at both left and right?memberAnonymous6 Mar '02 - 12:36 
Thanks for the nice article.
 
But, I have an question.
 
I have an app which requires to show two strings on the caption of an opened Window and align at both left and right side as shown below:
__________________________________
string1 string2
__________________________________
 
Can anyone tell me how to do that?
 
Thanks in advance.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 30 Jun 2000
Article Copyright 2000 by Dr. Asad Altimeemy
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid