Skip to main content
GameDev.net gamedev.net
🔒 Locked

Dialog Problem

Started by jonnii May 24, 2002 at 1:14 PM 10 replies 350+ views
Original Post
jonnii
jonnii
Hi, I''ve created my dialog in visual studio and i want to display it from my code. I''m using this function: DialogBox(theApp.m_hInstance, (LPCTSTR) IDD_CONSOLE, NULL, ConsoleDlgProc); The only problem is that apparently IDD_CONSOLE is not declared. Also, i have named the resource IDD_CONSOLE in the properties and i openened the resource file and its named right in there too.. what should i do?? thanks -jonnii
-jonnii=========jon@voodooextreme.comwww.voodooextreme.com
pafcu
pafcu
Have you included resource.h or whatever the header file is called where IDD_CONSOLE is #defined?

--
So Long To Red Dye #2
-- So Long To Red Dye #2
Soulkeeper
Soulkeeper
As an extension to the original question...

I'm working on a map editor and I want to have a dialog box with options for adding certain tiles to the map.

I've drawn up the dialog in the resource editor (called IDD_DIALOG) and included the resource.h that was generated into my winmain.cpp (contains winmain, wndproc, dlgproc)

When I try to create the dialog it fails for some reason (not really sure why)

This is the code I'm using to try and make the dialog:

if ((g_hDlg = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_DIALOG), hWnd, DlgProc)) == NULL)
{
MessageBox(NULL, "dlg failed", "d", MB_OK);
//return NULL;
}

It seems I always have a little bit of trouble when making dialogs, I've gotten it work before with a different program that just ran as a dialog box (an item editor for a previous game). But, This program has the main window that shows the map and the dialog and now it just won't work.

I'm not sure what I'm doing wrong. Any help would be appreciated.

Soulkeeper

I'm learning, just like the best of us...


[edited by - Soulkeeper on May 24, 2002 4:28:37 PM]
I'm learning, just like the best of us...Ok, now assume a spherical cow... :)
Soulkeeper
Soulkeeper
Ok, I tried some of that and it still doesn't work.

Here's some code snippets

DlgProc:

BOOL CALLBACK DlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_INITDIALOG:
{
// Do stuff to init the dialog
return FALSE;
}
case WM_COMMAND:
{
return TRUE;
}
}

return FALSE;
}


A repeat of the creation code:

if ((g_hDlg = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_DIALOG), hWnd, DlgProc)) == NULL)
{
MessageBox(NULL, "dlg failed", "d", MB_OK);
//return NULL;
}


I looked at the msdn docs and all it said about the DlgProc was that it had to return nonzero or zero in WM_INITDIALOG to set the keyboard focus to a control you specify or the default control respectively. Still, that doesn't help with why it doesn't create the instance of the dialog.

[edited by - Soulkeeper on May 24, 2002 5:35:54 PM]
I'm learning, just like the best of us...Ok, now assume a spherical cow... :)
IndirectX
IndirectX
Are you using common controls or other similar oddities? Remember to call InitCommonControls[Ex] if you''re using them.
---visit #directxdev on afternet <- not just for directx, despite the name
Chem0sh
Chem0sh
Try using GetLastError and FormatMessaget to see what''s going on.

From MSDN:

GetLastError
The GetLastError function retrieves the calling thread''s last-error code value. The last-error code is maintained on a per-thread basis. Multiple threads do not overwrite each other''s last-error code.

DWORD GetLastError(VOID);
Parameters
This function has no parameters.

Return Values
The return value is the calling thread''s last-error code value. Functions set this value by calling the SetLastError function. The Return Value section of each reference page notes the conditions under which the function sets the last-error code.

Windows 95/98/Me: Functions that are actually implemented in 16-bit code do not set the last-error code. You should ignore the last-error code when you call these functions. They include window management functions, GDI functions, and Multimedia functions.

Remarks
To obtain an error string for system error codes, use the FormatMessage function. For a complete list of error codes, see System Error Codes.

-----------------------------------------------

FormatMessage
The FormatMessage function formats a message string. The function requires a message definition as input. The message definition can come from a buffer passed into the function. It can come from a message table resource in an already-loaded module. Or the caller can ask the function to search the system''s message table resource(s) for the message definition. The function finds the message definition in a message table resource based on a message identifier and a language identifier. The function copies the formatted message text to an output buffer, processing any embedded insert sequences if requested.

DWORD FormatMessage(
DWORD dwFlags, // source and processing options
LPCVOID lpSource, // message source
DWORD dwMessageId, // message identifier
DWORD dwLanguageId, // language identifier
LPTSTR lpBuffer, // message buffer
DWORD nSize, // maximum size of message buffer
va_list *Arguments // array of message inserts
);

-----------------------------------------------------

See MSDN for full info on these functions.

/*=========================================*/
/* Chem0sh */
/* Lead Software Engineer & Tech Support */
/* http://www.eFaces.biz */
/*=========================================*/
/*=========*/
/*=========================================// Chem0sh// Lead Software Engineer & Tech Support// http://www.eFaces.biz=========================================*/
jonnii
jonnii
i did include the header file but that hasn''t resolved the problem... i''m still playing with it, but i''m new to visual studio .net and have had a few problems with it...

i''ll fiddle with it a bit and then when i format in a few days i''ll see if a fresh install of it flushes out the problem...

nm, thanks for your help anyway =)

thanks

-jonnii
-jonnii=========jon@voodooextreme.comwww.voodooextreme.com
Soulkeeper
Soulkeeper
Ok, I did FormatMessage with GetLastError.

It says I have an invalid window handle.

Now, the thing that I don't get is that if I had an invalid window handle then the main window wouldn't have even been created right? Well, it was and everywhere else (DirectX init after creating the dialog) I use the hWnd (supposedly invalid) works just fine.

So, what the heck is going on here?

Here's my winmain code:


int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int nCmdShow)
{
// Initialize the tracer (to help debug fullscreen apps)
TraceInit();

BOOL bDone = FALSE;

WNDCLASSEX winclass; // Window class
HWND hWnd; // Generic window handle
MSG msg; // Generic message

// First fill in the window class stucture
winclass.cbSize = sizeof(WNDCLASSEX);
winclass.style = CS_DBLCLKS | CS_OWNDC |
CS_HREDRAW | CS_VREDRAW;
winclass.lpfnWndProc = WndProc;
winclass.cbClsExtra = 0;
winclass.cbWndExtra = 0;
winclass.hInstance = hInstance;
winclass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(ID_ICON));
winclass.hCursor = LoadCursor(NULL, IDC_ARROW);
winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
winclass.lpszMenuName = NULL;
winclass.lpszClassName = APPNAME;
winclass.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(ID_ICON));

// Register the window class
if (!RegisterClassEx(&winclass))
{
return NULL;
}

// Create the window
if (!(hWnd = CreateWindowEx(NULL, // Extended style
APPNAME, // Class
APPNAME, // Title
(g_normFull?WS_POPUP:WS_OVERLAPPED | // If fullscreen, then do only WS_POPUP
WS_CAPTION | WS_SYSMENU | // Otherwise, make a window that
WS_MINIMIZEBOX) | WS_VISIBLE | // Can't be sized manually
WS_CLIPCHILDREN, // So the dialog box doesn't get drawn over
GetSystemMetrics(SM_CXSCREEN)/2-320, // Initial X
GetSystemMetrics(SM_CYSCREEN)/2-240, // Initial Y
SCREEN_WIDTH+(g_normFull?0:6), // Initial width +6 for the border
SCREEN_HEIGHT+(g_normFull?0:44), // Initial height +44 for the border, caption, and menu
NULL, // Handle to parent
NULL, // Handle to menu
hInstance, // Instance of this application
NULL))) // Extra creation parms
{
return NULL;
}

// Check if the hWnd is valid
if (hWnd == NULL)
return 0;

// Load the menu
HMENU hmenuhandle = LoadMenu(hInstance, "Menu");

// Then, attach the menu to the window
SetMenu(hWnd, hmenuhandle);

// Save hinstance in global
g_hInstance = hInstance;

// Store our main window handle in a global variable
g_hWnd = hWnd;

// Show our main window
ShowWindow(hWnd, nCmdShow);

// Now, create a dialog so we can edit maps
if ((g_hDlg = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_DIALOG), hWnd, DlgProc)) == NULL)
{
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
// Process any inserts in lpMsgBuf.
// ...
// Display the string.
MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION );
//Free the buffer.
LocalFree( lpMsgBuf );
}

ShowWindow(g_hDlg, SW_SHOW);

// Initialize stuff to start the game
GameInit();

// Main message loop
while(!bDone)
{
// Test if there is a message in queue, if so get it
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
if (g_hDlg == NULL || !IsDialogMessage(g_hDlg, &msg))
{
// Test if this is a quit
if (msg.message == WM_QUIT)
bDone = TRUE;

// Translate any accelerator keys
TranslateMessage(&msg);
// Send the message to the window proc
DispatchMessage(&msg);
}
}
if (!bDone && !g_paused)
{
if (lpDD7 != NULL)
{
// Frame drawing goes here
DrawNextFrame();
}
}
Sleep(1);
}
// Clean up: unregister our main window class
UnregisterClass(APPNAME, hInstance);

// Terminate the tracer
TraceTerm();

// Return with the standard return code (from PostQuitMessage)
return msg.wParam;
}


[edited by - Soulkeeper on May 24, 2002 9:02:05 PM]

[edited by - Soulkeeper on May 24, 2002 9:03:16 PM]
I'm learning, just like the best of us...Ok, now assume a spherical cow... :)
IndirectX
IndirectX
What if you try using an empty dialog box, and/or moving the dialogbox code to the very beginning of WinMain for testing?
---visit #directxdev on afternet <- not just for directx, despite the name

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.