Why doesn't this default button react when Enter is pressed?
Code:CreateWindow (TEXT("button"),TEXT("Ok"), WS_CHILDWINDOW | WS_VISIBLE | BS_DEFPUSHBUTTON, 105, 160, 110, 20, hwnd, (HMENU)IDOK, GetModuleHandle(NULL), NULL);
Why doesn't this default button react when Enter is pressed?
Code:CreateWindow (TEXT("button"),TEXT("Ok"), WS_CHILDWINDOW | WS_VISIBLE | BS_DEFPUSHBUTTON, 105, 160, 110, 20, hwnd, (HMENU)IDOK, GetModuleHandle(NULL), NULL);
Without seeing how you are handling the parent's WM_COMMAND message, it's difficult to say. Assuming your handler is good, are you using IsDialogMessage in your message loop to get default keyboard action?
No, I'm not using IsDialogMessage(). I didnt know it was needed. The main window is created using CreateWindow instead of from a resource file.
For what it's worth:
Code:case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: SendMessage(hwnd,WM_CLOSE,0,0); break; default: break; } return 0;
Your WM_COMMAND handler looks fine. Put a call to IsDialogMessage in your message loop and it should work as you intended. It doesn't matter how the control/window is created; if you want default dialog keyboard behaviour you will need to use IsDialogMessage (or do it all manually).
Why are you using GetModualHandle()?CreateWindow (TEXT("button"),TEXT("Ok"),
WS_CHILDWINDOW | WS_VISIBLE | BS_DEFPUSHBUTTON,
105, 160, 110, 20, hwnd, (HMENU)IDOK, GetModuleHandle(NULL),NULL);
You don't need a handle to a file,you need the HINSTANCE for the main window. This is what you should be usingThe GetModuleHandle function returns a module handle for the specified module if the file has been mapped into the address space of the calling process.
HMODULE GetModuleHandle(LPCTSTR lpModuleName)
lpModuleName
Pointer to a null-terminated string that contains the name of the module (either a .DLL or .EXE file). If the filename extension is omitted, the default library extension .DLL is appended. The filename string can include a trailing point character (.) to indicate that the module name has no extension. The string does not have to specify a path. When specifying a path, be sure to use backslashes (\), not forward slashes (/). The name is compared (case independently) to the names of modules currently mapped into the address space of the calling process.
If this parameter is NULL, GetModuleHandle returns a handle to the file used to create the calling process.
Now I may be mistaken but I am pretty sure GetModualHandle is not what you need, but I could be wrong. I never seen this used before so that is why I am questioning it.Code:CreateWindow (TEXT("button"),TEXT("Ok"),WS_CHILDWINDOW | WS_VISIBLE | BS_DEFPUSHBUTTON, 105, 160, 110, 20, hwnd,(HMENU)IDOK, (HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE), NULL);
Last edited by Dohojar; 07-15-2003 at 08:54 PM.
Dohojar Moajbuj
Time is the greatest teacher, too bad it kills all its students
I don't know why I'm using GetModule(), but it does works. You probabley are right that I have an error and will correct it.
Thanks again for the help.
Lambs4: Use IsDialogMessage in your message loop as I have previously described as it will give you your intended functionality unless there is some other error in your code.
Because an HMODULE is the same basic type as an HANDLE and an HINSTANCE. Using GetModuleHandle(0) returns the application instance - try it for yourself by comparing its value with that passed to WinMain or returned from GetWindowLong and you will see that they are the same. I assure you the use of GetModuleHandle(0) in this way is very common.Originally posted by Dohojar
Why are you using GetModualHandle()?
See one can learn something new everyday. After re-reading microsoft's documentation on it for the 5th time, I was starting to wonder if they were the same. Thanks for the info. I will try using that the next app I make. sure is a lot easier to type. So the return from GetModualHandle() doesn't need to be cast either then?
Dohojar Moajbuj
Time is the greatest teacher, too bad it kills all its students