/* Window message handle function */ LRESULT CALLBACK MyWinFunc( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam ) { INT i; HDC hDC; PAINTSTRUCT ps; static INT w, h; static BITMAP bm; static HBITMAP hBm, hBmLogo; static HDC hMemDC, hMemDCLogo; switch (Msg) { case WM_CREATE: SetTimer(hWnd, 30, 10, NULL); hBmLogo = LoadImage(NULL, "GLOBE.BMP", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); GetObject(hBmLogo, sizeof(bm), &bm); hDC = GetDC(hWnd); hMemDC = CreateCompatibleDC(hDC); hMemDCLogo = CreateCompatibleDC(hDC); SelectObject(hMemDCLogo, hBmLogo); ReleaseDC(hWnd, hDC); return 0; case WM_SIZE: w = LOWORD(lParam); h = HIWORD(lParam); if (hBm != NULL) DeleteObject(hBm); hDC = GetDC(hWnd); hBm = CreateCompatibleBitmap(hDC, w, h); ReleaseDC(hWnd, hDC); SelectObject(hMemDC, hBm); SendMessage(hWnd, WM_TIMER, 0, 0); return 0; case WM_TIMER: Rectangle(hMemDC, 0, 0, w + 1, h + 1); /* BitBlt(hMemDC, 0, 0, bm.bmWidth, bm.bmHeight, hMemDCLogo, 0, 0, SRCCOPY); */ SetStretchBltMode(hMemDC, COLORONCOLOR); StretchBlt(hMemDC, 0, 0, w, h, hMemDCLogo, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY); DrawEye(hWnd, hMemDC, 100, 100, 50, 15); DrawEye(hWnd, hMemDC, 300, 200, 150, 30); DrawEye(hWnd, hMemDC, 100, 200, 50, 30); DrawEye(hWnd, hMemDC, 400, 200, 130, 30); DrawEye(hWnd, hMemDC, w / 2, h / 2, 80, 15); srand(59); for (i = 0; i < 30; i++) DrawEye(hWnd, hMemDC, rand() % 800, rand() % 700, 30, 8); SetBkMode(hMemDC, TRANSPARENT); SetTextColor(hMemDC, RGB(255, 0, 0)); TextOut(hMemDC, 30, 30, "30!", 3); InvalidateRect(hWnd, NULL, FALSE); return 0; case WM_PAINT: hDC = BeginPaint(hWnd, &ps); BitBlt(hDC, 0, 0, w, h, hMemDC, 0, 0, SRCCOPY); EndPaint(hWnd, &ps); return 0; case WM_DESTROY: KillTimer(hWnd, 30); DeleteDC(hMemDC); DeleteObject(hBm); PostQuitMessage(0); return 0; } return DefWindowProc(hWnd, Msg, wParam, lParam); } /* End of 'MyWinFunc' function */
LRESULT FAR PASCAL WndProc( HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam) { DWORD dwImmRet = 0; // return value of ImmSrvProcessKey() try { switch (Message) { case CONIME_CREATE: DBGPRINT(("CONIME: CONIME_CREATE: Console Handle=%08x\n", wParam)); return InsertNewConsole(hWnd,(HANDLE)wParam,(HWND)lParam); case CONIME_DESTROY: DBGPRINT(("CONIME: CONIME_DESTROY: Console Handle=%08x\n", wParam)); return RemoveConsole(hWnd, (HANDLE)wParam); case CONIME_SETFOCUS: DBGPRINT(("CONIME: CONIME_SETFOCUS: Console Handle=%08x\n", wParam)); return ConsoleSetFocus(hWnd, (HANDLE)wParam, (HKL)lParam); case CONIME_KILLFOCUS: DBGPRINT(("CONIME: CONIME_KILLFOCUS: Console Handle=%08x\n", wParam)); return ConsoleKillFocus(hWnd, (HANDLE)wParam); case CONIME_GET_NLSMODE: DBGPRINT(("CONIME: CONIME_GET_NLSMODE: Console Handle=%08x\n", wParam)); return GetNLSMode(hWnd, (HANDLE)wParam); case CONIME_SET_NLSMODE: DBGPRINT(("CONIME: CONIME_SET_NLSMODE: Console Handle=%08x\n", wParam)); return SetNLSMode(hWnd, (HANDLE)wParam, (DWORD)lParam); case CONIME_HOTKEY: DBGPRINT(("CONIME: CONIME_HOTKEY\n")); return ConimeHotkey(hWnd, (HANDLE)wParam, (DWORD)lParam); case CONIME_NOTIFY_VK_KANA: DBGPRINT(("CONIME: CONIME_NOTIFY_VK_KANA\n")); return ImeUISetConversionMode(hWnd); case CONIME_NOTIFY_SCREENBUFFERSIZE: { COORD ScreenBufferSize; DBGPRINT(("CONIME: CONIME_NOTIFY_SCREENBUFFERSIZE: Console Handle=%08x\n", wParam)); ScreenBufferSize.X = LOWORD(lParam); ScreenBufferSize.Y = HIWORD(lParam); return ConsoleScreenBufferSize(hWnd, (HANDLE)wParam, ScreenBufferSize); } case CONIME_INPUTLANGCHANGE: { DBGPRINT(("CONIME: CONIME_INPUTLANGCHANGE: Console Handle=%08x \n",wParam)); ConImeInputLangchange(hWnd, (HANDLE)wParam, (HKL)lParam ); return TRUE; } case CONIME_NOTIFY_CODEPAGE: { BOOL Output; WORD Codepage; Codepage = HIWORD(lParam); Output = LOWORD(lParam); DBGPRINT(("CONIME: CONIME_NOTIFY_CODEPAGE: Console Handle=%08x %04x %04x\n",wParam, Output, Codepage)); return ConsoleCodepageChange(hWnd, (HANDLE)wParam, Output, Codepage); } case WM_KEYDOWN +CONIME_KEYDATA: case WM_KEYUP +CONIME_KEYDATA: case WM_SYSKEYDOWN +CONIME_KEYDATA: case WM_SYSKEYUP +CONIME_KEYDATA: case WM_DEADCHAR +CONIME_KEYDATA: case WM_SYSDEADCHAR+CONIME_KEYDATA: case WM_SYSCHAR +CONIME_KEYDATA: case WM_CHAR +CONIME_KEYDATA: CharHandlerFromConsole( hWnd, Message, (ULONG)wParam, (ULONG)lParam ); break; case WM_KEYDOWN: case WM_KEYUP: case WM_SYSKEYDOWN: case WM_SYSKEYUP: case WM_DEADCHAR: case WM_SYSDEADCHAR: case WM_SYSCHAR: case WM_CHAR: CharHandlerToConsole( hWnd, Message, (ULONG)wParam, (ULONG)lParam ); break; case WM_INPUTLANGCHANGE: DBGPRINT(("CONIME: CONIME_INPUTLANGCHANGE: Console Handle=%08x \n",wParam)); InputLangchange(hWnd, (DWORD)wParam, (HKL)lParam ); return TRUE; case WM_INPUTLANGCHANGEREQUEST: // Console IME never receive this message for this window is hidden // and doesn't have focus. // // However, Hot key of IME_CHOTKEY_IME_NONIME_TOGGLE/IME_THOTKEY_IME_NONIME_TOGGLE // are send this message by ImmSimulateHotKey API. // // If nothing processing by this message, then DefWindowProc calls // ActivateKeyboardLayout on kernel side. // And, ActivateKeyboardLayout send WM_INPUTLANGCHANGE message to focus window // on this message queue. // It window is console window procedure. // Console window procedure can do send CONIME_INPUTLANGCHANGE message to // console IME window. // In console window is windowed case, this sequence as well. // But, In console window is full screen case, message queue have not focus. // WM_INPUTLANGCHANGE message can not send to console window procedure. // // This code avoid console full screen mode problem. // Send message to console window procedure when this window receive it. // { PCONSOLE_TABLE ConTbl; ConTbl = SearchConsole(LastConsole); if (ConTbl == NULL) { return DefWindowProc(hWnd, Message, wParam, lParam); } PostMessage(ConTbl->hWndCon, Message, wParam, lParam); } return TRUE; // TRUE : process this message by application case CONIME_INPUTLANGCHANGEREQUEST: DBGPRINT(("CONIME: CONIME_INPUTLANGCHANGEREQUEST: Console Handle=%08x \n",wParam)); return ConImeInputLangchangeRequest(hWnd, (HANDLE)wParam, (HKL)lParam, CONIME_DIRECT); case CONIME_INPUTLANGCHANGEREQUESTFORWARD: DBGPRINT(("CONIME: CONIME_INPUTLANGCHANGEREQUEST: Console Handle=%08x \n",wParam)); return ConImeInputLangchangeRequest(hWnd, (HANDLE)wParam, (HKL)lParam, CONIME_FORWARD); case CONIME_INPUTLANGCHANGEREQUESTBACKWARD: DBGPRINT(("CONIME: CONIME_INPUTLANGCHANGEREQUEST: Console Handle=%08x \n",wParam)); return ConImeInputLangchangeRequest(hWnd, (HANDLE)wParam, (HKL)lParam, CONIME_BACKWARD); #ifdef DEBUG_MODE case WM_MOVE: ImeUIMoveCandWin( hWnd ); break; case WM_COMMAND: // message: command from application menu // Message packing of wparam and lparam have changed for Win32, // so use the GET_WM_COMMAND macro to unpack the commnad switch (LOWORD(wParam)) { case MM_EXIT: PostMessage(hWnd,WM_CLOSE,0,0L); break; case MM_ACCESS_VIOLATION: { PBYTE p = 0; *p = 0; } break; } break; #endif case WM_IME_STARTCOMPOSITION: ImeUIStartComposition( hWnd ); break; case WM_IME_ENDCOMPOSITION: ImeUIEndComposition( hWnd ); break; case WM_IME_COMPOSITION: ImeUIComposition( hWnd, wParam, lParam ); break; case WM_IME_COMPOSITIONFULL: break; case WM_IME_NOTIFY: if ( !ImeUINotify( hWnd, wParam, lParam ) ) { return DefWindowProc(hWnd, Message, wParam, lParam); } break; case WM_IME_SETCONTEXT: // // The application have to pass WM_IME_SETCONTEXT to DefWindowProc. // When the application want to handle the IME at the timing of // focus changing, the application should use WM_GETFOCUS or // WM_KILLFOCUS. // lParam &= ~ISC_SHOWUIALL; return DefWindowProc( hWnd, Message, wParam, lParam ); case WM_IME_SYSTEM: switch (wParam) { case IMS_CLOSEPROPERTYWINDOW: case IMS_OPENPROPERTYWINDOW: ImeSysPropertyWindow(hWnd, wParam, lParam); break; default: return DefWindowProc( hWnd, Message, wParam, lParam ); } break; case WM_CREATE: return Create(hWnd); break; case WM_DESTROY: DBGPRINT(("CONIME:Recieve WM_DESTROY\n")); ExitList(hWnd); PostQuitMessage(0); return 0; break; case WM_CLOSE: DBGPRINT(("CONIME:Recieve WM_CLOSE\n")); DestroyWindow(hWnd); return 0; break; case WM_ENABLE:{ PCONSOLE_TABLE FocusedConsole; if (!wParam) { FocusedConsole = SearchConsole(LastConsole); if (FocusedConsole != NULL && FocusedConsole->hConsole != NULL) { FocusedConsole->Enable = FALSE; EnableWindow(FocusedConsole->hWndCon,FALSE); gfDoNotKillFocus = TRUE; } } else{ DWORD i; LockConsoleTable(); for ( i = 1; i < NumberOfConsoleTable; i ++){ FocusedConsole = ConsoleTable[i]; if (FocusedConsole != NULL) { if ((FocusedConsole->hConsole != NULL)&& (!FocusedConsole->Enable)&& (!IsWindowEnabled(FocusedConsole->hWndCon))){ EnableWindow(FocusedConsole->hWndCon,TRUE); FocusedConsole->Enable = TRUE; if (!FocusedConsole->LateRemove) SetForegroundWindow(FocusedConsole->hWndCon); } } } UnlockConsoleTable(); } return DefWindowProc(hWnd, Message, wParam, lParam); break; } #ifdef DEBUG_MODE case WM_SETFOCUS: CreateCaret( hWnd, NULL, IsUnicodeFullWidth( ConvertLine[xPos] ) ? CaretWidth*2 : CaretWidth, (UINT)cyMetrics ); SetCaretPos( xPos * cxMetrics, 0 ); ShowCaret( hWnd ); break; case WM_KILLFOCUS: HideCaret( hWnd ); DestroyCaret(); break; case WM_PAINT: { PAINTSTRUCT pstruc; HDC hDC; hDC = BeginPaint(hWnd,&pstruc); ReDraw(hWnd); EndPaint(hWnd,&pstruc); break; } #endif case WM_QUERYENDSESSION: #ifdef HIRSHI_DEBUG /* * If specified ntsd debugger on this process, * then never catch WM_QUERYENDSESSION when logoff/shutdown because * this process will terminate when ntsd process terminated. */ { int i; i = MessageBox(hWnd,TEXT("Could you approve exit session?"), TEXT("Console IME"), MB_ICONSTOP | MB_YESNO); return (i == IDYES ? TRUE : FALSE); } #endif return TRUE; // Logoff or shutdown time. case WM_ENDSESSION: DBGPRINT(("CONIME:Recieve WM_ENDSESSION\n")); ExitList(hWnd); return 0; default: // Passes it on if unproccessed return DefWindowProc(hWnd, Message, wParam, lParam); } } except (InputExceptionFilter(GetExceptionInformation())) { if (dwConsoleThreadId) { DBGPRINT(("CONIME: Exception on WndProc!!\n")); UnregisterConsoleIME(); dwConsoleThreadId = 0; DestroyWindow(hWnd); return 0; } } return TRUE; }
LRESULT debugwin_info::window_proc(UINT message, WPARAM wparam, LPARAM lparam) { // handle a few messages switch (message) { // paint: draw bezels as necessary case WM_PAINT: { PAINTSTRUCT pstruct; HDC dc = BeginPaint(m_wnd, &pstruct); draw_contents(dc); EndPaint(m_wnd, &pstruct); break; } // keydown: handle debugger keys case WM_KEYDOWN: if (handle_key(wparam, lparam)) set_ignore_char_lparam(lparam); break; // char: ignore chars associated with keys we've handled case WM_CHAR: if (check_ignore_char_lparam(lparam)) { if (waiting_for_debugger() || !seq_pressed()) return DefWindowProc(m_wnd, message, wparam, lparam); } break; // activate: set the focus case WM_ACTIVATE: if (wparam != WA_INACTIVE) set_default_focus(); break; // get min/max info: set the minimum window size case WM_GETMINMAXINFO: { MINMAXINFO *minmax = (MINMAXINFO *)lparam; minmax->ptMinTrackSize.x = m_minwidth; minmax->ptMinTrackSize.y = m_minheight; minmax->ptMaxSize.x = minmax->ptMaxTrackSize.x = m_maxwidth; minmax->ptMaxSize.y = minmax->ptMaxTrackSize.y = m_maxheight; break; } // sizing: recompute child window locations case WM_SIZE: case WM_SIZING: recompute_children(); InvalidateRect(m_wnd, NULL, FALSE); break; // mouse wheel: forward to the first view case WM_MOUSEWHEEL: { static int units_carryover = 0; UINT lines_per_click; if (!SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &lines_per_click, 0)) lines_per_click = 3; int const units = GET_WHEEL_DELTA_WPARAM(wparam) + units_carryover; int const clicks = units / WHEEL_DELTA; units_carryover = units % WHEEL_DELTA; int const delta = clicks * lines_per_click; int viewnum = 0; POINT point; // figure out which view we are hovering over GetCursorPos(&point); ScreenToClient(m_wnd, &point); HWND const child = ChildWindowFromPoint(m_wnd, point); if (child) { for (viewnum = 0; viewnum < MAX_VIEWS; viewnum++) { if ((m_views[viewnum] != NULL) && m_views[viewnum]->owns_window(child)) break; } if (viewnum == MAX_VIEWS) break; } // send the appropriate message to this view's scrollbar if (m_views[viewnum] != NULL) m_views[viewnum]->send_vscroll(delta); break; } // activate: set the focus case WM_INITMENU: update_menu(); break; // command: handle a comment case WM_COMMAND: if (!handle_command(wparam, lparam)) return DefWindowProc(m_wnd, message, wparam, lparam); break; // close: close the window if it's not the main console case WM_CLOSE: if (m_is_main_console) { debugger().hide_all(); debug_cpu_get_visible_cpu(machine())->debug()->go(); } else { destroy(); } break; // destroy: close down the window case WM_NCDESTROY: m_wnd = NULL; debugger().remove_window(*this); break; // everything else: defaults default: return DefWindowProc(m_wnd, message, wparam, lparam); } return 0; }
LRESULT CALLBACK WinProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam) { PAINTSTRUCT Ps; switch(msg) { case WM_CREATE: { /** * Create AddFood Button */ HFONT hFont = CreateFont(30,0,0,0,FW_DONTCARE,FALSE,TRUE,FALSE,DEFAULT_CHARSET,OUT_OUTLINE_PRECIS, CLIP_DEFAULT_PRECIS,NULL, VARIABLE_PITCH,TEXT("Impact")); HWND hButtonAddFood = CreateWindowEx(NULL, "BUTTON", "ADD FOOD", WS_TABSTOP|WS_VISIBLE| WS_CHILD|BS_DEFPUSHBUTTON|BS_TOP, 10, 150, 100, 25, hWnd, (HMENU)BUTTON_ADD_FOOD, GetModuleHandle(NULL), NULL); /** * Create button ShowFoodNumber */ HWND hShowFoodNumber = CreateWindowEx(NULL, "BUTTON", "Funny", WS_TABSTOP|WS_VISIBLE| WS_CHILD|BS_DEFPUSHBUTTON|BS_TOP, 10, 180, 300, 40, hWnd, (HMENU)BUTTON_DISPLAY_FOOD_NR, GetModuleHandle(NULL), NULL); SendMessage (hShowFoodNumber, WM_SETFONT, WPARAM (hFont), TRUE); /** * Draw Food List (In a input box) */ hFoodList = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "", WS_CHILD|WS_VISIBLE|WS_VSCROLL|ES_READONLY| ES_MULTILINE, 10, 40, 300, 100, hWnd, (HMENU)INPUT_TEXT_SHOW_FOOD, GetModuleHandle(NULL), NULL); /** * Draw main Input food field */ hInputFood = CreateWindowEx( (DWORD)NULL, TEXT("edit"), "", WS_VISIBLE | WS_CHILD | WS_BORDER, 120, 150, 190, 25, hWnd, (HMENU)INPUT_TEXT_ADD_FOOD, GetModuleHandle(NULL), NULL); } break; case WM_PAINT: { HDC hdc = BeginPaint(hWnd, &Ps); RECT rect; /** * Draw Text */ // Second Text char foodNrMessage[256] = "Number : "; char nr[50]; strcat(foodNrMessage, itoa(foodNumber, nr, 10)); SetBkMode(hdc, TRANSPARENT); SetRect(&updateRect, 210, 10, 300, 30); DrawText( hdc, foodNrMessage, -1, &updateRect, DT_SINGLELINE | DT_NOCLIP ) ; // First Text HFONT hFont = CreateFont(25,0,0,0,FW_DONTCARE,FALSE,TRUE,FALSE,DEFAULT_CHARSET,OUT_OUTLINE_PRECIS, CLIP_DEFAULT_PRECIS,NULL, VARIABLE_PITCH,TEXT("Impact")); SetRect(&rect, 10, 10, 50, 50); SelectObject(hdc, hFont); SetBkMode(hdc, OPAQUE); SetBkColor(hdc, RGB(0,255,255)); SetTextColor(hdc, RGB(255,0,0)); DrawText(hdc, TEXT(firstText), -1,&rect, DT_NOCLIP); EndPaint(hWnd, &Ps); } break; case WM_CTLCOLOREDIT: { HDC hdc = (HDC)wParam; HWND hwnd = (HWND)lParam; HBRUSH color; if (GetDlgCtrlID(hwnd) == INPUT_TEXT_ADD_FOOD) { color = CreateSolidBrush(RGB(225, 225, 225)); SetTextColor(hdc, RGB(0, 0, 255)); SetBkMode(hdc, TRANSPARENT); SetBkColor(hdc,(LONG)color); } return (LONG) color; } break; case WM_COMMAND: { switch(LOWORD(wParam)) { case BUTTON_ADD_FOOD: { char buffer[256]; SendMessage(hInputFood, WM_GETTEXT, sizeof(buffer)/sizeof(buffer[0]), reinterpret_cast<LPARAM>(buffer)); if(strlen(buffer) > 0){ char newInput[255] = ""; char stat[30]; strcat(newInput, itoa((foodNumber+1), stat, 10) ); strcat(newInput, " ) "); strcat(newInput, buffer); strcat(newInput, "\r\n"); SendMessage(hFoodList, EM_REPLACESEL, FALSE, (LPARAM)newInput); SendMessage(hInputFood, WM_SETTEXT, NULL, (LPARAM)""); foodNumber++; InvalidateRect(hWnd, &updateRect, TRUE); } } break; case BUTTON_DISPLAY_FOOD_NR: { char buffer[255] = ""; switch(foodNumber){ case 0:http://pastebin.com/62fGU90U case 1: case 2: case 3: strcat(buffer, "You are not hungry at all"); break; case 4: case 5: case 6: strcat(buffer, "I see you are hungry now"); break; default: strcat(buffer, "You are starvin... go get something to eat"); break; } MessageBox(NULL, buffer, "Funny", MB_ICONINFORMATION); } break; } } break; case WM_SIZE: { INT nWidth = LOWORD(lParam); HWND hFunnyButton = GetDlgItem(hWnd, BUTTON_DISPLAY_FOOD_NR); MoveWindow(hFunnyButton, 10, 180, nWidth - 17, 40, TRUE); HWND hShowFoodInput = GetDlgItem(hWnd, INPUT_TEXT_SHOW_FOOD); HWND hAddFood = GetDlgItem(hWnd, INPUT_TEXT_ADD_FOOD); MoveWindow(hShowFoodInput, 10, 40, nWidth - 18, 100, TRUE); MoveWindow(hAddFood, 120, 150, nWidth - 128, 25, TRUE); } break; case WM_GETMINMAXINFO: { MINMAXINFO * mmiStruct; mmiStruct = (MINMAXINFO*)lParam; POINT ptPoint; ptPoint.x = 335; //Minimum width of the window. ptPoint.y = 260; //Minimum height of the window. mmiStruct->ptMinTrackSize = ptPoint; ptPoint.x = GetSystemMetrics(SM_CXMAXIMIZED); //Maximum width of the window. ptPoint.y = GetSystemMetrics(SM_CYMAXIMIZED); //Maximum height of the window. mmiStruct->ptMaxTrackSize = ptPoint; } break; case WM_DESTROY: { PostQuitMessage(0); return 0; } break; } return DefWindowProc(hWnd,msg,wParam,lParam); }
// Processes messages for main Window LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { PTOUCHINPUT pInputs; TOUCHINPUT tInput; HTOUCHINPUT hInput; int iNumContacts; POINT ptInputs; PAINTSTRUCT ps; // Handle each type of inData and based on which event we handle continue processing // the inData for manipulations by calling the ComTouchDriver switch (msg) { case WM_TOUCH: iNumContacts = LOWORD(wParam); hInput = (HTOUCHINPUT)lParam; pInputs = new (std::nothrow) TOUCHINPUT[iNumContacts]; // Get each touch input info and feed each TOUCHINPUT into the process input handler if(pInputs != NULL) { if(GetTouchInputInfo(hInput, iNumContacts, pInputs, sizeof(TOUCHINPUT))) { for(int i = 0; i < iNumContacts; i++) { // Bring touch input info into client coordinates ptInputs.x = pInputs[i].x/100; ptInputs.y = pInputs[i].y/100; ScreenToClient(g_hWnd, &ptInputs); pInputs[i].x = ptInputs.x; pInputs[i].y = ptInputs.y; g_ctDriver->ProcessInputEvent(&pInputs[i]); } g_ctDriver->ProcessChanges(); } } delete [] pInputs; CloseTouchInputHandle(hInput); break; // For each Mouse event build a TOUCHINPUT struct and feed into the process input handler case WM_LBUTTONDOWN: FillInputData(&tInput, MOUSE_CURSOR_ID, TOUCHEVENTF_DOWN, (DWORD)GetMessageTime(),LOWORD(lParam),HIWORD(lParam)); g_ctDriver->ProcessInputEvent(&tInput); break; case WM_MOUSEMOVE: if(LOWORD(wParam) == MK_LBUTTON) { FillInputData(&tInput, MOUSE_CURSOR_ID, TOUCHEVENTF_MOVE, (DWORD)GetMessageTime(),LOWORD(lParam), HIWORD(lParam)); g_ctDriver->ProcessInputEvent(&tInput); g_ctDriver->ProcessChanges(); } break; case WM_LBUTTONUP: FillInputData(&tInput, MOUSE_CURSOR_ID, TOUCHEVENTF_UP, (DWORD)GetMessageTime(),LOWORD(lParam), HIWORD(lParam)); g_ctDriver->ProcessInputEvent(&tInput); break; case WM_DESTROY: if(g_ctDriver) { delete g_ctDriver; } PostQuitMessage(0); return 1; case WM_SIZE: g_iCWidth = LOWORD(lParam); g_iCHeight = HIWORD(lParam); break; case WM_PAINT: BeginPaint(g_hWnd, &ps); g_ctDriver->RenderInitialState(g_iCWidth, g_iCHeight); EndPaint(g_hWnd, &ps); break; case WM_TIMER: g_ctDriver->ProcessChanges(); break; default: return DefWindowProc(hWnd, msg, wParam, lParam); } return 0; }
// // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) // // PURPOSE: Processes messages for the main window. // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { static HWND backWnd = NULL, forwardWnd = NULL, reloadWnd = NULL, stopWnd = NULL, editWnd = NULL; static WNDPROC editWndOldProc = NULL; // Static members used for the find dialog. static FINDREPLACE fr; static WCHAR szFindWhat[80] = {0}; static WCHAR szLastFindWhat[80] = {0}; static bool findNext = false; static bool lastMatchCase = false; int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; #ifdef SHOW_TOOLBAR_UI if (hWnd == editWnd) { // Callback for the edit window switch (message) { case WM_CHAR: if (wParam == VK_RETURN && g_handler.get()) { // When the user hits the enter key load the URL CefRefPtr<CefBrowser> browser = g_handler->GetBrowser(); wchar_t strPtr[MAX_URL_LENGTH+1] = {0}; *((LPWORD)strPtr) = MAX_URL_LENGTH; LRESULT strLen = SendMessage(hWnd, EM_GETLINE, 0, (LPARAM)strPtr); if (strLen > 0) { strPtr[strLen] = 0; browser->GetMainFrame()->LoadURL(strPtr); } return 0; } } return (LRESULT)CallWindowProc(editWndOldProc, hWnd, message, wParam, lParam); } else #endif // SHOW_TOOLBAR_UI { // Callback for the main window switch (message) { case WM_CREATE: { // Create the single static handler class instance g_handler = new ClientHandler(); g_handler->SetMainHwnd(hWnd); // Create the child windows used for navigation RECT rect; int x = 0; GetClientRect(hWnd, &rect); #ifdef SHOW_TOOLBAR_UI backWnd = CreateWindow(L"BUTTON", L"Back", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_DISABLED, x, 0, BUTTON_WIDTH, URLBAR_HEIGHT, hWnd, (HMENU) IDC_NAV_BACK, hInst, 0); x += BUTTON_WIDTH; forwardWnd = CreateWindow(L"BUTTON", L"Forward", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_DISABLED, x, 0, BUTTON_WIDTH, URLBAR_HEIGHT, hWnd, (HMENU) IDC_NAV_FORWARD, hInst, 0); x += BUTTON_WIDTH; reloadWnd = CreateWindow(L"BUTTON", L"Reload", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_DISABLED, x, 0, BUTTON_WIDTH, URLBAR_HEIGHT, hWnd, (HMENU) IDC_NAV_RELOAD, hInst, 0); x += BUTTON_WIDTH; stopWnd = CreateWindow(L"BUTTON", L"Stop", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_DISABLED, x, 0, BUTTON_WIDTH, URLBAR_HEIGHT, hWnd, (HMENU) IDC_NAV_STOP, hInst, 0); x += BUTTON_WIDTH; editWnd = CreateWindow(L"EDIT", 0, WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT | ES_AUTOVSCROLL | ES_AUTOHSCROLL| WS_DISABLED, x, 0, rect.right - BUTTON_WIDTH * 4, URLBAR_HEIGHT, hWnd, 0, hInst, 0); // Assign the edit window's WNDPROC to this function so that we can // capture the enter key editWndOldProc = reinterpret_cast<WNDPROC>(GetWindowLongPtr(editWnd, GWLP_WNDPROC)); SetWindowLongPtr(editWnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(WndProc)); g_handler->SetEditHwnd(editWnd); g_handler->SetButtonHwnds(backWnd, forwardWnd, reloadWnd, stopWnd); rect.top += URLBAR_HEIGHT; #endif // SHOW_TOOLBAR_UI CefWindowInfo info; CefBrowserSettings settings; // Populate the settings based on command line arguments. AppGetBrowserSettings(settings); settings.file_access_from_file_urls_allowed = true; settings.universal_access_from_file_urls_allowed = true; // Initialize window info to the defaults for a child window info.SetAsChild(hWnd, rect); // Creat the new child browser window CefBrowserHost::CreateBrowser(info, static_cast<CefRefPtr<CefClient> >(g_handler), szInitialUrl, settings); return 0; } case WM_COMMAND: { CefRefPtr<CefBrowser> browser; if (g_handler.get()) browser = g_handler->GetBrowser(); wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_EXIT: if (g_handler.get()) { g_handler->QuittingApp(true); g_handler->DispatchCloseToNextBrowser(); } else { DestroyWindow(hWnd); } return 0; case ID_WARN_CONSOLEMESSAGE: if (g_handler.get()) { std::wstringstream ss; ss << L"Console messages will be written to " << std::wstring(CefString(g_handler->GetLogFile())); MessageBox(hWnd, ss.str().c_str(), L"Console Messages", MB_OK | MB_ICONINFORMATION); } return 0; case ID_WARN_DOWNLOADCOMPLETE: case ID_WARN_DOWNLOADERROR: if (g_handler.get()) { std::wstringstream ss; ss << L"File \"" << std::wstring(CefString(g_handler->GetLastDownloadFile())) << L"\" "; if (wmId == ID_WARN_DOWNLOADCOMPLETE) ss << L"downloaded successfully."; else ss << L"failed to download."; MessageBox(hWnd, ss.str().c_str(), L"File Download", MB_OK | MB_ICONINFORMATION); } return 0; #ifdef SHOW_TOOLBAR_UI case IDC_NAV_BACK: // Back button if (browser.get()) browser->GoBack(); return 0; case IDC_NAV_FORWARD: // Forward button if (browser.get()) browser->GoForward(); return 0; case IDC_NAV_RELOAD: // Reload button if (browser.get()) browser->Reload(); return 0; case IDC_NAV_STOP: // Stop button if (browser.get()) browser->StopLoad(); return 0; #endif // SHOW_TOOLBAR_UI } break; } case WM_PAINT: hdc = BeginPaint(hWnd, &ps); EndPaint(hWnd, &ps); return 0; case WM_SETFOCUS: if (g_handler.get() && g_handler->GetBrowser()) { // Pass focus to the browser window CefWindowHandle hwnd = g_handler->GetBrowser()->GetHost()->GetWindowHandle(); if (hwnd) PostMessage(hwnd, WM_SETFOCUS, wParam, NULL); } return 0; case WM_SIZE: // Minimizing resizes the window to 0x0 which causes our layout to go all // screwy, so we just ignore it. if (wParam != SIZE_MINIMIZED && g_handler.get() && g_handler->GetBrowser()) { CefWindowHandle hwnd = g_handler->GetBrowser()->GetHost()->GetWindowHandle(); if (hwnd) { // Resize the browser window and address bar to match the new frame // window size RECT rect; GetClientRect(hWnd, &rect); #ifdef SHOW_TOOLBAR_UI rect.top += URLBAR_HEIGHT; int urloffset = rect.left + BUTTON_WIDTH * 4; #endif // SHOW_TOOLBAR_UI HDWP hdwp = BeginDeferWindowPos(1); #ifdef SHOW_TOOLBAR_UI hdwp = DeferWindowPos(hdwp, editWnd, NULL, urloffset, 0, rect.right - urloffset, URLBAR_HEIGHT, SWP_NOZORDER); #endif // SHOW_TOOLBAR_UI hdwp = DeferWindowPos(hdwp, hwnd, NULL, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOZORDER); EndDeferWindowPos(hdwp); } } break; case WM_ERASEBKGND: if (g_handler.get() && g_handler->GetBrowser()) { CefWindowHandle hwnd = g_handler->GetBrowser()->GetHost()->GetWindowHandle(); if (hwnd) { // Dont erase the background if the browser window has been loaded // (this avoids flashing) return 0; } } break; case WM_CLOSE: if (g_handler.get()) { // If we already initiated the browser closing, then let default window proc handle it. HWND browserHwnd = g_handler->GetBrowser()->GetHost()->GetWindowHandle(); HANDLE closing = GetProp(browserHwnd, CLOSING_PROP); if (closing) { RemoveProp(browserHwnd, CLOSING_PROP); break; } g_handler->QuittingApp(true); g_handler->DispatchCloseToNextBrowser(); return 0; } break; case WM_DESTROY: // The frame window has exited PostQuitMessage(0); return 0; } return DefWindowProc(hWnd, message, wParam, lParam); } }
/** * @param hwnd - window handle. * @param uMsg - message identifier. * @param wParam - first message parameter. * @param lParam - second message parameter. */ LRESULT CALLBACK CSplitter::SplitterWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { int x, y, nSplitterPos, nSplitterSize; POINT point; HCURSOR hCursor; PAINTSTRUCT ps; HDC hdc; DWORD dwResult; CSplitter* _this = (CSplitter*)GetWindowLongPtr(hwnd, GWL_USERDATA); _ASSERTE(_this != NULL); switch(uMsg) { case WM_NCHITTEST: if (GetCapture() == hwnd) return HTCLIENT; point.x = GET_X_LPARAM(lParam); point.y = GET_Y_LPARAM(lParam); ScreenToClient(hwnd, &point); return (_this->HitTest(point) ? HTCLIENT : HTTRANSPARENT); case WM_SETCURSOR: _ASSERTE(g_pResManager != NULL); dwResult = GetMessagePos(); point.x = GET_X_LPARAM(dwResult); point.y = GET_Y_LPARAM(dwResult); ScreenToClient(hwnd, &point); if (_this->HitTest(point)) hCursor = _this->m_eDirection == SD_VERTICAL ? g_pResManager->m_hUpDownCursor : g_pResManager->m_hLeftRightCursor; else hCursor = g_pResManager->m_hArrowCursor; if (hCursor) { SetCursor(hCursor); return TRUE; } return FALSE; case WM_LBUTTONDOWN: if (GetCapture() != hwnd) { x = GET_X_LPARAM(lParam); y = GET_Y_LPARAM(lParam); if (_this->HitTest(x, y)) SetCapture(hwnd); } return 0; case WM_MOUSEMOVE: if (GetCapture() == hwnd) { nSplitterPos = _this->m_eDirection == SD_VERTICAL ? GET_Y_LPARAM(lParam) : GET_X_LPARAM(lParam); _this->SetSplitterPos(nSplitterPos); } return 0; case WM_LBUTTONUP: if (GetCapture() == hwnd) ReleaseCapture(); return 0; case WM_CAPTURECHANGED: return 0; case WM_ERASEBKGND: return TRUE; case WM_SIZE: nSplitterSize = _this->m_eDirection == SD_VERTICAL ? GET_Y_LPARAM(lParam) : GET_X_LPARAM(lParam); _this->ResizeSplitter(nSplitterSize); return 0; case WM_PAINT: hdc = (HDC)wParam; if (! hdc) { hdc = BeginPaint(hwnd, &ps); if (hdc) { _this->DrawSplitter(hdc); EndPaint(hwnd, &ps); } } else _this->DrawSplitter(hdc); return 0; case WM_PRINTCLIENT: hdc = (HDC)wParam; _this->DrawSplitter(hdc); return 0; case WM_GETDLGCODE: return DLGC_STATIC; default: return DefWindowProc(hwnd, uMsg, wParam, lParam); } }
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; HDC hdc; RECT rect; COLORREF colorText = RGB(0, 0, 255); // задаём цвет текста switch (message) { case WM_COMMAND: case BN_CLICKED: if (LOWORD(wParam) == ID_BUTTON1) { GetClientRect(hWnd, &rect); edit1 = CreateWindowEx( WS_EX_CLIENTEDGE, L"edit", L"Нажмите правую клавишу мыши", WS_CHILD | WS_VISIBLE | EM_FMTLINES, rect.right / 4, /*координаты по X*/ rect.bottom / 4, /*координаты по Y*/ rect.right / 2, /*Ширина окошка*/ rect.bottom / 2, hWnd, (HMENU)ID_EDIT1, hinst, NULL); } break; case WM_RBUTTONDOWN: ShowWindow(edit1, SW_HIDE); break; case WM_CREATE: GetClientRect(hWnd, &rect); button1 = CreateWindowEx( WS_EX_CLIENTEDGE, L"button", L"Показать", WS_CHILD | WS_VISIBLE, rect.right / 2 - ARRAYSIZE(L"Показать") * 4 - 10, /*координаты по X*/ rect.bottom - 30, /*координаты по Y*/ ARRAYSIZE(L"Показать") * 10, /*Ширина окошка*/ 25, hWnd, (HMENU)ID_BUTTON1, hinst, NULL); break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // инициализируем контекст устройства GetClientRect(hWnd, &rect); // получаем ширину и высоту области для рисования SetTextColor(hdc, colorText); // устанавливаем цвет контекстного устройства DrawText(hdc, L"В в е д и т е т е к с т", -1, &rect, DT_SINGLELINE | DT_CENTER); // рисуем текст break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); break; } return 0; }
LRESULT CALLBACK WinProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; switch (uMsg) { case WM_SIZE: // If the window is resized if(!g_bFullScreen) // Do this only if we are NOT in full screen { SizeOpenGLScreen(LOWORD(lParam),HIWORD(lParam));// LoWord=Width, HiWord=Height GetClientRect(hWnd, &g_rRect); // Get the window rectangle } break; case WM_PAINT: // If we need to repaint the scene BeginPaint(hWnd, &ps); // Init the paint struct EndPaint(hWnd, &ps); // EndPaint, Clean up break; //////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** //////////////////// // Below we define our controls for this simple tutorial. // The controls are: // Left Mouse Button - Changes the Render mode from normal to wireframe. // Right Mouse Button - Turns lighting On/Off // Left Arrow Key - Spins the model to the left // Right Arrow Key - Spins the model to the right // Escape - Quits case WM_LBUTTONDOWN: // If the left mouse button was clicked if(g_ViewMode == GL_TRIANGLES) { // We our drawing mode is at triangles g_ViewMode = GL_LINE_STRIP; // Go to line strips } else { g_ViewMode = GL_TRIANGLES; // Go to triangles } break; case WM_RBUTTONDOWN: // If the right mouse button was clicked. g_bLighting = !g_bLighting; // Turn lighting ON/OFF if(g_bLighting) { // If lighting is ON glEnable(GL_LIGHTING); // Enable OpenGL lighting } else { glDisable(GL_LIGHTING); // Disable OpenGL lighting } break; case WM_KEYDOWN: // If we pressed a key switch(wParam) { // Check if we hit a key case VK_ESCAPE: // If we hit the escape key PostQuitMessage(0); // Send a QUIT message to the window break; case VK_LEFT: // If the LEFT arrow key was pressed g_RotationSpeed -= 0.05f; // Decrease the rotation speed (eventually rotates left) break; case VK_RIGHT: // If the RIGHT arrow key is pressed g_RotationSpeed += 0.05f; // Increase the rotation speed (rotates right) break; } break; //////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** //////////////////// case WM_CLOSE: // If the window is being closed PostQuitMessage(0); // Send a QUIT Message to the window break; default: // Return by default return DefWindowProc (hWnd, uMsg, wParam, lParam); } return 0; // If we handled the messge return 0 }
BOOL CALLBACK MsgBoxDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { MBDATA * pMbd; switch (uMsg) { // center in parent but on screen if hWndPar != NULL case WM_INITDIALOG : { CRect rWin; GetClientRect (hDlg, &rWin); ASSERT ((rWin.left == 0) && (rWin.top == 0)); HWND hWndPar = GetParent (hDlg); if (hWndPar == NULL) rWin += CPoint ((GetSystemMetrics (SM_CXSCREEN) - rWin.Width ()) / 2, (GetSystemMetrics (SM_CYSCREEN) - rWin.Height ()) / 2); else { CRect rPar; GetWindowRect (hWndPar, &rPar); rWin += CPoint (rPar.left + (rPar.Width () - rWin.Width ()) / 2, rPar.top + (rPar.Height () - rWin.Height ()) / 2); if (rWin.left < 0) rWin += CPoint (- rWin.left, 0); else if (rWin.right > GetSystemMetrics (SM_CXSCREEN)) rWin -= CPoint (rWin.right - GetSystemMetrics (SM_CXSCREEN), 0); if (rWin.top < 0) rWin += CPoint (0, - rWin.top); else if (rWin.bottom > GetSystemMetrics (SM_CYSCREEN)) rWin -= CPoint (0, rWin.bottom - GetSystemMetrics (SM_CYSCREEN)); } SetWindowPos (hDlg, NULL, rWin.left, rWin.top, 0, 0, SWP_NOSIZE | SWP_NOZORDER); } // NO BREAK - falls through case WM_ACTIVATE : case WM_ACTIVATEAPP : hDlgBox = hDlg; return (TRUE); case WM_DESTROY : hDlgBox = NULL; break; case WM_PAINT : pMbd = (MBDATA *) GetWindowLong (hDlg, DWL_USER); if ((pMbd == NULL) || (pMbd->hIcon == NULL)) break; PAINTSTRUCT ps; BeginPaint (hDlg, &ps); DrawIcon (ps.hdc, pMbd->iXicon, pMbd->iYicon, pMbd->hIcon); EndPaint (hDlg, &ps); return (TRUE); case WM_COMMAND : if ((LOWORD (lParam) == 0) || (HIWORD (lParam) != BN_CLICKED)) break; if ((pMbd = (MBDATA *) GetWindowLong (hDlg, DWL_USER)) == NULL) break; // check for help if (wParam == pMbd->wHelpBtn) { const char *pHelpFile; char sName[130]; CWinApp *pApp = AfxGetApp (); if (pApp != NULL) pHelpFile = pApp->m_pszHelpFilePath; else { GetModuleFileName (AfxGetInstanceHandle (), sName, 128); int iLen = strlen (sName); if (iLen < 3) break; sName[iLen-3] = 0; strcat (sName, "HLP"); pHelpFile = sName; } if (pMbd->lHelp == 0) WinHelp (hDlg, pHelpFile, HELP_CONTENTS, 0); else WinHelp (hDlg, pHelpFile, HELP_CONTEXT, pMbd->lHelp); return (TRUE); } *(pMbd->piRtn) = wParam; return (TRUE); } return (FALSE); }
// // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) // // PURPOSE: Processes messages for the main window. // // WM_COMMAND - process the application menu // WM_PAINT - Paint the main window // WM_DESTROY - post a quit message and return // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; int mX, mY; PAINTSTRUCT ps; HDC hdc; ::GetClientRect(hWnd, &winRect); WorldRenderer worldHandle(hWnd, hdc, winRect, player); /* */ switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_ABOUT: DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); break; case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); worldHandle.update(playerAct); EndPaint(hWnd, &ps); break; case WM_MOUSEMOVE: // 부드럽게 보이기 위해서는 잔상처리를 그대로 하는 게 더 부드럽게 보임 // 잔상처리를 안할경우 화면이 번쩍거리는 현상이 보이게 됨 mX = LOWORD(lParam); // x coordinate mY = HIWORD(lParam); // y coordinate /* */ switch (wParam){ case MK_LBUTTON: if (player.moveFlag == true){ player.pos = worldHandle.getPlayerCoordinate(mX, mY); player.curpos = { mX, mY }; if (worldHandle.isCurInside(player)){ player.obj = worldHandle.getTileCoordnate(mX, mY); hdc = ::GetDC(hWnd); ::Ellipse(hdc, player.obj.left, player.obj.top, player.obj.right, player.obj.bottom); ::ReleaseDC(hWnd, hdc); playerAct = true; } else if (playerAct){ hdc = ::GetDC(hWnd); ::Ellipse(hdc, player.obj.left, player.obj.top, player.obj.right, player.obj.bottom); ::ReleaseDC(hWnd, hdc); } else{ // } } break; } /* */ break; case WM_LBUTTONUP: InvalidateRect(hWnd, NULL, true); break; case WM_LBUTTONDOWN: mX = LOWORD(lParam); // x coordinate mY = HIWORD(lParam); // y coordinate //test if (player.pos.x == worldHandle.getPlayerCoordinate(mX, mY).x && player.pos.y == worldHandle.getPlayerCoordinate(mX, mY).y){ player.moveFlag = true; } else { player.moveFlag = false; } // player.pos = worldHandle.getPlayerCoordinate(mX, mY); player.curpos = { mX, mY }; if ( worldHandle.isCurInside(player) ){ player.obj = worldHandle.getTileCoordnate(mX, mY); InvalidateRect(hWnd, NULL, true); playerAct = true; } else if(playerAct){ InvalidateRect(hWnd, NULL, true); } else{ playerAct = false; } break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
static LRESULT CALLBACK WndProc(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam) { switch (uMessage) { case WM_PAINT: { PAINTSTRUCT ps; BeginPaint(hwnd, &ps); SetMapMode(ps.hdc, MM_ANISOTROPIC); /* Set the window extent to a sane value in case the metafile doesn't */ SetWindowExtEx(ps.hdc, width, height, NULL); SetViewportExtEx(ps.hdc, width, height, NULL); SetViewportOrgEx(ps.hdc, deltax, deltay, NULL); if (isEnhanced && enhmf) { RECT r; GetClientRect(hwnd, &r); PlayEnhMetaFile(ps.hdc, enhmf, &r); } else if (hmf) PlayMetaFile(ps.hdc, hmf); EndPaint(hwnd, &ps); } break; case WM_COMMAND: /* message: command from application menu */ switch (LOWORD(wparam)) { case IDM_OPEN: { WCHAR filename[MAX_PATH]; if (FileOpen(hwnd, filename, sizeof(filename)/sizeof(WCHAR))) { szFileTitle[0] = 0; GetFileTitleW(filename, szFileTitle, sizeof(szFileTitle)/sizeof(WCHAR)); DoOpenFile(filename); UpdateWindowCaption(); } } break; case IDM_SET_EXT_TO_WIN: { RECT r; GetClientRect(hwnd, &r); width = r.right - r.left; height = r.bottom - r.top; deltax = deltay = 0; InvalidateRect( hwnd, NULL, TRUE ); } break; case IDM_LEFT: deltax += 100; InvalidateRect( hwnd, NULL, TRUE ); break; case IDM_RIGHT: deltax -= 100; InvalidateRect( hwnd, NULL, TRUE ); break; case IDM_UP: deltay += 100; InvalidateRect( hwnd, NULL, TRUE ); break; case IDM_DOWN: deltay -= 100; InvalidateRect( hwnd, NULL, TRUE ); break; case IDM_EXIT: DestroyWindow(hwnd); break; default: return DefWindowProcW(hwnd, uMessage, wparam, lparam); } break; case WM_DESTROY: /* message: window being destroyed */ PostQuitMessage(0); break; default: /* Passes it on if unprocessed */ return DefWindowProcW(hwnd, uMessage, wparam, lparam); } return 0; }
/************************************************************************* Win32 'Window Procedure' function *************************************************************************/ LRESULT CALLBACK Win32AppHelper::wndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_CHAR: s_samplesFramework->injectChar((CEGUI::utf32)wParam); break; case WM_MOUSELEAVE: mouseLeaves(); break; case WM_NCMOUSEMOVE: mouseLeaves(); break; case WM_MOUSEMOVE: mouseEnters(); s_samplesFramework->injectMousePosition((float)(LOWORD(lParam)), (float)(HIWORD(lParam))); break; case WM_LBUTTONDOWN: s_samplesFramework->injectMouseButtonDown(CEGUI::LeftButton); break; case WM_LBUTTONUP: s_samplesFramework->injectMouseButtonUp(CEGUI::LeftButton); break; case WM_RBUTTONDOWN: s_samplesFramework->injectMouseButtonDown(CEGUI::RightButton); break; case WM_RBUTTONUP: s_samplesFramework->injectMouseButtonUp(CEGUI::RightButton); break; case WM_MBUTTONDOWN: s_samplesFramework->injectMouseButtonDown(CEGUI::MiddleButton); break; case WM_MBUTTONUP: s_samplesFramework->injectMouseButtonUp(CEGUI::MiddleButton); break; case 0x020A: // WM_MOUSEWHEEL: s_samplesFramework->injectMouseWheelChange(static_cast<float>((short)HIWORD(wParam)) / static_cast<float>(120)); break; case WM_DESTROY: PostQuitMessage(0); break; case WM_SIZE: { // get CEGUI::System as a pointer so we can detect if it's not // instantiated yet. CEGUI::System* cegui_system = CEGUI::System::getSingletonPtr(); // only continue if CEGUI is up an running and window was not // minimised (else it's just a waste of time) if ((cegui_system != 0) && (wParam != SIZE_MINIMIZED)) { // get renderer identification string CEGUI::Renderer* renderer = cegui_system->getRenderer(); CEGUI::String id(renderer->getIdentifierString()); // invoke correct function based on the renderer we have ID'd #ifdef CEGUI_BUILD_RENDERER_DIRECT3D9 if (id.find("Official Direct3D 9") != id.npos) DeviceReset_Direct3D9(hWnd, renderer); #endif #ifdef CEGUI_BUILD_RENDERER_DIRECT3D10 if (id.find("Official Direct3D 10") != id.npos) DeviceReset_Direct3D10(hWnd, renderer); #endif #ifdef CEGUI_BUILD_RENDERER_DIRECT3D11 if (id.find("Official Direct3D 11") != id.npos) DeviceReset_Direct3D11(hWnd, renderer); #endif } } break; case WM_PAINT: { HDC hDC; PAINTSTRUCT ps; hDC = BeginPaint(hWnd, &ps); EndPaint(hWnd, &ps); break; } default: return(DefWindowProc(hWnd, message, wParam, lParam)); break; } return 0; }
static u32 win_proc(MSG *pMsg) { HWND hwnd; HDC hdc; RECT rc,rc0; u32 i; hwnd =pMsg->hwnd; switch(pMsg->Code) { case MSG_CREATE: GetClientRect(hwnd,&rc0); CreateWindow(BUTTON,"关闭",WS_CHILD|BS_NORMAL|WS_BORDER|WS_VISIBLE,RectW(&rc0)-64,RectH(&rc0)-28,60,24,hwnd,ID_CLOSE,NULL); SetRect(&rc,4,8,120,100); hwndLB1=CreateWindow(LISTBOX,"列表框1",WS_CHILD|WS_BORDER|WS_VISIBLE,rc.left,rc.top,RectW(&rc),RectH(&rc),hwnd,ID_LISTBOX1,NULL); OffsetRect(&rc,RectW(&rc)+8,0); hwndLB2=CreateWindow(LISTBOX,"列表框2",WS_CHILD|WS_BORDER|WS_VISIBLE,rc.left,rc.top,RectW(&rc),RectH(&rc),hwnd,ID_LISTBOX2,NULL); GetWindowRect(hwndLB1,&rc); OffsetRect(&rc,0,RectH(&rc)+4); ScreenToClient(hwnd,(POINT*)&rc,2); CreateWindow(BUTTON,"-->",WS_CHILD|BS_NORMAL|WS_BORDER|WS_VISIBLE,rc.right-50,rc.top,50,20,hwnd,ID_RIGHT,NULL); GetWindowRect(hwndLB2,&rc); OffsetRect(&rc,0,RectH(&rc)+4); ScreenToClient(hwnd,(POINT*)&rc,2); CreateWindow(BUTTON,"<--",WS_CHILD|BS_NORMAL|WS_BORDER|WS_VISIBLE,rc.left,rc.top,50,20,hwnd,ID_LEFT,NULL); SendMessage(hwndLB1,LBM_ADDSTRING,0,(u32)"ListItem-0"); SendMessage(hwndLB1,LBM_ADDSTRING,1,(u32)"ListItem-1"); SendMessage(hwndLB1,LBM_ADDSTRING,2,(u32)"ListItem-2"); SendMessage(hwndLB1,LBM_ADDSTRING,3,(u32)"ListItem-3"); SendMessage(hwndLB1,LBM_ADDSTRING,4,(u32)"ListItem-4"); SendMessage(hwndLB1,LBM_ADDSTRING,5,(u32)"ListItem-5"); SendMessage(hwndLB1,LBM_ADDSTRING,6,(u32)"ListItem-6"); SendMessage(hwndLB1,LBM_ADDSTRING,7,(u32)"ListItem-7"); SendMessage(hwndLB1,LBM_ADDSTRING,8,(u32)"ListItem-8"); SendMessage(hwndLB1,LBM_ADDSTRING,9,(u32)"ListItem-9"); SendMessage(hwndLB1,LBM_SETTOPINDEX,0,0); SendMessage(hwndLB1,LBM_SETCURSEL,3,0); SendMessage(hwndLB2,LBM_ADDSTRING,0,(u32)"ListItem-10"); SendMessage(hwndLB2,LBM_ADDSTRING,1,(u32)"ListItem-11"); SendMessage(hwndLB2,LBM_ADDSTRING,2,(u32)"ListItem-12"); SendMessage(hwndLB2,LBM_ADDSTRING,3,(u32)"ListItem-13"); SendMessage(hwndLB2,LBM_ADDSTRING,4,(u32)"ListItem-14"); SendMessage(hwndLB2,LBM_ADDSTRING,5,(u32)"ListItem-15"); SendMessage(hwndLB2,LBM_ADDSTRING,6,(u32)"ListItem-16"); SendMessage(hwndLB2,LBM_ADDSTRING,7,(u32)"ListItem-17"); SendMessage(hwndLB2,LBM_ADDSTRING,8,(u32)"ListItem-18"); SendMessage(hwndLB2,LBM_ADDSTRING,9,(u32)"ListItem-19"); SendMessage(hwndLB2,LBM_SETTOPINDEX,0,0); SendMessage(hwndLB2,LBM_SETCURSEL,3,0); GDD_CreateTimer(hwnd,1,3000,TMR_START); GDD_CreateTimer(hwnd,2,100,TMR_START); break; //// case MSG_TIMER: { switch(pMsg->Param1) { case 1: { } break; ///// case 2: { } break; ///// } } break; case MSG_NOTIFY: { u16 event,id; event =HI16(pMsg->Param1); id =LO16(pMsg->Param1); if(event==BTN_UP && id==ID_CLOSE) { PostMessage(hwnd,MSG_CLOSE,0,0); }//// if(event==BTN_UP && id==ID_RIGHT) { char *buf; int i; i =SendMessage(hwndLB1,LBM_GETCURSEL,0,0); if(i>=0) { buf =(char*)malloc(SendMessage(hwndLB1,LBM_GETTEXTLEN,i,0)); if(buf!=NULL) { SendMessage(hwndLB1,LBM_GETTEXT,i,(u32)buf); SendMessage(hwndLB1,LBM_DELSTRING,i,0); SendMessage(hwndLB2,LBM_ADDSTRING,-1,(u32)buf); i=SendMessage(hwndLB2,LBM_GETCOUNT,0,0)-1; SendMessage(hwndLB2,LBM_SETTOPINDEX,i-3,0); SendMessage(hwndLB2,LBM_SETCURSEL,-1,0); free(buf); } } }//// if(event==BTN_UP && id==ID_LEFT) { char *buf; int i; i =SendMessage(hwndLB2,LBM_GETCURSEL,0,0); if(i>=0) { buf =(char*)malloc(SendMessage(hwndLB2,LBM_GETTEXTLEN,i,0)); if(buf!=NULL) { SendMessage(hwndLB2,LBM_GETTEXT,i,(u32)buf); SendMessage(hwndLB2,LBM_DELSTRING,i,0); SendMessage(hwndLB1,LBM_ADDSTRING,-1,(u32)buf); i=SendMessage(hwndLB1,LBM_GETCOUNT,0,0)-1; SendMessage(hwndLB1,LBM_SETTOPINDEX,i-3,0); SendMessage(hwndLB1,LBM_SETCURSEL,-1,0); free(buf); } } }//// if(event==LBN_SELCHANGE && id==ID_LISTBOX1) { printf("listbox1 sel change.\r\n"); }//// if(event==LBN_SELCHANGE && id==ID_LISTBOX2) { printf("listbox2 sel change.\r\n"); }//// } break; //// case MSG_PAINT: { hdc =BeginPaint(hwnd); GetClientRect(hwnd,&rc0); SetFillColor(hdc,RGB(200,200,200)); FillRect(hdc,&rc0); EndPaint(hwnd,hdc); } break; //// default: return DefWindowProc(pMsg); } return 0; }
/**************************************************************************** * * * Function: CreateHypCtrl * * * * Purpose : Create Hyperlink control. * * * * History : Date Reason * * 00/00/00 Created * * * ****************************************************************************/ HWND CreateHypCtrl(HWND hWndParent, HYPCTRL* pHc, int x, int y, int width, int height) { HYPCTRL* pHcWnd; HWND hWndHyperlink; RECT rect; LOGFONT lf; HFONT hFontParent, hFontNormal, hFontHover; // some error checking if (hInst == NULL) return (HWND) NULL; if (hWndParent == NULL) return (HWND) NULL; if (pHc->cbFn == NULL) { // if the hyperlink opens a normal link, require the szLink member if (pHc->szLink == NULL) return (HWND) NULL; } else { // if the hyperlink calls a callback function, require the szText member if (pHc->szText == NULL) return (HWND) NULL; } hWndHyperlink = CreateWindow(lpszClassname, NULL, WS_CHILD, x, y, width, height, hWndParent, NULL, hInst, NULL); if (!hWndHyperlink) return (HWND) NULL; // alloc some space to hold all hyperlink stuff if ((pHcWnd = GlobalAllocPtr(GPTR, sizeof(HYPCTRL))) == NULL) { DestroyWindow(hWndHyperlink); return (HWND) NULL; } CopyMemory(pHcWnd, pHc, sizeof(HYPCTRL)); // copy the text entries from HYPCTRL if (pHcWnd->cbFn == NULL) { if (pHcWnd->szLink != NULL) { if ((pHcWnd->szLink = (LPTSTR) GlobalAllocPtr(GPTR, STRBYTESIZE(pHc->szLink))) == NULL) { if (pHcWnd) GlobalFreePtr(pHcWnd); DestroyWindow(hWndHyperlink); return (HWND) NULL; } CopyMemory(pHcWnd->szLink, pHc->szLink, STRBYTESIZE(pHc->szLink)); } } if (pHcWnd->szText != NULL) { if ((pHcWnd->szText = GlobalAllocPtr(GPTR, STRBYTESIZE(pHc->szText))) == NULL) { if (pHcWnd->szLink) GlobalFreePtr(pHcWnd->szLink); if (pHcWnd) GlobalFreePtr(pHcWnd); DestroyWindow(hWndHyperlink); return (HWND) NULL; } CopyMemory(pHcWnd->szText, pHc->szText, STRBYTESIZE(pHc->szText)); } else { // no callback function and no szText given so we use szLink as text if(pHcWnd->cbFn == NULL) pHcWnd->szText = pHcWnd->szLink; } if (pHcWnd->szTooltip != NULL) { if ((pHcWnd->szTooltip = GlobalAllocPtr(GPTR, STRBYTESIZE(pHc->szTooltip))) == NULL) { if (pHcWnd->szLink) GlobalFreePtr(pHcWnd->szLink); if (pHcWnd->szText) GlobalFreePtr(pHcWnd->szText); if (pHcWnd) GlobalFreePtr(pHcWnd); DestroyWindow(hWndHyperlink); return (HWND) NULL; } CopyMemory(pHcWnd->szTooltip, pHc->szTooltip, STRBYTESIZE(pHc->szTooltip)); } // save a pointer to the structure in the window extra space SetWindowLong(hWndHyperlink, WND_HYPSTRUCT, (LONG) (pHcWnd)); SetWindowWord(hWndHyperlink, WND_ISHOVER, (WORD) FALSE); // create the fonts for the control hFontParent = (HFONT) SendMessage(GetParent(hWndHyperlink), WM_GETFONT, 0, 0); if (hFontParent != NULL) { GetObject(hFontParent, sizeof(LOGFONT), &lf); switch (pHcWnd->ulStyle) { case ulHover: hFontNormal = CreateFontIndirect(&lf); lf.lfUnderline = (BYTE) TRUE; hFontHover = CreateFontIndirect(&lf); break; case ulAlways: lf.lfUnderline = (BYTE) TRUE; hFontNormal = CreateFontIndirect(&lf); hFontHover = CreateFontIndirect(&lf); break; case ulNone: hFontNormal = CreateFontIndirect(&lf); hFontHover = CreateFontIndirect(&lf); break; } // save the fonts in the window extra space SetWindowLong(hWndHyperlink, WND_FONTN, (LONG) hFontNormal); SetWindowLong(hWndHyperlink, WND_FONTH, (LONG) hFontHover); } else { // use the system font SetWindowLong(hWndHyperlink, WND_FONTN, (LONG) NULL); SetWindowLong(hWndHyperlink, WND_FONTH, (LONG) NULL); } GetClientRect(hWndHyperlink, &rect); // adjust window size to fit the text if (pHcWnd->bAutoSize) { PAINTSTRUCT ps; HDC hdc; SIZE size; hdc = BeginPaint(hWndHyperlink, &ps); SelectObject(hdc, (HFONT) GetWindowLong(hWndHyperlink, WND_FONTN)); GetTextExtentPoint32(hdc, pHcWnd->szText, GetStringLength(pHcWnd->szText), &size); rect.right = size.cx - rect.left; rect.bottom = size.cy - rect.top; EndPaint(hWndHyperlink, &ps); SetWindowPos(hWndHyperlink, 0, 0, 0, size.cx, size.cy, SWP_NOMOVE | SWP_NOZORDER); } // save window size in the window extra space SetWindowLong(hWndHyperlink, WND_LEFT, (LONG) (rect.left)); SetWindowLong(hWndHyperlink, WND_TOP, (LONG) (rect.top)); SetWindowLong(hWndHyperlink, WND_RIGHT, (LONG) (rect.right)); SetWindowLong(hWndHyperlink, WND_BOTTOM, (LONG) (rect.bottom)); // create tooltip if requested if (pHcWnd->szTooltip != NULL) { HWND hWndTT; TOOLINFO ti; hWndTT = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL, WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hWndHyperlink, NULL, hInst, NULL); if (!hWndTT) return FALSE; SetWindowPos(hWndTT, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); ti.cbSize = sizeof(TOOLINFO); ti.uFlags = TTF_SUBCLASS; ti.hwnd = hWndHyperlink; ti.hinst = hInst; ti.uId = 0; ti.lpszText = pHcWnd->szTooltip; // get text for tooltip ti.rect.left = (LONG) GetWindowLong(hWndHyperlink, WND_LEFT); ti.rect.top = (LONG) GetWindowLong(hWndHyperlink, WND_TOP); ti.rect.right = (LONG) GetWindowLong(hWndHyperlink, WND_RIGHT); ti.rect.bottom = (LONG) GetWindowLong(hWndHyperlink, WND_BOTTOM); // add tooltip SendMessage(hWndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti); } // show the window ShowWindow(hWndHyperlink, SW_NORMAL); UpdateWindow(hWndHyperlink); return hWndHyperlink; }
internal LRESULT CALLBACK Win32MainWindowCallback(HWND window, UINT msg, WPARAM w_param, LPARAM l_param) { if (EasyTab_HandleEvent(window, msg, l_param, w_param) == EASYTAB_OK) { return true; // Tablet input } LRESULT result = 0; ImGuiIO& io = ImGui::GetIO(); switch (msg) { // Mouse case WM_LBUTTONDOWN: { io.MouseDown[0] = true; return true; } break; case WM_LBUTTONUP: { io.MouseDown[0] = false; return true; } break; case WM_RBUTTONDOWN: { io.MouseDown[1] = true; return true; } break; case WM_RBUTTONUP: { io.MouseDown[1] = false; return true; } break; case WM_MBUTTONDOWN: { io.MouseDown[2] = true; return true; } break; case WM_MBUTTONUP: { io.MouseDown[2] = false; return true; } break; case WM_MOUSEWHEEL: { io.MouseWheel += GET_WHEEL_DELTA_WPARAM(w_param) > 0 ? +1.0f : -1.0f; return true; } break; case WM_MOUSEMOVE: { TRACKMOUSEEVENT track_param = {}; track_param.dwFlags |= TME_LEAVE; track_param.hwndTrack = window; track_param.cbSize = sizeof(track_param); TrackMouseEvent(&track_param); io.MousePos.x = (signed short)(l_param); io.MousePos.y = (signed short)(l_param >> 16); return true; } break; case WM_MOUSELEAVE: { ImGui::GetIO().MouseDown[0] = false; ImGui::GetIO().MouseDown[1] = false; ImGui::GetIO().MouseDown[2] = false; return true; } break; // Keyboard case WM_KEYDOWN: { if (w_param < 256) io.KeysDown[w_param] = 1; return true; } break; case WM_KEYUP: { if (w_param < 256) io.KeysDown[w_param] = 0; return true; } break; case WM_CHAR: { // You can also use ToAscii()+GetKeyboardState() to retrieve characters. if (w_param > 0 && w_param < 0x10000) io.AddInputCharacter((unsigned short)w_param); return true; } break; // window handling case WM_DESTROY: { mem.is_running = false; if (rendering_context) { wglMakeCurrent(NULL, NULL); wglDeleteContext(rendering_context); } ReleaseDC(window, device_context); PostQuitMessage(0); } break; case WM_PAINT: { PAINTSTRUCT paint; BeginPaint(window, &paint); // TODO: Redraw here EndPaint(window, &paint); } break; case WM_CLOSE: { // TODO: Handle this with a message to the user? mem.is_running = false; } break; case WM_SIZE: { int32 width, height; if (w_param == SIZE_MAXIMIZED) { int32 work_area_width = windows_work_area.right - windows_work_area.left; int32 work_area_height = windows_work_area.bottom - windows_work_area.top; SetWindowPos(window, HWND_TOP, windows_work_area.left, windows_work_area.top, work_area_width, work_area_height, NULL); width = work_area_width; height = work_area_height; } else { width = (int32) LOWORD(l_param); height = (int32) HIWORD(l_param); } core::resize(&mem, width, height); // Clear and swap buffers { if (mem.colors[PapayaCol_Clear]) { glClearBufferfv(GL_COLOR, 0, (GLfloat*)&mem.colors[PapayaCol_Clear]); } SwapBuffers(device_context); } } break; // WM_NCHITTEST case WM_NCHITTEST: { const LONG border_width = 8; //in pixels RECT window_rect; GetWindowRect(window, &window_rect); long X = GET_X_LPARAM(l_param); long Y = GET_Y_LPARAM(l_param); if (!IsMaximized(window)) { //bottom left corner if (X >= window_rect.left && X < window_rect.left + border_width && Y < window_rect.bottom && Y >= window_rect.bottom - border_width) { return HTBOTTOMLEFT; } //bottom right corner if (X < window_rect.right && X >= window_rect.right - border_width && Y < window_rect.bottom && Y >= window_rect.bottom - border_width) { return HTBOTTOMRIGHT; } //top left corner if (X >= window_rect.left && X < window_rect.left + border_width && Y >= window_rect.top && Y < window_rect.top + border_width) { return HTTOPLEFT; } //top right corner if (X < window_rect.right && X >= window_rect.right - border_width && Y >= window_rect.top && Y < window_rect.top + border_width) { return HTTOPRIGHT; } //left border if (X >= window_rect.left && X < window_rect.left + border_width) { return HTLEFT; } //right border if (X < window_rect.right && X >= window_rect.right - border_width) { return HTRIGHT; } //bottom border if (Y < window_rect.bottom && Y >= window_rect.bottom - border_width) { return HTBOTTOM; } //top border if (Y >= window_rect.top && Y < window_rect.top + border_width) { return HTTOP; } } if (Y - window_rect.top <= (float)mem.window.title_bar_height && X > window_rect.left + 200.0f && X < window_rect.right - (float)(mem.window.title_bar_buttons_width + 10)) { return HTCAPTION; } SetCursor(LoadCursor(NULL, IDC_ARROW)); return HTCLIENT; } break; default: { result = DefWindowProcA(window, msg, w_param, l_param); } break; } return(result); }
/**************************************************************************** * * * Function: HypCtrlWndProc * * * * Purpose : Process Hyperlink control messages. * * * * History : Date Reason * * 00/00/00 Created * * * ****************************************************************************/ static LRESULT CALLBACK HypCtrlWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg){ case WM_LBUTTONUP: { HYPCTRL* pHcWnd = (HYPCTRL*) GetWindowLong(hWnd, WND_HYPSTRUCT); if (pHcWnd->bPlaySound) PlayNavigatingSound(); if (pHcWnd->cbFn != NULL) { // call user function (callback) pHcWnd->cbFn(pHcWnd->cbID); } else { // jump to link ShellExecute(NULL, _T("open"), pHcWnd->szLink, NULL, NULL, SW_SHOW); } return FALSE; } case WM_PAINT: { PAINTSTRUCT ps; HDC hdc; RECT rect; HYPCTRL* pHcWnd = (HYPCTRL*) GetWindowLong(hWnd, WND_HYPSTRUCT); BOOL bIsOverControl = (BOOL) GetWindowWord(hWnd, WND_ISHOVER); rect.left = (LONG) GetWindowLong(hWnd, WND_LEFT); rect.top = (LONG) GetWindowLong(hWnd, WND_TOP); rect.right = (LONG) GetWindowLong(hWnd, WND_RIGHT); rect.bottom = (LONG) GetWindowLong(hWnd, WND_BOTTOM); hdc = BeginPaint(hWnd, &ps); if (bIsOverControl) { // draws hover state SetBkColor(hdc, (COLORREF) pHcWnd->bgcHover); SelectObject(hdc, (HFONT) GetWindowLong(hWnd, WND_FONTH)); SetTextColor(hdc, pHcWnd->fgcHover); } else { // draws normal state SetBkColor(hdc, (COLORREF) pHcWnd->bgcNormal); SelectObject(hdc, (HFONT) GetWindowLong(hWnd, WND_FONTN)); SetTextColor(hdc, pHcWnd->fgcNormal); } // draw the text DrawText(hdc, pHcWnd->szText, -1, &rect, pHcWnd->dtStyle); EndPaint(hWnd, &ps); return FALSE; } case WM_CAPTURECHANGED: SetWindowWord(hWnd, WND_ISHOVER, (WORD) FALSE); InvalidateRect(hWnd, NULL, TRUE); return FALSE; case WM_MOUSEMOVE: { RECT rect; rect.left = (LONG) GetWindowLong(hWnd, WND_LEFT); rect.top = (LONG) GetWindowLong(hWnd, WND_TOP); rect.right = (LONG) GetWindowLong(hWnd, WND_RIGHT); rect.bottom = (LONG) GetWindowLong(hWnd, WND_BOTTOM); // check if mouse is over control if ((BOOL) GetWindowWord(hWnd, WND_ISHOVER)) { POINT ptMousePos; DWORD dwMousePos; dwMousePos = GetMessagePos(); ptMousePos.x = LOWORD(dwMousePos); ptMousePos.y = HIWORD(dwMousePos); ScreenToClient(hWnd, &ptMousePos); if (!(BOOL) PtInRect(&rect, ptMousePos)) { SetWindowWord(hWnd, WND_ISHOVER, (WORD) FALSE); InvalidateRect(hWnd, &rect, TRUE); ReleaseCapture(); } } else { SetWindowWord(hWnd, WND_ISHOVER, (WORD) TRUE); InvalidateRect(hWnd, &rect, TRUE); SetCapture(hWnd); } return FALSE; } case WM_CLOSE: { HYPCTRL* pHcWnd = (HYPCTRL*) GetWindowLong(hWnd, WND_HYPSTRUCT); HFONT hFontTemp; // clean up if (pHcWnd->szLink) GlobalFreePtr(pHcWnd->szLink); if (pHcWnd->szText) GlobalFreePtr(pHcWnd->szText); if (pHcWnd->szTooltip) GlobalFreePtr(pHcWnd->szTooltip); if (pHcWnd->cbFn) GlobalFreePtr(pHcWnd->cbFn); hFontTemp = (HFONT) GetWindowLong(hWnd, WND_FONTN); if (hFontTemp) DeleteObject(hFontTemp); hFontTemp = (HFONT) GetWindowLong(hWnd, WND_FONTH); if (hFontTemp) DeleteObject(hFontTemp); if (pHcWnd) GlobalFreePtr(pHcWnd); DestroyWindow(hWnd); return FALSE; } } return DefWindowProc(hWnd, msg, wParam, lParam); }
// // FUNCTION: WndProc(HWND, unsigned, WORD, LONG) // // PURPOSE: Processes messages for the main window. // // WM_COMMAND - process the application menu // WM_PAINT - Paint the main window // WM_DESTROY - post a quit message and return // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; TCHAR szHello[MAX_LOADSTRING]; LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING); SOCKET s,newsock; char recvbuf[128]; struct sockaddr remote; int len; int retval; switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_ABOUT: DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About); break; case IDM_EXIT: Stop_server(hWnd); DestroyWindow(hWnd); break; case IDM_START: Start_server(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here... RECT rt; GetClientRect(hWnd, &rt); DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER); EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; case UM_SOCK: s = (SOCKET)wParam; wmEvent = LOWORD(lParam); switch(wmEvent){ case FD_ACCEPT: len = sizeof(remote); newsock = accept(s,&remote,&len); WSAAsyncSelect(newsock,hWnd,UM_SOCK,FD_READ|FD_CLOSE);//|FD_WRITE); break; case FD_READ: retval = recv(s,recvbuf,sizeof(recvbuf),0); if(retval <= 0){ closesocket(s); break; } recvbuf[retval] = 0; hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here... hdc = GetDC(hWnd); TextOut(hdc,0,row,recvbuf,strlen(recvbuf)); row += 16; ReleaseDC(hWnd,hdc); //»ØËÍÐÅÏ¢ send(s,"ACK",3,0); break; case FD_CLOSE: MessageBox(hWnd,"closesocket\n","server",MB_OK); closesocket(s); break; case FD_WRITE: MessageBox(hWnd,"write event\n","server",MB_OK); break; default: if(WSAGETSELECTERROR(lParam) != 0){ MessageBox(hWnd,"select report error\n","server",MB_OK); closesocket(s); WSACleanup(); } } break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
//----------------------------------------------------------------------------- void Win32Frame::paint (HWND hwnd) { HRGN rgn = CreateRectRgn (0, 0, 0, 0); if (GetUpdateRgn (hwnd, rgn, false) == NULLREGION) { DeleteObject (rgn); return; } inPaint = true; PAINTSTRUCT ps; HDC hdc = BeginPaint (hwnd, &ps); if (hdc) { CRect updateRect ((CCoord)ps.rcPaint.left, (CCoord)ps.rcPaint.top, (CCoord)ps.rcPaint.right, (CCoord)ps.rcPaint.bottom); CRect frameSize; getSize (frameSize); frameSize.offset (-frameSize.left, -frameSize.top); if (deviceContext == 0) deviceContext = createDrawContext (hwnd, hdc, frameSize); if (deviceContext) { deviceContext->setClipRect (updateRect); CDrawContext* drawContext = backBuffer ? backBuffer : deviceContext; drawContext->beginDraw (); DWORD len = GetRegionData (rgn, 0, NULL); if (len) { if (len > updateRegionListSize) { if (updateRegionList) free (updateRegionList); updateRegionListSize = len; updateRegionList = (RGNDATA*) malloc (updateRegionListSize); } GetRegionData (rgn, len, updateRegionList); if (updateRegionList->rdh.nCount > 0) { RECT* rp = (RECT*)updateRegionList->Buffer; for (uint32_t i = 0; i < updateRegionList->rdh.nCount; i++) { CRect ur (rp->left, rp->top, rp->right, rp->bottom); paintRect = ur; drawContext->clearRect (ur); getFrame ()->platformDrawRect (drawContext, ur); rp++; } } else { getFrame ()->platformDrawRect (drawContext, updateRect); } } drawContext->endDraw (); if (backBuffer) { deviceContext->beginDraw (); deviceContext->clearRect (updateRect); backBuffer->copyFrom (deviceContext, updateRect, CPoint (updateRect.left, updateRect.top)); deviceContext->endDraw (); } } } EndPaint (hwnd, &ps); DeleteObject (rgn); inPaint = false; }
LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { static int cxClient, cyClient; static int cxGrid, cyGrid; static int CheckedGrid[5][5]; PAINTSTRUCT ps; HDC hdc; int i, j; int cxCursor, cyCursor; RECT rectGrid; POINT ptCursor; switch(uMsg) { case WM_KEYDOWN: { //Get Cursor current position GetCursorPos(&ptCursor); ScreenToClient(hwnd, &ptCursor); i = ptCursor.x / cxGrid; j = ptCursor.y / cyGrid; switch(wParam) { case VK_LEFT: i--; break; case VK_RIGHT: i++; break; case VK_UP: j--; break; case VK_DOWN: j++; break; case VK_HOME: i = 0; j = 0; break; case VK_END: i = ROWCOUNT - 1; j = COLUMNCOUNT - 1; break; default: break; } if (i > COLUMNCOUNT - 1) { i = 0; } else if (i < 0) { i = COLUMNCOUNT - 1; } if (j > ROWCOUNT - 1) { j = 0; } else if (j < 0) { j = ROWCOUNT - 1; } ptCursor.x = i * cxGrid + cxGrid / 2; ptCursor.y = j * cyGrid + cyGrid / 2; ClientToScreen(hwnd, &ptCursor); SetCursorPos(ptCursor.x, ptCursor.y); break; } case WM_CHAR: { switch (wParam) { case ' ': //Space case '\r': //Enter { GetCursorPos(&ptCursor); ScreenToClient(hwnd, &ptCursor); SendMessage(hwnd, WM_LBUTTONDOWN, 0, MAKELONG(ptCursor.x, ptCursor.y)); break; } } break; } case WM_SIZE: { cxClient = LOWORD(lParam); cyClient = HIWORD(lParam); cxGrid = cxClient / COLUMNCOUNT; cyGrid = cyClient / ROWCOUNT; InvalidateRect(hwnd, NULL, TRUE); break; } case WM_LBUTTONDOWN: { cxCursor = LOWORD(lParam); cyCursor = HIWORD(lParam); i = cxCursor / cxGrid; j = cyCursor /cyGrid; CheckedGrid[i][j] = !CheckedGrid[i][j]; rectGrid.left = i * cxGrid; rectGrid.right = (i+1) * cxGrid; rectGrid.top = j * cyGrid; rectGrid.bottom = (j+1) * cyGrid; InvalidateRect(hwnd, &rectGrid, TRUE); break; } case WM_PAINT: { hdc = BeginPaint(hwnd, &ps); // Draw lines for (i = 0; i < ROWCOUNT; ++i) { MoveToEx(hdc, 0, cyGrid * (1 + i), NULL); LineTo(hdc, cxGrid * COLUMNCOUNT, cyGrid * (1 + i)); } for (i = 0; i < COLUMNCOUNT; ++i) { MoveToEx(hdc, cxGrid * (1 + i), 0, NULL); LineTo(hdc, cxGrid * (1 + i), cyGrid * ROWCOUNT); } for (i = 0; i < ROWCOUNT; ++i) { for (j=0; j < COLUMNCOUNT; ++j) { if (CheckedGrid[i][j]) { //Draw Cross line MoveToEx(hdc, i * cxGrid, j * cyGrid, NULL); LineTo(hdc, (i+1) * cxGrid, (j+1) * cyGrid); MoveToEx(hdc, (i+1) * cxGrid, j * cyGrid, NULL); LineTo(hdc, i * cxGrid, (j+1) * cyGrid); } } } // Draw Checkers EndPaint(hwnd, &ps); break; } case WM_DESTROY: { PostQuitMessage(0); return 0; } } return DefWindowProc(hwnd, uMsg, wParam, lParam); }
LRESULT CALLBACK DownloadProgressProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData) { static WCHAR szProgressText[MAX_STR_LEN] = {0}; switch (uMsg) { case WM_SETTEXT: { if (lParam) { StringCbCopyW(szProgressText, sizeof(szProgressText), (PCWSTR)lParam); } } case WM_ERASEBKGND: case WM_PAINT: { PAINTSTRUCT ps; HDC hDC = BeginPaint(hWnd, &ps), hdcMem; HBITMAP hbmMem; HANDLE hOld; RECT myRect; UINT win_width, win_height; GetClientRect(hWnd, &myRect); /* grab the progress bar rect size */ win_width = myRect.right - myRect.left; win_height = myRect.bottom - myRect.top; /* create an off-screen DC for double-buffering */ hdcMem = CreateCompatibleDC(hDC); hbmMem = CreateCompatibleBitmap(hDC, win_width, win_height); hOld = SelectObject(hdcMem, hbmMem); /* call the original draw code and redirect it to our memory buffer */ DefSubclassProc(hWnd, uMsg, (WPARAM)hdcMem, lParam); /* draw our nifty progress text over it */ SelectFont(hdcMem, GetStockFont(DEFAULT_GUI_FONT)); DrawShadowText(hdcMem, szProgressText, wcslen(szProgressText), &myRect, DT_CENTER | DT_VCENTER | DT_NOPREFIX | DT_SINGLELINE, GetSysColor(COLOR_CAPTIONTEXT), GetSysColor(COLOR_3DSHADOW), 1, 1); /* transfer the off-screen DC to the screen */ BitBlt(hDC, 0, 0, win_width, win_height, hdcMem, 0, 0, SRCCOPY); /* free the off-screen DC */ SelectObject(hdcMem, hOld); DeleteObject(hbmMem); DeleteDC(hdcMem); EndPaint(hWnd, &ps); return 0; } /* Raymond Chen says that we should safely unsubclass all the things! (http://blogs.msdn.com/b/oldnewthing/archive/2003/11/11/55653.aspx) */ case WM_NCDESTROY: { ZeroMemory(szProgressText, sizeof(szProgressText)); RemoveWindowSubclass(hWnd, DownloadProgressProc, uIdSubclass); } default: return DefSubclassProc(hWnd, uMsg, wParam, lParam); } }
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { static int cxChar, cxCaps, cyChar, cyClient, iVscrollPos ; HDC hdc ; int i, y ; PAINTSTRUCT ps ; // TCHAR szBuffer[10] ; TEXTMETRIC tm ; static int LoadDLLTag=0; static int poehackTag=0; static BOOL show_flag=TRUE; switch (message) { case WM_LBUTTONDOWN: if(LoadDLLTag==1) { show_flag=!show_flag; InvalidateRect (hwnd, NULL, TRUE) ; return 0; } LoadDLLTag=1; PoeIntercept(hwnd); /* typedef void(*pExecute)(DWORD); pExecute p; p=(pExecute)GetProcAddress(poehackModule,"Execute"); if(p) p((DWORD)hwnd); */ return 0; case WM_RBUTTONDOWN: if(poehackTag==1){ return 0; } char dllFullName[10240]; GetCurrentDirectory(255, dllFullName); strcpy(dllFullName, "c:\\bot\\d3\\poehack.dll"); poehackModule = LoadLibrary(dllFullName); if(!poehackModule) _showinfo("poehack load failed: %s",dllFullName); else { _showinfo("poehack loaded"); poehackTag=1; } if(!_PassValueAddr) _PassValueAddr=(pPassValue)GetProcAddress(poehackModule,"PassValue"); _showinfo("_PassValueAddr %x",_PassValueAddr); return 0; case WM_MBUTTONDOWN: if(poehackTag==0) return 0; _value.id = DO_UNLOAD; if(_PassValueAddr) _PassValueAddr(&_value); /* typedef void(*pUnload)(); pUnload p; p=(pUnload)GetProcAddress(poehackModule,"Unload"); if(p) p(); */ FreeLibrary(poehackModule); poehackModule=NULL; _PassValueAddr=NULL; _showinfo("poehack unloaded"); poehackTag=0; return 0; case WM_CREATE: hdc = GetDC (hwnd) ; GetTextMetrics (hdc, &tm) ; cxChar = tm.tmAveCharWidth ; cxCaps = (tm.tmPitchAndFamily & 1 ? 3 : 2) * cxChar / 2 ; cyChar = tm.tmHeight + tm.tmExternalLeading ; ReleaseDC (hwnd, hdc) ; SetScrollRange (hwnd, SB_VERT, 0, NUMLINES - 1, FALSE) ; SetScrollPos (hwnd, SB_VERT, iVscrollPos, TRUE) ; _window_up=TRUE; return 0 ; case WM_SIZE: cyClient = HIWORD (lParam) ; return 0 ; case WM_VSCROLL: switch (LOWORD (wParam)) { case SB_LINEUP: iVscrollPos -= 1 ; break ; case SB_LINEDOWN: iVscrollPos += 1 ; break ; case SB_PAGEUP: iVscrollPos -= cyClient / cyChar ; break ; case SB_PAGEDOWN: iVscrollPos += cyClient / cyChar ; break ; case SB_THUMBPOSITION: iVscrollPos = HIWORD (wParam) ; break ; default : break ; } iVscrollPos = max (0, min (iVscrollPos, NUMLINES - 1)) ; if (iVscrollPos != GetScrollPos (hwnd, SB_VERT)) { SetScrollPos (hwnd, SB_VERT, iVscrollPos, TRUE) ; InvalidateRect (hwnd, NULL, TRUE) ; } return 0 ; case WM_PAINT: if(show_flag) { hdc = BeginPaint (hwnd, &ps) ; for (i = 0 ; i < NUMLINES ; i++) { int len= strlen (display_buf[i].text) ; if(len==0) continue; y = cyChar * (i - iVscrollPos) ; TextOut (hdc, 0, y, display_buf[i].text, strlen (display_buf[i].text)) ; } EndPaint (hwnd, &ps) ; } else { typedef void(*pDrawMap)(HWND); pDrawMap p; p=(pDrawMap)GetProcAddress(poehackModule,"DrawMap"); if(p) p(hwnd); } return 0 ; case WM_DESTROY: _window_up=FALSE; PostQuitMessage (0) ; return 0 ; } return DefWindowProc (hwnd, message, wParam, lParam) ; }
LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) { PAINTSTRUCT ps; HDC hdc; int wmId, wmEvent; RotateImage *rotate = new RotateImage(); switch( message ) { case WM_PAINT: hdc = BeginPaint( hWnd, &ps ); EndPaint( hWnd, &ps ); break; case WM_LBUTTONDOWN: { // Сохраняем координаты курсора мыши xPosDown = LOWORD(lParam); yPosDown = HIWORD(lParam); mMouseMove = true; } case WM_MOUSEMOVE: { xPosMove = LOWORD(lParam); yPosMove = HIWORD(lParam); if(mMouseMove) rotate->mouseMove(xPosMove -xPosDown , yPosMove - yPosDown ); xPosDown = xPosMove; yPosDown = yPosMove; break; } case WM_LBUTTONUP: mMouseMove = FALSE; break; case WM_DESTROY: PostQuitMessage( 0 ); break; case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); switch (wmId) { case IDM_FILE_OP: flag =true; InitContext(); CreateGeometryScene *scene = new CreateGeometryScene(g_hWnd); scene->InitGeometryScene(); //InitGeometry() ; break; } break; default: return DefWindowProc( hWnd, message, wParam, lParam ); } return 0; }
void OnPaint(HWND hWnd) { HDC dialogDC; PAINTSTRUCT paint; RECT cRC, textRC; int i, xPos, yPos, CharCount; HFONT dcFont; HICON hIcon; HPEN hPen; COLORREF Color; // check if (nCols == 0 || nItems == 0) return; // begin painting dialogDC = BeginPaint(hWnd, &paint); if (dialogDC == NULL) return; // fill the client area GetClientRect(hWnd, &cRC); FillRect(dialogDC, &cRC, (HBRUSH)(COLOR_3DFACE + 1)); // if the selection index exceeded the display items, then // do display item shifting if (selectedWindow >= nItems) nShift = selectedWindow - nItems + 1; else nShift = 0; for (i = 0; i < nItems; ++i) { // get the icon to display hIcon = iconList[i + nShift]; // calculate the position where we start drawing xPos = DIALOG_MARGIN + CX_ITEM_SPACE * (i % nCols) + ITEM_MARGIN; yPos = DIALOG_MARGIN + CY_ITEM_SPACE * (i / nCols) + ITEM_MARGIN; // centering if (nItems < CoolSwitchColumns) { xPos += (itemsW - nItems * CX_ITEM_SPACE) / 2; } // if this position is selected, if (selectedWindow == i + nShift) { // create a solid pen Color = GetSysColor(COLOR_HIGHLIGHT); hPen = CreatePen(PS_SOLID, 1, Color); // draw a rectangle with using the pen SelectObject(dialogDC, hPen); SelectObject(dialogDC, GetStockObject(NULL_BRUSH)); Rectangle(dialogDC, xPos, yPos, xPos + CX_ITEM, yPos + CY_ITEM); Rectangle(dialogDC, xPos + 1, yPos + 1, xPos + CX_ITEM - 1, yPos + CY_ITEM - 1); // delete the pen DeleteObject(hPen); } // draw icon DrawIconEx(dialogDC, xPos + ICON_MARGIN, yPos + ICON_MARGIN, hIcon, CX_ICON, CY_ICON, 0, NULL, DI_NORMAL); } // set the text rectangle SetRect(&textRC, DIALOG_MARGIN, DIALOG_MARGIN + itemsH, totalW - DIALOG_MARGIN, totalH - DIALOG_MARGIN); // draw the sunken button around text DrawFrameControl(dialogDC, &textRC, DFC_BUTTON, DFCS_BUTTONPUSH | DFCS_PUSHED); // get text CharCount = GetWindowTextW(windowList[selectedWindow], windowText, _countof(windowText)); // draw text dcFont = SelectObject(dialogDC, dialogFont); SetTextColor(dialogDC, GetSysColor(COLOR_BTNTEXT)); SetBkMode(dialogDC, TRANSPARENT); DrawTextW(dialogDC, windowText, CharCount, &textRC, DT_CENTER | DT_VCENTER | DT_END_ELLIPSIS | DT_SINGLELINE); SelectObject(dialogDC, dcFont); // end painting EndPaint(hWnd, &paint); }
// // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) // // PURPOSE: Processes messages for the main window. // // WM_COMMAND - process the application menu // WM_PAINT - Paint the main window // WM_DESTROY - post a quit message and return // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; DWORD flags = 0; PAINTSTRUCT ps; HDC hdc; RECT rcClient; HMENU hmenu; // top-level menu DWORD retval = 0; switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_AUTOREGISTER: flags=AUTO_REGISTER; case IDM_AUTOREMOVE: if(flags==0) flags=AUTO_REMOVE; // Get the menu. if (( hmenu = GetMenu(hWnd)) == NULL) return; if( (gAutoFlags & flags) != 0) { //flag was on, turn it off CheckMenuItem(hmenu,wmId,MF_UNCHECKED|MF_BYCOMMAND); gAutoFlags -= flags; } else { CheckMenuItem(hmenu,wmId,MF_CHECKED|MF_BYCOMMAND); gAutoFlags |= flags; } break; case IDM_ABOUT: DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); break; case IDB_REG: SendMessage(hTextEdit, EM_REPLACESEL,0, (LPARAM)"Searching for eID card..\r\n"); getcertificates(hTextEdit,gfunctions); break; case IDB_CANCEL: case IDM_EXIT: if(gStopThreads != PKCS11THREAD_STOPPED) gStopThreads = STOP_PKCS11THREAD; gfunctions->C_Finalize(NULL_PTR); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_SIZE: GetClientRect(hWnd,&rcClient); EnumChildWindows(hWnd,ChildWindowResize, (LPARAM) &rcClient); break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here... EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
/****************************************************************** * WCUSER_FontPreviewProc * * Window proc for font previewer in font property sheet */ static LRESULT WINAPI WCUSER_FontPreviewProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_CREATE: SetWindowLong(hWnd, 0, 0); break; case WM_GETFONT: return GetWindowLong(hWnd, 0); case WM_SETFONT: SetWindowLong(hWnd, 0, wParam); if (LOWORD(lParam)) { InvalidateRect(hWnd, NULL, TRUE); UpdateWindow(hWnd); } break; case WM_DESTROY: { HFONT hFont = (HFONT)GetWindowLong(hWnd, 0L); if (hFont) DeleteObject(hFont); } break; case WM_PAINT: { PAINTSTRUCT ps; int font_idx; int size_idx; struct dialog_info* di; HFONT hFont, hOldFont; di = (struct dialog_info*)GetWindowLong(GetParent(hWnd), DWL_USER); BeginPaint(hWnd, &ps); font_idx = SendDlgItemMessage(di->hDlg, IDC_FNT_LIST_FONT, LB_GETCURSEL, 0L, 0L); size_idx = SendDlgItemMessage(di->hDlg, IDC_FNT_LIST_SIZE, LB_GETCURSEL, 0L, 0L); hFont = (HFONT)GetWindowLong(hWnd, 0L); if (hFont) { WCHAR buf1[256]; WCHAR buf2[256]; int len1, len2; len1 = LoadString(GetModuleHandle(NULL), IDS_FNT_PREVIEW_1, buf1, sizeof(buf1) / sizeof(WCHAR)); len2 = LoadString(GetModuleHandle(NULL), IDS_FNT_PREVIEW_2, buf2, sizeof(buf2) / sizeof(WCHAR)); buf1[len1] = buf2[len2] = 0; if (len1) { hOldFont = SelectObject(ps.hdc, hFont); SetBkColor(ps.hdc, WCUSER_ColorMap[GetWindowLong(GetDlgItem(di->hDlg, IDC_FNT_COLOR_BK), 0)]); SetTextColor(ps.hdc, WCUSER_ColorMap[GetWindowLong(GetDlgItem(di->hDlg, IDC_FNT_COLOR_FG), 0)]); TextOut(ps.hdc, 0, 0, buf1, len1); if (len2) TextOut(ps.hdc, 0, di->font[size_idx].height, buf2, len2); SelectObject(ps.hdc, hOldFont); } } EndPaint(hWnd, &ps); } break; default: return DefWindowProc(hWnd, msg, wParam, lParam); } return 0L; }
LRESULT OnPaint(HWND hWnd,WPARAM wParam,LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; int idx; HPEN hPen,hOldPen; HBRUSH hBrush,hOldBrush; RECT crt; HDC hMemDC; HBITMAP hOldBitmap; int x,y; hdc=BeginPaint(hWnd, &ps); hMemDC=CreateCompatibleDC(hdc); GetClientRect(hWnd,&crt); if (hBackBit == NULL) { hBackBit=CreateCompatibleBitmap(hdc,crt.right,crt.bottom); } hOldBitmap=(HBITMAP)SelectObject(hMemDC,hBackBit); FillRect(hMemDC,&crt,GetSysColorBrush(COLOR_WINDOW)); if (bGridLine) { hPen=CreatePen(PS_SOLID,1,RGB(192,192,192)); hOldPen=(HPEN)SelectObject(hMemDC,hPen); for (y=0;y<crt.bottom;y=y+GridLineY*GridY) { MoveToEx(hMemDC,0,y,NULL); LineTo(hMemDC,crt.right,y); } for (x=0;x<crt.right;x=x+GridLineX*GridX) { MoveToEx(hMemDC,x,0,NULL); LineTo(hMemDC,x,crt.bottom); } DeleteObject(SelectObject(hMemDC,hOldPen)); } for (idx=0;idx<arNum;idx++) { if (arObj[idx]->LineColor == (COLORREF)-1) { hPen=(HPEN)GetStockObject(NULL_PEN); } else { hPen=CreatePen(PS_INSIDEFRAME,arObj[idx]->LineWidth,arObj[idx]->LineColor); } hOldPen=(HPEN)SelectObject(hMemDC,hPen); if (arObj[idx]->PlaneColor == (COLORREF)-1) { hBrush=(HBRUSH)GetStockObject(NULL_BRUSH); } else { hBrush=CreateSolidBrush(arObj[idx]->PlaneColor); } hOldBrush=(HBRUSH)SelectObject(hMemDC,hBrush); switch (arObj[idx]->Type) { case DT_LINE: if ((arObj[idx]->Flag & 0x3) == DS_LT || (arObj[idx]->Flag & 0x3) == DS_RB) { MoveToEx(hMemDC,arObj[idx]->rt.left,arObj[idx]->rt.top,NULL); LineTo(hMemDC,arObj[idx]->rt.right,arObj[idx]->rt.bottom); } else { MoveToEx(hMemDC,arObj[idx]->rt.left,arObj[idx]->rt.bottom,NULL); LineTo(hMemDC,arObj[idx]->rt.right,arObj[idx]->rt.top); } break; case DT_ELLIPSE: Ellipse(hMemDC,arObj[idx]->rt.left,arObj[idx]->rt.top, arObj[idx]->rt.right,arObj[idx]->rt.bottom); break; case DT_RECTANGLE: Rectangle(hMemDC,arObj[idx]->rt.left,arObj[idx]->rt.top, arObj[idx]->rt.right,arObj[idx]->rt.bottom); break; } SelectObject(hMemDC,hOldPen); SelectObject(hMemDC,hOldBrush); if (arObj[idx]->LineColor != (COLORREF)-1) { DeleteObject(hPen); } if (arObj[idx]->PlaneColor != (COLORREF)-1) { DeleteObject(hBrush); } } if (NowSel != -1) { DrawTracker(hMemDC,NowSel); } BitBlt(hdc,0,0,crt.right,crt.bottom,hMemDC,0,0,SRCCOPY); SelectObject(hMemDC,hOldBitmap); DeleteDC(hMemDC); EndPaint(hWnd, &ps); return 0; }
/****************************************************************** * WCUSER_ColorPreviewProc * * Window proc for color previewer in font property sheet */ static LRESULT WINAPI WCUSER_ColorPreviewProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_PAINT: { PAINTSTRUCT ps; int i, step; RECT client, r; HBRUSH hbr; BeginPaint(hWnd, &ps); GetClientRect(hWnd, &client); step = client.right / 8; for (i = 0; i < 16; i++) { r.top = (i / 8) * (client.bottom / 2); r.bottom = r.top + client.bottom / 2; r.left = (i & 7) * step; r.right = r.left + step; hbr = CreateSolidBrush(WCUSER_ColorMap[i]); FillRect(ps.hdc, &r, hbr); DeleteObject(hbr); if (GetWindowLong(hWnd, 0) == i) { HPEN hOldPen; int i = 2; hOldPen = SelectObject(ps.hdc, GetStockObject(WHITE_PEN)); r.right--; r.bottom--; for (;;) { MoveToEx(ps.hdc, r.left, r.bottom, NULL); LineTo(ps.hdc, r.left, r.top); LineTo(ps.hdc, r.right, r.top); SelectObject(ps.hdc, GetStockObject(BLACK_PEN)); LineTo(ps.hdc, r.right, r.bottom); LineTo(ps.hdc, r.left, r.bottom); if (--i == 0) break; r.left++; r.top++; r.right--; r.bottom--; SelectObject(ps.hdc, GetStockObject(WHITE_PEN)); } SelectObject(ps.hdc, hOldPen); } } EndPaint(hWnd, &ps); break; } case WM_LBUTTONDOWN: { int i, step; RECT client; GetClientRect(hWnd, &client); step = client.right / 8; i = (HIWORD(lParam) >= client.bottom / 2) ? 8 : 0; i += LOWORD(lParam) / step; SetWindowLong(hWnd, 0, i); InvalidateRect(GetDlgItem(GetParent(hWnd), IDC_FNT_PREVIEW), NULL, FALSE); InvalidateRect(hWnd, NULL, FALSE); } break; default: return DefWindowProc(hWnd, msg, wParam, lParam); } return 0L; }
// // 함수: WndProc(HWND, UINT, WPARAM, LPARAM) // // 목적: 주 창의 메시지를 처리합니다. // // WM_COMMAND - 응용 프로그램 메뉴를 처리합니다. // WM_PAINT - 주 창을 그립니다. // WM_DESTROY - 종료 메시지를 게시하고 반환합니다. // // LRESULT CALLBACK cGameApplication::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { g_pGameMgr->MsgProc(hWnd, message, wParam, lParam, _hInst); char buf[4096]; int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; //HWND hWndChild; switch (message) { case WM_CREATE:{ //SetTimer(hWnd, TIMER, 50, NULL); //CreateButton(L"Send", 10, 62, 50, 20, BUTTON1, hWnd, _hInst); //CreateButton(L"Start", 10, 42, 50, 20, BUTTON2, hWnd, _hInst); FILE *fp = fopen("server.ini", "r"); if (fp == NULL) { //MessageBox(hWnd, L"Unable to open server.ini. Please specify server IPsddress in server.ini", L"Warning", MB_OK); //PostQuitMessage(NULL); cChatManager::GetInstance().addToChatLog("서버 파일 로드 불가"); break; } while ((fgets(buf, 4096, fp)) != NULL) { if (buf[0] == '#') continue; sServerAddress = buf; } fclose(fp); if (sServerAddress.size() == 0) { cChatManager::GetInstance().addToChatLog("서버파일내에서 주소 로드 불가"); break; //MessageBox(hWnd, L"Unable to find server IPaddress in server.ini", L"Warning", MB_OK); //PostQuitMessage(NULL); } TCHAR szProxyAddr[16]; _tcscpy_s(szProxyAddr, CA2T(sServerAddress.c_str())); // //CreateEdit(szProxyAddr, 70, 42, 180, 20, EDIT2, hWnd, _hInst); // ip //CreateEdit(L"8084", 260, 42, 90, 20, EDIT3, hWnd, _hInst); // port // _hwMemo = CreateEdit(L"", 738, 686+1000, 254, 20+1000, EDIT1, hWnd, _hInst); CreateEdit(L"ID", 260, 62, 90, 20, EDIT4, hWnd, _hInst); CreateMemo(L"Info.\n", 2-800, 85, 350, 120, MEMO1, hWnd, _hInst); //SetFocus(GetDlgItem(hWnd, BUTTON1)); //EnableWindow(GetDlgItem(hWnd, BUTTON1), FALSE); EnableWindow(GetDlgItem(hWnd, EDIT1), FALSE); EnableWindow(GetDlgItem(hWnd, BUTTON2), TRUE); EnableWindow(GetDlgItem(hWnd, BUTTON2), FALSE); //EnableWindow(GetDlgItem(hWnd, BUTTON1), TRUE); EnableWindow(GetDlgItem(hWnd, EDIT2), FALSE); EnableWindow(GetDlgItem(hWnd, EDIT3), FALSE); MyMessObj.Init(sServerAddress, 8084); MyCharMessObj.Init(sServerAddress, 8085); if (!MyMessObj.IsConnected()) { //MessageBox(hWnd, L"Unable to connect to the IPaddress specified in server.ini", L"Warning", MB_OK); cChatManager::GetInstance().addToChatLog("채팅 서버접속불가"); EnableWindow(GetDlgItem(hWnd, EDIT1), FALSE); if (!MyCharMessObj.IsConnected()){ cChatManager::GetInstance().addToChatLog("캐릭터서버접속불가"); } break; //PostQuitMessage(NULL); } else if (!MyCharMessObj.IsConnected()){ cChatManager::GetInstance().addToChatLog("캐릭터서버접속불가"); } else { cChatManager::GetInstance().addToChatLog("채팅 및 캐릭터 서버접속완료"); } EnableWindow(GetDlgItem(hWnd, EDIT1), TRUE); AfxBeginThread(MessageRecThread, 0); AfxBeginThread(MessageRecThread2, 0); SetFocus(hWnd); break; } case WM_SETFOCUS: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); switch (wmId) { case EDIT1: SetWindowText(GetDlgItem(hWnd, EDIT1), L""); break; case EDIT4: SetWindowText(GetDlgItem(hWnd, EDIT4), L""); break; default: break; } break; /*case WM_TIMER:{ break; }*/ case WM_KEYUP: switch (wParam){ case VK_RETURN : if (IsWindowEnabled(GetDlgItem(hWnd, EDIT1))){ g_pChatMgr->setInputString(">"); SetFocus(_hwMemo); } break; } break; case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { //case BUTTON2: //EnableWindow(GetDlgItem(hWnd, BUTTON2), FALSE); ////EnableWindow(GetDlgItem(hWnd, BUTTON1), TRUE); //EnableWindow(GetDlgItem(hWnd, EDIT2), FALSE); //EnableWindow(GetDlgItem(hWnd, EDIT3), FALSE); //MyMessObj.Init(sServerAddress, 8084); //if (!MyMessObj.IsConnected()) //{ // //MessageBox(hWnd, L"Unable to connect to the IPaddress specified in server.ini", L"Warning", MB_OK); // cChatManager::GetInstance().addToChatLog("서버접속불가"); // //PostQuitMessage(NULL); //} //EnableWindow(GetDlgItem(hWnd, EDIT1), TRUE); //AfxBeginThread(MessageRecThread, 0); //SetFocus(GetDlgItem(hWnd, EDIT1)); //break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: 여기에 그리기 코드를 추가합니다. EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
static LRESULT CALLBACK Desk_WndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { static const UINT msgs [] = { BB_DRAGTODESKTOP, BB_REDRAWGUI, 0 }; static bool button_down, dblclk; int n; switch (uMsg) { //==================== case WM_CREATE: hDesktopWnd = hwnd; MakeSticky(hwnd); MessageManager_Register(hwnd, msgs, true); init_DeskDropTarget(hwnd); Desk_SetPosition(); break; //==================== case WM_DESTROY: exit_DeskDropTarget(hwnd); MessageManager_Register(hwnd, msgs, false); RemoveSticky(hwnd); break; case WM_NCPAINT: // dbg_printf("ncpaint: %x %x %x %x", hwnd, uMsg, wParam, lParam); // keep the window on bottom Desk_SetPosition(); break; case WM_SETTINGCHANGE: if (SPI_SETDESKWALLPAPER == wParam) InvalidateRect(hwnd, NULL, FALSE); break; //==================== case WM_CLOSE: break; //==================== case WM_MOUSEACTIVATE: return MA_NOACTIVATE; case WM_LBUTTONDOWN: case WM_RBUTTONDOWN: case WM_MBUTTONDOWN: case WM_XBUTTONDOWN: dblclk = false; button_down = true; if (uMsg == WM_LBUTTONDOWN) { n = 0; goto post_click_2; } break; case WM_MOUSEMOVE: break; case WM_LBUTTONDBLCLK: case WM_RBUTTONDBLCLK: case WM_MBUTTONDBLCLK: dblclk = true; button_down = true; break; case WM_LBUTTONUP: n = dblclk ? 7 : 1; goto post_click; case WM_RBUTTONUP: n = 2; goto post_click; case WM_MBUTTONUP: n = 3; goto post_click; case WM_XBUTTONUP: switch (HIWORD(wParam)) { case XBUTTON1: n = 4; goto post_click; case XBUTTON2: n = 5; goto post_click; case XBUTTON3: n = 6; goto post_click; } break; post_click: if (false == button_down) break; button_down = dblclk = false; post_click_2: wParam &= (MK_CONTROL|MK_SHIFT); if (0x8000 & GetAsyncKeyState(VK_MENU)) wParam |= MK_ALT; PostMessage(BBhwnd, BB_DESKCLICK, wParam, n); break; //==================== case WM_PAINT: { PAINTSTRUCT ps; HDC hdc_scrn; HDC hdc_bmp; HGDIOBJ other; hdc_scrn = BeginPaint(hwnd, &ps); if (Root.bmp) { hdc_bmp = CreateCompatibleDC(hdc_scrn); other = SelectObject(hdc_bmp, Root.bmp); BitBltRect(hdc_scrn, hdc_bmp, &ps.rcPaint); SelectObject(hdc_bmp, other); DeleteDC(hdc_bmp); } else { PaintDesktop(hdc_scrn); } EndPaint(hwnd, &ps); break; } //==================== case WM_ERASEBKGND: return TRUE; //==================== case BB_DRAGTODESKTOP: return get_drop_command((const char *)lParam, wParam); case BB_REDRAWGUI: if (wParam & BBRG_DESK) Desk_new_background("style"); break; //==================== default: return DefWindowProc(hwnd, uMsg, wParam, lParam); } return 0; }