15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Adding menu to property sheet app

CADD Design Solutions -- cds59@idt.net
Wednesday, January 29, 1997

Environment: VC++ 1.52 Windows 3.1

Hello all!

I have created a very simple app that consists of a CWinApp object that
constructs a CPropertySheet object in its InitInstance function.  All works
fine as is, however, I need to add a standard Windows menu to it.  I can't
seem to figure out how to do this, although I have searched on-line help and
Microsoft KB.  I thought it would be a simple matter of constructing a CMenu
object and attaching it to the window, but when I do that, the menu does not
show up.  Can someone please tell me what I'm missing?  My code follows:

// propdlg.h : Declares the class interfaces for the application.
//

#include "resource.h"       // resource IDs

/////////////////////////////////////////////////////////////////////////////
// CDialogApp:

class CDialogApp : public CWinApp
{
public:
   BOOL InitInstance();
};

/////////////////////////////////////////////////////////////////////////////

// dialog.cpp : minimum dialog-box based application
//

#include "stdafx.h"
#include "propdlg.h"
#include "page1.h"
#include "page2.h"

/////////////////////////////////////////////////////////////////////////////
// CDialogApp

BOOL CDialogApp::InitInstance()
{
   SetDialogBkColor();     // grey look

   //DialogApp mainDlg;      // construct the dialog object
   CPropertySheet mainDlg(AFX_IDS_APP_TITLE);
   m_pMainWnd = &mainDlg;  // assign it to main wnd member variable

   //Create new menu
   CMenu menu;
   m_pMainWnd->SetMenu(&menu);
   menu.Detach();
   menu.LoadMenu(IDR_MENU1);

   CPage1 page1;
   CPage2 page2;

   mainDlg.AddPage(&page1);
   mainDlg.AddPage(&page2);

   if(mainDlg.DoModal() == IDOK)
   {
      if(!page1.m_textbox.IsEmpty()) AfxMessageBox(page1.m_textbox);
      //Include any update statements here
   }

   return TRUE;
}

CDialogApp theApp;


-----------------------------------------------
Shawn L. Bradley
CADD Design Solutions

e-mail: cds59@mail.idt.net

Visit our web site for latest news, neat tips,
and FREE AutoLISP utilities!
	http://metropolis.idt.net/~cds59
-----------------------------------------------
All that must happen for evil to prevail, is
for good men to do nothing. -Edmund Burke

"A democracy cannot exist as a permanent form of government.
It can only exist until the voters discover that they can vote
themselves money from the Public Treasury.  From that moment on,
the majority always votes for the candidates promising the most
benifits from the Public Treasury with a result that a democracy
always collapses over loose fiscal policy always followed by a
dictatorship." -Alexander Fraser Tytler




Brian Jones -- BrianJ@apptechsys.com
Friday, January 31, 1997

[Mini-digest: 2 responses]

Shawn,

If have added my own menu to a PropSheet by handling OnCreate and adding
the menu there.

Since my PropSheet was Modeless, I added the System Menu, Caption Bar,
and MinimizeBox as style params in my call to Create.  You might try
ORing them to the lpCreateStruct in OnCreate as follows (I haven't tried
that, but IDR_MY_MENU works fine):

int CMySheet::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	CMenu* pmenu;

	// add the system menu to the propsheet
	lpCreateStruct->style |= WS_SYSMENU;

	// add the caption to the propsheet
	lpCreateStruct->style |= WS_CAPTION;

	// add the minimize box to the propsheet
	lpCreateStruct->style |= WS_MINIMIZEBOX;

	if (CPropertySheet::OnCreate(lpCreateStruct) == -1)
		return -1;

	// set up the menu
	pmenu = new CMenu;
	pmenu->LoadMenu(IDR_MY_MENU);
	SetMenu(pmenu);
	pmenu->Detach();
	delete pmenu;

	return 0;
}



