Solved

Creating modeless dialog box (VC++)

Posted on 2004-10-14
5
1,250 Views
Last Modified: 2011-04-14
Hi,
I intend to create a simple dialog box using VC++. The code snippet is given below. The call of CreateDialog always returns a NULL handle. Why is it so?

--Sachin


// dialog.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "resource.h"

BOOL
InitMainDialog ( HINSTANCE hInstance,
                         int nCmdShow);

BOOL CALLBACK
MainDlgProc ( HWND hwDlg,
                    UINT uiMsg,
                    WPARAM wParam,
                    LPARAM lParam );

HINSTANCE      ghInstance;
HWND            ghWnd;

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
      MSG msg;
      if (!hPrevInstance ) {
             if (!InitMainDialog ( hInstance, nCmdShow ) ) {
                  return FALSE;
            }
      }
      while (GetMessage (&msg, NULL, 0, 0)) {
            TranslateMessage ( &msg );
            DispatchMessage ( &msg );
      }
      return 0;
}

BOOL
InitMainDialog (HINSTANCE hInstance,
                        int nCmdShow)
{
      // Save instance handle in a global variable
      ghInstance      = hInstance;
      
      char *strInResource      = MAKEINTRESOURCE ( IDD_MAIN_DLG );
      // Try to create a dialog box
      ghWnd            = CreateDialog ( hInstance,
                                                 MAKEINTRESOURCE (IDD_MAIN_DLG),
                                                 NULL,
                                                 (DLGPROC) MainDlgProc );
      if ( ghWnd == NULL ) {
            return FALSE;
      }

      ShowWindow ( ghWnd, SW_SHOW );
      return TRUE;
}


BOOL CALLBACK
MainDlgProc ( HWND hwDlg,
                    UINT uiMsg,
                    WPARAM wParam,
                    LPARAM lParam )
{
      switch ( uiMsg ) {
      
      }
      return TRUE;
}




0
Comment
Question by:m_sachin
  • 2
  • 2
5 Comments
 
LVL 13

Expert Comment

by:SteH
ID: 12306224
You should call GetLastError in the case that the call to CreateDialog fails. The reason for failing is stored in a "global" error value.

Can you post that value.
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 12306568
The CreateDialog returned not NULL after i added resource file to the project.

However, as there was no WM_PAINT handler there was no output ;-)

Regards, Alex
0
 

Author Comment

by:m_sachin
ID: 12306694
Error value returned is 1406
--Sachin
0
 
LVL 13

Accepted Solution

by:
SteH earned 125 total points
ID: 12306788
error code help:
1406 Cannot create a top-level child window.

Your dialog seems to have child flag and the window will be top level. You need to make remove child flag and add toplevel instead.
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 12306802
1406 == //  Cannot create a top-level child window

Your dialog resource has Child Window property. You have to switch to Popup or Overlapped Style.

Regards, Alex

P. S. You'll find all errors in "winerror.h"
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now