static void mouse_push_event_thread(void *arg) { (void) arg; t_current_set_name("MouEvents"); t_current_set_priority(PHANTOM_SYS_THREAD_PRIO); while(1) { hal_sem_acquire( &mouse_sem ); if(video_drv->mouse_redraw_cursor != NULL) video_drv->mouse_redraw_cursor(); //hal_mutex_lock( &mouse_mutex ); struct ui_event e, e1; while( get_buf(&e) ) { if( peek_buf( &e1 ) ) { // We already have one more event and buttons state is the same? // Throw away current event, use next one. if( e1.m.buttons == e.m.buttons ) continue; } ev_q_put_any( &e ); } //hal_mutex_unlock( &mouse_mutex ); } }
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam) { HDC hDC; PAINTSTRUCT lpPaint; switch(iMessage) { case WM_CLOSE: case WM_DESTROY: exit(0); if(MessageBox(hWnd, "Do you really want to quit?", "Message", MB_YESNO) == IDYES) PostQuitMessage(0); break; case WM_ERASEBKGND: return 1; // Done case WM_PAINT: GdiFlush(); hDC = BeginPaint( hWnd, &lpPaint); // Assume hPaintDC is a variable of type HDC, and the dc we're rendering to HDC hBitmapDC = CreateCompatibleDC(hDC); HBITMAP hOldBitmap = (HBITMAP)SelectObject(hBitmapDC, screenBitmap); //HPALETTE hOldPalette = SelectPalette(hPaintDC, hPalette, FALSE); GdiFlush(); if( !BitBlt(hDC, 0, 0, VSCREEN_WIDTH, VSCREEN_HEIGHT, hBitmapDC, 0, 0, SRCCOPY) ) { DWORD err = GetLastError(); //FormatMessage(); printf("Win error %d", (int)err); LPVOID lpMsgBuf; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language (LPTSTR) &lpMsgBuf, 0, NULL ); printf("WinErr: %s\n", (const char *)lpMsgBuf ); } GdiFlush(); //SelectPalette(hPaintDC, hOldPalette, TRUE); SelectObject(hBitmapDC, hOldBitmap); DeleteDC(hBitmapDC); /*if(eline) { MoveToEx(hDC, 60, 20, NULL); LineTo(hDC, 264, 122); }*/ // TODO: paint OS mouse cursor EndPaint( hWnd, &lpPaint); break; #if HOVER case WM_MOUSEHOVER: { int xPos = (short)(0x0FFFF & lParam);//GET_X_LPARAM(lParam); int yPos = VSCREEN_HEIGHT - (short)(0x0FFFF & (lParam>>16));//GET_Y_LPARAM(lParam); printf("%d,%d\n", xPos, yPos ); TrackMouseEvent(&eventTrack); } break; #endif //case WM_KEYDOWN: //case WM_KEYUP: TranslateMessage( __in const MSG *lpMsg ); case WM_CHAR: { printf("-%x-", (int)lParam ); } break; case WM_MOUSEMOVE: { int xPos = (short)(0x0FFFF & lParam);//GET_X_LPARAM(lParam); int yPos = VSCREEN_HEIGHT - (short)(0x0FFFF & (lParam>>16));//GET_Y_LPARAM(lParam); // printf("%d,%d\n", xPos, yPos ); drv_video_win32.mouse_x = xPos; drv_video_win32.mouse_y = yPos; drv_video_win32.mouse_flags = wParam; drv_video_win32.mouse(); #if 1 struct ui_event e; e.type = UI_EVENT_TYPE_MOUSE; e.time = fast_time(); e.focus= 0; e.m.buttons = wParam; e.abs_x = xPos; e.abs_y = VSCREEN_HEIGHT - yPos - 1; ev_q_put_any( &e ); //printf("-ms-"); printf("%d,%d\n", xPos, yPos ); #endif } break; default: return DefWindowProc(hWnd, iMessage, wParam, lParam); } return 0; }