Help testing a CDialog based class
-
I'm having trouble using the code that MFC app-wizard spits out for a custom dialog as the base class for another few custom dialogs. My problem is that I can't seem to write (or borrow) the simplest app possible that is able to instantiate one of my dialog classes. I copied Nishant Sivakumar's simplest MFC app in the world, FirstProg.zip, from somewhere on the internet, which looks something like this:
//NWinApp.h
class CNWinApp : public CWinApp
{
public:
BOOL InitInstance();
};//NWinApp.cpp
#include #include "NWinApp.h"CNWinApp app;
BOOL CNWinApp::InitInstance()
{
CFrameWnd *pnframe=new CFrameWnd;
m_pMainWnd=pnframe;
pnframe->Create(0,"Buster");
pnframe->ShowWindow(SW_SHOW);
return TRUE;
}This also looks like the generic code for testing a CDialog based class generated by MFC AppWizard. I replaced the CFrameWnd bit like this
CMyGuiDlg *pGuiDlg= new CMyGuiDlg;
m_pMainWnd=pGuiDlg;
pGuiDlg->DoModal();
return TRUE;I can compile & run this project, and nothing shows up on the screen. If I compile and run the original AppWizard-produced project, the dialog (CMyGuiDlg) will show up no problem. I've also tried to write my own CWinApp derivation in a Win32Console App project, and got it to compile & run by calling _tWinMain(...), however my program was exiting as fast as it started. I think I need to use CWinApp as the basis for my program, and AfxWinMain(...). What am I missing? Currently I have resorted to creating all the dialog derivations in the same project, so that I can use the AppWizard generated test files to run them. I had hoped I could have a different project for each derivation.
-
I'm having trouble using the code that MFC app-wizard spits out for a custom dialog as the base class for another few custom dialogs. My problem is that I can't seem to write (or borrow) the simplest app possible that is able to instantiate one of my dialog classes. I copied Nishant Sivakumar's simplest MFC app in the world, FirstProg.zip, from somewhere on the internet, which looks something like this:
//NWinApp.h
class CNWinApp : public CWinApp
{
public:
BOOL InitInstance();
};//NWinApp.cpp
#include #include "NWinApp.h"CNWinApp app;
BOOL CNWinApp::InitInstance()
{
CFrameWnd *pnframe=new CFrameWnd;
m_pMainWnd=pnframe;
pnframe->Create(0,"Buster");
pnframe->ShowWindow(SW_SHOW);
return TRUE;
}This also looks like the generic code for testing a CDialog based class generated by MFC AppWizard. I replaced the CFrameWnd bit like this
CMyGuiDlg *pGuiDlg= new CMyGuiDlg;
m_pMainWnd=pGuiDlg;
pGuiDlg->DoModal();
return TRUE;I can compile & run this project, and nothing shows up on the screen. If I compile and run the original AppWizard-produced project, the dialog (CMyGuiDlg) will show up no problem. I've also tried to write my own CWinApp derivation in a Win32Console App project, and got it to compile & run by calling _tWinMain(...), however my program was exiting as fast as it started. I think I need to use CWinApp as the basis for my program, and AfxWinMain(...). What am I missing? Currently I have resorted to creating all the dialog derivations in the same project, so that I can use the AppWizard generated test files to run them. I had hoped I could have a different project for each derivation.
When you say nothing appears... does the app actially close? You can debug the program line by line. My guess is that you forgot to set the WS_VISIBLE bit in your dialog settings... Iain.
Codeproject MVP for C++, I can't believe it's for my lounge posts...