void mouse_click(int button, int state, int x, int y){ clicked_button = button; if (current_graphics_mode == MODE_FULLSCREEN) { set_mode(MODE_HIDE_GRAPHICS); } else { if (state) { boinc_app_mouse_button(x, y, button, false); } else { boinc_app_mouse_button(x, y, button, true); } } }
// message handler (includes timer, Windows msgs) // LRESULT CALLBACK WndProc( HWND hWnd, // Handle For This Window UINT uMsg, // Message For This Window WPARAM wParam, // Additional Message Information LPARAM lParam // Additional Message Information ) { switch(uMsg) { case WM_ERASEBKGND: // Check To See If Windows Is Trying To Erase The Background return 0; case WM_KEYDOWN: if(!window_ready) return 0; if (fullscreen) { boinc_close_window_and_quit("key down"); } else { boinc_app_key_press((int)wParam, (int)lParam); } return 0; case WM_KEYUP: if(!window_ready) return 0; if (fullscreen) { boinc_close_window_and_quit("key up"); } else { boinc_app_key_release((int)wParam, (int)lParam); } return 0; case WM_LBUTTONDOWN: case WM_MBUTTONDOWN: case WM_RBUTTONDOWN: case WM_LBUTTONUP: case WM_MBUTTONUP: case WM_RBUTTONUP: if(!window_ready) return 0; if (fullscreen) { boinc_close_window_and_quit("button up"); } else { int which; bool down; parse_mouse_event(uMsg, which, down); boinc_app_mouse_button( (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam), which, down ); } return 0; case WM_MOUSEMOVE: if(!window_ready) return 0; if (fullscreen) { if((int)(short)LOWORD(lParam) != mousePos.x || (int)(short)HIWORD(lParam) != mousePos.y) { boinc_close_window_and_quit("mouse move"); } } else { boinc_app_mouse_move( (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam), (wParam&MK_LBUTTON)!=0, (wParam&MK_MBUTTON)!=0, (wParam&MK_RBUTTON)!=0 ); } return 0; case WM_CLOSE: boinc_close_window_and_quit("WM_CLOSE"); return 0; case WM_SHUTDOWNGFX: boinc_close_window_and_quit("WM_SHUTDOWNGFX"); return 0; case WM_DESTROY: PostQuitMessage(0); return 0; case WM_PAINT: PAINTSTRUCT ps; RECT winRect; HDC pdc; pdc = BeginPaint(hWnd, &ps); GetClientRect(hWnd, &winRect); FillRect(pdc, &winRect, (HBRUSH)GetStockObject(BLACK_BRUSH)); EndPaint(hWnd, &ps); return 0; case WM_SIZE: if ( SIZE_MINIMIZED == wParam ) { visible = FALSE; } else { visible = TRUE; } if(!window_ready) return 0; app_graphics_resize(LOWORD(lParam), HIWORD(lParam)); return 0; } // Pass All Unhandled Messages To DefWindowProc return DefWindowProc(hWnd,uMsg,wParam,lParam); }
// message handler (includes timer, Windows msgs) // LRESULT CALLBACK WndProc( HWND hWnd, // Handle For This Window UINT uMsg, // Message For This Window WPARAM wParam, // Additional Message Information LPARAM lParam // Additional Message Information ) { switch(uMsg) { case WM_ERASEBKGND: // Check To See If Windows Is Trying To Erase The Background return 0; case WM_KEYDOWN: if(!window_ready) return 0; if (current_graphics_mode == MODE_FULLSCREEN) { set_mode(MODE_HIDE_GRAPHICS); } else { boinc_app_key_press((int)wParam, (int)lParam); } return 0; case WM_KEYUP: if(!window_ready) return 0; if (current_graphics_mode == MODE_FULLSCREEN) { set_mode(MODE_HIDE_GRAPHICS); } else { boinc_app_key_release((int)wParam, (int)lParam); } return 0; case WM_LBUTTONDOWN: case WM_MBUTTONDOWN: case WM_RBUTTONDOWN: case WM_LBUTTONUP: case WM_MBUTTONUP: case WM_RBUTTONUP: if(!window_ready) return 0; if (current_graphics_mode == MODE_FULLSCREEN) { set_mode(MODE_HIDE_GRAPHICS); } else { int which; bool down; POINT cPos; GetCursorPos(&cPos); parse_mouse_event(uMsg, which, down); boinc_app_mouse_button(cPos.x, cPos.y, which, down); } return 0; case WM_MOUSEMOVE: if(!window_ready) return 0; POINT cPos; GetCursorPos(&cPos); if (current_graphics_mode == MODE_FULLSCREEN) { if(cPos.x != mousePos.x || cPos.y != mousePos.y) { set_mode(MODE_HIDE_GRAPHICS); } } else { boinc_app_mouse_move( cPos.x, cPos.y, (wParam&MK_LBUTTON)!=0, (wParam&MK_MBUTTON)!=0, (wParam&MK_RBUTTON)!=0 ); } return 0; case WM_CLOSE: if (boinc_is_standalone()) { boinc_exit(0); } else { if (current_graphics_mode != MODE_FULLSCREEN) { set_mode(MODE_HIDE_GRAPHICS); } } return 0; case WM_POWERBROADCAST: if (PBT_APMSUSPEND == wParam) { set_mode(MODE_HIDE_GRAPHICS); suspend_activities(); return TRUE; } if (PBT_APMQUERYSUSPENDFAILED == wParam || PBT_APMRESUMESUSPEND == wParam) { set_mode(acked_graphics_mode); restore_activities(); return TRUE; } if (PBT_APMQUERYSUSPEND == wParam) { return TRUE; } break; case WM_PAINT: PAINTSTRUCT ps; RECT winRect; HDC pdc; if (!graphics_threadh) graphics_threadh=(HANDLE)GetCurrentThreadId(); pdc = BeginPaint(hWnd, &ps); GetClientRect(hWnd, &winRect); FillRect(pdc, &winRect, (HBRUSH)GetStockObject(BLACK_BRUSH)); EndPaint(hWnd, &ps); return 0; case WM_SIZE: if ( SIZE_MINIMIZED == wParam ) { visible = FALSE; } else { visible = TRUE; } if(!window_ready) return 0; app_graphics_resize(LOWORD(lParam), HIWORD(lParam)); return 0; case WM_SHUTDOWNGFX: set_mode(MODE_HIDE_GRAPHICS); return 0; default: if ( WM_BOINCSFW == uMsg ) { SetForegroundWindow(hWnd); } } // Pass All Unhandled Messages To DefWindowProc return DefWindowProc(hWnd,uMsg,wParam,lParam); }