Click to See Complete Forum and Search --> : Problem with dialog box in VS2005


Sh@dow
November 3rd, 2009, 08:10 AM
Hi all.
I'm trying to create dialog box using pure API in VS2005.First i'm creating window and then dialog box.The problem is that dialog box is not shown correctly.I can see only buttos which are in the dialog box,the dialog box frame and system menu(close,minimie) are not shown.It looks like:
http://img27.imageshack.us/img27/7273/dbbug.jpg
Where can be the problem?The same source in VS6 works fine.I tried to play aroud with option in the resource editor but still no result.
The code is as folows:

#include <windows.h>
#include "resource.h"

LRESULT CALLBACK wndproc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam );
BOOL CALLBACK dproc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam);

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
WNDCLASSEX wnd;
wnd.cbSize=sizeof(wnd);
wnd.style=CS_HREDRAW|CS_VREDRAW;
wnd.lpfnWndProc=wndproc;
wnd.cbClsExtra=0;
wnd.cbWndExtra=0;
wnd.hInstance=0;
wnd.hIcon=0;//LoadIcon(gInstance,MAKEINTRESOURCE(668));;
wnd.hCursor=LoadCursor(NULL,IDC_ARROW);
wnd.hbrBackground=(HBRUSH)13;
wnd.lpszMenuName=MAKEINTRESOURCE(5000);
wnd.lpszClassName=L"class";
wnd.hIconSm=NULL;

RegisterClassEx(&wnd);
HWND handle=CreateWindowEx(NULL,L"class",L"test",WS_OVERLAPPEDWINDOW|WS_CLIPCHILDREN|WS_MAXIMIZE,
0,0,790,550,NULL,NULL,
NULL,NULL);

ShowWindow(handle,SW_SHOW);
UpdateWindow(handle);

MSG message;

while(GetMessage(&message,0,0,0))
{
TranslateMessage(&message);
DispatchMessage(&message);
}

return 0;
}


LRESULT CALLBACK wndproc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam )
{
switch(uMsg)
{
case WM_CREATE:
{
}
break;

case WM_COMMAND:
{
if(wParam == 140)
{
DialogBox(0,MAKEINTRESOURCE(IDD_DIALOG1),hwnd,dproc);
}
}
break;

case WM_CLOSE:
{
ExitProcess(0);
}
break;

default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}


BOOL CALLBACK dproc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
switch(uMsg)
{
case WM_INITDIALOG:
{
return 1;
}
break;

return 0;
}
}

olivthill2
November 3rd, 2009, 08:58 AM
Unfortunately, there are only 13 lines in the code you posted which are related to your dialog box, and the most important part, the resource file, is not shown.

DialogBox(0,MAKEINTRESOURCE(IDD_DIALOG1),hwnd,dproc);
...
BOOL CALLBACK dproc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
switch(uMsg)
{
case WM_INITDIALOG:
{
return 1;
}
break;

return 0;
}
}
I have almost the same thing:

DialogBox(hinst, "DIALOG1" , hwnd, (DLGPROC)Dialog1Proc);
...
BOOL APIENTRY Dialog1Proc(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
switch (uMsg)
{
case WM_INITDIALOG:

return TRUE;

case WM_COMMAND:
if (LOWORD(wParam) == IDCANCEL || LOWORD(wParam) == IDOK)
{
EndDialog(hDlg,0);
return TRUE;
}

default:
return FALSE;
}
}The problem must be in definition of your dialog box in the resource file, or maybe that resource file is not well compiled, or the settings of your project file are no good.

Sh@dow
November 3rd, 2009, 01:14 PM
Thanks for reply.The source code of resource is:

// Microsoft Visual C++ generated resource script.
//
#include "resource.h"

#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"

/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS

/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32

#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//

1 TEXTINCLUDE
BEGIN
"resource.h\0"
END

2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END

3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END

#endif // APSTUDIO_INVOKED


/////////////////////////////////////////////////////////////////////////////
//
// Menu
//

5000 MENU
BEGIN
POPUP "Help"
BEGIN
MENUITEM "About", 140
END
END


/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//

#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
IDD_DIALOG1, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 309
TOPMARGIN, 7
BOTTOMMARGIN, 178
END
END
#endif // APSTUDIO_INVOKED


/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//

IDD_DIALOG1 DIALOGEX 0, 0, 316, 185
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Dialog"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
DEFPUSHBUTTON "OK",IDOK,205,164,50,14
PUSHBUTTON "Cancel",2,259,164,50,14
END

#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////



#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//


/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

Sh@dow
November 4th, 2009, 03:07 PM
fixed.
Dialog procedure must return false value by default:
default:
return FALSE;
Thanks.

VladimirF
November 5th, 2009, 08:16 PM
I understand that your problem is resolved.
Anyway, I am curious if you saw this warning:
warning C4715: 'dproc' : not all control paths return a value