Link to home
Start Free TrialLog in
Avatar of qqqqqqqqq
qqqqqqqqq

asked on

Dialog Box

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?
Avatar of Axter
Axter
Flag of United States of America image

Did you make your CDialog derived class using the Wizard?
Avatar of Crius
Crius

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()
Avatar of qqqqqqqqq

ASKER

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.
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!");
}
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");
}
-----------------------------------------------------------
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.
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
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?
ASKER CERTIFIED SOLUTION
Avatar of DanRollins
DanRollins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks, i knew i was doing somthing stupid. I was making a CDialog object instead of an object from my new class.
you're welcome -- Dan