Solved

Dialog Box

Posted on 2002-06-21
11
327 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
Comment Utility
Did you make your CDialog derived class using the Wizard?
0
 
LVL 3

Expert Comment

by:Crius
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
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).

 
LVL 3

Expert Comment

by:Crius
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
you're welcome -- Dan
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

744 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

15 Experts available now in Live!

Get 1:1 Help Now