[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 299
  • Last Modified:

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
0
liseperu
Asked:
liseperu
  • 5
  • 3
2 Solutions
 
AndyAinscowCommented:
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
 
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
 
AndyAinscowCommented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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
 
AndyAinscowCommented:
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now