?
Solved

Dialog Box

Posted on 2002-06-21
11
Medium Priority
?
335 Views
Last Modified: 2008-03-03
I'm trying to create a simple dialog box. I made a template with the resource editor (MSVC++6). I made a class that was derived from CDialog and was associated with my dialog. I added a button to my dialog box. I added a BN_CLICKED function associated with that button in the class that i made for the button.

I display my dialog box and click the button. Nothing happens. The code i put in the handler function is not executed.

I know I'm making a stupid, simple mistake. What am I doing wrong?
0
Comment
Question by:qqqqqqqqq
[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
  • 4
  • 3
  • 3
  • +1
11 Comments
 
LVL 30

Expert Comment

by:Axter
ID: 7098498
Did you make your CDialog derived class using the Wizard?
0
 
LVL 3

Expert Comment

by:Crius
ID: 7098896
First thing to do is verify you have done everything you said properly.

Check the Resource ID of the button. Does it match what you see written in the message map of your .cpp class? Did you, perchance, rename the button resource ID after you had created the BN_CLICKED message?

While I'm on the topic, did you use the class wizard to add the BN_CLICKED message handler? Make sure you have in your message map the entry for your function.

BEGIN_MESSAGE_MAP(CMyDialog, CDialog)
    //{{AFX_MSG_MAP(CMyDialog)
    ON_BN_CLICKED(IDC_DialogBtnID, OnDialogIDBNClicked)
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()
0
 

Author Comment

by:qqqqqqqqq
ID: 7099411
I made the class my clicking on the button on the dialog and then pressing Ctrl+W (class wizard). It asked if i wanted to create a new class for this resource, and i said yes.

I didn't rename my button, and it does match the messagemap entry.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:Crius
ID: 7099430
I'm out of blind guesses then. We would need to see parts of your source code to continue.

Please include:

You message mapping (Including the BEGIN_MESSAGE_MAP, and END_MESSAGE_MAP).

Your handler function with its complete function list:

void CMyDialog::OnDialogIDBNClicked()
{
   MessageBox("I once was clicked, but now, am not.", "Was down, but now, I see, err, am up!");
}
0
 

Author Comment

by:qqqqqqqqq
ID: 7099497
My dialog is IDD_COMNUM and the button is IDC_SET.

-----------------------------------------------------------
// Dialog Data
     //{{AFX_DATA(CComnum)
     enum { IDD = IDD_COMNUM };
     //}}AFX_DATA
-----------------------------------------------------------
     // Generated message map functions
     //{{AFX_MSG(CComnum)
     afx_msg void OnSet();
     //}}AFX_MSG
-----------------------------------------------------------
BEGIN_MESSAGE_MAP(CComnum, CDialog)
     //{{AFX_MSG_MAP(CComnum)
     ON_BN_CLICKED(IDC_SET, OnSet)
     //}}AFX_MSG_MAP
END_MESSAGE_MAP()
-----------------------------------------------------------
void CComnum::OnSet()
{
     AfxMessageBox("testing123");
}
-----------------------------------------------------------
0
 
LVL 3

Expert Comment

by:Crius
ID: 7099514
Do a project search on IDC_SET, and make sure it's not being redefined anywhere.

Other than that, I can't imagine the problem because your code is good.

I just created a project myself, and did the exact same thing. It worked perfectly.

Try doing a rebuild all on your project too. Let's make certain it is getting the latest code.

If it still doesn't work, I'd suggest you copy out all the functions you have added, nuke the dialog class, and recreate it.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7099619
1) Try adding a new button and see if you get the same problem.  If not, the look carefully at whatever is different.

2) Put a breakpoint on the AfxMessagBox() call to see if control stops there.  

3)Use Spy++ and watch the messages fly as you click the button.  It will reveal what is actually happening.  

-- Dan
0
 

Author Comment

by:qqqqqqqqq
ID: 7099849
i made a new project with nothing but the basics and it still didn't work. the only thing i can think i did wrong was display the dialog incorrectly. what code should i be using to display my dialog?
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 200 total points
ID: 7100017
1) Start a new project:
   MFC AppWizard (exe) set Name to MyApp
   [OK]
   Dialog based
   [Finish]

2) Draw a button.  Then double click it.  You will end up in an OnClickButton1 handler.  Make it look like this:

#include "MyOtherDlg.h"
void CMyAppDlg::OnButton1()
{
     CMyOtherDlg dlg;
     dlg.DoModal();
}

3) In the resource view, under MyApp resources, right- click "Dialog" and choose "Insert Dialog"  Its ID is IDD_DIALOG1 and its title is "Dialog"

4) double-click the titlebar of that dialog in the resource editor.  the ClassWizard says "IDD_DIALOG1 is a new resource yada yada..."  Click OK to create a new class:

   Name: CMyOtherDialog
   [OK] (leave all of the defaults)

5) build and run the app.  The main window (a dialog named MyApp) appears.  Click the button in it.  Up comes the second dialog named Dialog.

-- Dan
0
 

Author Comment

by:qqqqqqqqq
ID: 7100059
thanks, i knew i was doing somthing stupid. I was making a CDialog object instead of an object from my new class.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7100255
you're welcome -- Dan
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses
Course of the Month11 days, 20 hours left to enroll

752 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