m_sachin
asked on
Creating modeless dialog box (VC++)
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;
}
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;
}
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
However, as there was no WM_PAINT handler there was no output ;-)
Regards, Alex
ASKER
Error value returned is 1406
--Sachin
--Sachin
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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"
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"
Can you post that value.