switch(uMsg)
{
case WM_KEYDOWN:
//Fresh pressed //<-- We don't get here
TheScene.HandlePresses(wParam);
break;
case WM_KEYUP:
//Fresh released //<-- or here
TheScene.HandleReleases(wParam);
break;
...
WM_KEYDOWN doesn't gets triggered
Hi!
I've got a problem: The Keyboard wrapper I wrote was working before, but now it doesn't do anymore! When I put a breakpoint into the "case WM_KEYDOWN" of my MsgProc, and I press a key, just nothing happens. There is also NO other control which could steal the focus. There is just my self written Direct2D browser (Which is painted on the glassy client area) and a static frame control for the viewport. You also should know, that WM_LBUTTONDOWN, WM_RBUTTONDOWN/Up/DblClick/etc... is still working...
Any ideas?
Even if no other window should be able to have the focus, I would start by trying to use SetFocus(hWnd) in WM_LBUTTONDOWN and then try pressing a key again, just to be sure.
I had some buttons around there before, so I did this allready:
case WM_LBUTTONDOWN: SetFocus(hDlg); GetCursorPos(&p); ScreenToClient(MainViewportHW,&p); GetClientRect(MainViewportHW,&vpr); if(PointInRect(&p,&vpr)) //Only tell the engine, when we are in the viewport { TheScene.PressedMouseButtons[0]=true; TheScene.HandleMouseButtonPresses(1,wParam); if(wParam & MK_CONTROL) //TODO: Put out this crappy code { TheScene.PressedKeys[VK_CONTROL]=true; } } break;
Is the WM_LBUTTONDOWN and the WM_KEYDOWN message in the same WndProc/DlgProc, and is hDlg the HWND passed as a parameter to it?
Yes, it is. Here is the whole thing:
Hm.. I really need to clean it up ;)
//--------------------------------------------------------------------------------------// Handle messages to the application//--------------------------------------------------------------------------------------LRESULT CALLBACK MainMsgProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam){ RECT MainWnd = {0,0,0,0}; RECT ViewportWnd = {0,0,0,0}; HWND ViewportHW = NULL; D3DXVECTOR3 HitLoc=D3DXVECTOR3(0,0,0); POINT p; RECT vpr; if(uMsg==WM_PAINT) { RECT ur; GetUpdateRect(hDlg,&ur,FALSE); GDI_MAKEBLACKur } //c(hDlg); switch(uMsg) { case WM_PAINT: D2DBrowser.RenderWindow(true); break; case WM_INITDIALOG: ExtendIntoClientAll(hDlg); break; case WM_KEYDOWN: //Fresh pressed TheScene.HandlePresses(wParam); TheScene.PressedKeys[wParam]=true; break; case WM_KEYUP: //Fresh released TheScene.HandleReleases(wParam); TheScene.PressedKeys[wParam]=false; break; case WM_NCPAINT: //GUIStyle.DrawTitleBar(MainHW,wParam); break; case WM_LBUTTONDBLCLK: SetFocus(hDlg); GetCursorPos(&p); ScreenToClient(MainViewportHW,&p); GetClientRect(MainViewportHW,&vpr); if(PointInRect(&p,&vpr)) //Only tell the engine, when we are in the viewport { TheScene.HandleMouseButtonReleases(1); } break; case WM_RBUTTONDBLCLK: SetFocus(hDlg); GetCursorPos(&p); ScreenToClient(MainViewportHW,&p); GetClientRect(MainViewportHW,&vpr); if(PointInRect(&p,&vpr)) //Only tell the engine, when we are in the viewport { TheScene.HandleMouseButtonReleases(3); } break; case WM_LBUTTONDOWN: SetFocus(hDlg); GetCursorPos(&p); ScreenToClient(MainViewportHW,&p); GetClientRect(MainViewportHW,&vpr); if(PointInRect(&p,&vpr)) //Only tell the engine, when we are in the viewport { TheScene.PressedMouseButtons[0]=true; TheScene.HandleMouseButtonPresses(1,wParam); if(wParam & MK_CONTROL) //TODO: Put out this crappy code { TheScene.PressedKeys[VK_CONTROL]=true; } } break; case WM_RBUTTONDOWN: //if(GetCapture()) //{ GetCursorPos(&p); ScreenToClient(MainViewportHW,&p); GetClientRect(MainViewportHW,&vpr); if(PointInRect(&p,&vpr)) //Only tell the engine, when we are in the viewport { TheScene.PressedMouseButtons[1]=true; TheScene.HandleMouseButtonPresses(2,wParam); } //} break; case WM_MBUTTONDOWN: //if(GetCapture()) //{ GetCursorPos(&p); ScreenToClient(MainViewportHW,&p); GetClientRect(MainViewportHW,&vpr); if(PointInRect(&p,&vpr)) //Only tell the engine, when we are in the viewport { TheScene.PressedMouseButtons[2]=true; TheScene.HandleMouseButtonPresses(3,wParam);#ifndef BUILD_TECHDEMO /*if(CreateClickMesh()) //if false, we would see the Warnings twice { DXUTSetTimer((LPDXUTCALLBACKTIMER)AddClickMeshTimer,CMBSpeed,&ClickMeshTimer); }*/ //Try to paint a mesh PaintBrowserMesh();#endif } //} break; case WM_LBUTTONUP: GetCursorPos(&p); ScreenToClient(MainViewportHW,&p); GetClientRect(MainViewportHW,&vpr); if(PointInRect(&p,&vpr)) //Only tell the engine, when we are in the viewport { //if(TheScene.PressedMouseButtons[0]==true) //{ TheScene.PressedMouseButtons[0]=false; TheScene.HandleMouseButtonReleases(1); TheScene.PressedKeys[VK_CONTROL]=false; //} } break; case WM_RBUTTONUP: GetCursorPos(&p); ScreenToClient(MainViewportHW,&p); GetClientRect(MainViewportHW,&vpr); if(PointInRect(&p,&vpr)) //Only tell the engine, when we are in the viewport { if(TheScene.PressedMouseButtons[1]==true) { TheScene.PressedMouseButtons[1]=false; TheScene.HandleMouseButtonReleases(2); } } break; case WM_MBUTTONUP: GetCursorPos(&p); ScreenToClient(MainViewportHW,&p); GetClientRect(MainViewportHW,&vpr); if(PointInRect(&p,&vpr)) //Only tell the engine, when we are in the viewport { if(TheScene.PressedMouseButtons[2]==true) { TheScene.PressedMouseButtons[2]=false; TheScene.HandleMouseButtonReleases(3); DXUTKillTimer(ClickMeshTimer); } } break; //TheScene.PressedMouseButtons[3]=bSideButton1Down; //TheScene.PressedMouseButtons[4]=bSideButton2Down; case WM_MOUSEMOVE: TheScene.MousePos.x=LOWORD(lParam); TheScene.MousePos.y=HIWORD(lParam); break; case WM_SIZE: if(hDlg!=MainHW) { break; } HWND vpHW; GetClientRect(hDlg,&MainWnd); vpHW=NULL; vpHW=GetDlgItem(hDlg,IDC_Viewport); GetClientRect(vpHW,&ViewportWnd); if(MainWnd.right-50>5 && MainWnd.bottom-50>5 && vpHW) { OutputDebugString(L"Before SetWindowPos()\n"); SetWindowPos(vpHW,HWND_TOP,5,40,MainWnd.right-255,MainWnd.bottom-45,SWP_SHOWWINDOW); OutputDebugString(L"After SetWindowPos()\n"); } OutputDebugString(L"Before UpdateWindowSize()\n"); TheScene.UpdateWindowSize(); OutputDebugString(L"After UpdateWindowSize()\n"); MARGINS margins; margins.cxLeftWidth=5; margins.cyTopHeight=40; margins.cxRightWidth=250; margins.cyBottomHeight=5; DwmExtendFrameIntoClientArea(hDlg,&margins); RECT MainSize; GetClientRect(hDlg,&MainSize); //SetWindowPos(hDlg,NULL,MainSize.left,MainSize.top,ScreenSize.right-BrowserSize.right,MainSize.bottom,SWP_SHOWWINDOW); SetWindowPos(D2DBrowser.MyVars.MyWindow,HWND_TOP,MainWnd.right-249,-1,249,MainSize.bottom,SWP_SHOWWINDOW); //DXUTStaticWndProc(DXUTGetHWND(),uMsg,wParam,lParam); break; case WM_CLOSE: #ifndef BUILD_TECHDEMO switch(MessageBox(NULL,L"Do you really want to quit [w]tech?",L"Quit?",MB_YESNO | MB_ICONASTERISK)) { case IDYES: WDestroyWindow(hDlg); break; } #else WDestroyWindow(hDlg); #endif break; case WM_QUIT: WDestroyWindow(hDlg); break; case WM_COMMAND: switch(wParam) { case IDM_XAudio2Tests: WCreateDialog( DXUTGetHINSTANCE(), L"IDD_XAudio2Tests", DXUTGetHWND(),(DLGPROC)XAudio2TestsMsgProc ); break; case IDM_ClassCreator: WCreateDialog( DXUTGetHINSTANCE(), L"IDD_ClassMaker", DXUTGetHWND(),(DLGPROC)ClassMakerMsgProc ); break; //########################################## - Settings - ######################################## //Colors case IDM_Black: ClearColor=D3DXCOLOR(0,0,0,0); break; case IDM_White: ClearColor=D3DXCOLOR(255,255,255,0); break; case IDM_LightBlue: ClearColor=D3DXCOLOR(0.176f, 0.196f, 0.667f,0); break; case IDM_DarkBlue: ClearColor=D3DXCOLOR(0.176/2, 0.196/2, 0.667/2,0); break; //Widget case IDM_WidgetSmall: WidgetSize=1; break; case IDM_WidgetMedium: WidgetSize=2; break; case IDM_WidgetLarge: WidgetSize=3; break; //ContentMark-Brush Speed case IDM_CMBSMegaSlow: CMBSpeed=0.6; break; case IDM_CMBSSlow: CMBSpeed=0.2; break; case IDM_CMBSMedium: CMBSpeed=0.08; break; case IDM_CMBSFast: CMBSpeed=0.05; break; case IDM_CMBSRapid: CMBSpeed=0.02; break; //Grid case IDM_MG0: TheScene.Params.MovementGrid=0; break; case IDM_MG1: TheScene.Params.MovementGrid=1; break; case IDM_MG2: TheScene.Params.MovementGrid=2; break; case IDM_MG4: TheScene.Params.MovementGrid=4; break; case IDM_MG8: TheScene.Params.MovementGrid=8; break; case IDM_MG16: TheScene.Params.MovementGrid=16; break; } break; } D2DBrowser.WindowProc(hDlg,uMsg,wParam,lParam); return 0;//DefDlgProc(hDlg,uMsg,wParam,lParam);//0;//DefWindowProc( hDlg, uMsg, wParam, lParam );;}
Hm.. I really need to clean it up ;)
Is this a window proc? (it looks like it is from its signature)
You should really pass on the message to DefWindowProc (you probably do in D2DBrowser.WindowProc), but you also MUST return the return value from DefWindowProc.
You should really pass on the message to DefWindowProc (you probably do in D2DBrowser.WindowProc), but you also MUST return the return value from DefWindowProc.
Most of the processed messages need to return 0 (WM_KEYDOWN too, look it up in MSDN), but non-processed messages have to return DefWindProc
So replace your breaks in the switch with return whatever_said_to_return_in_msdn
and outside switch: return DefWindowProc(hWnd,uMsg,wParam,lParam);
Maybe posting the main loop would be useful too (just in case).
So replace your breaks in the switch with return whatever_said_to_return_in_msdn
and outside switch: return DefWindowProc(hWnd,uMsg,wParam,lParam);
Maybe posting the main loop would be useful too (just in case).
I was not sure which to use. this is my last line there:
You see, I tried some Window Procs. But when I used them, everything was drawn wrong. No menus, everything was black, Buttons were not drawn, etc. So, 0 was the only thing that worked. And everything works with it, even if I don't handle it in my WndProc. But what does it exactly?
Hm. You said
Do I have to put it into a "default:" case value?
Anyways, it worked before, even without the default procs. The focus seems to be the problem. I will try to add the DefProcs, but I'm sure that this won't fix my problem. :(
EDIT: The main loop gets handled by DXUT.
return 0;//DefDlgProc(hDlg,uMsg,wParam,lParam);//0;//DefWindowProc( hDlg, uMsg, wParam, lParam );;
You see, I tried some Window Procs. But when I used them, everything was drawn wrong. No menus, everything was black, Buttons were not drawn, etc. So, 0 was the only thing that worked. And everything works with it, even if I don't handle it in my WndProc. But what does it exactly?
Hm. You said
Quote:but non-processed messages have to return DefWindProc
Do I have to put it into a "default:" case value?
Anyways, it worked before, even without the default procs. The focus seems to be the problem. I will try to add the DefProcs, but I'm sure that this won't fix my problem. :(
EDIT: The main loop gets handled by DXUT.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement