GIDForums  

Go Back   GIDForums > Computer Programming Forums > MS Visual C++ / MFC Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 11-May-2004, 07:54
vadharah vadharah is offline
Junior Member
 
Join Date: Apr 2004
Posts: 45
vadharah is on a distinguished road
Angry

Adding A Dialog to Single Doc in Visual MFC


im using the single doc and i have created a Dialog i intend to display it when i run the program how do i do that? i mean attach it to my main interface?..... any i deas??
  #2  
Old 11-May-2004, 20:18
Max Payne's Avatar
Max Payne Max Payne is offline
Regular Member
 
Join Date: Apr 2004
Location: 3° 08 North 101° 42 East
Posts: 332
Max Payne is a jewel in the roughMax Payne is a jewel in the roughMax Payne is a jewel in the rough
Have you created the dialog and its class, I assume you did.

in your SDIview or Mainframe class, declare a new class of your dialog class.
CPP / C++ / C Code:
CMyDialog MyDialog;
and in the implementation, just call domodal to pop a modal dialog;
CPP / C++ / C Code:
MyDialog.DoModal();
for a modaless dialog,use this code:

CPP / C++ / C Code:
MyDialog.ShowWindow(SW_SHOW);
__________________
When you say "I wrote a program that crashed Windows," people just stare at you blankly and say "Hey, I got those with the system, for free." Linus Torvalds
  #3  
Old 12-May-2004, 01:26
vadharah vadharah is offline
Junior Member
 
Join Date: Apr 2004
Posts: 45
vadharah is on a distinguished road
Thanks i have created my dialog, created a class named it MyDialog but when u say in the implementation where exactly do i add the
CPP / C++ / C Code:
MyDialog.DoModal();
i have included the header i the main frame but which function do i include this call
  #4  
Old 12-May-2004, 01:28
vadharah vadharah is offline
Junior Member
 
Join Date: Apr 2004
Posts: 45
vadharah is on a distinguished road
Quote:
Originally Posted by Max Payne
Have you created the dialog and its class, I assume you did.

in your SDIview or Mainframe class, declare a new class of your dialog class.
CPP / C++ / C Code:
CMyDialog MyDialog;
and in the implementation, just call domodal to pop a modal dialog;
CPP / C++ / C Code:
MyDialog.DoModal();
for a modaless dialog,use this code:

CPP / C++ / C Code:
MyDialog.ShowWindow(SW_SHOW);


Thanks i have created my dialog, created a class named it MyDialog but when u say in the implementation where exactly do i add the
CPP / C++ / C Code:
MyDialog.DoModal();
i have included the header i the main frame but which function do i include this call
  #5  
Old 12-May-2004, 01:39
Max Payne's Avatar
Max Payne Max Payne is offline
Regular Member
 
Join Date: Apr 2004
Location: 3° 08 North 101° 42 East
Posts: 332
Max Payne is a jewel in the roughMax Payne is a jewel in the roughMax Payne is a jewel in the rough
It depends on when you want to pop the dialog. Lets say that the dialog should pop when user clicks on a button in the toolbar, the ID of the button is ID_POPDIALOG.

CPP / C++ / C Code:
// add this in the mainframe.h

//{{AFX_MSG(CMainFrame)
	afx_msg void OnPopDialog();
//AFX_MSG

// In the mainframe.cpp
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
	//{{AFX_MSG_MAP(CMainFrame)
             // Add this here, it will handle the command message of the button
             // and call OnPopDialog()
	ON_COMMAND(ID_POPDIALOG, OnPopDialog)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

//this is still in the mainframe.cpp 
void CMainFrame::OnFormatFont() 
{
     //show the dialog
     MyDialog.DoModal();
}
__________________
When you say "I wrote a program that crashed Windows," people just stare at you blankly and say "Hey, I got those with the system, for free." Linus Torvalds
  #6  
Old 12-May-2004, 01:54
vadharah vadharah is offline
Junior Member
 
Join Date: Apr 2004
Posts: 45
vadharah is on a distinguished road
Quote:
Originally Posted by Max Payne
It depends on when you want to pop the dialog. Lets say that the dialog should pop when user clicks on a button in the toolbar, the ID of the button is ID_POPDIALOG.

CPP / C++ / C Code:
// add this in the mainframe.h

//{{AFX_MSG(CMainFrame)
	afx_msg void OnPopDialog();
//AFX_MSG

// In the mainframe.cpp
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
	//{{AFX_MSG_MAP(CMainFrame)
             // Add this here, it will handle the command message of the button
             // and call OnPopDialog()
	ON_COMMAND(ID_POPDIALOG, OnPopDialog)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

//this is still in the mainframe.cpp 
void CMainFrame::OnFormatFont() 
{
     //show the dialog
     MyDialog.DoModal();
}


what i want is that when i run the program the dialog will be already there. when the menu is displayed the dialog should also be there (attaching the dialog to the menu)
thanx
  #7  
Old 12-May-2004, 02:32
Max Payne's Avatar
Max Payne Max Payne is offline
Regular Member
 
Join Date: Apr 2004
Location: 3° 08 North 101° 42 East
Posts: 332
Max Payne is a jewel in the roughMax Payne is a jewel in the roughMax Payne is a jewel in the rough
Thats Kind of hard to do.. Just follow the instructions below:
CPP / C++ / C Code:
in the mainframe.h file
#define WM_STARTUP (WM_APP +1)

	//{{AFX_MSG(CMainFrame)
             //Add this here
	afx_msg void OnStartUp(WPARAM wParam, LPARAM lParam);
	//}}AFX_MSG

then in the mainframe.cpp file
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
	//{{AFX_MSG_MAP(CMainFrame)
	// add this here
             ON_MESSAGE(WM_STARTUP, OnStartUp)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

and add the handler

void   CMainFrame::OnStartUp(WPARAM wParam, LPARAM lParam)
{

    MyDialog.DoModal();
}

Then at the end of OnCreate()  add
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
...
...
...
PostMessage(WM_STARTUP, 0,0);
return 0;
}
That should do it...
__________________
When you say "I wrote a program that crashed Windows," people just stare at you blankly and say "Hey, I got those with the system, for free." Linus Torvalds
  #8  
Old 12-May-2004, 06:47
vadharah vadharah is offline
Junior Member
 
Join Date: Apr 2004
Posts: 45
vadharah is on a distinguished road
Quote:
Originally Posted by Max Payne
Thats Kind of hard to do.. Just follow the instructions below:
CPP / C++ / C Code:
in the mainframe.h file
#define WM_STARTUP (WM_APP +1)

	//{{AFX_MSG(CMainFrame)
             //Add this here
	afx_msg void OnStartUp(WPARAM wParam, LPARAM lParam);
	//}}AFX_MSG

then in the mainframe.cpp file
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
	//{{AFX_MSG_MAP(CMainFrame)
	// add this here
             ON_MESSAGE(WM_STARTUP, OnStartUp)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

and add the handler


void   CMainFrame::OnStartUp(WPARAM wParam, LPARAM lParam)
{

    MyDialog.DoModal();
}

Then at the end of OnCreate()  add
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
...
...
...
PostMessage(WM_STARTUP, 0,0);
return 0;
}
That should do it...
thanx for the help also adapted ur first idea and it worked will try this one thanx
 
 

Recent GIDBlogPython ebook by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Tutorial] GUI programming with FLTK dsmith FLTK Forum 10 03-Oct-2005 16:41
Visual C++ Edge Detection surgio MS Visual C++ / MFC Forum 5 26-Mar-2005 02:46
Art and Maths.....a single hypervoxel paulselhi Graphics Forum 0 10-Mar-2004 07:11
Convertin C++ to eMbedded Visual C++ kiara C++ Forum 0 14-Jan-2004 02:05
Convertin C++ to eMbedded Visual C++ jbalart C++ Forum 0 23-Dec-2003 07:44

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 08:34.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.