Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Creating modeless dialog box (VC++)

Posted on 2004-10-14
5
1,255 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Find Visual Studio Tools 2 111
Dynamically allocate memory 9 62
c++ syntax question 9 52
Create a path if not exists 7 87
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

809 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