简体   繁体   English

CPropertySheet仅显示一秒钟

[英]CPropertySheet only shows for a second

I am trying to add a CPropertySheet with three CPropertyPages to my MFC application. 我试图将具有三个CPropertyPages的CPropertySheet添加到我的MFC应用程序中。 My problem is that the Property sheet only shows for less than a second then closes. 我的问题是,属性表仅显示不到一秒钟,然后关闭。 When I open a different modal dialog after creating the CPropertySheet, the CPropertySheet stays open and I can use it with no problems. 创建CPropertySheet后打开另一个模式对话框时,CPropertySheet保持打开状态,我可以毫无问题地使用它。 Here is my code: 这是我的代码:

BOOL CSLIMOptCplusplusApp::InitInstance()
{

CWinApp::InitInstance();
SQLHENV m_1;
EnvGetHandle(m_1);


Login lgn;
lgn.DoModal();




CImageSheet*      imagedlg            = new CImageSheet("Image Capture Dialog" );
CImageDisplay*    pageImageDisplay    = new CImageDisplay;
CImageDimensions* pageImageDimensions = new CImageDimensions;
ListOption*       pageListOption      = new ListOption;

ASSERT( imagedlg );
ASSERT( pageImageDisplay );
ASSERT( pageImageDimensions );  
ASSERT( pageListOption );

imagedlg->AddPage( pageListOption);
imagedlg->AddPage( pageImageDimensions );
imagedlg->AddPage( pageImageDisplay );

imagedlg->Create( NULL,
              -1,
              WS_EX_CONTROLPARENT | WS_EX_TOOLWINDOW ); 

imagedlg->ShowWindow( SW_SHOW );

I think my problem may be at imagedlg->Create( when I use NULL as the first parameter. The tutorial I was following used this in place of the NULL . However, that gives the error: 我认为我的问题可能出在imagedlg->Create(当我使用NULL作为第一个参数时。我所遵循的教程使用了this来代替NULL 。但是,这给出了错误:

IntelliSense: argument of type "CSLIMOptCplusplusApp *" is incompatible with parameter of type "CWnd *" IntelliSense:类型为“ CSLIMOptCplusplusApp *”的参数与类型为“ CWnd *”的参数不兼容

I also tried imagedlg->Create(); 我也尝试了imagedlg->Create(); and it also only flashes for a moment. 而且也只闪烁片刻。 I would like my CPropertySheet to stay open until it is closed. 我希望CPropertySheet保持打开状态直到关闭。 Thanks for any help! 谢谢你的帮助!

EDIT: Here is an image of what I wish my property sheet to look like. 编辑:这是我希望我的属性表看起来像的图像。 My first tab used a ListControl to change database options, the other two tabs are going to do other things. 我的第一个选项卡使用ListControl更改数据库选项,其他两个选项卡将执行其他操作。 My intent is to keep the dialog/propertysheet looking the same as it does now, but to stay open instead of closing. 我的意图是使对话框/属性表看起来与现在相同,但保持打开状态而不是关闭状态。 CPropertySheet的

Your problem lies in trying to construct a property sheet within a dialog based application. 您的问题在于尝试在基于对话框的应用程序中构造属性表。 Actually, your choice of executing everything within InitInstance can be problematic at times. 实际上,您选择在InitInstance中执行所有操作有时可能会出现问题。

For starters, there's no need to create all of your objects on the heap (ie. using 'new'). 对于初学者,不需要在堆上创建所有对象(即,使用“ new”)。 But, if that's what you want, ok. 但是,如果那是您想要的,那就好。 As for your original problem of the sheet only displaying for a moment, InitInstance is designed to return immediately if not told otherwise. 至于您的表格仅显示片刻的原始问题,InitInstance旨在立即返回,除非另有说明。 Thus, you see the sheet for an instance. 因此,您将看到一个实例的工作表。 This is due to MFC expecting a valid pointer to the CWinApp class derived member variable called ' m_pMainWnd ' (actually, CWinThread::m_pMainWnd). 这是由于MFC期望指向CWinApp类派生成员变量的有效指针称为' m_pMainWnd '(实际上是CWinThread :: m_pMainWnd)。 If you want to start a property sheet, or, main dialog from within InitInstance, you need to set that variable to a valid window. 如果要从InitInstance中启动属性表或主对话框,则需要将该变量设置为有效窗口。 Here's a quick sample I wrote: 这是我写的一个简单示例:

CPropertySheet* m_pdlgPropertySheet = new CPropertySheet(_T("Simple PropertySheet"));
    ASSERT(m_pdlgPropertySheet);

    // Add three pages to the CPropertySheet object.  Both m_pstylePage,  
    // m_pcolorPage, and m_pshapePage are data members of type  
    // CPropertyPage-derived classes in CView-derived class.
    Page1* m_pstylePage = new Page1;
    m_pstylePage->Construct(IDD_DIALOG1);
    Page2* m_pcolorPage = new Page2;
    m_pcolorPage->Construct(IDD_DIALOG2);
    m_pdlgPropertySheet->AddPage(m_pstylePage);
    m_pdlgPropertySheet->AddPage(m_pcolorPage);

    m_pMainWnd = m_pdlgPropertySheet;
    INT_PTR nResponse = m_pdlgPropertySheet->DoModal();

Note the line above DoModal. 请注意DoModal上方的行。 If you need additional info, take a look at Creating a full application using the CPropertySheet . 如果您需要其他信息,请参阅使用CPropertySheet创建完整的应用程序 Lastly, you may want to read up on how MFC starts an application and what is expected. 最后,您可能需要阅读MFC如何启动应用程序以及预期的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM