CWnd::Create -> program terminates immediately after window creation

This is a discussion on CWnd::Create -> program terminates immediately after window creation within the Windows Programming forums, part of the Platform Specific Boards category; hi, i am new in MFC so i would need detail explaination and preferbly some codes here is the application ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    114

    CWnd::Create -> program terminates immediately after window creation

    hi, i am new in MFC so i would need detail explaination and preferbly some codes

    here is the application initialization


    Code:
    /////////////////////////////////////////////////////////////////////////////
    CAsevApp theApp;
    // CAsevApp initialization
    
    BOOL CAsevApp::InitInstance()
    {
    	// Standard initialization
    	// If you are not using these features and wish to reduce the size
    	//  of your final executable, you should remove from the following
    	//  the specific initialization routines you do not need.
    	RECT rec;
    	rec.bottom=100;
    	rec.left = 100;
    	rec.right = 100;
    	rec.top = 100;
    
    	main_window *m_pMainWnd = new main_window;
    	m_pMainWnd->Create(
    		"myWindowClass",
    		"title",
    		WS_OVERLAPPEDWINDOW,
    		rec,  CWnd::GetDesktopWindow(),0,0);
    return TRUE;
    main_window is a derived class from CWnd, no extra stuff has been added

    here i am trying to create a simple window with the "create" command
    or more specifically, CWnd::Create command
    what happens is that the program terminates immediately

    i was expecting an empty movable/resizable window with the titlebar "title" to appear and stay there

    is there something i did wrong?

    please assist

  2. #2
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005
    Posts
    483
    That seems to be the wrong place to create the window...
    you need 2 classes, One derived from CFrameWnd and One Derived from CWinApp.

    in the one derived from CFrameWnd, in the constructor is where you put the create command..
    here is an example for you:
    Code:
    #include <afxwin.h>
    class MyWnd : public CFrameWnd
    {
    public:
    	MyWnd();
    protected:
    	void OnPaint();
    	DECLARE_MESSAGE_MAP()
    };
    
    BEGIN_MESSAGE_MAP(MyWnd, CFrameWnd)
    	ON_WM_PAINT ()
    END_MESSAGE_MAP()
    
    MyWnd::MyWnd()
    {
    	Create(NULL, "MFC APP");
    }
    class MyApp : public CWinApp
    {
    public:
    	virtual BOOL InitInstance ();
    };
    
    BOOL MyApp::InitInstance ()
    {
        m_pMainWnd = new MyWnd;
    	
    
       m_pMainWnd->ShowWindow (m_nCmdShow);
        m_pMainWnd->UpdateWindow ();
        return TRUE;
    }
    void MyWnd::OnPaint ()
    {
        CPaintDC dc (this);
        
        CRect rect;
        GetClientRect (&rect);
        dc.DrawText (_T ("Hello, MFC"), -1, &rect,
            DT_SINGLELINE | DT_CENTER | DT_VCENTER);
    }
    
    
    MyApp App;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program Plan
    By Programmer_P in forum C++ Programming
    Replies: 0
    Last Post: 05-11-2009, 01:42 AM
  2. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 08:23 AM
  3. Window scrollbar
    By maxorator in forum Windows Programming
    Replies: 2
    Last Post: 10-07-2005, 12:31 PM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 11:39 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21