Solved

Dialog Box

Posted on 2002-06-21
11
330 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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 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 AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

803 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