Jump to content
  • Advertisement
Sign in to follow this  
ukdeveloper

RESOLVED: Yet another Win32 Dialog question

This topic is 4772 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

Hi all, I'm posting in response to a previous thread I had regarding Win32 dialogs not behaving properly. I fixed that, but now there's another problem. The dialogue loads fine at startup, and the OK button I put in works. But the tab button, despite working in the resource editor, doesn't work. It just makes the standard Windows XP system sound and the cursor won't move to the next textbox. Also, the X button on the toolbar up top won't work. I can click on it, it goes down, but doesn't close the dialogue. I've got the code for the whole app thus far here:
#include <iostream>
#include <windows.h>
#include "resource.h"

HWND LogonBox;
MSG MsgPump;

BOOL CALLBACK LogonProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam);

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nShowCmd)
{

	CreateDialog(hInstance,MAKEINTRESOURCE(ICARUS_LOGONFORM),LogonBox,(DLGPROC)LogonProc);

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

	return MsgPump.wParam;

}

BOOL CALLBACK LogonProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
{

	switch(msg)
	{

	case WM_INITDIALOG:
		break;
	
	case WM_COMMAND:
		{
			switch(LOWORD(wParam))
			{
			case LOGONFORM_LOGON:
				PostQuitMessage(0);
				break;
			}
		}
		
	
	break;

	case WM_DESTROY:
	PostQuitMessage(0);

	case WM_CLOSE:
		EndDialog(LogonBox,TRUE);
		break;

	default:

	return FALSE;
	}


return TRUE;
	
}


Here's resource.h:
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by LogonForm.rc
//
#define ICARUS_LOGONFORM                101
#define LOGONFORM_USERNAME              1000
#define LOGONFORM_PASSWORD              1001
#define LOGONFORM_LOGON                 1003
#define LOGONFORM_FORGOTPASSLINK        1005
#define LOGONFORM_NEWACCLINK            1006

// Next default values for new objects
// 
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE        102
#define _APS_NEXT_COMMAND_VALUE         40001
#define _APS_NEXT_CONTROL_VALUE         1007
#define _APS_NEXT_SYMED_VALUE           101
#endif
#endif


And here's LogonForm.rc:
//Microsoft Developer Studio 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.K.) resources

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

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

ICARUS_LOGONFORM DIALOG DISCARDABLE  0, 0, 320, 159
STYLE DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_VISIBLE | WS_CAPTION | 
    WS_SYSMENU
CAPTION "Log on to the Icarus Network"
FONT 8, "Tahoma"
BEGIN
    EDITTEXT        LOGONFORM_USERNAME,103,70,157,12,ES_AUTOHSCROLL
    EDITTEXT        LOGONFORM_PASSWORD,103,85,157,12,ES_PASSWORD | 
                    ES_AUTOHSCROLL
    PUSHBUTTON      "Log on",LOGONFORM_LOGON,86,114,160,14
    LTEXT           "Forgot your password?",LOGONFORM_FORGOTPASSLINK,7,145,
                    75,8
    LTEXT           "Create a new Icarus Network account",
                    LOGONFORM_NEWACCLINK,190,145,125,8
    LTEXT           "Username:",IDC_STATIC,62,71,39,11
    GROUPBOX        "Enter your username and password to log on",IDC_STATIC,
                    51,56,218,48,BS_CENTER
    LTEXT           "Password:",IDC_STATIC,62,86,39,11
END


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

#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO DISCARDABLE 
BEGIN
    ICARUS_LOGONFORM, DIALOG
    BEGIN
        TOPMARGIN, 7
    END
END
#endif    // APSTUDIO_INVOKED


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

1 TEXTINCLUDE DISCARDABLE 
BEGIN
    "resource.h\0"
END

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

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

#endif    // APSTUDIO_INVOKED

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



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


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


I'm using VC++ 6's resource editor. But I'm then loading the resources into VC++ 2005 BETA 2 and coding in there, if it helps you to know. So, what's causing Tab and the X button to not work? I think it's to do with my CallBack function, but I'm new to Win32 so I couldn't really say. Thanks in advance for any advice, ukdeveloper. [Edited by - ukdeveloper on July 27, 2005 10:32:53 AM]

Share this post


Link to post
Share on other sites
Advertisement
You need to call IsDialogMessage in your message pump to get the tab handling (among other things). The neat thing about this design is that you can actually use IsDialogMessage to get the same functionality for non-dialog windows too.

So try something like this instead:
HWND DialogInstance = CreateDialog(hInstance,MAKEINTRESOURCE(ICARUS_LOGONFORM),LogonBox,(DLGPROC)LogonProc);

while( GetMessage(&MsgPump, NULL, 0, 0) )
{
if(!IsDialogMessage(DialogInstance, &MsgPump))
{
TranslateMessage(&MsgPump);
DispatchMessage(&MsgPump);
}
}

Share this post


Link to post
Share on other sites
OK, that worked, but:

1) I'm still getting the Windows standard sound when tabbing between the boxes (although I can now tab between them, and back again).

2) Clicking the X button makes the form invisible, but the program keeps running. Clicking the X button should end the program entirely.

3) If I type something into either text box, it replicates itself 4 times. So if I type e, I get eeee in the textbox.


If I can fix these problems then I'm onto something I think.

Share this post


Link to post
Share on other sites
Okay.. I read through some of the code.

First of all you shouldn't call EndDialog on modeless dialogs, a simple DestroyWindow is enough. Overriding the default WM_CLOSE handler like that looks odd too, the default should be enough though. So try calling DestroyWindow and PostQuitMessage in your WM_DESTROY handler isntead.

I don't know why you're getting multiple keystrokes though. I assume that the messages are is sent more than once somehow but I can't figure out why.

I suggest that you try copying some dialog tutorial and gradually transform it into your current program instead. It's a method that usually works for me when I encounter mysterious API errors.

Share this post


Link to post
Share on other sites
Quote:
Original post by doynax
I don't know why you're getting multiple keystrokes though. I assume that the messages are is sent more than once somehow but I can't figure out why.


Anybody know?

I'm sick of restarting simple projects over and over just because of one niggling problem. I always get one per project at least, causing a restart.

Share this post


Link to post
Share on other sites
Quote:
Original post by ukdeveloper
bumpity bump

It's a strange problem my program's got.
I just tried it myself (in VC6 on Win2k3) and it seems to work just fine..
It's a long shot but you could try to use VC6's resource compiler to produce the dialog template.
And post your new message pump code too, just in case you missed something.

Another thing too.. You've got a global LogonBox variable (automatically initialized to NULL) which is later sent to as the parent window when creating the dialog. There's no harm in it right now but it may become problematic later on if you're not careful.

Share this post


Link to post
Share on other sites
OK, it still had the same problem for me in VC6, WinXP Home SP2. The resource was originally created using the VC6 resource editor.

Here's the message pump:

while( GetMessage(&MsgPump, NULL, 0, 0) )
{
if(!IsDialogMessage(LogonBox,&MsgPump));
{
TranslateMessage(&MsgPump);
DispatchMessage(&MsgPump);
}
}

return MsgPump.wParam;



Hope that helps.

Share this post


Link to post
Share on other sites
FIXED IT:

I commented out TranslateMessage() and DispatchMessage(), and it worked fine.

I'm not overly concerned because this dialog only gets used the once, so I don't need a rocksteady Messaging system for it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!