mfc dialog buttons not working

hi
i have created a simple app interface
and i am just at intial stages and have run into prbs

i have a main window that interherits from the CDialog class
all the buttons work fine on this window

i have one button that opens another window
which will have some data input boxes on

i have create a simple button to just bling up a messagebox when pressed
the thing is it doesnt do anything!!!

i have added control variable in the class wizard member variables but all to now effect

heres the handler code------------------------------------

void Second_Interface::OnTestButt()
{
      // TODO: Add your control notification handler code here
      MessageBox( "Test.","Test", MB_YESNO | MB_ICONQUESTION );


}

-----------------------------------------------------------------

i think i have done something wrong when creating classes
or when i open the window froem the main area


the second window inherits from hte CDialog class
is the the write way to do it
or should it inherit from the main window class

thanks
lis
liseperuAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AndyAinscowFreelance programmer / ConsultantCommented:
Inherit from CDialog is correct (assuming it is a dialog that is).
For a button event you don't require any variables.  Do you mean you added the event handler with the class wizard?

How do you start this entry dialog? is it like
...
Second_Interface dlg(this);
dlg.DoModal();
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
liseperuAuthor Commented:
no
i was going to post another question about the diference between modal and modeless
which i dont understand
anyway i just opened a modaless using the code below

-----------------------------------------------

      CDialog* pDialog;
      
      pDialog = new CDialog();
      pDialog->Create(IDD_DIALOG2, this);
      pDialog->ShowWindow(SW_SHOW);
      pDialog->CenterWindow();

-----------------------------------------------
is this ok?
lis
0
AndyAinscowFreelance programmer / ConsultantCommented:
No.  (Not far off).  You need to have a class based on CDialog that is for the resource IDD_DIALOG2 and you create an instance of that class.

     CMyDialog* pDialog;   <---------------------
     
     pDialog = new CMyDialog();   <----------------------
     pDialog->Create(IDD_DIALOG2, this);
     pDialog->ShowWindow(SW_SHOW);
     pDialog->CenterWindow();




Modal - the dialog stops the app receiving mouse/keyboard events until it is dismissed.
Modeless - the app and dialog are both active and both respond to mouse/keyboard events.

Rule of thumb.  Use modal dialogs for things that the user must respond to before continuing.
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

liseperuAuthor Commented:
ok
i think i need a modal  one as i want the user to complete the inputs in the second window before returning to the first

so should i use
-----------------------------------------
IDD_DIALOG2 dlg(this);
dlg.DoModal();
---------------------------------------

thanks
0
AndyAinscowFreelance programmer / ConsultantCommented:
Not quite.  You derive a class from CDialog (eg. CMyDialog) which is using the resource with the ID IDD_DIALOG2. Then you use

CMyDialog dlg(this);
if(dlg.DoModal()==IDOK)
{
//OK button pressed
}
else
{
//cancel pressed
}
0
liseperuAuthor Commented:
thanks
that works fine
but it htakes about 5 seconds to open

i have been checkin out classes

and this is what i have got

i have two interfaces Cinterface1 , Cinterface2

class CInterface1 : public CDialog
class CInterface2 : public CDialog

i am trying to call interface 2 from interface 1

any ideas why it is taking so long

here the open dialog code

void CInterface1::OnEnterCInterface1()
{
    // TODO: Add your control notification handler code here
    CInterface2 sDlg;
    sDlg.DoModal();

}

thanks
lis
0
liseperuAuthor Commented:
arh sorry
i am such a dozy cow
forget about my post above

i think the problem is that the smaller interface2 window was is hidden
behind the rather large interface1 window
it is kind of hard to tell cus i cant mimize the big window

is there a simple line of code to ensure that the second windowopens on top of the first?

thanks
sarah
0
liseperuAuthor Commented:
hello again

i think there must havebeen a bug inthe program
i open an older version of the program and inserted the code as suggest above
and it worked fine

i inserted the following ode to opena modal dialoge

   CInterface2 sDlg;
    sDlg.DoModal();

into the button handler
and bingo it worked fine

thanks again

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.