Skip to main content
gamedev.net
🔒 Locked

Default Button problems

Started by Kars 8 replies 650+ views
Original Post
Kars
Kars
I am useing VC++ to create a top score dialog box for my game. Even though I have the button set to Default Button, pressing Enter key does not work. I also used Spy++ to try and find a message that I could use to intercept an Enter key press, but no messages are sent to either the parent or dialog box when any key is pressed. Any suggestions? Thanks, Kars
KarsQ: What do you get if you cross a tsetse fly with a mountain climber?A: Nothing. You can't cross a vector with a scalar.
NaliXL
NaliXL
"The button"? You mean an OK button on your highscore-dialog? Have you tried clicking it with your mouse? Does that give you the right results? If yes, set the focus to the button manually, using the TAB-key on your keyboard. Then press enter. Does it work then?

In other words : try things out, and if you post here, you might want to describe more precise what you''re doing.
Newbie programmers think programming is hard.Amature programmers think programming is easy.Professional programmers know programming is hard.
Kars
Kars
I am trying to set the dialog box up so that if the enter key is pressed while you are in the dialog box, it is the same as ckicling the ok button.

This is what I have tried so far.

Tabing to the button and pressing enter, does not work.
Clicking the button, does work.
Pressing the space bar allways works, but not sure why.
I tried to set the focus programaticly under the WM_INITDIALOG message, does not work.
I also tried setting various properties on the button in the resource editor, didnt work for me.
I also spent about 2 hours last night tried to find some documentation in MSDN on this. So either it is not in MSDN or more likely I am not searching on the correct words.

Here is the code from my dialog box:

  
BOOL CALLBACK TopScoreDialogBox( HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam )
{
HWND TempHwnd;
char Score[25];
char Level[25];
int i;

switch( message )
{
case WM_INITDIALOG:

for( i = 0; i < 10; i++ )
{
itoa( TopScores[i].Score, Score, 10 );
itoa( TopScores[i].Level, Level, 10 );
SetDlgItemText(hwnd, DlgIDs[i][NAME],
TopScores[i].Name);
SetDlgItemText(hwnd, DlgIDs[i][SCORE],
Score );
SetDlgItemText(hwnd, DlgIDs[i][LEVEL],
Level );
if( TopPosition == i )
{
TempHwnd = GetDlgItem( hwnd, DlgIDs[i][NAME] );
SendMessage( TempHwnd, EM_SETREADONLY, FALSE, 0 );
}
}

return 1;

case WM_COMMAND:
switch( LOWORD(wParam) )
{
case IDOK:

GetDlgItemText( hwnd, DlgIDs[TopPosition][NAME],
TopScores[TopPosition].Name, 24 );

EndDialog( hwnd, 0 );
return 1;
}
}
return 0;

}


I am out of ideas on what to do or look for on this. Any advice would be appreciated.

Kars
KarsQ: What do you get if you cross a tsetse fly with a mountain climber?A: Nothing. You can't cross a vector with a scalar.
Kars
Kars
I am trying to set the dialog box up so that if the enter key is pressed while you are in the dialog box, it is the same as ckicling the ok button.

This is what I have tried so far.

Tabing to the button and pressing enter, does not work.
Clicking the button, does work.
Pressing the space bar allways works, but not sure why.
I tried to set the focus programaticly under the WM_INITDIALOG message, does not work.
I also tried setting various properties on the button in the resource editor, didnt work for me.
I also spent about 2 hours last night tried to find some documentation in MSDN on this. So either it is not in MSDN or more likely I am not searching on the correct words.

Here is the code from my dialog box:

  
BOOL CALLBACK TopScoreDialogBox( HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam )
{
HWND TempHwnd;
char Score[25];
char Level[25];
int i;

switch( message )
{
case WM_INITDIALOG:

for( i = 0; i < 10; i++ )
{
itoa( TopScores[i].Score, Score, 10 );
itoa( TopScores[i].Level, Level, 10 );
SetDlgItemText(hwnd, DlgIDs[i][NAME],
TopScores[i].Name);
SetDlgItemText(hwnd, DlgIDs[i][SCORE],
Score );
SetDlgItemText(hwnd, DlgIDs[i][LEVEL],
Level );
if( TopPosition == i )
{
TempHwnd = GetDlgItem( hwnd, DlgIDs[i][NAME] );
SendMessage( TempHwnd, EM_SETREADONLY, FALSE, 0 );
}
}

return 1;

case WM_COMMAND:
switch( LOWORD(wParam) )
{
case IDOK:

GetDlgItemText( hwnd, DlgIDs[TopPosition][NAME],
TopScores[TopPosition].Name, 24 );

EndDialog( hwnd, 0 );
return 1;
}
}
return 0;

}


I am out of ideas on what to do or look for on this. Any advice would be appreciated.

Kars
KarsQ: What do you get if you cross a tsetse fly with a mountain climber?A: Nothing. You can't cross a vector with a scalar.
SilentCoder
SilentCoder
Are you sure you created the button correctly? Show us the part of your resource file where the button is created.
ELS1
ELS1
trap the VK_RETURN message
GoofProg
GoofProg
ELS1 is right. you should trap the return message by using something like
case WM_CHAR:
switch(wparam)
{
......
case VK_RETURN:
SendMessage(yourbuttonhwnd,.....);
.....
just send the mouse button press message(forgot the constant name) to the button.. that should clear things up

The nightmare travels across the cosmos with his burning mane.  The trail of ash that is produced. ?Have a nice day!?
Kars
Kars
Here is the dialog box as it appears in the resource file.

I also tried traping the VK_ENTER witht the WM_CHAR and WM_KEYDOWN messages but thats not working either. Again Spy++ is not showing any messages for either the parent window or the dialog box when I press any key.

Any other suggestions?


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

IDD_TOP_SCORE_DIALOG DIALOGEX 0, 0, 239, 202
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION
CAPTION "Top Scores"
FONT 8, "MS Sans Serif"
BEGIN
LTEXT "First Place",IDC_STATIC,7,24,34,8
LTEXT "Second Place",IDC_STATIC,7,39,46,8
LTEXT "Third Place",IDC_STATIC,7,54,37,8
LTEXT "Fourth Place",IDC_STATIC,7,69,41,8
LTEXT "Fifth Place",IDC_STATIC,7,84,34,8
LTEXT "Sixth Place",IDC_STATIC,7,99,36,8
LTEXT "Seventh Place",IDC_STATIC,7,114,48,8
LTEXT "Eighth Place",IDC_STATIC,7,129,41,8
LTEXT "Ninth Place",IDC_STATIC,7,144,38,8
LTEXT "Tenth Place",IDC_STATIC,7,159,40,8
LTEXT "Name",IDC_STATIC,64,7,20,8
EDITTEXT IDC_FIRST_NAME,64,21,98,14,ES_MULTILINE | ES_AUTOHSCROLL |
ES_READONLY
EDITTEXT IDC_SECOND_NAME,64,36,98,14,ES_MULTILINE |
ES_AUTOHSCROLL | ES_READONLY
EDITTEXT IDC_THIRD_NAME,64,51,98,14,ES_MULTILINE | ES_AUTOHSCROLL |
ES_READONLY
EDITTEXT IDC_FOURTH_NAME,64,66,98,14,ES_MULTILINE |
ES_AUTOHSCROLL | ES_READONLY
EDITTEXT IDC_FIFTH_NAME,64,81,98,14,ES_MULTILINE | ES_AUTOHSCROLL |
ES_READONLY
EDITTEXT IDC_SIXTH_NAME,64,96,98,14,ES_MULTILINE | ES_AUTOHSCROLL |
ES_READONLY
EDITTEXT IDC_SEVENTH_NAME,64,111,98,14,ES_MULTILINE |
ES_AUTOHSCROLL | ES_READONLY
EDITTEXT IDC_EIGHTH_NAME,64,126,98,14,ES_MULTILINE |
ES_AUTOHSCROLL | ES_READONLY
EDITTEXT IDC_NINTH_NAME,64,141,98,14,ES_MULTILINE |
ES_AUTOHSCROLL | ES_READONLY
EDITTEXT IDC_TENTH_NAME,64,156,98,14,ES_MULTILINE |
ES_AUTOHSCROLL | ES_READONLY
LTEXT "Score",IDC_STATIC,164,7,20,8
EDITTEXT IDC_FIRST_SCORE,164,21,39,14,ES_AUTOHSCROLL |
ES_READONLY
EDITTEXT IDC_SECOND_SCORE,164,36,39,14,ES_AUTOHSCROLL |
ES_READONLY
EDITTEXT IDC_THIRD_SCORE,164,51,39,14,ES_AUTOHSCROLL |
ES_READONLY
EDITTEXT IDC_FOURTH_SCORE,164,66,39,14,ES_AUTOHSCROLL |
ES_READONLY
EDITTEXT IDC_FIFTH_SCORE,164,81,39,14,ES_AUTOHSCROLL |
ES_READONLY
EDITTEXT IDC_SIXTH_SCORE,164,96,39,14,ES_AUTOHSCROLL |
ES_READONLY
EDITTEXT IDC_SEVENTH_SCORE,164,111,39,14,ES_AUTOHSCROLL |
ES_READONLY
EDITTEXT IDC_EIGHTH_SCORE,164,126,39,14,ES_AUTOHSCROLL |
ES_READONLY
EDITTEXT IDC_NINTH_SCORE,164,141,39,14,ES_AUTOHSCROLL |
ES_READONLY
EDITTEXT IDC_TENTH_SCORE,164,156,39,14,ES_AUTOHSCROLL |
ES_READONLY
LTEXT "Level",IDC_STATIC,203,7,18,8
EDITTEXT IDC_FIRST_LEVEL,205,21,13,14,ES_AUTOHSCROLL |
ES_READONLY | ES_NUMBER,WS_EX_TRANSPARENT
EDITTEXT IDC_SECOND_LEVEL,205,36,13,14,ES_AUTOHSCROLL |
ES_READONLY | ES_NUMBER,WS_EX_TRANSPARENT
EDITTEXT IDC_THIRD_LEVEL,205,51,13,14,ES_AUTOHSCROLL |
ES_READONLY | ES_NUMBER,WS_EX_TRANSPARENT
EDITTEXT IDC_FOURTH_LEVEL,205,66,13,14,ES_AUTOHSCROLL |
ES_READONLY | ES_NUMBER,WS_EX_TRANSPARENT
EDITTEXT IDC_FIFTH_LEVEL,205,81,13,14,ES_AUTOHSCROLL |
ES_READONLY | ES_NUMBER,WS_EX_TRANSPARENT
EDITTEXT IDC_SIXTH_LEVEL,205,96,13,14,ES_AUTOHSCROLL |
ES_READONLY | ES_NUMBER,WS_EX_TRANSPARENT
EDITTEXT IDC_SEVENTH_LEVEL,205,111,13,14,ES_AUTOHSCROLL |
ES_READONLY | ES_NUMBER,WS_EX_TRANSPARENT
EDITTEXT IDC_EIGHTH_LEVEL,205,126,13,14,ES_AUTOHSCROLL |
ES_READONLY | ES_NUMBER,WS_EX_TRANSPARENT
EDITTEXT IDC_NINTH_LEVEL,205,141,13,14,ES_AUTOHSCROLL |
ES_READONLY | ES_NUMBER,WS_EX_TRANSPARENT
EDITTEXT IDC_TENTH_LEVEL,205,156,13,14,ES_AUTOHSCROLL |
ES_READONLY | ES_NUMBER,WS_EX_TRANSPARENT
DEFPUSHBUTTON "OK",IDOK,182,181,50,14,BS_DEFPUSHBUTTON
END

KarsQ: What do you get if you cross a tsetse fly with a mountain climber?A: Nothing. You can't cross a vector with a scalar.
Fragmo
Fragmo
from msdn on WM_INITDIALOG... "The control to receive the default keyboard focus is always the first control in the dialog box that is visible, not disabled, and that has the WS_TABSTOP style. When the dialog box procedure returns TRUE, the system checks the control to ensure that the procedure has not disabled it. If it has been disabled, the system sets the keyboard focus to the next control that is visible, not disabled, and has the WS_TABSTOP. "

so you have 2 options, in the resource editor change the tab index on the ok button to be #1 (i believe its in the menu Layout/TabOrder) and return 1 from WM_INITDIALOG OR you could return 0 and set the focus programmatically in WM_INITDIALOG.
Kars
Kars
Fixed the problem. I was creating the dialog box with CreateDialog, but when I changed to DialogBox it works fine. If any one wants to venture a guess as to why that fixed the problem, I''d like to hear it.

Thanks,
Kars
KarsQ: What do you get if you cross a tsetse fly with a mountain climber?A: Nothing. You can't cross a vector with a scalar.

Topic Locked

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

Sign in to reply to this topic.