>----------
>From: 	CADD Design Solutions[SMTP:cds59@idt.net]
>Sent: 	Wednesday, January 29, 1997 1:33 PM
>To: 	mfc-l@netcom.com
>Subject: 	Adding menu to property sheet app
>
>Environment: VC++ 1.52 Windows 3.1
>
>Hello all!
>
>I have created a very simple app that consists of a CWinApp object that
>constructs a CPropertySheet object in its InitInstance function.  All works
>fine as is, however, I need to add a standard Windows menu to it.  I can't
>seem to figure out how to do this, although I have searched on-line help and
>Microsoft KB.  I thought it would be a simple matter of constructing a CMenu
>object and attaching it to the window, but when I do that, the menu does not
>show up.  Can someone please tell me what I'm missing?  My code follows:
>
>// propdlg.h : Declares the class interfaces for the application.
>//
>
>#include "resource.h"       // resource IDs
>
>/////////////////////////////////////////////////////////////////////////////
>// CDialogApp:
>
>class CDialogApp : public CWinApp
>{
>public:
>   BOOL InitInstance();
>};
>
>/////////////////////////////////////////////////////////////////////////////
>
>// dialog.cpp : minimum dialog-box based application
>//
>
>#include "stdafx.h"
>#include "propdlg.h"
>#include "page1.h"
>#include "page2.h"
>
>/////////////////////////////////////////////////////////////////////////////
>// CDialogApp
>
>BOOL CDialogApp::InitInstance()
>{
>   SetDialogBkColor();     // grey look
>
>   //DialogApp mainDlg;      // construct the dialog object
>   CPropertySheet mainDlg(AFX_IDS_APP_TITLE);
>   m_pMainWnd = &mainDlg;  // assign it to main wnd member variable
>
>   //Create new menu
>   CMenu menu;
>   m_pMainWnd->SetMenu(&menu);
>   menu.Detach();
>   menu.LoadMenu(IDR_MENU1);
>
>   CPage1 page1;
>   CPage2 page2;
>
>   mainDlg.AddPage(&page1);
>   mainDlg.AddPage(&page2);
>
>   if(mainDlg.DoModal() == IDOK)
>   {
>      if(!page1.m_textbox.IsEmpty()) AfxMessageBox(page1.m_textbox);
>      //Include any update statements here
>   }
>
>   return TRUE;
>}
>
>CDialogApp theApp;
>
>
>-----------------------------------------------
>Shawn L. Bradley
>CADD Design Solutions
>
>e-mail: cds59@mail.idt.net
>
>Visit our web site for latest news, neat tips,
>and FREE AutoLISP utilities!
>	http://metropolis.idt.net/~cds59
>-----------------------------------------------
>All that must happen for evil to prevail, is
>for good men to do nothing. -Edmund Burke
>
>"A democracy cannot exist as a permanent form of government.
>It can only exist until the voters discover that they can vote
>themselves money from the Public Treasury.  From that moment on,
>the majority always votes for the candidates promising the most
>benifits from the Public Treasury with a result that a democracy
>always collapses over loose fiscal policy always followed by a
>dictatorship." -Alexander Fraser Tytler
>
>
-----From: David Little 

It is very easy.  Add a menu name to the Dialog properties in the =
resource editor.  ClassWizard won't add any WM_COMMAND functionality, =
but you can do it by hand and every thing is fine.  If you didn't want =
to do that, why not just make it an SDI app?

And what are you doing using 16-bit junk for CAD?

David

----------
From: 	CADD Design Solutions[SMTP:cds59@idt.net]
Sent: 	Wednesday, January 29, 1997 3:33 PM
To: 	mfc-l@netcom.com
Subject: 	Adding menu to property sheet app

Environment: VC++ 1.52 Windows 3.1

Hello all!

I have created a very simple app that consists of a CWinApp object that
constructs a CPropertySheet object in its InitInstance function.  All =
works
fine as is, however, I need to add a standard Windows menu to it.  I =
can't
seem to figure out how to do this, although I have searched on-line help =
and
Microsoft KB.  I thought it would be a simple matter of constructing a =
CMenu
object and attaching it to the window, but when I do that, the menu does =
not
show up.  Can someone please tell me what I'm missing?  My code follows:

// propdlg.h : Declares the class interfaces for the application.
//

#include "resource.h"       // resource IDs

/////////////////////////////////////////////////////////////////////////=
////
// CDialogApp:

class CDialogApp : public CWinApp
{
public:
   BOOL InitInstance();
};

/////////////////////////////////////////////////////////////////////////=
////

// dialog.cpp : minimum dialog-box based application
//

#include "stdafx.h"
#include "propdlg.h"
#include "page1.h"
#include "page2.h"

/////////////////////////////////////////////////////////////////////////=
////
// CDialogApp

BOOL CDialogApp::InitInstance()
{
   SetDialogBkColor();     // grey look

   //DialogApp mainDlg;      // construct the dialog object
   CPropertySheet mainDlg(AFX_IDS_APP_TITLE);
   m_pMainWnd =3D &mainDlg;  // assign it to main wnd member variable

   //Create new menu
   CMenu menu;
   m_pMainWnd->SetMenu(&menu);
   menu.Detach();
   menu.LoadMenu(IDR_MENU1);

   CPage1 page1;
   CPage2 page2;

   mainDlg.AddPage(&page1);
   mainDlg.AddPage(&page2);

   if(mainDlg.DoModal() =3D=3D IDOK)
   {
      if(!page1.m_textbox.IsEmpty()) AfxMessageBox(page1.m_textbox);
      //Include any update statements here
   }

   return TRUE;
}

CDialogApp theApp;


-----------------------------------------------
Shawn L. Bradley
CADD Design Solutions

e-mail: cds59@mail.idt.net

Visit our web site for latest news, neat tips,
and FREE AutoLISP utilities!
	http://metropolis.idt.net/~cds59
-----------------------------------------------
All that must happen for evil to prevail, is
for good men to do nothing. -Edmund Burke

"A democracy cannot exist as a permanent form of government.
It can only exist until the voters discover that they can vote
themselves money from the Public Treasury.  From that moment on,
the majority always votes for the candidates promising the most
benifits from the Public Treasury with a result that a democracy
always collapses over loose fiscal policy always followed by a
dictatorship." -Alexander Fraser Tytler






| Вернуться в корень Архива |