Solved

Dialog Box

Posted on 2002-06-21
11
328 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
  • 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 50 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

867 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

13 Experts available now in Live!

Get 1:1 Help Now