LONG WINAPI WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { static PAINTSTRUCT ps; static GLboolean left = GL_FALSE; /* left button currently down? */ static GLboolean right = GL_FALSE; /* right button currently down? */ static int omx, omy, mx, my; switch(uMsg) { case WM_PAINT: BeginPaint(hWnd, &ps); EndPaint(hWnd, &ps); return 0; case WM_SIZE: Reshape(LOWORD(lParam), HIWORD(lParam)); PostMessage(hWnd, WM_PAINT, 0, 0); return 0; case WM_CHAR: switch (wParam) { case 27: /* ESC key */ PostQuitMessage(0); break; } return 0; case WM_LBUTTONDOWN: /* if we don't set the capture we won't get mouse move messages when the mouse moves outside the window. */ SetCapture(hWnd); MouseX = LOWORD(lParam); MouseY = HIWORD(lParam); ComputeMouseVector(); MouseState = 1; return 0; case WM_LBUTTONUP: MouseX = LOWORD(lParam); MouseY = HIWORD(lParam); if(MouseX & 1 << 15) MouseX -= (1 << 16); if(MouseY & 1 << 15) MouseY -= (1 << 16); ComputeMouseVector(); if(MouseState) SpinIt(); MouseState=0; /* remember to release the capture when we are finished. */ ReleaseCapture(); return 0; case WM_MOUSEMOVE: MouseX = LOWORD(lParam); MouseY = HIWORD(lParam); /* Win32 is pretty braindead about the x, y position that it returns when the mouse is off the left or top edge of the window (due to them being unsigned). therefore, roll the Win32's 0..2^16 pointer co-ord range to the more amenable (and useful) 0..+/-2^15. */ if(MouseX & 1 << 15) MouseX -= (1 << 16); if(MouseY & 1 << 15) MouseY -= (1 << 16); ComputeMouseVector(); if(MouseState) SpinIt(); return 0; case WM_PALETTECHANGED: if (hWnd == (HWND)wParam) break; /* fall through to WM_QUERYNEWPALETTE */ case WM_QUERYNEWPALETTE: if (hPalette) { UnrealizeObject(hPalette); SelectPalette(hDC, hPalette, FALSE); RealizePalette(hDC); return TRUE; } return FALSE; case WM_CLOSE: PostQuitMessage(0); return 0; } return DefWindowProc(hWnd, uMsg, wParam, lParam); }
LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) { switch( msg ) { case WM_DROPFILES: { /*RECT rect; POINT pt; GetWindowRect(hWnd,&rect); GetCursorPos(&pt); if(windowed) { rect.left -= window_inset.left; // todo: look into the function: ScreenToClient(hwnd,point) rect.top -= window_inset.top; } ComputeMouseVector(pt.x-rect.left,pt.y-rect.top); */ //MouseVector = float3(0,0,-1); HDROP hDrop = (HDROP)wParam; unsigned int n = DragQueryFileA(hDrop, 0xFFFFFFFF, NULL, 0); for(unsigned int i=0; i<n; i++) { char fname[1024]; if(DragQueryFileA(hDrop, i, fname, sizeof(fname))) { char *s = fname+strlen(fname); while (s>fname && *s != '.' ) s--; if(*s=='.') s++; dropfiles.Add(String(s) + " \"" + fname + "\""); } } DragFinish(hDrop); break; } case WM_SETFOCUS: focus=1; break; case WM_KILLFOCUS: focus=0; break; case WM_DESTROY: PostQuitMessage( 0 ); quitrequest=1; return 0; case WM_CLOSE: PostQuitMessage(0); quitrequest=1; return 0; case WM_CHAR: if(entertext) { doconsole(wParam); return 0; } if(ManipulatorKeyPress((int) wParam)) // manipulator is taking the key input!!! return 0; switch (wParam) { case 27: /* ESC key */ PostQuitMessage(0); quitrequest=1; break; case '`': case '\n': case '\r': entertext=1; comstring[0]='\0'; break; default: { extern void keyvent(const char *name,int k); keyvent("keydown",toupper((int)wParam)); break; } } return 0; case WM_KEYUP: { if(entertext || ManipulatorKeysGrab()) return 0; extern void keyvent(const char *name,int k); keyvent("keyup",toupper((int)wParam)); return 0; } case WM_LBUTTONDOWN: /* if we don't set the capture we won't get mouse move messages when the mouse moves outside the window. */ SetCapture(hWnd); ComputeMouseVector(LOWORD(lParam),HIWORD(lParam)); shiftdown = (wParam&MK_SHIFT)?1:0; ctrldown = (wParam&MK_CONTROL)?1:0; MouseLeft = 1; return 0; case WM_RBUTTONDOWN: SetCapture(hWnd); ComputeMouseVector(LOWORD(lParam),HIWORD(lParam)); shiftdown = (wParam&MK_SHIFT)?1:0; ctrldown = (wParam&MK_CONTROL)?1:0; MouseRight = 1; FuncInterp("rbuttondown"); return 0; case WM_LBUTTONUP: ComputeMouseVector(LOWORD(lParam),HIWORD(lParam)); shiftdown = (wParam&MK_SHIFT)?1:0; ctrldown = (wParam&MK_CONTROL)?1:0; MouseLeft=0; /* remember to release the capture when we are finished. */ if(!MouseRight) ReleaseCapture(); return 0; case WM_RBUTTONUP: ComputeMouseVector(LOWORD(lParam),HIWORD(lParam)); shiftdown = (wParam&MK_SHIFT)?1:0; ctrldown = (wParam&MK_CONTROL)?1:0; MouseRight=0; /* remember to release the capture when we are finished. */ if(!MouseLeft) ReleaseCapture(); return 0; case WM_MOUSEMOVE: ComputeMouseVector(LOWORD(lParam),HIWORD(lParam)); shiftdown = (wParam&MK_SHIFT)?1:0; ctrldown = (wParam&MK_CONTROL)?1:0; return 0; case WM_MOUSEWHEEL: shiftdown = (wParam&MK_SHIFT)?1:0; ctrldown = (wParam&MK_CONTROL)?1:0; mousewheel += GET_WHEEL_DELTA_WPARAM(wParam)/WHEEL_DELTA; return 0; case WM_SETCURSOR: // Turn off Windows cursor SetCursor( NULL ); g_pd3dDevice->ShowCursor( 0 ); return 1; case WM_SYSCHAR: switch(wParam) { case 27: /* ESC key */ PostQuitMessage(0); quitrequest=1; break; case '\n': case '\r': windowed = !windowed; resetdevice(NULL); break; } return 0; case WM_MOVE: if(windowed) { windowx = LOWORD(lParam); windowy = HIWORD(lParam); } return 1; case WM_SIZE: wm_size_width = LOWORD(lParam); wm_size_height = HIWORD(lParam); windowwidth = LOWORD(lParam); windowheight= HIWORD(lParam); return 1; case WM_EXITSIZEMOVE: if(windowed && (Width != (int)(windowwidth ) || Height!= (int)(windowheight))) { resetdevice(NULL); } return 1; } return DefWindowProc( hWnd, msg, wParam, lParam ); }