Archived

This topic is now archived and is closed to further replies.

Dialog Boxes WinApi

This topic is 5132 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m trying to make a windowed level editor (d3d) but I''m having trouble getting a dialogbar I''ve created with the vc++ 6 resource editor to even show up. I''ve called DialogBox() and CreateDialog() but it''s not doing anything while a tutorial source code seems to work fine. I can''t find any differences between the sample and my code.
WNDCLASSEX  wndclass;

	wndclass.cbSize        = sizeof (WNDCLASSEX);
    wndclass.style         = CS_HREDRAW | CS_VREDRAW;
    wndclass.lpfnWndProc   = WndProc;
    wndclass.cbClsExtra    = 0;
    wndclass.cbWndExtra    = 0;
    wndclass.hInstance     = hInstance;
    wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION);
    wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW);
    wndclass.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
    wndclass.lpszMenuName  = (LPCSTR)IDR_MENU1;
    wndclass.lpszClassName = "EuEnv Application";
    wndclass.hIconSm       = LoadIcon (NULL, IDI_APPLICATION);

	RegisterClassEx(&wndclass);
	hWnd = CreateWindowEx(
				NULL, //WS_EX_CONTROLPARENT,        // Extended style

                WindowTitle,
                WindowTitle,
				WS_OVERLAPPEDWINDOW,
				0,
				0,
				width,
                height,
				NULL,            // Handle of parent

                NULL,            // Handle to menu

                hInstance,       // Application instance

                NULL);           // Additional data

	char str[10];
	HWND hDialog = CreateDialog (hInstance, MAKEINTRESOURCE(DLG_BOX), hWnd, (DLGPROC)DlgProc);
	sprintf (str, "%d", GetLastError());
	if (!hDialog)
	{
		MessageBox (hWnd, str, "Error", MB_OK);
	}
The GetLastError () gives me 1407 which corresponds to a "Could Not Find Win Class" error on one computer and it gives me a 0 which is "successful" but does not work on either computer. Any help is greatly appreciated. Thank you!

Share this post


Link to post
Share on other sites
I''m not sure what your variable WindowTitle contains. However, that could explain your error if it is not the exact same as
the class name you listed when registering window:

wndclass.lpszClassName = "EuEnv Application";

Ensure that the second param in CreateWindowEx is the exact same as the one above.

And your right, the Visible tag removes the need for ShowWindow for the dialog. But, I did not see a ShowWindow(hWnd , SW_SHOW); for your main window? I pretty positive you need to call:

ShowWindow(hDialog , SW_SHOW);
UpdateWindow(hWnd);

after creation.

Thats all I can see from your source listing however.

Share this post


Link to post
Share on other sites
WindowTitle holds "EuEnv Application" as well that CreateWindowEx () function was a cut and paste from one of my engine functions so that''s why it had WindowTitle instead (oops) sorry
And yup, I call ShowWindow and UpdateWindow afterwards.
This is the Dialog Bar part of the rc file:

DLG_BOX DIALOGEX 0, 0, 123, 263
STYLE WS_CHILD | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_TOOLWINDOW | WS_EX_CLIENTEDGE
CAPTION "Dialog Box"
MENU IDR_MENU1
FONT 8, "MS Sans Serif"
BEGIN
LTEXT "Name",IDC_STATIC,13,15,24,8
EDITTEXT IDC_EDITNAME,37,14,71,12,ES_AUTOHSCROLL
LTEXT "TileWidth",IDC_STATIC,13,28,34,9
LTEXT "TileHeight",IDC_STATIC,13,42,33,9
EDITTEXT IDC_EDITWIDTH,50,27,58,12,ES_AUTOHSCROLL
EDITTEXT IDC_EDITHEIGHT,50,42,57,12,ES_AUTOHSCROLL
LTEXT "NumRows",IDC_STATIC,13,62,35,11
LTEXT "NumCols",IDC_STATIC,13,78,35,11
EDITTEXT IDC_EDITROWS,51,60,56,13,ES_AUTOHSCROLL
EDITTEXT IDC_EDITCOLS,51,77,56,13,ES_AUTOHSCROLL
LTEXT "NumTiles",IDC_STATIC,13,97,35,11
EDITTEXT IDC_EDITNUMTILES,51,95,56,12,ES_AUTOHSCROLL
CONTROL "Spin1",IDC_SPIN1,"msctls_updown32",UDS_ARROWKEYS,32,115,
10,16
EDITTEXT IDC_EDITTILENUM,13,116,19,14,ES_AUTOHSCROLL
EDITTEXT IDC_EDITTILEFILE,44,116,64,14,ES_AUTOHSCROLL
EDITTEXT IDC_EDITTILEX,29,138,23,17,ES_AUTOHSCROLL
EDITTEXT IDC_EDITTILEY,73,137,23,17,ES_AUTOHSCROLL
LTEXT "X",IDC_STATIC,20,146,8,9
LTEXT "Y",IDC_STATIC,64,146,9,8
LTEXT "NumObjs",IDC_STATIC,13,170,35,11
EDITTEXT IDC_EDITNUMOBJS,51,168,56,12,ES_AUTOHSCROLL
CONTROL "Spin1",IDC_SPIN2,"msctls_updown32",UDS_ARROWKEYS,32,188,
12,16
EDITTEXT IDC_EDITOBJNUM,13,190,19,14,ES_AUTOHSCROLL
EDITTEXT IDC_EDITOBJFILE,44,190,64,14,ES_AUTOHSCROLL
EDITTEXT IDC_EDITOBJX,29,211,23,17,ES_AUTOHSCROLL
EDITTEXT IDC_EDITOBJY,73,210,23,17,ES_AUTOHSCROLL
LTEXT "X",IDC_STATIC,20,219,8,9
LTEXT "Y",IDC_STATIC,64,219,9,8
END


