I have this weird problem with keyboard checking.
Neither the GetKeyState() function works nor can i use the WM_KEYDOWN message.
What can be wrong?
Are there any libraries or something that i need to include???
I have this weird problem with keyboard checking.
Neither the GetKeyState() function works nor can i use the WM_KEYDOWN message.
What can be wrong?
Are there any libraries or something that i need to include???
hmm, thats odd can you post your code/errors please
TNT
You Can Stop Me, But You Cant Stop Us All
Im not getting any errors. But when i click a key nothing happens.
I just did a WM_KEYDOWN case in my dialog processor with a messagebox as the only code in it.
But nothing happens....
Code:case WM_KEYDOWN: MessageBox(hwndDlg, "Go shopping", "Shops", MB_OK); return TRUE; break;
Hmm very strange, that code is correct and works fine with me, so i recon all that it can be is a problem with the handle to your dlg...
So i think you need to do some checking for instance replace the msgbox with MessageBeep(0); or somthing else and see if you can get that to execute when you press a key. If it does then i think theres somthing wrong with your handle to the dialog. If it still dont work then i dont know , If it works then use FindWindow() with your applications details and it will return a hopefully working handle. I would also to advise you to do some error checking:
Code:if(hWnd != NULL) { //do your code } else { //do somthing else }
I hope that helps,
TNT
TNT
You Can Stop Me, But You Cant Stop Us All
Hmm i tried making another program with a real registered window class instead of just a dialog box. And that worked fine.
Heres the complete prog:
EDIT:: Removed some unnecessary code (Command Proc)Code:#include <windows.h> #include <windowsx.h> #include <tchar.h> #include <stdio.h> #include <stdlib.h> #include "sunrsc.h" int hp; char name[50]; char race[50]; int gc; int Str = 0; char SString[2]; int Cha = 0; char CString[2]; int Dex = 0; char DString[2]; int Int = 0; char IString[2]; int ppool = 12; char PString[3]; int exswitch; int exrand; bool keys[256]; HWND dlgHWnd; BOOL CALLBACK DialogProc(HWND hwndDlg,UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_INITDIALOG : HWND EditHandle; SetDlgItemText(hwndDlg, ID_NAME, name); SetDlgItemText(hwndDlg, ID_RACE, race); sprintf(PString, "%i", ppool); SetDlgItemText(hwndDlg, ID_CPPOOL, PString); EditHandle = GetDlgItem(hwndDlg, ID_NAME); SetFocus(EditHandle); SendMessage(EditHandle, EM_SETSEL, 0,-1); return 0; break; case WM_CLOSE: EndDialog(hwndDlg, 0); return TRUE; break; case WM_COMMAND: return MainDialog_OnCommand(hwndDlg, LOWORD(wParam), HIWORD(wParam), (HWND)lParam); } switch(wParam) { case VK_UP: EndDialog(hwndDlg, 0); } return FALSE; } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { DialogBox(hInstance, MAKEINTRESOURCE(400), dlgHWnd, DialogProc); return 0; }
Last edited by ErionD; 04-20-2002 at 07:50 AM.
dlgHWnd is never initialised to a value or given one in the code.
But is also a param in the callback ie global and local in the callback function.
DialogBox(hInstance, MAKEINTRESOURCE(400), dlgHWnd, DialogProc);
should be
iKill=DialogBox(hInstance, MAKEINTRESOURCE(400), NULL, DialogProc);//there is no parent to this window
WM_KEYUP is a msg in itself. Testing all unprocessed msg's for one with the up arrow pressed is not the best code. Not to mention you have missed the 'break' after the only case in the switch.
"Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
Friedrich Nietzsche
"I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
George Best
"If you are going through hell....keep going."
Winston Churchill