Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Creating modeless dialog box (VC++)

Posted on 2004-10-14
5
Medium Priority
?
1,277 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 375 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

782 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