If this still doesn''t make any sense, is there a better way of getting dialog input from the user?
Thanks for everything!

Share this post


Link to post
Share on other sites
I'm no prob on the windows resource script. In fact, I had a similar problem before, which I have not found a solution for. But, I have little need for windows dialogs anyway. The problem I was having was that I couldn't use a richedit, or I would get an error in my dialog and it would not show. But I see you are only using the spin control , some static text, and some inputs... Hmm.. I see no problem there.

try changing the WS_CHILD to WS_POPUP or WS_OVERLAPPED.

As for as a better way to get input... Well, if your making a windows app (Such as an level/stats editor or something), win dialogs are the best way. But, if your making a game, I would suggest making a custom GUI control.

If your project is small (under a meg), I wouldn't mind taking a look at it if you zipped it up and sent me the wholle project directory.

[edited by - pjcast on November 29, 2003 6:03:24 PM]

[edited by - pjcast on November 29, 2003 6:13:10 PM]

Share this post


Link to post
Share on other sites
Thanks! I''ve simplified everything to just the window and zipped it and emailed it to you. It''s about 8kb but same problem still so I dunno. It''s a really weird problem. I hope you can find out what''s wrong. Thank you so much again!

Share this post


Link to post
Share on other sites
posting the whole simplified main.cpp here just in case as well...

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

#define WIDTH 640
#define HEIGHT 480
#define g_PI D3DX_PI//3.14159265f

#define CLASSNAME "EuEnv Application"

HWND hWnd;
HWND hDialog;

void Quit (void)
{
PostQuitMessage (0);
}

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam,
LPARAM lParam);
BOOL CALLBACK DlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam);

//*****************************************************************

//WinMain

//*****************************************************************

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR szCmdLine, int iCmdShow)
{
WNDCLASSEX wndclass;

wndclass.cbSize = sizeof (WNDCLASSEX);
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
wndclass.lpszMenuName = (LPCSTR)IDR_MENU1;
wndclass.lpszClassName = CLASSNAME;
wndclass.hIconSm = LoadIcon (NULL, IDI_APPLICATION);

RegisterClassEx(&wndclass);
hWnd = CreateWindowEx(
NULL, //WS_EX_CONTROLPARENT, // Extended style

CLASSNAME,
CLASSNAME,
WS_OVERLAPPEDWINDOW,
0,
0,
WIDTH,
HEIGHT,
NULL, // Handle of parent

NULL, // Handle to menu

hInstance, // Application instance

NULL); // Additional data

char str[10];
hDialog = CreateDialog (hInstance, MAKEINTRESOURCE(DLG_BOX), hWnd, (DLGPROC)DlgProc);
sprintf (str, "%d", GetLastError());
ShowWindow(hDialog, SW_SHOW);
if (!hDialog)
{
MessageBox (hWnd, str, "Error", MB_OK);
}
ShowCursor (TRUE);
ShowWindow(hWnd, SW_SHOW);
UpdateWindow(hWnd);

MSG msg;
while (1)
{
if ( PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) )
{
if ( !GetMessage( &msg, NULL, 0, 0 ) )
{
return msg.wParam;
}
TranslateMessage( &msg );
DispatchMessage( &msg );
}
else
WaitMessage();
}
return 0;
}

//*****************************************************************

//WndProc

//*****************************************************************

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam,
LPARAM lParam)
{
int wmId, wmEvent;
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Menu Selections

switch (wmId)
{
case IDCREATE:
case IDOPEN:
case IDSAVE:
case IDCLOSE:
DestroyWindow (hwnd);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
break;
case WM_PAINT:
return 0;

case WM_KEYUP:
break;

case WM_KEYDOWN:
switch (wParam)
{
case VK_LEFT:
break;
case VK_RIGHT:
break;
case VK_UP:
break;
case VK_DOWN:
break;
case VK_ESCAPE:
Quit ();
break;
}
break;

case WM_LBUTTONDOWN:
break;

case WM_LBUTTONUP:
break;

case WM_RBUTTONDOWN:
break;

case WM_RBUTTONUP:
break;

case WM_DESTROY:
PostQuitMessage (0);
return 0L;
break;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}

BOOL CALLBACK DlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
case WM_INITDIALOG:
// This is where we set up the dialog box, and initialise any default values

//MessageBox (EuEngine.hWnd, "Init", "MSG", MB_OK);

return TRUE;
case WM_COMMAND:
//switch(LOWORD(wParam))

break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
default:
return FALSE;
}
return TRUE;
}

Share this post


Link to post
Share on other sites
Okay, this is weird... I just made a completely new dialog box and it worked. I'm not sure what it is about the last one that made it not work. I'll keep looking into it but hmm...

Edit: found it! It's the spin controls that are causing it to not work! ARGH...

[edited by - RaphaelMun on November 29, 2003 12:57:06 AM]

Share this post


Link to post
Share on other sites