Solved

Creating modeless dialog box (VC++)

Posted on 2004-10-14
5
1,262 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
[X]
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
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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++.

710 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