INT_PTR CALLBACK device_list_wndproc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { TCHAR tipText[80]; POINT pt; static int oldX, oldY; int newX, newY; LVHITTESTINFO hitTestInfo; LVITEM lvitem; device_context_t* dev_context; BOOL ignored; switch(message) { case WM_MOUSELEAVE: // The mouse pointer has left our window. // Deactivate the tooltip. SendMessage(g_hwndTrackingTT, TTM_TRACKACTIVATE, (WPARAM)FALSE, (LPARAM)&g_toolItem); g_TrackingMouse = FALSE; return FALSE; case WM_MOUSEMOVE: if (!g_TrackingMouse) { // The mouse has just entered the window. // Request notification when the mouse leaves. TRACKMOUSEEVENT tme = { sizeof(TRACKMOUSEEVENT) }; tme.hwndTrack = hDlg; tme.dwFlags = TME_LEAVE; TrackMouseEvent(&tme); // Activate the tooltip. SendMessage(g_hwndTrackingTT, TTM_TRACKACTIVATE, (WPARAM)TRUE, (LPARAM)&g_toolItem); g_TrackingMouse = TRUE; } newX = LOWORD(lParam); newY = HIWORD(lParam); // Make sure the mouse has actually moved. The presence of the tooltip // causes Windows to send the message continuously. if ((newX != oldX) || (newY != oldY)) { oldX = newX; oldY = newY; memset(&hitTestInfo,0,sizeof(hitTestInfo)); hitTestInfo.pt.x = newX; hitTestInfo.pt.y = newY; if ((ListView_HitTest(hDlg, &hitTestInfo) == -1) || newX > ListView_GetColumnWidth(hDlg, 0)) { safe_sprintf(tipText, sizeof(tipText) - 1, TEXT("%s"), TEXT("")); SendMessage(g_hwndTrackingTT, TTM_TRACKACTIVATE,FALSE, (LPARAM)&g_toolItem); } else { SendMessage(g_hwndTrackingTT, TTM_SETDELAYTIME,TTDT_INITIAL, 1000); memset(&lvitem, 0 , sizeof(lvitem)); lvitem.iItem = hitTestInfo.iItem; lvitem.mask = LVIF_PARAM; ignored = ListView_GetItem(hDlg,&lvitem); dev_context = (device_context_t*)lvitem.lParam; // Update the text. safe_sprintf(tipText, sizeof(tipText)-1 , TEXT("%s"), wdi_get_vendor_name(dev_context->wdi->vid)); SendMessage(g_hwndTrackingTT, TTM_TRACKACTIVATE,TRUE, (LPARAM)&g_toolItem); } g_toolItem.lpszText = tipText; SendMessage(g_hwndTrackingTT, TTM_SETTOOLINFO, 0, (LPARAM)&g_toolItem); // Position the tooltip. // The coordinates are adjusted so that the tooltip does not // overlap the mouse pointer. pt.x = newX; pt.y = newY; ClientToScreen(hDlg, &pt); SendMessage(g_hwndTrackingTT, TTM_TRACKPOSITION, 0, (LPARAM)MAKELONG(pt.x + 10, pt.y - 20)); } break; } return CallWindowProc(device_list_wndproc_orig, hDlg, message, wParam, lParam); }
LRESULT CALLBACK ConnListBoxProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_LBUTTONDOWN: { int index = SendMessage(hwnd, LB_ITEMFROMPOINT, 0, lParam); if(index >= 0x10000) { SendMessage(hwnd, LB_SETCURSEL, (DWORD)-1, 0L); } } break; case WM_RBUTTONDOWN: { POINT pos; MENUITEMINFO info; HMENU hMenu; DWORD dwID; int index = SendMessage(hwnd, LB_ITEMFROMPOINT, 0, lParam); if(index < 0x10000) { SendMessage(hwnd, LB_SETCURSEL, (DWORD)index, 1L); } else { SendMessage(hwnd, LB_SETCURSEL, (DWORD)-1, 0L); break; } hMenu = CreatePopupMenu(); memset(&info, 0, sizeof(MENUITEMINFO)); info.cbSize = sizeof(MENUITEMINFO); info.fMask = MIIM_ID | MIIM_TYPE; info.fType = MFT_STRING; info.wID = 1001; info.dwTypeData = "切断(&X)"; InsertMenuItem(hMenu, -1, true, &info); GetCursorPos(&pos); dwID = TrackPopupMenu(hMenu, TPM_LEFTALIGN | TPM_RETURNCMD, pos.x, pos.y, 0, hwnd, NULL); DestroyMenu(hMenu); switch(dwID) { case 1001: SendMessage(guiWnd, WM_COMMAND, IDC_BUTTON6, NULL); break; } } break; } return CallWindowProc(wndOldConnListBox, hwnd, message, wParam, lParam); }
static LRESULT CALLBACK SpringWndProc(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam) { if (mouse) { switch (msg) { case WM_XBUTTONDOWN: { if ((short)LOWORD(wParam) & MK_XBUTTON1) mouse->MousePress((short)LOWORD(lParam), (short)HIWORD(lParam), 4); if ((short)LOWORD(wParam) & MK_XBUTTON2) mouse->MousePress((short)LOWORD(lParam), (short)HIWORD(lParam), 5); } return 0; case WM_XBUTTONUP: { if ((short)LOWORD(wParam) & MK_XBUTTON1) mouse->MouseRelease((short)LOWORD(lParam), (short)HIWORD(lParam), 4); if ((short)LOWORD(wParam) & MK_XBUTTON2) mouse->MouseRelease((short)LOWORD(lParam), (short)HIWORD(lParam), 5); } return 0; } } switch (msg) { case WM_MOUSEMOVE: return wsdl::OnMouseMotion(wnd, (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam), (UINT)wParam); case WM_MOUSEWHEEL: return wsdl::OnMouseWheel(wnd, (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam), (int)(short)HIWORD(wParam), (UINT)(short)LOWORD(wParam)); //! can't use message crackers: they do not provide for passing uMsg case WM_LBUTTONDOWN: case WM_LBUTTONUP: case WM_RBUTTONDOWN: case WM_RBUTTONUP: case WM_MBUTTONDOWN: case WM_MBUTTONUP: return wsdl::OnMouseButton(wnd, msg, (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam), (UINT)wParam); case WM_SETCURSOR: { if (inst->hCursor!=NULL) { Uint16 hittest = LOWORD(lParam); if ( hittest == HTCLIENT ) { SetCursor(inst->hCursor); return TRUE; } } } break; case WM_ACTIVATE: { wsdl::ResetMouseButtons(); // wsdl::OnActivate(wnd, LOWORD(wParam), NULL, HIWORD(lParam)); // FIXME: move to SpringApp somehow and use GLContext.h instead! if (globalRendering->fullScreen) { if (LOWORD(wParam) == WA_INACTIVE) { FBO::GLContextLost(); } else if (LOWORD(wParam) == WA_ACTIVE) { FBO::GLContextReinit(); } } } break; } return CallWindowProc((WNDPROC)inst->sdl_wndproc, wnd, msg, wParam, lParam); }
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HWND hwndParent = hWndParent; HWND hwndImage = hWndImage; if (hwnd == hwndParent) { if (message == WM_SIZE) { ShowWindow(hwndImage, wParam == SIZE_MINIMIZED ? SW_HIDE : SW_SHOW); } if (message == WM_WINDOWPOSCHANGED) { SetWindowPos(hwndImage, hwndParent, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE); } return CallWindowProc( (long (__stdcall *)(HWND,unsigned int,unsigned int,long))oldProc, hwnd, message, wParam, lParam ); } switch (message) { case WM_PAINT: if (bgBitmap.bReady) { ECS(); PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd, &ps); if (bgBitmap.iType == MIL_BITMAP) { HDC cdc = CreateCompatibleDC(hdc); SelectObject(cdc, bgBitmap.hBitmap); for (unsigned int x = 0; x < uWndWidth; x += bgBitmap.rPos.right) { for (unsigned int y = 0; y < uWndHeight; y += bgBitmap.rPos.bottom) { BitBlt(hdc, x, y, bgBitmap.rPos.right, bgBitmap.rPos.bottom, cdc, 0, 0, SRCCOPY); } } DeleteDC(cdc); } else { int r = GetRValue(bgBitmap.cGradientFrom) << 10; int g = GetGValue(bgBitmap.cGradientFrom) << 10; int b = GetBValue(bgBitmap.cGradientFrom) << 10; int dr = ((GetRValue(bgBitmap.cGradientTo) << 10) - r) / (int)uWndHeight * 4; int dg = ((GetGValue(bgBitmap.cGradientTo) << 10) - g) / (int)uWndHeight * 4; int db = ((GetBValue(bgBitmap.cGradientTo) << 10) - b) / (int)uWndHeight * 4; RECT rect; rect.left = 0; rect.top = 0; rect.right = uWndWidth; rect.bottom = 4; while (rect.top < (int)uWndHeight) { HBRUSH brush = CreateSolidBrush(RGB(r>>10,g>>10,b>>10)); FillRect(hdc, &rect, brush); DeleteObject(brush); rect.top+=4; rect.bottom+=4; r+=dr; g+=dg; b+=db; } } myImageList *img = bgBitmap.next; while (img) { if (img->iType == MIL_TEXT) { SetBkMode(hdc, TRANSPARENT); SetTextColor(hdc, img->cTextColor); SelectObject(hdc, img->hFont); DrawText(hdc, img->szText, -1, &img->rPos, DT_TOP | DT_LEFT | DT_NOPREFIX | DT_WORDBREAK); } else if (img->iType == MIL_BITMAP) { HDC cdc = CreateCompatibleDC(hdc); SelectObject(cdc, img->hBitmap); BitBlt(hdc, img->rPos.left, img->rPos.top, img->rPos.right - img->rPos.left, img->rPos.bottom - img->rPos.top, cdc, 0, 0, SRCCOPY); DeleteDC(cdc); } else { COLORREF cColor; HBITMAP bmAndBack, bmAndObject, bmAndMem, bmSave; HBITMAP bmBackOld, bmObjectOld, bmMemOld, bmSaveOld; HDC hdcMem, hdcBack, hdcObject, hdcTemp, hdcSave; POINT ptSize; HBITMAP hBitmap = img->hBitmap; hdcTemp = CreateCompatibleDC(hdc); SelectObject(hdcTemp, hBitmap); // Select the bitmap ptSize.x = img->rPos.right - img->rPos.left; ptSize.y = img->rPos.bottom - img->rPos.top; DPtoLP(hdcTemp, &ptSize, 1); // Convert from device to logical points // Create some DCs to hold temporary data. hdcBack = CreateCompatibleDC(hdc); hdcObject = CreateCompatibleDC(hdc); hdcMem = CreateCompatibleDC(hdc); hdcSave = CreateCompatibleDC(hdc); // Create a bitmap for each DC. DCs are required for a number of // GDI functions. // Monochrome DC bmAndBack = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL); // Monochrome DC bmAndObject = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL); bmAndMem = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y); bmSave = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y); // Each DC must select a bitmap object to store pixel data. bmBackOld = (HBITMAP)SelectObject(hdcBack, bmAndBack); bmObjectOld = (HBITMAP)SelectObject(hdcObject, bmAndObject); bmMemOld = (HBITMAP)SelectObject(hdcMem, bmAndMem); bmSaveOld = (HBITMAP)SelectObject(hdcSave, bmSave); // Set proper mapping mode. SetMapMode(hdcTemp, GetMapMode(hdc)); // Save the bitmap sent here, because it will be overwritten. BitBlt(hdcSave, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCCOPY); // Set the background color of the source DC to the color. // contained in the parts of the bitmap that should be transparent cColor = SetBkColor(hdcTemp, img->cTransparent); // Create the object mask for the bitmap by performing a BitBlt // from the source bitmap to a monochrome bitmap. BitBlt(hdcObject, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCCOPY); // Set the background color of the source DC back to the original // color. SetBkColor(hdcTemp, cColor); // Create the inverse of the object mask. BitBlt(hdcBack, 0, 0, ptSize.x, ptSize.y, hdcObject, 0, 0, NOTSRCCOPY); // Copy the background of the main DC to the destination. BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdc, img->rPos.left, img->rPos.top, SRCCOPY); // Mask out the places where the bitmap will be placed. BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdcObject, 0, 0, SRCAND); // Mask out the transparent colored pixels on the bitmap. BitBlt(hdcTemp, 0, 0, ptSize.x, ptSize.y, hdcBack, 0, 0, SRCAND); // XOR the bitmap with the background on the destination DC. BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCPAINT); // Copy the destination to the screen. BitBlt(hdc, img->rPos.left, img->rPos.top, ptSize.x, ptSize.y, hdcMem, 0, 0, SRCCOPY); // Place the original bitmap back into the bitmap sent here. BitBlt(hdcTemp, 0, 0, ptSize.x, ptSize.y, hdcSave, 0, 0, SRCCOPY); // Delete the memory bitmaps. DeleteObject(SelectObject(hdcBack, bmBackOld)); DeleteObject(SelectObject(hdcObject, bmObjectOld)); DeleteObject(SelectObject(hdcMem, bmMemOld)); DeleteObject(SelectObject(hdcSave, bmSaveOld)); // Delete the memory DCs. DeleteDC(hdcMem); DeleteDC(hdcBack); DeleteDC(hdcObject); DeleteDC(hdcSave); DeleteDC(hdcTemp); } img = img->next; } LCS(); EndPaint(hwnd, &ps); } break; case WM_WINDOWPOSCHANGING: if (IsWindow(hwndParent)) { LPWINDOWPOS wp = (LPWINDOWPOS) lParam; wp->flags |= SWP_NOACTIVATE; wp->hwndInsertAfter = hwndParent; } break; case WM_CLOSE: DestroyWindow(hwnd); break; default: return DefWindowProc(hwnd, message, wParam, lParam); }
// // Subclass procedure for the OVEN pushbutton window instance. // The purpose of having this subclass is to do all "OVEN" related // messages separately here. In particular, it processes these messages: // - WM_MOUSEMOVE // - WM_CHAR // - WM_TIMER // LRESULT APIENTRY NewButtonWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { RECT rect; POINT pt; //HWND parent; switch (uMsg) { // The WM_MOUSEMOVE message is posted whenever the mouse is moved. // If no window is captured, this message is posted to the window where cursor is; // Otherwise, it is posted to the capture window. // // The default wndproc must NOT check for MouseMovement. // First entry into this code will be when cursor is over button. // // Use PtInRect() to check if the cursor is placed over the button window area. // If so, turn OVEN on. // Use PtInRect() to check if the cursor is placed outside the button window area. // If so, turn OVEN off. // // When the mouse is over OVEN button, capture window with SetCapture(), // so subsequent mousemove to outside of OVEN button will still be processed here. // case WM_MOUSEMOVE: GetClientRect(hwnd, &rect); // get rect of button window pt.x = LOWORD(lParam); // is this client co-ordinate the button, or parent window? pt.y = HIWORD(lParam); // fill start here if(PtInRect(&rect, pt)) { SetToasted(hwnd, 1); SetCapture(hwnd); }else { SetToasted(hwnd, 0); ReleaseCapture(); } // fill end here return 0; // The WM_CHAR message is generated by the OS when a keyboard key is pressed, // and the system calls TranslateMessage(). By default this message is // sent to the window where keyboard was pressed, or the to keyboard // focus window (which we have set to be the OVEN button using SetFocus()). // That's why we are processing this message here, in the OVEN button subclass proc. case WM_CHAR: // fill start here switch(wParam) { case 'b': SetToasted(hwnd, 1); SetTimer(hwnd, 1, 5000, NULL); Sleep(5000); } // fill end here return 0; case WM_TIMER: // this message is generated when timer timesout. SetToasted(hwnd, 0); // set OVEN OFF return 0; } // return to original wndproc and process all other messages there. return CallWindowProc((WNDPROC)GetClassLong(GetParent(hwnd),0), hwnd, uMsg, wParam, lParam); }
LRESULT NativeWindowHolder::CallBaseWindowProcedure(UINT message, WPARAM wParam, LPARAM lParam) const { return CallWindowProc(baseWindowProcedure, windowHandle, message, wParam, lParam); }
LRESULT CALLBACK CCoolMenu::MenuProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { WNDPROC pWndProc = (WNDPROC)::GetProp( hWnd, wpnOldProc ); switch ( uMsg ) { case WM_NCCALCSIZE: { NCCALCSIZE_PARAMS* pCalc = (NCCALCSIZE_PARAMS*)lParam; pCalc->rgrc[0].left ++; pCalc->rgrc[0].top ++; pCalc->rgrc[0].right --; pCalc->rgrc[0].bottom --; } return 0; case WM_WINDOWPOSCHANGING: if ( WINDOWPOS* pWndPos = (WINDOWPOS*)lParam ) { DWORD nStyle = GetWindowLong( hWnd, GWL_STYLE ); DWORD nExStyle = GetWindowLong( hWnd, GWL_EXSTYLE ); CRect rc( 0, 0, 32, 32 ); AdjustWindowRectEx( &rc, nStyle, FALSE, nExStyle ); pWndPos->cx -= ( rc.Width() - 34 ); pWndPos->cy -= ( rc.Height() - 34 ) - 1; if ( pWndPos->x != m_nEdgeLeft || pWndPos->y != m_nEdgeTop ) pWndPos->x ++; } break; case WM_PRINT: if ( ( lParam & PRF_CHECKVISIBLE ) && ! IsWindowVisible( hWnd ) ) return 0; if ( lParam & PRF_NONCLIENT ) { CWnd* pWnd = CWnd::FromHandle( hWnd ); CDC* pDC = CDC::FromHandle( (HDC)wParam ); CRect rc; pWnd->GetWindowRect( &rc ); BOOL bEdge = ( rc.left == m_nEdgeLeft && rc.top == m_nEdgeTop ); rc.OffsetRect( -rc.left, -rc.top ); pDC->Draw3dRect( &rc, CoolInterface.m_crDisabled, CoolInterface.m_crDisabled ); if ( bEdge ) pDC->FillSolidRect( rc.left + 1, rc.top, min( rc.Width(), m_nEdgeSize ) - 2, 1, CoolInterface.m_crBackNormal ); } if ( lParam & PRF_CLIENT ) { CWnd* pWnd = CWnd::FromHandle( hWnd ); CDC* pDC = CDC::FromHandle( (HDC)wParam ); CBitmap bmBuf, *pbmOld; CDC dcBuf; CRect rc; pWnd->GetClientRect( &rc ); dcBuf.CreateCompatibleDC( pDC ); bmBuf.CreateCompatibleBitmap( pDC, rc.Width(), rc.Height() ); pbmOld = (CBitmap*)dcBuf.SelectObject( &bmBuf ); m_bPrinted = TRUE; dcBuf.FillSolidRect( &rc, GetSysColor( COLOR_MENU ) ); SendMessage( hWnd, WM_PRINTCLIENT, (WPARAM)dcBuf.GetSafeHdc(), 0 ); pDC->BitBlt( 1, 1, rc.Width(), rc.Height(), &dcBuf, 0, 0, SRCCOPY ); dcBuf.SelectObject( pbmOld ); } return 0; case WM_NCPAINT: { CWnd* pWnd = CWnd::FromHandle( hWnd ); CWindowDC dc( pWnd ); CRect rc; pWnd->GetWindowRect( &rc ); BOOL bEdge = ( rc.left == m_nEdgeLeft && rc.top == m_nEdgeTop ); rc.OffsetRect( -rc.left, -rc.top ); dc.Draw3dRect( &rc, CoolInterface.m_crDisabled, CoolInterface.m_crDisabled ); if ( bEdge ) dc.FillSolidRect( rc.left + 1, rc.top, min( rc.Width(), m_nEdgeSize ) - 2, 1, CoolInterface.m_crBackNormal ); } return 0; case WM_PAINT: m_bPrinted = FALSE; break; case WM_NCDESTROY: ::RemoveProp( hWnd, wpnOldProc ); break; } return CallWindowProc( pWndProc, hWnd, uMsg, wParam, lParam ); }
LRESULT CALLBACK StandButtonProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) { if (msg == WM_LBUTTONDOWN) { GameEngine* gameEngine = GameEngine::getInstance(); User* user = gameEngine->getUser(); Table* table = gameEngine->getTable(); table->setState(TABLE_STATE_STANDING); Hand* dealerHand = table->getDealerHand(); Hand* playerHand = table->getPlayerHand(); // // Flip over the first card. // dealerHand->GetCards()->at(0)->setFacedown(false); PlaySound(L"sound-flipcard.wav", NULL, SND_FILENAME | SND_ASYNC); RedrawWindow(gameEngine->getHWnd(), NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW); Sleep(500); // // See if we need additional cards. // while (true) { std::vector<int>* vals = dealerHand->GetValues(); bool done = false; for (int i = 0; i < vals->size(); i++) { // Dealer must stop taking cards // if he has a value of 17 or higher. if (vals->at(i) >= 17) { done = true; break; } } if (done) { break; } PlaySound(L"sound-flipcard.wav", NULL, SND_FILENAME | SND_ASYNC); dealerHand->dealCard(false); RedrawWindow(gameEngine->getHWnd(), NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW); Sleep(500); } // // Determine winner. Update balance amounts. // // table->setState(TABLE_STATE_READY); std::vector<int>* dealerValues = dealerHand->GetValues(); std::vector<int>* playerValues = playerHand->GetValues(); int dealerFinal = 0; int playerFinal = 0; for (int i = 0; i < dealerValues->size(); i++) { if (dealerValues->at(i) > dealerFinal && dealerValues->at(i) < 22) { dealerFinal = dealerValues->at(i); } } for (int i = 0; i < playerValues->size(); i++) { if (playerValues->at(i) > playerFinal && playerValues->at(i) < 22) { playerFinal = playerValues->at(i); } } table->setState(TABLE_STATE_FINISHED); // If values are same, this is a push. if (dealerFinal == playerFinal) { updateTextarea(hStaticTableMiddleMessage, "Push"); // Return player's bet money. int bet = playerHand->getBetAmount(); user->setBalance(user->getBalance() + bet); } else if (dealerFinal < playerFinal) { // Player wins, return bet and winning. updateTextarea(hStaticTableMiddleMessage, "Player Wins!"); int bet = playerHand->getBetAmount(); user->setBalance(user->getBalance() + (bet*2) ); } else if (dealerFinal > playerFinal) { // No need to update cash. Has already been deducted // at time of bet. Update the middle message area. updateTextarea(hStaticTableMiddleMessage, "Dealer Wins."); } RedrawWindow(gameEngine->getHWnd(), NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW); } return CallWindowProc(oldStandButtonProc, hwnd, msg, wp, lp); }
static VOID PhListTick( __in PPH_EXTLV_CONTEXT Context ) { HWND hwnd = Context->Handle; ULONG tickCount; BOOLEAN redrawDisabled = FALSE; PPH_LIST itemsToRemove = NULL; PH_HASHTABLE_ENUM_CONTEXT enumContext; PPH_TICK_ENTRY entry; if (!Context->TickHashtable) return; tickCount = GetTickCount(); // First pass PhBeginEnumHashtable(Context->TickHashtable, &enumContext); while (entry = PhNextEnumHashtable(&enumContext)) { LVITEM item; PH_ITEM_STATE itemState; if (PhRoundNumber(tickCount - entry->TickCount, PH_DURATION_MULT) < Context->HighlightingDuration) continue; item.mask = LVIF_STATE; item.iItem = ListView_MapIDToIndex(hwnd, entry->Id); item.iSubItem = 0; item.stateMask = LVIS_STATEIMAGEMASK; CallWindowProc(Context->OldWndProc, hwnd, LVM_GETITEM, 0, (LPARAM)&item); itemState = PH_GET_ITEM_STATE(item.state); if (itemState == NewItemState) { item.state = INDEXTOSTATEIMAGEMASK(NormalItemState); CallWindowProc(Context->OldWndProc, hwnd, LVM_SETITEM, 0, (LPARAM)&item); if (!itemsToRemove) itemsToRemove = PhCreateList(2); PhAddItemList(itemsToRemove, (PVOID)entry->Id); entry->TickCount = tickCount; } } // Second pass // This pass is specifically for deleting items. PhBeginEnumHashtable(Context->TickHashtable, &enumContext); while (entry = PhNextEnumHashtable(&enumContext)) { LVITEM item; PH_ITEM_STATE itemState; if (itemsToRemove) { if (PhFindItemList(itemsToRemove, (PVOID)entry->Id) != -1) continue; } if (PhRoundNumber(tickCount - entry->TickCount, PH_DURATION_MULT) < Context->HighlightingDuration) continue; item.mask = LVIF_STATE; item.iItem = ListView_MapIDToIndex(hwnd, entry->Id); item.iSubItem = 0; item.stateMask = LVIS_STATEIMAGEMASK; CallWindowProc(Context->OldWndProc, hwnd, LVM_GETITEM, 0, (LPARAM)&item); itemState = PH_GET_ITEM_STATE(item.state); if (itemState == RemovingItemState) { if (!redrawDisabled) { ExtendedListView_SetRedraw(hwnd, FALSE); redrawDisabled = TRUE; } CallWindowProc(Context->OldWndProc, hwnd, LVM_DELETEITEM, item.iItem, 0); if (!itemsToRemove) itemsToRemove = PhCreateList(2); PhAddItemList(itemsToRemove, (PVOID)entry->Id); entry->TickCount = tickCount; } } if (redrawDisabled) { ExtendedListView_SetRedraw(hwnd, TRUE); } if (itemsToRemove) { ULONG i; for (i = 0; i < itemsToRemove->Count; i++) { PH_TICK_ENTRY removeEntry; removeEntry.Id = (ULONG)itemsToRemove->Items[i]; PhRemoveEntryHashtable(Context->TickHashtable, &removeEntry); } PhDereferenceObject(itemsToRemove); } }
/*------------------------------------------------------------------------ Procedure: SubClassEdit ID:1 Purpose: Handles messages to the editbox Input: Output: Errors: -------------------------------------------------------------------------- Edit History: 14 Sept 2003 - Chris Watford [email protected] - Setup handler for up and down arrows 15 Sept 2003 - Chris Watford [email protected] - Setup framework for history on up arrow - Saves lines you move off of in the edit buffer 16 Sept 2003 - Chris Watford [email protected] - Proper handling of newline message finished - Fixed ENTER on middle of interior line, moves cursor to the end and sends the line - Setup the copying and destroying of the old buffer - Included buffer rewrite 17 Sept 2003 - Chris Watford [email protected] - Added C-p/C-n support - Changed UpArrow to C-UpArrow so as to not confuse users 18 Sept 2003 - Chris Watford [email protected] - Added Left and Right arrow line saving - Added backspace and delete line saving and removing - Fixed history scrolling 21 Sept 2003 - Chris Watford [email protected] - Fixed pasting errors associated with lines being out of bounds for the buffer - Added error handling, possibly able to handle it diff down the line - Removed C-Up/C-Dn for history scrolling, buggy at best on my machine ------------------------------------------------------------------------*/ static LRESULT CALLBACK SubClassEdit(HWND hwnd, UINT msg, WPARAM mp1, LPARAM mp2) { LRESULT r; int postit=0,nl; if (msg == WM_CHAR && mp1 == '\r') { if (!busy) { r = GetCurLineIndex(hwnd); nl = GetNumberOfLines(hwnd); // if we're not the last line if (r != nl-1) { // update or add us, we might not have any lines in the edit buffer editbuffer_updateoraddline(CurrentEditBuffer, r-LastPromptPosition.line, GetLastLine(hwnd)); // scroll to the end, add CrLf then post the newline message GotoEOF(); AddStringToControl("\r\n"); PostMessage(GetParent(hwnd),WM_NEWLINE,0,0); return 0; } CallWindowProc(lpEProc,hwnd,WM_KEYDOWN,VK_END,1); CallWindowProc(lpEProc,hwnd,WM_KEYUP,VK_END,1); postit = 1; } } else if (msg == WM_CHAR && mp1 == (char)0x08) { int lineindex = SendMessage(hwnd, EM_LINEINDEX, LastPromptPosition.line, 0) + 2; int curline = SendMessage(hwnd,EM_LINEFROMCHAR,(WPARAM)-1,0); int nextline = 0; int curpoint = 0; SendMessage(hwnd, EM_GETSEL, (WPARAM)&curpoint, (LPARAM)NULL); nextline = SendMessage(hwnd,EM_LINEFROMCHAR,(WPARAM)(curpoint - 1),0); if(curpoint <= lineindex) { return 0; } else if(nextline != curline) { // delete the line we're on // grab the index curline -= LastPromptPosition.line; // kill it editbuffer_removeline(CurrentEditBuffer, curline); } } else if (msg == WM_KEYDOWN && mp1 == VK_F1) { DoHelp(hwnd); } else if ((msg == WM_KEYDOWN || msg == WM_KEYUP) && mp1 == VK_UP) { int curline = GetCurLineIndex(hwnd); /*if((msg == WM_KEYDOWN) && (GetKeyState(VK_CONTROL) && 0x8000)) { // go forward once in history NextHistoryEntry(); return 0; } else */ if((curline > LastPromptPosition.line) && (curline <= (LastPromptPosition.line + CurrentEditBuffer->LineCount))) { // update current line if (msg == WM_KEYDOWN) { int lineidx = (curline - LastPromptPosition.line); CallWindowProc(lpEProc,hwnd,WM_KEYDOWN,VK_END,1); CallWindowProc(lpEProc,hwnd,WM_KEYUP,VK_END,1); // we may have to add this line, otherwise update it editbuffer_updateoraddline(CurrentEditBuffer, lineidx, GetLastLine(hwnd)); } } else { return 0; } } else if ((msg == WM_KEYDOWN || msg == WM_KEYUP) && (mp1 == VK_LEFT)) { int lineindex = SendMessage(hwnd, EM_LINEINDEX, LastPromptPosition.line, 0) + 2; int curline = SendMessage(hwnd,EM_LINEFROMCHAR,(WPARAM)-1,0); int nextline = 0; int curpoint = 0; SendMessage(hwnd, EM_GETSEL, (WPARAM)&curpoint, (LPARAM)NULL); nextline = SendMessage(hwnd,EM_LINEFROMCHAR,(WPARAM)(curpoint - 1),0); if(curpoint <= lineindex) { // no left arrow to the left of the prompt return 0; } else if(nextline != curline) { // update current line if (msg == WM_KEYDOWN) { int lineidx = (curline - LastPromptPosition.line); CallWindowProc(lpEProc,hwnd,WM_KEYDOWN,VK_END,1); CallWindowProc(lpEProc,hwnd,WM_KEYUP,VK_END,1); // we may have to add this line, otherwise update it editbuffer_updateoraddline(CurrentEditBuffer, lineidx, GetLastLine(hwnd)); CallWindowProc(lpEProc,hwnd,WM_KEYDOWN,VK_HOME,1); CallWindowProc(lpEProc,hwnd,WM_KEYUP,VK_HOME,1); } } } else if ((msg == WM_KEYDOWN || msg == WM_KEYUP) && (mp1 == VK_DOWN)) { int curline = GetCurLineIndex(hwnd); /*if((msg == WM_KEYDOWN) && (GetKeyState(VK_CONTROL) && 0x8000)) { // go back once in history PrevHistoryEntry(); return 0; } else*/ if((curline >= LastPromptPosition.line) && (curline < (LastPromptPosition.line + CurrentEditBuffer->LineCount))) { // We don't post the newline, but instead update the current line if (msg == WM_KEYDOWN) { int lineidx = (curline - LastPromptPosition.line); CallWindowProc(lpEProc,hwnd,WM_KEYDOWN,VK_END,1); CallWindowProc(lpEProc,hwnd,WM_KEYUP,VK_END,1); editbuffer_updateline(CurrentEditBuffer, lineidx, GetLastLine(hwnd)); } } else { return 0; } } else if ((msg == WM_KEYDOWN || msg == WM_KEYUP) && (mp1 == VK_RIGHT)) { int lineindex = SendMessage(hwnd, EM_LINEINDEX, LastPromptPosition.line, 0) + 1; int curline = SendMessage(hwnd,EM_LINEFROMCHAR,(WPARAM)-1,0); int nextline = 0; int curpoint = 0; SendMessage(hwnd, EM_GETSEL, (WPARAM)&curpoint, (LPARAM)NULL); nextline = SendMessage(hwnd,EM_LINEFROMCHAR,(WPARAM)(curpoint + 2),0); if(curpoint <= lineindex) { // no movement behind the prompt return 0; } else if((nextline != curline) && (msg = WM_KEYDOWN)) { int lineidx = (curline - LastPromptPosition.line); CallWindowProc(lpEProc,hwnd,WM_KEYDOWN,VK_END,1); CallWindowProc(lpEProc,hwnd,WM_KEYUP,VK_END,1); editbuffer_updateline(CurrentEditBuffer, lineidx, GetLastLine(hwnd)); } } else if ((msg == WM_KEYDOWN) && (mp1 == VK_PRIOR) && (GetKeyState(VK_CONTROL) && 0x8000)) { // C-p NextHistoryEntry(); return 0; } else if ((msg == WM_KEYDOWN) && (mp1 == VK_NEXT) && (GetKeyState(VK_CONTROL) && 0x8000)) { // C-n PrevHistoryEntry(); return 0; } else if ((msg == WM_KEYDOWN || msg == WM_KEYUP) && (mp1 == VK_DELETE)) { // see if we're the last char on the line, if so delete the next line // don't allow deleting left of the prompt int lineindex = SendMessage(hwnd, EM_LINEINDEX, LastPromptPosition.line, 0) + 2; int curline = SendMessage(hwnd,EM_LINEFROMCHAR,(WPARAM)-1,0); int nextline = 0; int curpoint = 0; SendMessage(hwnd, EM_GETSEL, (WPARAM)&curpoint, (LPARAM)NULL); nextline = SendMessage(hwnd,EM_LINEFROMCHAR,(WPARAM)(curpoint + 2),0); if(curpoint < lineindex) { // no chomping behind the prompt return 0; } else if(nextline != curline) { // deleting // grab the next line index curline -= LastPromptPosition.line; // kill it editbuffer_removeline(CurrentEditBuffer, curline+1); } } else if (msg == WM_PASTE) { // if they paste text, allow it r = CallWindowProc(lpEProc, hwnd, msg, mp1, mp2); // update the current edit buffer RefreshCurrentEditBuffer(); return r; } // handle errors switch(msg) { case WM_SYNTAXERROR: case WM_ILLEGALCHAR: case WM_UNBOUNDVAL: { // currently I handle them all the same // get the start of the line int start = SendMessage(hwnd, EM_LINEINDEX, LastPromptPosition.line, 0) + 2; // get the statement that error'd NextHistoryEntry(); // tell the history that the last line errored if(History != NULL) if(History->Statement != NULL) History->Statement->isCorrect = FALSE; // highlight the offending chars SendMessage(hwnd,EM_SETSEL,(WPARAM)(start + mp1), (LPARAM)(start + mp2)); return 0; } } r = CallWindowProc(lpEProc, hwnd, msg, mp1, mp2); if (postit) PostMessage(GetParent(hwnd),WM_NEWLINE,0,0); return r; }
LRESULT CALLBACK DealButtonProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) { if (msg == WM_LBUTTONDOWN) { TCHAR buff[64]; GetWindowText(hTextboxBetAmount, buff, 20); int bet = _ttoi(buff); /* for (int i = 0; buff[i] != NULL; i++) { if (! std::isdigit(buff[i]) ) { MessageBox( GameEngine::getInstance()->getHWnd(), L"Invalid bet amount.", L"Error", NULL); return 0; } } */ // int bet = atoi(buff); Table* table = GameEngine::getInstance()->getTable(); User* user = GameEngine::getInstance()->getUser(); // Can player bet this much? if (bet > user->getBalance()) { MessageBox( GameEngine::getInstance()->getHWnd(), L"Insufficient funds available to place this bet.", L"Error", NULL); return 0; } if (bet == 0) { MessageBox( GameEngine::getInstance()->getHWnd(), L"Must bet more than $0.", L"Error", NULL); return 0; } Hand* dealerHand = new Hand(); Hand* playerHand = new Hand(); playerHand->setBetAmount(bet); user->setBalance(user->getBalance() - bet); dealerHand->dealCard(true); dealerHand->dealCard(false); playerHand->dealCard(false); playerHand->dealCard(false); table->setDealerHand(dealerHand); table->setPlayerHand(playerHand); GameEngine::getInstance()->setState(GameEngine::STATE_PLAYING); PlaySound(L"sound-chips.wav", NULL, SND_FILENAME | SND_ASYNC); // // Check if we have blackjack, if so player // wins right away. Otherwise move to substate // "playing" // if (playerHand->isBlackjack()) { table->setState(TABLE_STATE_FINISHED); updateTextarea(hStaticTableMiddleMessage, "Blackjack! Player Wins."); // Play YAY sound PlaySound(L"sound-yay.wav", NULL, SND_FILENAME | SND_ASYNC); // Update user balance. user->setBalance(user->getBalance() + (bet*2)); } else { table->setState(TABLE_STATE_PLAYING); } // // Force redraw of window, which should now render the new // card data. // // https://msdn.microsoft.com/en-us/library/dd162911%28VS.85%29.aspx // http://stackoverflow.com/questions/2325894/difference-between-invalidaterect-and-redrawwindow // RedrawWindow(GameEngine::getInstance()->getHWnd(), NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW); return 0; } return CallWindowProc(oldDealButtonProc, hwnd, msg, wp, lp); }
LONG WINAPI InputLineWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { int key, cursor; switch( uMsg ) { case WM_KILLFOCUS: if( ( HWND ) wParam == s_wcd.hWnd || ( HWND ) wParam == s_wcd.hwndErrorBox ) { SetFocus( hWnd ); return 0; } break; case WM_KEYDOWN: key = MapKey( lParam ); // command history if( ( key == K_UPARROW ) || ( key == K_KP_UPARROW ) ) { if( s_wcd.nextHistoryLine - s_wcd.historyLine < COMMAND_HISTORY && s_wcd.historyLine > 0 ) { s_wcd.historyLine--; } s_wcd.consoleField = s_wcd.historyEditLines[ s_wcd.historyLine % COMMAND_HISTORY ]; SetWindowText( s_wcd.hwndInputLine, s_wcd.consoleField.GetBuffer() ); SendMessage( s_wcd.hwndInputLine, EM_SETSEL, s_wcd.consoleField.GetCursor(), s_wcd.consoleField.GetCursor() ); return 0; } if( ( key == K_DOWNARROW ) || ( key == K_KP_DOWNARROW ) ) { if( s_wcd.historyLine == s_wcd.nextHistoryLine ) { return 0; } s_wcd.historyLine++; s_wcd.consoleField = s_wcd.historyEditLines[ s_wcd.historyLine % COMMAND_HISTORY ]; SetWindowText( s_wcd.hwndInputLine, s_wcd.consoleField.GetBuffer() ); SendMessage( s_wcd.hwndInputLine, EM_SETSEL, s_wcd.consoleField.GetCursor(), s_wcd.consoleField.GetCursor() ); return 0; } break; case WM_CHAR: key = MapKey( lParam ); GetWindowText( s_wcd.hwndInputLine, s_wcd.consoleField.GetBuffer(), MAX_EDIT_LINE ); SendMessage( s_wcd.hwndInputLine, EM_GETSEL, ( WPARAM ) NULL, ( LPARAM ) &cursor ); s_wcd.consoleField.SetCursor( cursor ); // enter the line if( key == K_ENTER || key == K_KP_ENTER ) { strncat( s_wcd.consoleText, s_wcd.consoleField.GetBuffer(), sizeof( s_wcd.consoleText ) - strlen( s_wcd.consoleText ) - 5 ); strcat( s_wcd.consoleText, "\n" ); SetWindowText( s_wcd.hwndInputLine, "" ); Sys_Printf( "]%s\n", s_wcd.consoleField.GetBuffer() ); // copy line to history buffer s_wcd.historyEditLines[s_wcd.nextHistoryLine % COMMAND_HISTORY] = s_wcd.consoleField; s_wcd.nextHistoryLine++; s_wcd.historyLine = s_wcd.nextHistoryLine; s_wcd.consoleField.Clear(); return 0; } // command completion if( key == K_TAB ) { s_wcd.consoleField.AutoComplete(); SetWindowText( s_wcd.hwndInputLine, s_wcd.consoleField.GetBuffer() ); //s_wcd.consoleField.SetWidthInChars( strlen( s_wcd.consoleField.GetBuffer() ) ); SendMessage( s_wcd.hwndInputLine, EM_SETSEL, s_wcd.consoleField.GetCursor(), s_wcd.consoleField.GetCursor() ); return 0; } // clear autocompletion buffer on normal key input if( ( key >= K_SPACE && key <= K_BACKSPACE ) || ( key >= K_KP_SLASH && key <= K_KP_PLUS ) || ( key >= K_KP_STAR && key <= K_KP_EQUALS ) ) { s_wcd.consoleField.ClearAutoComplete(); } break; } return CallWindowProc( s_wcd.SysInputLineWndProc, hWnd, uMsg, wParam, lParam ); }
/* The main Win32 event handler */ LRESULT DIB_HandleMessage(_THIS, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { extern int posted; switch (msg) { case WM_SYSKEYDOWN: case WM_KEYDOWN: { SDL_keysym keysym; #ifdef SDL_VIDEO_DRIVER_GAPI if(this->hidden->gapiInfo) { // Drop GAPI artefacts if (wParam == 0x84 || wParam == 0x5B) return 0; wParam = rotateKey(wParam, this->hidden->gapiInfo->coordinateTransform); } #endif /* Ignore repeated keys */ if ( lParam&REPEATED_KEYMASK ) { return(0); } switch (wParam) { case VK_CONTROL: if ( lParam&EXTENDED_KEYMASK ) wParam = VK_RCONTROL; else wParam = VK_LCONTROL; break; case VK_SHIFT: /* EXTENDED trick doesn't work here */ { Uint8 *state = SDL_GetKeyState(NULL); if (state[SDLK_LSHIFT] == SDL_RELEASED && (GetKeyState(VK_LSHIFT) & 0x8000)) { wParam = VK_LSHIFT; } else if (state[SDLK_RSHIFT] == SDL_RELEASED && (GetKeyState(VK_RSHIFT) & 0x8000)) { wParam = VK_RSHIFT; } else { /* Win9x */ int sc = HIWORD(lParam) & 0xFF; if (sc == 0x2A) wParam = VK_LSHIFT; else if (sc == 0x36) wParam = VK_RSHIFT; else wParam = VK_LSHIFT; } } break; case VK_MENU: if ( lParam&EXTENDED_KEYMASK ) wParam = VK_RMENU; else wParam = VK_LMENU; break; } #ifdef NO_GETKEYBOARDSTATE /* this is the workaround for the missing ToAscii() and ToUnicode() in CE (not necessary at KEYUP!) */ if ( SDL_TranslateUNICODE ) { MSG m; m.hwnd = hwnd; m.message = msg; m.wParam = wParam; m.lParam = lParam; m.time = 0; if ( TranslateMessage(&m) && PeekMessage(&m, hwnd, 0, WM_USER, PM_NOREMOVE) && (m.message == WM_CHAR) ) { GetMessage(&m, hwnd, 0, WM_USER); wParam = m.wParam; } } #endif /* NO_GETKEYBOARDSTATE */ posted = SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(wParam,HIWORD(lParam),&keysym,1)); } return(0); case WM_SYSKEYUP: case WM_KEYUP: { SDL_keysym keysym; #ifdef SDL_VIDEO_DRIVER_GAPI if(this->hidden->gapiInfo) { // Drop GAPI artifacts if (wParam == 0x84 || wParam == 0x5B) return 0; wParam = rotateKey(wParam, this->hidden->gapiInfo->coordinateTransform); } #endif switch (wParam) { case VK_CONTROL: if ( lParam&EXTENDED_KEYMASK ) wParam = VK_RCONTROL; else wParam = VK_LCONTROL; break; case VK_SHIFT: /* EXTENDED trick doesn't work here */ { Uint8 *state = SDL_GetKeyState(NULL); if (state[SDLK_LSHIFT] == SDL_PRESSED && !(GetKeyState(VK_LSHIFT) & 0x8000)) { wParam = VK_LSHIFT; } else if (state[SDLK_RSHIFT] == SDL_PRESSED && !(GetKeyState(VK_RSHIFT) & 0x8000)) { wParam = VK_RSHIFT; } else { /* Win9x */ int sc = HIWORD(lParam) & 0xFF; if (sc == 0x2A) wParam = VK_LSHIFT; else if (sc == 0x36) wParam = VK_RSHIFT; else wParam = VK_LSHIFT; } } break; case VK_MENU: if ( lParam&EXTENDED_KEYMASK ) wParam = VK_RMENU; else wParam = VK_LMENU; break; } /* Windows only reports keyup for print screen */ if ( wParam == VK_SNAPSHOT && SDL_GetKeyState(NULL)[SDLK_PRINT] == SDL_RELEASED ) { posted = SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(wParam,HIWORD(lParam),&keysym,1)); } posted = SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(wParam,HIWORD(lParam),&keysym,0)); } return(0); #if defined(SC_SCREENSAVE) && defined(SC_MONITORPOWER) case WM_SYSCOMMAND: { const DWORD val = (DWORD) (wParam & 0xFFF0); if ((val == SC_SCREENSAVE) || (val == SC_MONITORPOWER)) { if (this->hidden->dibInfo && !allow_screensaver) { /* Note that this doesn't stop anything on Vista if the screensaver has a password. */ return(0); } } } /* Fall through to default processing */ #endif /* SC_SCREENSAVE && SC_MONITORPOWER */ default: { /* Only post the event if we're watching for it */ if ( SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE ) { SDL_SysWMmsg wmmsg; SDL_VERSION(&wmmsg.version); wmmsg.hwnd = hwnd; wmmsg.msg = msg; wmmsg.wParam = wParam; wmmsg.lParam = lParam; posted = SDL_PrivateSysWMEvent(&wmmsg); /* DJM: If the user isn't watching for private messages in her SDL event loop, then pass it along to any win32 specific window proc. */ } else if (userWindowProc) { return CallWindowProc(userWindowProc, hwnd, msg, wParam, lParam); } } break; } return(DefWindowProc(hwnd, msg, wParam, lParam)); }
LRESULT CALLBACK CSearchBar::EditProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { CSearchBar* This = (CSearchBar*)::GetWindowLong(hwnd, GWL_USERDATA); switch (msg) { case WM_KEYDOWN: switch (wparam) { case VK_RETURN: This->GetParent()->PostMessage(WM_COMMAND, ID_WEB_SEARCH, 0); break; case VK_ESCAPE: return 0; } break; case WM_CONTEXTMENU: if (riched20) { HMENU menu = ::LoadMenu(AfxGetResourceHandle(), LPCTSTR(IDR_POPUP2)); HMENU popup = ::GetSubMenu(menu, 2); TrackPopupMenu(popup, TPM_LEFTALIGN, GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam), 0, hwnd, NULL); DestroyMenu(menu); return 0; } break; case WM_COMMAND: if (riched20) { switch (LOWORD(wparam)) { case ID_EDIT_UNDO: ::SendMessage(hwnd, WM_UNDO, 0, 0); return 0; case ID_EDIT_CUT: ::SendMessage(hwnd, WM_CUT, 0, 0); return 0; case ID_EDIT_COPY: ::SendMessage(hwnd, WM_COPY, 0, 0); return 0; case ID_EDIT_PASTE: ::SendMessage(hwnd, WM_PASTE, 0, NULL); return 0; case ID_EDIT_DELETE: ::SendMessage(hwnd, WM_CLEAR, 0, 0); return 0; case ID_EDIT_SELALL: { CHARRANGE cr = {0, -1}; ::SendMessage(hwnd, EM_EXSETSEL, 0, (LPARAM)&cr); return 0; } } } break; case WM_SETFOCUS: CallWindowProc(This->old_search_bar_proc, hwnd, msg, wparam, lparam); if (riched20) { CHARRANGE cr = {0, -1}; ::SendMessage(hwnd, EM_EXSETSEL, 0, (LPARAM)&cr); } else ::SendMessage(hwnd, EM_SETSEL, 0, -1); return 0; case WM_GETDLGCODE: return DLGC_WANTALLKEYS; case WM_SETCURSOR: if (riched20) ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_IBEAM)); break; } return CallWindowProc(This->old_search_bar_proc, hwnd, msg, wparam, lparam); }
LRESULT CALLBACK CardImageWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { PCARDBACK pCardBack = (PCARDBACK)GetWindowLongPtr(hwnd, GWL_USERDATA); static WNDPROC hOldProc = NULL; if (!hOldProc && pCardBack) hOldProc = pCardBack->hOldProc; switch (msg) { case WM_PAINT: { HDC hdc; PAINTSTRUCT ps; HPEN hPen, hOldPen; HBRUSH hBrush, hOldBrush; RECT rc; hdc = BeginPaint(hwnd, &ps); if (pCardBack->bSelected) { hPen = CreatePen(PS_SOLID, 2, RGB(0,0,0)); } else { DWORD Face = GetSysColor(COLOR_3DFACE); hPen = CreatePen(PS_SOLID, 2, Face); } GetClientRect(hwnd, &rc); hBrush = (HBRUSH)GetStockObject(NULL_BRUSH); hOldPen = (HPEN)SelectObject(hdc, hPen); hOldBrush = (HBRUSH)SelectObject(hdc, hBrush); Rectangle(hdc, rc.left+1, rc.top+1, rc.right, rc.bottom); StretchBlt(hdc, 2, 2, CARDBACK_OPTIONS_WIDTH, CARDBACK_OPTIONS_HEIGHT, __hdcCardBitmaps, pCardBack->hdcNum * __cardwidth, 0, __cardwidth, __cardheight, SRCCOPY); SelectObject(hdc, hOldPen); SelectObject(hdc, hOldBrush); EndPaint(hwnd, &ps); break; } case WM_LBUTTONDOWN: pCardBack->bSelected = pCardBack->bSelected ? FALSE : TRUE; break; } return CallWindowProc(hOldProc, hwnd, msg, wParam, lParam); }
LRESULT CALLBACK PhpExtendedListViewWndProc( __in HWND hwnd, __in UINT uMsg, __in WPARAM wParam, __in LPARAM lParam ) { PPH_EXTLV_CONTEXT context; WNDPROC oldWndProc; context = (PPH_EXTLV_CONTEXT)GetProp(hwnd, PhpMakeExtLvContextAtom()); oldWndProc = context->OldWndProc; switch (uMsg) { case WM_DESTROY: { SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)oldWndProc); if (context->TickHashtable) PhDereferenceObject(context->TickHashtable); PhFree(context); RemoveProp(hwnd, PhpMakeExtLvContextAtom()); } break; case WM_NOTIFY: { LPNMHDR header = (LPNMHDR)lParam; switch (header->code) { case HDN_ITEMCLICK: { HWND headerHandle; headerHandle = (HWND)CallWindowProc(context->OldWndProc, hwnd, LVM_GETHEADER, 0, 0); if (header->hwndFrom == headerHandle) { LPNMHEADER header2 = (LPNMHEADER)header; if (header2->iItem == context->SortColumn) { if (context->TriState) { if (context->SortOrder == AscendingSortOrder) context->SortOrder = DescendingSortOrder; else if (context->SortOrder == DescendingSortOrder) context->SortOrder = NoSortOrder; else context->SortOrder = AscendingSortOrder; } else { if (context->SortOrder == AscendingSortOrder) context->SortOrder = DescendingSortOrder; else context->SortOrder = AscendingSortOrder; } } else { context->SortColumn = header2->iItem; context->SortOrder = AscendingSortOrder; } PhSetHeaderSortIcon(headerHandle, context->SortColumn, context->SortOrder); ExtendedListView_SortItems(hwnd); } } break; } } break; case WM_REFLECT + WM_NOTIFY: { LPNMHDR header = (LPNMHDR)lParam; switch (header->code) { case NM_CUSTOMDRAW: { if (header->hwndFrom == hwnd) { LPNMLVCUSTOMDRAW customDraw = (LPNMLVCUSTOMDRAW)header; switch (customDraw->nmcd.dwDrawStage) { case CDDS_PREPAINT: return CDRF_NOTIFYITEMDRAW; case CDDS_ITEMPREPAINT: { LVITEM item; PH_ITEM_STATE itemState; BOOLEAN colorChanged = FALSE; HFONT newFont = NULL; item.mask = LVIF_STATE; item.iItem = (INT)customDraw->nmcd.dwItemSpec; item.iSubItem = 0; item.stateMask = LVIS_STATEIMAGEMASK; CallWindowProc(oldWndProc, hwnd, LVM_GETITEM, 0, (LPARAM)&item); itemState = PH_GET_ITEM_STATE(item.state); if (!context->EnableState || itemState == NormalItemState) { if (context->ItemColorFunction) { customDraw->clrTextBk = context->ItemColorFunction( (INT)customDraw->nmcd.dwItemSpec, (PVOID)customDraw->nmcd.lItemlParam, context->Context ); colorChanged = TRUE; } if (context->ItemFontFunction) { newFont = context->ItemFontFunction( (INT)customDraw->nmcd.dwItemSpec, (PVOID)customDraw->nmcd.lItemlParam, context->Context ); } if (newFont) SelectObject(customDraw->nmcd.hdc, newFont); } else if (itemState == NewItemState) { customDraw->clrTextBk = context->NewColor; colorChanged = TRUE; } else if (itemState == RemovingItemState) { customDraw->clrTextBk = context->RemovingColor; colorChanged = TRUE; } if (colorChanged) { if (PhGetColorBrightness(customDraw->clrTextBk) > 100) // slightly less than half customDraw->clrText = RGB(0x00, 0x00, 0x00); else customDraw->clrText = RGB(0xff, 0xff, 0xff); } if (!newFont) return CDRF_DODEFAULT; else return CDRF_NEWFONT; } break; } } } break; } } break; case WM_SETCURSOR: { if (context->Cursor) { SetCursor(context->Cursor); return TRUE; } } break; case WM_UPDATEUISTATE: { // Disable focus rectangles by setting or masking out the flag where appropriate. switch (LOWORD(wParam)) { case UIS_SET: wParam |= UISF_HIDEFOCUS << 16; break; case UIS_CLEAR: case UIS_INITIALIZE: wParam &= ~(UISF_HIDEFOCUS << 16); break; } } break; case LVM_INSERTITEM: { LPLVITEM item = (LPLVITEM)lParam; INT index; if (!context->EnableState) break; // pass through if (!(item->mask & LVIF_STATE)) { item->mask |= LVIF_STATE; item->stateMask = LVIS_STATEIMAGEMASK; item->state = 0; } else { item->stateMask |= LVIS_STATEIMAGEMASK; item->state &= ~LVIS_STATEIMAGEMASK; } if (context->EnableStateHighlighting > 0) { item->state |= INDEXTOSTATEIMAGEMASK(NewItemState); } else { item->state = NormalItemState; } if ((index = (INT)CallWindowProc(oldWndProc, hwnd, LVM_INSERTITEM, 0, (LPARAM)item)) == -1) return -1; if (context->EnableStateHighlighting > 0) { PH_TICK_ENTRY entry; PhpEnsureTickHashtableCreated(context); entry.Id = ListView_MapIndexToID(hwnd, index); entry.TickCount = GetTickCount(); PhAddEntryHashtable(context->TickHashtable, &entry); } return index; } case LVM_DELETEITEM: { if (!context->EnableState) break; // pass through if (context->EnableStateHighlighting > 0) { LVITEM item; item.mask = LVIF_STATE | LVIF_PARAM; item.iItem = (INT)wParam; item.iSubItem = 0; item.stateMask = LVIS_STATEIMAGEMASK; item.state = INDEXTOSTATEIMAGEMASK(RemovingItemState); // IMPORTANT: // We need to null the param. This is important because the user // will most likely be storing pointers to heap allocations in // here, and free the allocation after it has deleted the // item. The user may allocate sometime in the future and receive // the same pointer as is stored here. The user may call // LVM_FINDITEM or LVM_GETNEXTITEM and find this item, which // is supposed to be deleted. It may then attempt to delete // this item *twice*, which leads to bad things happening, // including *not* deleting the item that the user wanted to delete. item.lParam = (LPARAM)NULL; CallWindowProc(context->OldWndProc, hwnd, LVM_SETITEM, 0, (LPARAM)&item); { PH_TICK_ENTRY localEntry; PPH_TICK_ENTRY entry; PhpEnsureTickHashtableCreated(context); localEntry.Id = ListView_MapIndexToID(hwnd, (INT)wParam); entry = PhAddEntryHashtableEx(context->TickHashtable, &localEntry, NULL); entry->TickCount = GetTickCount(); } return TRUE; } else { // The item may still be under state highlighting. if (context->TickHashtable) { PH_TICK_ENTRY entry; entry.Id = ListView_MapIndexToID(hwnd, (INT)wParam); PhRemoveEntryHashtable(context->TickHashtable, &entry); } } } break; case LVM_GETITEM: { LVITEM item; ULONG itemState; ULONG oldMask; ULONG oldStateMask; if (!context->EnableState) break; // pass through memcpy(&item, (LPLVITEM)lParam, sizeof(LVITEM)); oldMask = item.mask; oldStateMask = item.stateMask; if (!(item.mask & LVIF_STATE)) { item.mask |= LVIF_STATE; item.stateMask = LVIS_STATEIMAGEMASK; } else { item.stateMask |= LVIS_STATEIMAGEMASK; } if (!CallWindowProc(oldWndProc, hwnd, LVM_GETITEM, 0, (LPARAM)&item)) return FALSE; // Check if the item is being deleted. If so, pretend it doesn't // exist. itemState = PH_GET_ITEM_STATE(item.state); if (itemState == RemovingItemState) return FALSE; item.mask = oldMask; item.stateMask = oldStateMask; item.state &= item.stateMask; memcpy((LPLVITEM)lParam, &item, sizeof(LVITEM)); } return TRUE; case ELVM_ADDFALLBACKCOLUMN: { if (context->NumberOfFallbackColumns < PH_MAX_COMPARE_FUNCTIONS) context->FallbackColumns[context->NumberOfFallbackColumns++] = (ULONG)wParam; else return FALSE; } return TRUE; case ELVM_ADDFALLBACKCOLUMNS: { ULONG numberOfColumns = (ULONG)wParam; PULONG columns = (PULONG)lParam; if (context->NumberOfFallbackColumns + numberOfColumns <= PH_MAX_COMPARE_FUNCTIONS) { memcpy( &context->FallbackColumns[context->NumberOfFallbackColumns], columns, numberOfColumns * sizeof(ULONG) ); context->NumberOfFallbackColumns += numberOfColumns; } else { return FALSE; } } return TRUE; case ELVM_ENABLESTATE: { context->EnableState = !!wParam; } return TRUE; case ELVM_INIT: { PhSetHeaderSortIcon(ListView_GetHeader(hwnd), context->SortColumn, context->SortOrder); // HACK to fix tooltips showing behind Always On Top windows. SetWindowPos(ListView_GetToolTips(hwnd), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE); // Make sure focus rectangles are disabled. SendMessage(hwnd, WM_CHANGEUISTATE, MAKELONG(UIS_SET, UISF_HIDEFOCUS), 0); } return TRUE; case ELVM_SETCOLUMNWIDTH: { ULONG column = (ULONG)wParam; LONG width = (LONG)lParam; if (width == ELVSCW_AUTOSIZE_REMAININGSPACE) { RECT clientRect; LONG availableWidth; ULONG i; LVCOLUMN lvColumn; GetClientRect(hwnd, &clientRect); availableWidth = clientRect.right; i = 0; lvColumn.mask = LVCF_WIDTH; while (TRUE) { if (i != column) { if (CallWindowProc(oldWndProc, hwnd, LVM_GETCOLUMN, i, (LPARAM)&lvColumn)) { availableWidth -= lvColumn.cx; } else { break; } } i++; } if (availableWidth >= 40) return CallWindowProc(oldWndProc, hwnd, LVM_SETCOLUMNWIDTH, column, availableWidth); } return CallWindowProc(oldWndProc, hwnd, LVM_SETCOLUMNWIDTH, column, width); } break; case ELVM_SETCOMPAREFUNCTION: { ULONG column = (ULONG)wParam; PPH_COMPARE_FUNCTION compareFunction = (PPH_COMPARE_FUNCTION)lParam; if (column >= PH_MAX_COMPARE_FUNCTIONS) return FALSE; context->CompareFunctions[column] = compareFunction; } return TRUE; case ELVM_SETCONTEXT: { context->Context = (PVOID)lParam; } return TRUE; case ELVM_SETCURSOR: { context->Cursor = (HCURSOR)lParam; } return TRUE; case ELVM_SETHIGHLIGHTINGDURATION: { context->HighlightingDuration = (ULONG)wParam; } return TRUE; case ELVM_SETITEMCOLORFUNCTION: { context->ItemColorFunction = (PPH_EXTLV_GET_ITEM_COLOR)lParam; } return TRUE; case ELVM_SETITEMFONTFUNCTION: { context->ItemFontFunction = (PPH_EXTLV_GET_ITEM_FONT)lParam; } return TRUE; case ELVM_SETNEWCOLOR: { context->NewColor = (COLORREF)wParam; } return TRUE; case ELVM_SETREDRAW: { if (wParam) context->EnableRedraw++; else context->EnableRedraw--; if (context->EnableRedraw == 1) { SendMessage(hwnd, WM_SETREDRAW, TRUE, 0); InvalidateRect(hwnd, NULL, FALSE); } else if (context->EnableRedraw == 0) { SendMessage(hwnd, WM_SETREDRAW, FALSE, 0); } } return TRUE; case ELVM_SETREMOVINGCOLOR: { context->RemovingColor = (COLORREF)wParam; } return TRUE; case ELVM_SETSORT: { context->SortColumn = (ULONG)wParam; context->SortOrder = (PH_SORT_ORDER)lParam; PhSetHeaderSortIcon(ListView_GetHeader(hwnd), context->SortColumn, context->SortOrder); } return TRUE; case ELVM_SETSORTFAST: { context->SortFast = !!wParam; } return TRUE; case ELVM_SETSTATEHIGHLIGHTING: { if (wParam) context->EnableStateHighlighting++; else context->EnableStateHighlighting--; } return TRUE; case ELVM_SETTRISTATE: { context->TriState = !!wParam; } return TRUE; case ELVM_SETTRISTATECOMPAREFUNCTION: { context->TriStateCompareFunction = (PPH_COMPARE_FUNCTION)lParam; } return TRUE; case ELVM_SORTITEMS: { if (context->SortFast) { // This sort method is faster than the normal sort because our comparison function // doesn't have to call the list view window procedure to get the item lParam values. // The disadvantage of this method is that default sorting is not available - if a // column doesn't have a comparison function, it doesn't get sorted at all. ListView_SortItems( hwnd, PhpExtendedListViewCompareFastFunc, (LPARAM)context ); } else { ListView_SortItemsEx( hwnd, PhpExtendedListViewCompareFunc, (LPARAM)context ); } } return TRUE; case ELVM_TICK: { if ( context->EnableStateHighlighting > 0 && context->TickHashtable && context->TickHashtable->Count != 0 ) { PhListTick(context); } } return TRUE; } return CallWindowProc(oldWndProc, hwnd, uMsg, wParam, lParam); }
LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) { logWndMsg(hWnd, Msg); switch (Msg) { // General window painting. case WM_PAINT: { RECT updRect; if (!GetUpdateRect(hWnd, &updRect, false)) { break; } PAINTSTRUCT ps; HDC hdc; BITMAP bitmap; HDC hdcMem; HGDIOBJ oldBitmap; hdc = BeginPaint(hWnd, &ps); hdcMem = CreateCompatibleDC(hdc); oldBitmap = SelectObject(hdcMem, testImg); GetObject(testImg, sizeof(bitmap), &bitmap); BitBlt(hdc, 0, 0, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, SRCCOPY); SelectObject(hdcMem, oldBitmap); DeleteDC(hdcMem); EndPaint(hWnd, &ps); } break; /* // Erasing the window background. case WM_ERASEBKGND: // break; */ // Drawing the window frame. case WM_NCPAINT: // break; // Timer calls, these happen every minute and redraw the clock in a way that bypasses the other 3 messages. case WM_TIMER: // break; // Mouse button down msg for clock for some reason.... case 1128: { RECT rc; GetWindowRect(hWnd, &rc); int width = rc.right - rc.left; int height = rc.bottom - rc.top; SizeWindow(hWnd, width + 10, height); MessageBoxA(0, "derp", "Derp", MB_OK); } break; // Mouse button up msg for clock case 1127: { // } break; // Mouse right button down. case WM_RBUTTONDOWN: // break; // Mouse right button up. case WM_RBUTTONUP: // break; case WM_NCHITTEST: { short xPos = LOWORD(lParam); short yPos = HIWORD(lParam); char buf[200]; char ibuf[10]; memset(buf, 0, 200); strcat(buf, "WM_NCHITTEST: "); strcat(buf, itoa(xPos, ibuf, 10)); strcat(buf, ", "); strcat(buf, itoa(yPos, ibuf, 10)); strcat(buf, "\r\n"); FILE *f = fopen("C:/debug.txt", "a+"); fwrite(buf, strlen(buf), 1, f); fclose(f); return HTCLIENT; } break; // Let every other message pass so the clock doesn't die. default: return CallWindowProc(OldWndProc, hWnd, Msg, wParam, lParam); } return 0; }
static int CALLBACK CheckboxWndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) { CCheckboxData *dat = (CCheckboxData*)GetWindowLongPtr(hWnd, GWLP_USERDATA); if (!dat) return 0; switch (Msg) { case UM_INITCHECKBOX: { HFONT hFont = (HFONT)SendMessage(hWnd, WM_GETFONT, 0, 0); if (!hFont) hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT); LOGFONT lf; GetObject(hFont, sizeof(lf), &lf); lf.lfWeight = FW_BOLD; dat->hFont = CreateFontIndirect(&lf); SendMessage(hWnd, UM_AUTOSIZE, 0, 0); } return 0; case UM_AUTOSIZE: { HTHEME hTheme = OpenThemeData(hWnd, L"BUTTON"); int Len = GetWindowTextLength(hWnd) + 1; HDC hdc = GetDC(hWnd); HFONT hOldFont = (HFONT)SelectObject(hdc, dat->hFont); RECT rcText = { 0 }; if (hTheme) { WCHAR *szText = (WCHAR*)_alloca(Len * sizeof(WCHAR)); GetWindowTextW(hWnd, szText, Len); GetThemeTextExtent(hTheme, hdc, BP_GROUPBOX, IsWindowEnabled(hWnd) ? GBS_NORMAL : GBS_DISABLED, szText, -1, DT_CALCRECT | DT_LEFT | DT_VCENTER | DT_SINGLELINE, nullptr, &rcText); } else { SIZE size; wchar_t *szText = (wchar_t*)_alloca(Len * sizeof(wchar_t)); GetWindowText(hWnd, szText, Len); GetTextExtentPoint32(hdc, szText, (int)mir_wstrlen(szText), &size); rcText.right = size.cx; rcText.bottom = size.cy; } SelectObject(hdc, hOldFont); ReleaseDC(hWnd, hdc); if (hTheme) CloseThemeData(hTheme); OffsetRect(&rcText, CG_CHECKBOX_INDENT + CG_CHECKBOX_WIDTH + CG_TEXT_INDENT, 0); RECT rc; GetClientRect(hWnd, &rc); SetWindowPos(hWnd, nullptr, 0, 0, rcText.right + CG_ADDITIONAL_WIDTH, rc.bottom, SWP_NOMOVE | SWP_NOZORDER); } break; case BM_CLICK: SendMessage(hWnd, WM_LBUTTONDOWN, 0, 0); SendMessage(hWnd, WM_LBUTTONUP, 0, 0); return 0; case BM_GETCHECK: return dat->State & CGSM_ISCHECKED; case BM_SETCHECK: if ((wParam != BST_UNCHECKED && wParam != BST_CHECKED && wParam != BST_INDETERMINATE) || (wParam == BST_INDETERMINATE && dat->Style != BS_3STATE && dat->Style != BS_AUTO3STATE)) wParam = BST_CHECKED; dat->State &= ~CGSM_ISCHECKED; dat->State |= wParam; InvalidateRect(hWnd, nullptr, false); SendMessage(GetParent(hWnd), WM_COMMAND, MAKEWPARAM(GetDlgCtrlID(hWnd), BN_CLICKED), (LPARAM)hWnd); return 0; case BM_SETSTATE: if (wParam) dat->State |= CGS_PRESSED; else dat->State &= ~CGS_PRESSED; InvalidateRect(hWnd, nullptr, false); return 0; case BM_GETSTATE: return (dat->State & CGSM_GETSTATE) | ((GetFocus() == hWnd) ? BST_FOCUS : 0); case WM_GETDLGCODE: return DLGC_BUTTON; case WM_THEMECHANGED: case WM_ENABLE: InvalidateRect(hWnd, nullptr, false); return 0; case WM_SETTEXT: if (CallWindowProc(dat->OldWndProc, hWnd, Msg, wParam, lParam)) SendMessage(hWnd, UM_AUTOSIZE, 0, 0); return 0; case WM_KEYDOWN: if (wParam == VK_SPACE) SendMessage(hWnd, BM_SETSTATE, true, 0); return 0; case WM_KEYUP: if (wParam == VK_SPACE) { SendMessage(hWnd, BM_SETCHECK, (SendMessage(hWnd, BM_GETCHECK, 0, 0) + 1) % ((dat->Style == BS_AUTO3STATE) ? 3 : 2), 0); SendMessage(hWnd, BM_SETSTATE, false, 0); } return 0; case WM_CAPTURECHANGED: SendMessage(hWnd, BM_SETSTATE, false, 0); return 0; case WM_ERASEBKGND: return true; case WM_LBUTTONDOWN: case WM_LBUTTONDBLCLK: SetFocus(hWnd); SendMessage(hWnd, BM_SETSTATE, true, 0); SetCapture(hWnd); return 0; case WM_LBUTTONUP: if (GetCapture() == hWnd) ReleaseCapture(); SendMessage(hWnd, BM_SETSTATE, false, 0); if (dat->State & CGS_HOVERED && (dat->Style == BS_AUTOCHECKBOX || dat->Style == BS_AUTO3STATE)) SendMessage(hWnd, BM_SETCHECK, (SendMessage(hWnd, BM_GETCHECK, 0, 0) + 1) % ((dat->Style == BS_AUTO3STATE) ? 3 : 2), 0); return 0; case WM_MOUSEMOVE: { TRACKMOUSEEVENT tme = { 0 }; tme.cbSize = sizeof(tme); tme.dwFlags = TME_LEAVE; tme.dwHoverTime = HOVER_DEFAULT; tme.hwndTrack = hWnd; _TrackMouseEvent(&tme); } POINT pt; GetCursorPos(&pt); if ((WindowFromPoint(pt) == hWnd) ^ ((dat->State & CGS_HOVERED) != 0)) { dat->State ^= CGS_HOVERED; InvalidateRect(hWnd, nullptr, false); } return 0; case WM_MOUSELEAVE: if (dat->State & CGS_HOVERED) { dat->State &= ~CGS_HOVERED; InvalidateRect(hWnd, nullptr, false); } return 0; case WM_SETFOCUS: case WM_KILLFOCUS: case WM_SYSCOLORCHANGE: InvalidateRect(hWnd, nullptr, false); return 0; case WM_PAINT: { HDC hdc; PAINTSTRUCT ps; hdc = BeginPaint(hWnd, &ps); RECT rc; GetClientRect(hWnd, &rc); HDC hdcMem = CreateCompatibleDC(hdc); HBITMAP hbmMem = CreateCompatibleBitmap(hdc, rc.right, rc.bottom); HBITMAP hbmOld = (HBITMAP)SelectObject(hdcMem, hbmMem); HTHEME hTheme = OpenThemeData(hWnd, L"BUTTON"); if (hTheme) DrawThemeParentBackground(hWnd, hdcMem, nullptr); else FillRect(hdcMem, &rc, GetSysColorBrush(COLOR_3DFACE)); int StateID = 0; switch (SendMessage(hWnd, BM_GETCHECK, 0, 0)) { case BST_CHECKED: StateID += CBSCHECK_CHECKED; break; case BST_UNCHECKED: StateID += CBSCHECK_UNCHECKED; break; case BST_INDETERMINATE: StateID += CBSCHECK_MIXED; break; } if (!IsWindowEnabled(hWnd)) StateID += CBSSTATE_DISABLED; else if (dat->State & CGS_PRESSED && (GetCapture() != hWnd || dat->State & CGS_HOVERED)) StateID += CBSSTATE_PRESSED; else if (dat->State & CGS_PRESSED || dat->State & CGS_HOVERED) StateID += CBSSTATE_HOT; rc.left += CG_CHECKBOX_INDENT; rc.right = rc.left + CG_CHECKBOX_WIDTH; // left-align the image in the client area rc.top += CG_CHECKBOX_VERTINDENT; rc.bottom = rc.top + CG_CHECKBOX_WIDTH; // exact rc dimensions are necessary for DrawFrameControl to draw correctly if (hTheme) DrawThemeBackground(hTheme, hdcMem, BP_CHECKBOX, StateID, &rc, &rc); else { int dfcStates[] = { 0, 0, DFCS_PUSHED, DFCS_INACTIVE, DFCS_CHECKED, DFCS_CHECKED, DFCS_CHECKED | DFCS_PUSHED, DFCS_CHECKED | DFCS_INACTIVE, DFCS_BUTTON3STATE | DFCS_CHECKED, DFCS_BUTTON3STATE | DFCS_CHECKED, DFCS_BUTTON3STATE | DFCS_INACTIVE | DFCS_CHECKED | DFCS_PUSHED, DFCS_BUTTON3STATE | DFCS_INACTIVE | DFCS_CHECKED | DFCS_PUSHED }; _ASSERT(StateID >= 1 && StateID <= _countof(dfcStates)); DrawFrameControl(hdcMem, &rc, DFC_BUTTON, dfcStates[StateID - 1]); } GetClientRect(hWnd, &rc); rc.left += CG_CHECKBOX_INDENT + CG_CHECKBOX_WIDTH + CG_TEXT_INDENT; int Len = GetWindowTextLength(hWnd) + 1; wchar_t *szTextT = (wchar_t*)_alloca(Len * sizeof(wchar_t)); GetWindowText(hWnd, szTextT, Len); HFONT hOldFont = (HFONT)SelectObject(hdcMem, dat->hFont); SetBkMode(hdcMem, TRANSPARENT); if (hTheme) DrawThemeText(hTheme, hdcMem, BP_GROUPBOX, IsWindowEnabled(hWnd) ? GBS_NORMAL : GBS_DISABLED, szTextT, -1, DT_LEFT | DT_VCENTER | DT_SINGLELINE, 0, &rc); else DrawText(hdcMem, szTextT, -1, &rc, DT_LEFT | DT_VCENTER | DT_SINGLELINE); if (GetFocus() == hWnd) { RECT rcText = { 0 }; if (hTheme) GetThemeTextExtent(hTheme, hdcMem, BP_GROUPBOX, IsWindowEnabled(hWnd) ? GBS_NORMAL : GBS_DISABLED, szTextT, -1, DT_CALCRECT | DT_LEFT | DT_VCENTER | DT_SINGLELINE, nullptr, &rcText); else { SIZE size; GetTextExtentPoint32(hdcMem, szTextT, (int)mir_wstrlen(szTextT), &size); rcText.right = size.cx; rcText.bottom = size.cy; } rcText.bottom = rc.bottom; OffsetRect(&rcText, rc.left, 0); InflateRect(&rcText, 1, -1); DrawFocusRect(hdcMem, &rcText); } SelectObject(hdcMem, hOldFont); if (hTheme) CloseThemeData(hTheme); BitBlt(hdc, 0, 0, rc.right, rc.bottom, hdcMem, 0, 0, SRCCOPY); SelectObject(hdcMem, hbmOld); DeleteObject(hbmMem); DeleteDC(hdcMem); EndPaint(hWnd, &ps); } return 0; case WM_DESTROY: if (dat->hFont) DeleteObject(dat->hFont); SetWindowLongPtr(hWnd, GWLP_USERDATA, 0); CallWindowProc(dat->OldWndProc, hWnd, Msg, wParam, lParam); delete dat; return 0; } return CallWindowProc(dat->OldWndProc, hWnd, Msg, wParam, lParam); }
/* The main Win32 event handler */ LONG DIB_HandleMessage(_THIS, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { extern int posted; switch (msg) { case WM_SYSKEYDOWN: case WM_KEYDOWN: { SDL_keysym keysym; /* Ignore repeated keys */ if ( lParam&REPEATED_KEYMASK ) { return(0); } switch (wParam) { case VK_CONTROL: if ( lParam&EXTENDED_KEYMASK ) wParam = VK_RCONTROL; else wParam = VK_LCONTROL; break; case VK_SHIFT: /* EXTENDED trick doesn't work here */ if (!prev_shiftstates[0] && (GetKeyState(VK_LSHIFT) & 0x8000)) { wParam = VK_LSHIFT; prev_shiftstates[0] = TRUE; } else if (!prev_shiftstates[1] && (GetKeyState(VK_RSHIFT) & 0x8000)) { wParam = VK_RSHIFT; prev_shiftstates[1] = TRUE; } else { /* Huh? */ } break; case VK_MENU: if ( lParam&EXTENDED_KEYMASK ) wParam = VK_RMENU; else wParam = VK_LMENU; break; } #ifdef NO_GETKEYBOARDSTATE /* this is the workaround for the missing ToAscii() and ToUnicode() in CE (not necessary at KEYUP!) */ if ( SDL_TranslateUNICODE ) { MSG m; m.hwnd = hwnd; m.message = msg; m.wParam = wParam; m.lParam = lParam; m.time = 0; if ( TranslateMessage(&m) && PeekMessage(&m, hwnd, 0, WM_USER, PM_NOREMOVE) && (m.message == WM_CHAR) ) { GetMessage(&m, hwnd, 0, WM_USER); wParam = m.wParam; } else { wParam = 0; } } else { wParam = 0; } #endif /* NO_GETKEYBOARDSTATE */ posted = SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(wParam,HIWORD(lParam),&keysym,1)); } return(0); case WM_SYSKEYUP: case WM_KEYUP: { SDL_keysym keysym; switch (wParam) { case VK_CONTROL: if ( lParam&EXTENDED_KEYMASK ) wParam = VK_RCONTROL; else wParam = VK_LCONTROL; break; case VK_SHIFT: /* EXTENDED trick doesn't work here */ if (prev_shiftstates[0] && !(GetKeyState(VK_LSHIFT) & 0x8000)) { wParam = VK_LSHIFT; prev_shiftstates[0] = FALSE; } else if (prev_shiftstates[1] && !(GetKeyState(VK_RSHIFT) & 0x8000)) { wParam = VK_RSHIFT; prev_shiftstates[1] = FALSE; } else { /* Huh? */ } break; case VK_MENU: if ( lParam&EXTENDED_KEYMASK ) wParam = VK_RMENU; else wParam = VK_LMENU; break; } posted = SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(wParam,HIWORD(lParam),&keysym,0)); } return(0); #if defined(SC_SCREENSAVE) && defined(SC_MONITORPOWER) case WM_SYSCOMMAND: { if ((wParam&0xFFF0)==SC_SCREENSAVE || (wParam&0xFFF0)==SC_MONITORPOWER) return(0); } /* Fall through to default processing */ #endif /* SC_SCREENSAVE && SC_MONITORPOWER */ default: { /* Only post the event if we're watching for it */ if ( SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE ) { SDL_SysWMmsg wmmsg; SDL_VERSION(&wmmsg.version); wmmsg.hwnd = hwnd; wmmsg.msg = msg; wmmsg.wParam = wParam; wmmsg.lParam = lParam; posted = SDL_PrivateSysWMEvent(&wmmsg); /* DJM: If the user isn't watching for private messages in her SDL event loop, then pass it along to any win32 specific window proc. */ } else if (userWindowProc) { return CallWindowProc(userWindowProc, hwnd, msg, wParam, lParam); } } break; } return(DefWindowProc(hwnd, msg, wParam, lParam)); }
/* Диалоговая процедура */ INT_PTR CALLBACK DlgPlayList::ProcPlayList(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { HANDLE_MSG(hWnd, WM_CONTEXTMENU, _this->Cls_OnContextMenu); case WM_COMMAND: { switch (LOWORD(wParam)) { case IDC_ADDSONG: { SendMessage(GetParent(hWnd), WM_COMMAND, IDC_ADDSONG, 0); break; } case IDC_DELETE: { int idxSel = ListBox_GetCurSel(_this->hPlayList); ListBox_DeleteString(_this->hPlayList, idxSel); _this->songs.erase(_this->songs.begin() + idxSel); break; } case IDC_CLEANPLAYLIST: { _this->songs.clear(); ListBox_ResetContent(_this->hPlayList); break; } case IDC_COLORTEXTRED: { _this->UncheckedAllItemContextMenu(); CheckMenuItem(_this->hColor, IDC_COLORTEXTRED, MF_BYCOMMAND | MF_CHECKED); _this->changeColorTextInPlayList(hWnd, 255, 0, 0); break; } case IDC_COLORTEXTGREEN: { _this->UncheckedAllItemContextMenu(); CheckMenuItem(_this->hColor, IDC_COLORTEXTGREEN, MF_BYCOMMAND | MF_CHECKED); _this->changeColorTextInPlayList(hWnd, 0, 255, 0); break; } case IDC_COLORTEXTBLUE: { _this->UncheckedAllItemContextMenu(); CheckMenuItem(_this->hColor, IDC_COLORTEXTBLUE, MF_BYCOMMAND | MF_CHECKED); _this->changeColorTextInPlayList(hWnd, 0, 0, 255); break; } case IDC_COLORWHITE: { _this->UncheckedAllItemContextMenu(); CheckMenuItem(_this->hColor, IDC_COLORWHITE, MF_BYCOMMAND | MF_CHECKED); _this->changeColorTextInPlayList(hWnd, 255, 255, 255); break; } case IDC_COLORYELLOW: { _this->UncheckedAllItemContextMenu(); CheckMenuItem(_this->hColor, IDC_COLORYELLOW, MF_BYCOMMAND | MF_CHECKED); _this->changeColorTextInPlayList(hWnd, 255, 255, 0); break; } case IDC_COLORTURQUOISE: { _this->UncheckedAllItemContextMenu(); CheckMenuItem(_this->hColor, IDC_COLORTURQUOISE, MF_BYCOMMAND | MF_CHECKED); _this->changeColorTextInPlayList(hWnd, 0, 245, 255); break; } } break; } /* WM_DROPFILES */ case WM_DROPFILES: { HDROP hDrop = (HDROP)wParam; HANDLE hThread = CreateThread(0, 0, Thread, hDrop, 0, 0); //Создание отдельного потока для загрузки музыки в PlayList break; } } return CallWindowProc(_this->origProcContextMenu, hWnd, uMsg, wParam, lParam); }
LRESULT CALLBACK g_NewProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { if(!g_mgui_candraw) return CallWindowProc(g_OldProc, hWnd, message, wParam, lParam); switch (message) { case WM_CHAR: { char *pText = MGUI_FindFocusTextEntryText(); if (pText) { if (wParam == VK_BACK) { int len = strlen(pText); if (pText[len - 1] < 0) pText[len - 2] = '\0'; else pText[len - 1] = '\0'; } else if(wParam != VK_RETURN) { int len = strlen(pText); pText[len] = wParam; pText[len + 1] = '\0'; } else { MGUI_SetFocusTextEntryDisabled(); } return 1; } break; } case WM_IME_CHAR: { char *pText = MGUI_FindFocusTextEntryText(); if (pText) { char buf[3]; buf[0] = wParam >> 8; buf[1] = (byte)wParam; buf[2] = '\0'; strcat(pText, buf); return 1; } break; } case WM_IME_NOTIFY: { HIMC hImc = ImmGetContext(hWnd); if(!hImc) break; if(wParam == IMN_CHANGECANDIDATE) { DWORD dwSize; dwSize = ImmGetCandidateList(hImc,0,NULL,0); if(dwSize > 0) { CandidateList = (LPCANDIDATELIST)GlobalAlloc( GPTR, dwSize ); g_bDrawIme = true; ImmGetCandidateList(hImc,0,CandidateList,dwSize); } else memset(CandidateList,0,sizeof(CandidateList)); } else if(wParam == IMN_CLOSECANDIDATE) { g_bDrawIme = false; } ImmReleaseContext( hWnd, hImc ); } } return CallWindowProc(g_OldProc, hWnd, message, wParam, lParam); }
LRESULT CALLBACK PhpExtendedListViewWndProc( _In_ HWND hwnd, _In_ UINT uMsg, _In_ WPARAM wParam, _In_ LPARAM lParam ) { PPH_EXTLV_CONTEXT context; WNDPROC oldWndProc; context = (PPH_EXTLV_CONTEXT)GetProp(hwnd, PhpMakeExtLvContextAtom()); oldWndProc = context->OldWndProc; switch (uMsg) { case WM_DESTROY: { SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)oldWndProc); PhFree(context); RemoveProp(hwnd, PhpMakeExtLvContextAtom()); } break; case WM_NOTIFY: { LPNMHDR header = (LPNMHDR)lParam; switch (header->code) { case HDN_ITEMCLICK: { HWND headerHandle; headerHandle = (HWND)CallWindowProc(context->OldWndProc, hwnd, LVM_GETHEADER, 0, 0); if (header->hwndFrom == headerHandle) { LPNMHEADER header2 = (LPNMHEADER)header; if (header2->iItem == context->SortColumn) { if (context->TriState) { if (context->SortOrder == AscendingSortOrder) context->SortOrder = DescendingSortOrder; else if (context->SortOrder == DescendingSortOrder) context->SortOrder = NoSortOrder; else context->SortOrder = AscendingSortOrder; } else { if (context->SortOrder == AscendingSortOrder) context->SortOrder = DescendingSortOrder; else context->SortOrder = AscendingSortOrder; } } else { context->SortColumn = header2->iItem; context->SortOrder = AscendingSortOrder; } PhSetHeaderSortIcon(headerHandle, context->SortColumn, context->SortOrder); ExtendedListView_SortItems(hwnd); } } break; } } break; case WM_REFLECT + WM_NOTIFY: { LPNMHDR header = (LPNMHDR)lParam; switch (header->code) { case NM_CUSTOMDRAW: { if (header->hwndFrom == hwnd) { LPNMLVCUSTOMDRAW customDraw = (LPNMLVCUSTOMDRAW)header; switch (customDraw->nmcd.dwDrawStage) { case CDDS_PREPAINT: return CDRF_NOTIFYITEMDRAW; case CDDS_ITEMPREPAINT: { BOOLEAN colorChanged = FALSE; HFONT newFont = NULL; if (context->ItemColorFunction) { customDraw->clrTextBk = context->ItemColorFunction( (INT)customDraw->nmcd.dwItemSpec, (PVOID)customDraw->nmcd.lItemlParam, context->Context ); colorChanged = TRUE; } if (context->ItemFontFunction) { newFont = context->ItemFontFunction( (INT)customDraw->nmcd.dwItemSpec, (PVOID)customDraw->nmcd.lItemlParam, context->Context ); } if (newFont) SelectObject(customDraw->nmcd.hdc, newFont); if (colorChanged) { if (PhGetColorBrightness(customDraw->clrTextBk) > 100) // slightly less than half customDraw->clrText = RGB(0x00, 0x00, 0x00); else customDraw->clrText = RGB(0xff, 0xff, 0xff); } if (!newFont) return CDRF_DODEFAULT; else return CDRF_NEWFONT; } break; } } } break; } } break; case WM_SETCURSOR: { if (context->Cursor) { SetCursor(context->Cursor); return TRUE; } } break; case WM_UPDATEUISTATE: { // Disable focus rectangles by setting or masking out the flag where appropriate. switch (LOWORD(wParam)) { case UIS_SET: wParam |= UISF_HIDEFOCUS << 16; break; case UIS_CLEAR: case UIS_INITIALIZE: wParam &= ~(UISF_HIDEFOCUS << 16); break; } } break; case ELVM_ADDFALLBACKCOLUMN: { if (context->NumberOfFallbackColumns < PH_MAX_COMPARE_FUNCTIONS) context->FallbackColumns[context->NumberOfFallbackColumns++] = (ULONG)wParam; else return FALSE; } return TRUE; case ELVM_ADDFALLBACKCOLUMNS: { ULONG numberOfColumns = (ULONG)wParam; PULONG columns = (PULONG)lParam; if (context->NumberOfFallbackColumns + numberOfColumns <= PH_MAX_COMPARE_FUNCTIONS) { memcpy( &context->FallbackColumns[context->NumberOfFallbackColumns], columns, numberOfColumns * sizeof(ULONG) ); context->NumberOfFallbackColumns += numberOfColumns; } else { return FALSE; } } return TRUE; case ELVM_INIT: { PhSetHeaderSortIcon(ListView_GetHeader(hwnd), context->SortColumn, context->SortOrder); // HACK to fix tooltips showing behind Always On Top windows. SetWindowPos(ListView_GetToolTips(hwnd), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE); // Make sure focus rectangles are disabled. SendMessage(hwnd, WM_CHANGEUISTATE, MAKELONG(UIS_SET, UISF_HIDEFOCUS), 0); } return TRUE; case ELVM_SETCOLUMNWIDTH: { ULONG column = (ULONG)wParam; LONG width = (LONG)lParam; if (width == ELVSCW_AUTOSIZE_REMAININGSPACE) { RECT clientRect; LONG availableWidth; ULONG i; LVCOLUMN lvColumn; GetClientRect(hwnd, &clientRect); availableWidth = clientRect.right; i = 0; lvColumn.mask = LVCF_WIDTH; while (TRUE) { if (i != column) { if (CallWindowProc(oldWndProc, hwnd, LVM_GETCOLUMN, i, (LPARAM)&lvColumn)) { availableWidth -= lvColumn.cx; } else { break; } } i++; } if (availableWidth >= 40) return CallWindowProc(oldWndProc, hwnd, LVM_SETCOLUMNWIDTH, column, availableWidth); } return CallWindowProc(oldWndProc, hwnd, LVM_SETCOLUMNWIDTH, column, width); } break; case ELVM_SETCOMPAREFUNCTION: { ULONG column = (ULONG)wParam; PPH_COMPARE_FUNCTION compareFunction = (PPH_COMPARE_FUNCTION)lParam; if (column >= PH_MAX_COMPARE_FUNCTIONS) return FALSE; context->CompareFunctions[column] = compareFunction; } return TRUE; case ELVM_SETCONTEXT: { context->Context = (PVOID)lParam; } return TRUE; case ELVM_SETCURSOR: { context->Cursor = (HCURSOR)lParam; } return TRUE; case ELVM_SETITEMCOLORFUNCTION: { context->ItemColorFunction = (PPH_EXTLV_GET_ITEM_COLOR)lParam; } return TRUE; case ELVM_SETITEMFONTFUNCTION: { context->ItemFontFunction = (PPH_EXTLV_GET_ITEM_FONT)lParam; } return TRUE; case ELVM_SETREDRAW: { if (wParam) context->EnableRedraw++; else context->EnableRedraw--; if (context->EnableRedraw == 1) { SendMessage(hwnd, WM_SETREDRAW, TRUE, 0); InvalidateRect(hwnd, NULL, FALSE); } else if (context->EnableRedraw == 0) { SendMessage(hwnd, WM_SETREDRAW, FALSE, 0); } } return TRUE; case ELVM_SETSORT: { context->SortColumn = (ULONG)wParam; context->SortOrder = (PH_SORT_ORDER)lParam; PhSetHeaderSortIcon(ListView_GetHeader(hwnd), context->SortColumn, context->SortOrder); } return TRUE; case ELVM_SETSORTFAST: { context->SortFast = !!wParam; } return TRUE; case ELVM_SETTRISTATE: { context->TriState = !!wParam; } return TRUE; case ELVM_SETTRISTATECOMPAREFUNCTION: { context->TriStateCompareFunction = (PPH_COMPARE_FUNCTION)lParam; } return TRUE; case ELVM_SORTITEMS: { if (context->SortFast) { // This sort method is faster than the normal sort because our comparison function // doesn't have to call the list view window procedure to get the item lParam // values. The disadvantage of this method is that default sorting is not available // - if a column doesn't have a comparison function, it doesn't get sorted at all. ListView_SortItems( hwnd, PhpExtendedListViewCompareFastFunc, (LPARAM)context ); } else { ListView_SortItemsEx( hwnd, PhpExtendedListViewCompareFunc, (LPARAM)context ); } } return TRUE; } return CallWindowProc(oldWndProc, hwnd, uMsg, wParam, lParam); }
LRESULT CALLBACK CMenuWndHook::CoolMenuProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { WNDPROC oldWndProc = (WNDPROC)::GetProp(hWnd, CoolMenu_oldProc); CMenuWndHook* pWnd = NULL; switch (uMsg) { case WM_CREATE: { LRESULT lResult = CallWindowProc(oldWndProc, hWnd, uMsg, wParam, lParam); if ((pWnd = GetWndHook(hWnd)) != NULL) { lResult = (LRESULT)pWnd->OnCreate((LPCREATESTRUCT)lParam); } return lResult; } break; case WM_NCCALCSIZE: { LRESULT lResult = CallWindowProc(oldWndProc, hWnd, uMsg, wParam, lParam); if ((pWnd = GetWndHook(hWnd)) != NULL) { pWnd->OnNcCalcsize((BOOL)wParam,(NCCALCSIZE_PARAMS*)lParam); } return lResult; } break; case WM_WINDOWPOSCHANGING: { if ((pWnd = GetWndHook(hWnd)) != NULL) { pWnd->OnWindowPosChanging((LPWINDOWPOS)lParam); } } break; case WM_WINDOWPOSCHANGED: { LRESULT lResult = CallWindowProc(oldWndProc, hWnd, uMsg, wParam, lParam); if ((pWnd = GetWndHook(hWnd)) != NULL) { pWnd->OnWindowPosChanged(); } return lResult; } break; case WM_PRINT: { LRESULT lResult = CallWindowProc(oldWndProc, hWnd, uMsg, wParam, lParam); if ((pWnd = GetWndHook(hWnd)) != NULL) { pWnd->OnPrint((HDC)wParam); } return lResult; } break; case WM_NCPAINT: { if ((pWnd = GetWndHook(hWnd)) != NULL) { pWnd->OnNcPaint(); return 0; } } break; case WM_NCDESTROY: { if ((pWnd = GetWndHook(hWnd)) != NULL) { pWnd->OnNcDestroy(); } } break; } return CallWindowProc(oldWndProc, hWnd, uMsg, wParam, lParam); }
static INT PhpExtendedListViewCompareFunc( _In_ LPARAM lParam1, _In_ LPARAM lParam2, _In_ LPARAM lParamSort ) { PPH_EXTLV_CONTEXT context = (PPH_EXTLV_CONTEXT)lParamSort; INT result; INT x = (INT)lParam1; INT y = (INT)lParam2; ULONG i; PULONG fallbackColumns; LVITEM xItem; LVITEM yItem; // Get the param values. xItem.mask = LVIF_PARAM | LVIF_STATE; xItem.iItem = x; xItem.iSubItem = 0; yItem.mask = LVIF_PARAM | LVIF_STATE; yItem.iItem = y; yItem.iSubItem = 0; // Don't use SendMessage/ListView_* because it will call our new window procedure, which will // use GetProp. This calls NtUserGetProp, and obviously having a system call in a comparison // function is very, very bad for performance. if (!CallWindowProc(context->OldWndProc, context->Handle, LVM_GETITEM, 0, (LPARAM)&xItem)) return 0; if (!CallWindowProc(context->OldWndProc, context->Handle, LVM_GETITEM, 0, (LPARAM)&yItem)) return 0; // First, do tri-state sorting. if ( context->TriState && context->SortOrder == NoSortOrder && context->TriStateCompareFunction ) { result = context->TriStateCompareFunction( (PVOID)xItem.lParam, (PVOID)yItem.lParam, context->Context ); if (result != 0) return result; } // Compare using the user-selected column and move on to the fallback columns if necessary. result = PhpCompareListViewItems(context, x, y, (PVOID)xItem.lParam, (PVOID)yItem.lParam, context->SortColumn, TRUE); if (result != 0) return result; fallbackColumns = context->FallbackColumns; for (i = context->NumberOfFallbackColumns; i != 0; i--) { ULONG fallbackColumn = *fallbackColumns++; if (fallbackColumn == context->SortColumn) continue; result = PhpCompareListViewItems(context, x, y, (PVOID)xItem.lParam, (PVOID)yItem.lParam, fallbackColumn, TRUE); if (result != 0) return result; } return 0; }
LRESULT CALLBACK ListBoxProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_LBUTTONDOWN: { int index = SendMessage(hwnd, LB_ITEMFROMPOINT, 0, lParam); if(index >= 0x10000) { SendMessage(hwnd, LB_SETCURSEL, (DWORD)-1, 0L); } sleep_skip = true; } break; case WM_LBUTTONDBLCLK: { int index = SendMessage(hwnd, LB_ITEMFROMPOINT, 0, lParam); if(index < 0x10000) { SendMessage(guiWnd, WM_COMMAND, IDC_BUTTON8, NULL); } } break; case WM_RBUTTONDOWN: { POINT pos; MENUITEMINFO info, separator; HMENU hMenu; DWORD dwID; int index = SendMessage(hwnd, LB_ITEMFROMPOINT, 0, lParam); if(index < 0x10000) { SendMessage(hwnd, LB_SETCURSEL, (DWORD)index, 1L); } else { SendMessage(hwnd, LB_SETCURSEL, (DWORD)-1, 0L); sleep_skip = true; break; } hMenu = CreatePopupMenu(); memset(&separator, 0, sizeof(MENUITEMINFO)); separator.cbSize = sizeof(MENUITEMINFO); separator.fMask = MIIM_ID | MIIM_TYPE; separator.fType = MFT_SEPARATOR; separator.wID = 8000; memset(&info, 0, sizeof(MENUITEMINFO)); info.cbSize = sizeof(MENUITEMINFO); info.fMask = MIIM_ID | MIIM_TYPE; info.fType = MFT_STRING; info.wID = 1001; info.dwTypeData = "切断(&X)"; InsertMenuItem(hMenu, -1, true, &info); InsertMenuItem(hMenu, -1, true, &separator); info.wID = 1000; info.dwTypeData = "再生(&P)"; InsertMenuItem(hMenu, -1, true, &info); InsertMenuItem(hMenu, -1, true, &separator); info.wID = 1002; info.dwTypeData = "再接続(&R)"; InsertMenuItem(hMenu, -1, true, &info); info.wID = 1003; info.dwTypeData = "キープ(&K)"; InsertMenuItem(hMenu, -1, true, &info); InsertMenuItem(hMenu, -1, true, &separator); info.wID = 2000; info.dwTypeData = "選択解除(&D)"; InsertMenuItem(hMenu, -1, true, &info); GetCursorPos(&pos); dwID = TrackPopupMenu(hMenu, TPM_LEFTALIGN | TPM_RETURNCMD, pos.x, pos.y, 0, hwnd, NULL); DestroyMenu(hMenu); switch(dwID) { case 1000: SendMessage(guiWnd, WM_COMMAND, IDC_BUTTON8, NULL); break; case 1001: SendMessage(guiWnd, WM_COMMAND, IDC_BUTTON5, NULL); break; case 1002: SendMessage(guiWnd, WM_COMMAND, IDC_BUTTON3, NULL); break; case 1003: SendMessage(guiWnd, WM_COMMAND, IDC_BUTTON9, NULL); break; case 2000: SendMessage(hwnd, LB_SETCURSEL, (DWORD)-1, 0L); sleep_skip = true; break; } } break; case WM_KEYDOWN: sleep_skip = true; break; } return CallWindowProc(wndOldListBox, hwnd, message, wParam, lParam); }
LRESULT CALLBACK urlctrl_proc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam) { URLCTRL *url=(URLCTRL*)GetWindowLong(hwnd,GWL_USERDATA); WNDPROC oldproc=url->oldproc; switch (uMsg) { case WM_NCDESTROY: { SetWindowLong(hwnd,GWL_WNDPROC,(LONG)oldproc); if (url->hcur) DestroyCursor(url->hcur); if (url->hfont) DeleteObject(url->hfont); this_free(url); break; } case WM_PAINT: { PAINTSTRUCT ps; HDC hdc=(HDC)wParam; if (wParam==0) hdc=BeginPaint(hwnd,&ps); if (hdc) { util_url_draw(hwnd,hdc,NULL); if (wParam==0) EndPaint(hwnd,&ps); } return 0; } case WM_SETTEXT: { LRESULT result=CallWindowProc(oldproc,hwnd,uMsg,wParam,lParam); if (url->dwFlags&UCF_FIT) util_url_fit(hwnd,FALSE); InvalidateRect(hwnd,NULL,TRUE); UpdateWindow(hwnd); return result; } case WM_SETFONT: //we always modify the font! { LOGFONT lf; HFONT hfont=(HFONT)wParam; if (hfont==NULL) hfont=(HFONT)GetStockObject(SYSTEM_FONT); GetObject(hfont,sizeof(LOGFONT),&lf); lf.lfUnderline=TRUE;//add underline if (url->hfont) DeleteObject(url->hfont);//delete old font url->hfont=CreateFontIndirect(&lf);//create new font CallWindowProc(oldproc,hwnd,uMsg,wParam,0);//block redraw if (url->dwFlags&UCF_FIT) util_url_fit(hwnd,FALSE); if (LOWORD(lParam)) { //redraw? InvalidateRect(hwnd,NULL,TRUE); UpdateWindow(hwnd); } return 0; } case WM_SETCURSOR: { HCURSOR hcur=url->hcur; if (hcur==NULL) hcur=LoadCursor(NULL,IDC_ARROW);//fall back SetCursor(hcur); return 1; } case WM_NCHITTEST: { // static returns HTTRANSPARENT (prevents receiving mouse msgs) return HTCLIENT; } case WM_LBUTTONDOWN: { if (url->dwFlags&UCF_KBD) SetFocus(hwnd); SetCapture(hwnd); url->fClicking=TRUE; break; } case WM_LBUTTONUP: { ReleaseCapture(); if (url->fClicking) { POINT pt; RECT rc; url->fClicking=FALSE; pt.x=(short)LOWORD(lParam); pt.y=(short)HIWORD(lParam); ClientToScreen(hwnd,&pt); GetWindowRect(hwnd,&rc); if (PtInRect(&rc,pt)) util_url_open(hwnd);//inside? } break; } case WM_KEYDOWN: { if (url->dwFlags&UCF_KBD) { if (wParam==VK_SPACE) { util_url_open(hwnd); return 0; } } break; } case WM_KEYUP: { if (url->dwFlags&UCF_KBD) { if (wParam==VK_SPACE) { return 0; } } break; } case WM_GETDLGCODE: { if (url->dwFlags&UCF_KBD) return DLGC_WANTCHARS; break; } case WM_SETFOCUS: case WM_KILLFOCUS: { if (url->dwFlags&UCF_KBD) { InvalidateRect(hwnd,NULL,TRUE); UpdateWindow(hwnd); return 0; } break; } } return CallWindowProc(oldproc,hwnd,uMsg,wParam,lParam); }
// // 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; 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] = {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 if (message == uFindMsg) { // Find event. LPFINDREPLACE lpfr = (LPFINDREPLACE)lParam; if (lpfr->Flags & FR_DIALOGTERM) { // The find dialog box has been dismissed so invalidate the handle and // reset the search results. hFindDlg = NULL; if(g_handler.get()) { g_handler->GetBrowser()->StopFinding(true); szLastFindWhat[0] = 0; findNext = false; } return 0; } if ((lpfr->Flags & FR_FINDNEXT) && g_handler.get()) { // Search for the requested string. bool matchCase = (lpfr->Flags & FR_MATCHCASE?true:false); if(matchCase != lastMatchCase || (matchCase && wcsncmp(szFindWhat, szLastFindWhat, sizeof(szLastFindWhat)/sizeof(WCHAR)) != 0) || (!matchCase && _wcsnicmp(szFindWhat, szLastFindWhat, sizeof(szLastFindWhat)/sizeof(WCHAR)) != 0)) { // The search string has changed, so reset the search results. if(szLastFindWhat[0] != 0) { g_handler->GetBrowser()->StopFinding(true); findNext = false; } lastMatchCase = matchCase; wcscpy_s(szLastFindWhat, sizeof(szLastFindWhat)/sizeof(WCHAR), szFindWhat); } g_handler->GetBrowser()->Find(0, lpfr->lpstrFindWhat, (lpfr->Flags & FR_DOWN)?true:false, matchCase, findNext); if(!findNext) findNext = true; } return 0; } else { // 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; GetClientRect(hWnd, &rect); /* int x = 0; 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; */ CefWindowInfo info; CefBrowserSettings settings; // Populate the settings based on command line arguments. AppGetBrowserSettings(settings); // Brackets - reduce file url security settings.universal_access_from_file_urls_allowed = TRUE; settings.file_access_from_file_urls_allowed = TRUE; // Initialize window info to the defaults for a child window info.SetAsChild(hWnd, rect); wchar_t initialUrl[MAX_PATH]; const wchar_t* appFolder = L"Brackets.exe"; // TODO (issue 68) - Proper finding of Brackets index.html file GetModuleFileName(NULL, initialUrl, MAX_PATH); wchar_t *pStr = wcsstr(initialUrl, appFolder); *pStr = NULL; wcscat(pStr, L"..\\..\\brackets\\src\\index.html"); pStr = initialUrl; while (*pStr) { if (*pStr == '\\') *pStr = '/'; pStr++; } // Make sure the file exists if (GetFileAttributes(initialUrl) == INVALID_FILE_ATTRIBUTES) { // Load the special "brackets/load_error" url. This will be // redirected to the error page in ClientHandler::OnBeforeResourceLoad(). wcscpy(initialUrl, L"http://brackets/load_error"); } // Create the new child browser window CefBrowser::CreateBrowser(info, static_cast<CefRefPtr<CefClient> >(g_handler), initialUrl, 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_ABOUT: // Brackets: Delegate to JavaScript code to show an HTML version of the about box. if (browser.get()) BracketsShellAPI::DispatchShowAboutToBracketsJS(browser); return 0; case IDM_EXIT: // Brackets: Delegate to JavaScript code to handle quit // so that JavaScript can handle things like saving files if (g_handler.get()) { if (!g_handler->DispatchQuitToAllBrowsers()) { return NO_ERROR; } } 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; case ID_FIND: if(!hFindDlg) { // Create the find dialog. ZeroMemory(&fr, sizeof(fr)); fr.lStructSize = sizeof(fr); fr.hwndOwner = hWnd; fr.lpstrFindWhat = szFindWhat; fr.wFindWhatLen = sizeof(szFindWhat); fr.Flags = FR_HIDEWHOLEWORD | FR_DOWN; hFindDlg = FindText(&fr); } else { // Give focus to the existing find dialog. ::SetFocus(hFindDlg); } return 0; case ID_PRINT: if(browser.get()) browser->GetMainFrame()->Print(); return 0; 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()) { if( !BracketsShellAPI::DispatchReloadToBracketsJS(browser) ) { return 0; } browser->ReloadIgnoreCache(); } return 0; case IDC_NAV_STOP: // Stop button if(browser.get()) browser->StopLoad(); return 0; case ID_TESTS_GETSOURCE: // Test the GetSource function if(browser.get()) RunGetSourceTest(browser); return 0; case ID_TESTS_GETTEXT: // Test the GetText function if(browser.get()) RunGetTextTest(browser); return 0; case ID_TESTS_JAVASCRIPT_BINDING: // Test the V8 binding handler if(browser.get()) RunBindingTest(browser); return 0; case ID_TESTS_JAVASCRIPT_EXTENSION: // Test the V8 extension handler if(browser.get()) RunExtensionTest(browser); return 0; case ID_TESTS_JAVASCRIPT_PERFORMANCE: // Test the V8 performance if(browser.get()) RunExtensionPerfTest(browser); return 0; case ID_TESTS_JAVASCRIPT_EXECUTE: // Test execution of javascript if(browser.get()) RunJavaScriptExecuteTest(browser); return 0; case ID_TESTS_JAVASCRIPT_INVOKE: if(browser.get()) RunJavaScriptInvokeTest(browser); return 0; case ID_TESTS_PLUGIN: // Test the custom plugin if(browser.get()) RunPluginTest(browser); return 0; case ID_TESTS_POPUP: // Test a popup window if(browser.get()) RunPopupTest(browser); return 0; case ID_TESTS_TRANSPARENT_POPUP: // Test a transparent popup window if(browser.get()) RunTransparentPopupTest(browser); return 0; case ID_TESTS_REQUEST: // Test a request if(browser.get()) RunRequestTest(browser); return 0; case ID_TESTS_SCHEME_HANDLER: // Test the scheme handler if(browser.get()) RunSchemeTest(browser); return 0; case ID_TESTS_UIAPP: // Test the UI app if(browser.get()) RunUIPluginTest(browser); return 0; case ID_TESTS_OSRAPP: // Test the OSR app if(browser.get()) RunOSRPluginTest(browser, false); return 0; case ID_TESTS_TRANSPARENT_OSRAPP: // Test the OSR app with transparency if(browser.get()) RunOSRPluginTest(browser, true); return 0; case ID_TESTS_DOMACCESS: // Test DOM access if(browser.get()) RunDOMAccessTest(browser); return 0; case ID_TESTS_LOCALSTORAGE: // Test localStorage if(browser.get()) RunLocalStorageTest(browser); return 0; case ID_TESTS_ACCELERATED2DCANVAS: // Test accelerated 2d canvas if(browser.get()) RunAccelerated2DCanvasTest(browser); return 0; case ID_TESTS_ACCELERATEDLAYERS: // Test accelerated layers if(browser.get()) RunAcceleratedLayersTest(browser); return 0; case ID_TESTS_WEBGL: // Test WebGL if(browser.get()) RunWebGLTest(browser); return 0; case ID_TESTS_HTML5VIDEO: // Test HTML5 video if(browser.get()) RunHTML5VideoTest(browser); return 0; case ID_TESTS_DRAGDROP: // Test drag & drop if(browser.get()) RunDragDropTest(browser); return 0; case ID_TESTS_XMLHTTPREQUEST: // Test XMLHttpRequest if(browser.get()) RunXMLHTTPRequestTest(browser); return 0; case ID_TESTS_WEBURLREQUEST: if (browser.get()) RunWebURLRequestTest(browser); return 0; case ID_TESTS_ZOOM_IN: if(browser.get()) browser->SetZoomLevel(browser->GetZoomLevel() + 0.5); return 0; case ID_TESTS_ZOOM_OUT: if(browser.get()) browser->SetZoomLevel(browser->GetZoomLevel() - 0.5); return 0; case ID_TESTS_ZOOM_RESET: if(browser.get()) browser->SetZoomLevel(0.0); return 0; case ID_TESTS_DEVTOOLS_SHOW: if (browser.get()) browser->ShowDevTools(); return 0; case ID_TESTS_DEVTOOLS_CLOSE: if (browser.get()) browser->CloseDevTools(); return 0; case ID_TESTS_MODALDIALOG: if(browser.get()) RunModalDialogTest(browser); return 0; case ID_TESTS_GETIMAGE: if(browser.get()) RunGetImageTest(browser); return 0; } } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); EndPaint(hWnd, &ps); return 0; case WM_SETFOCUS: if(g_handler.get() && g_handler->GetBrowserHwnd()) { // Pass focus to the browser window PostMessage(g_handler->GetBrowserHwnd(), WM_SETFOCUS, wParam, NULL); } return 0; case WM_SIZE: if(g_handler.get() && g_handler->GetBrowserHwnd()) { // Resize the browser window and address bar to match the new frame // window size RECT rect; GetClientRect(hWnd, &rect); //rect.top += URLBAR_HEIGHT; int urloffset = rect.left + BUTTON_WIDTH * 4; HDWP hdwp = BeginDeferWindowPos(1); //hdwp = DeferWindowPos(hdwp, editWnd, NULL, urloffset, // 0, rect.right - urloffset, URLBAR_HEIGHT, SWP_NOZORDER); hdwp = DeferWindowPos(hdwp, g_handler->GetBrowserHwnd(), 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->GetBrowserHwnd()) { // Dont erase the background if the browser window has been loaded // (this avoids flashing) return 0; } break; case WM_CLOSE: if (g_handler.get()) { CefRefPtr<CefBrowser> browser = g_handler->GetBrowser(); //currently brackets doesn't handle multiple browser windows that well. //Most of this code assume a single "main" browser window. If this one //goes away, so goes the others, so lets give them all a change to close first if (!g_handler->DispatchQuitToAllBrowsers()) { return 0; } // Let the browser window know we are about to destroy it. if (browser) { browser->ParentWindowWillClose(); } } break; case WM_DESTROY: // The frame window has exited PostQuitMessage(0); return 0; } return DefWindowProc(hWnd, message, wParam, lParam); } }
static LRESULT CALLBACK ParentWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { if (uMsgCreate && message == uMsgCreate) { static HWND hwndPrevFocus; static BOOL fCancelDisabled; if (wParam) { childwnd = FindWindowEx((HWND) lParam, NULL, "#32770", NULL); hwndL = GetDlgItem(childwnd, 1016); hwndB = GetDlgItem(childwnd, 1027); HWND hwndP = GetDlgItem(childwnd, 1004); HWND hwndS = GetDlgItem(childwnd, 1006); if (childwnd && hwndP && hwndS) { // Where to restore focus to before we disable the cancel button hwndPrevFocus = GetFocus(); if (!hwndPrevFocus) hwndPrevFocus = hwndP; if (IsWindowVisible(hwndL)) ShowWindow(hwndL, SW_HIDE); else hwndL = NULL; if (IsWindowVisible(hwndB)) ShowWindow(hwndB, SW_HIDE); else hwndB = NULL; RECT wndRect, ctlRect; GetClientRect(childwnd, &wndRect); GetWindowRect(hwndS, &ctlRect); HWND s = g_hwndStatic = CreateWindow( "STATIC", "", WS_CHILD | WS_CLIPSIBLINGS | SS_CENTER, 0, wndRect.bottom / 2 - (ctlRect.bottom - ctlRect.top) / 2, wndRect.right, ctlRect.bottom - ctlRect.top, childwnd, NULL, hModule, NULL ); DWORD dwStyle = WS_CHILD | WS_CLIPSIBLINGS; dwStyle |= GetWindowLong(hwndP, GWL_STYLE) & PBS_SMOOTH; GetWindowRect(hwndP, &ctlRect); HWND pb = g_hwndProgressBar = CreateWindow( "msctls_progress32", "", dwStyle, 0, wndRect.bottom / 2 + (ctlRect.bottom - ctlRect.top) / 2, wndRect.right, ctlRect.bottom - ctlRect.top, childwnd, NULL, hModule, NULL ); long c; c = SendMessage(hwndP, PBM_SETBARCOLOR, 0, 0); SendMessage(hwndP, PBM_SETBARCOLOR, 0, c); SendMessage(pb, PBM_SETBARCOLOR, 0, c); c = SendMessage(hwndP, PBM_SETBKCOLOR, 0, 0); SendMessage(hwndP, PBM_SETBKCOLOR, 0, c); SendMessage(pb, PBM_SETBKCOLOR, 0, c); // set font long hFont = SendMessage((HWND) lParam, WM_GETFONT, 0, 0); SendMessage(pb, WM_SETFONT, hFont, 0); SendMessage(s, WM_SETFONT, hFont, 0); ShowWindow(pb, SW_SHOWNA); ShowWindow(s, SW_SHOWNA); fCancelDisabled = EnableWindow(GetDlgItem(hwnd, IDCANCEL), TRUE); SendMessage(hwnd, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hwnd, IDCANCEL), TRUE); } else childwnd = NULL; } else if (childwnd) { if (hwndB) { ShowWindow(hwndB, SW_SHOWNA); hwndB = NULL; } if (hwndL) { ShowWindow(hwndL, SW_SHOWNA); hwndL = NULL; } // Prevent wierd stuff happening if the cancel button happens to be // pressed at the moment we are finishing and restore the previous focus // and cancel button states SendMessage(hwnd, WM_NEXTDLGCTL, (WPARAM)hwndPrevFocus, TRUE); SendMessage(GetDlgItem(hwnd, IDCANCEL), BM_SETSTATE, FALSE, 0); if (fCancelDisabled) EnableWindow(GetDlgItem(hwnd, IDCANCEL), FALSE); if (g_hwndStatic) { DestroyWindow(g_hwndStatic); g_hwndStatic = NULL; } if (g_hwndProgressBar) { DestroyWindow(g_hwndProgressBar); g_hwndProgressBar = NULL; } childwnd = NULL; } } else if (message == WM_COMMAND && LOWORD(wParam) == IDCANCEL) { g_cancelled = 1; } else { return CallWindowProc( (WNDPROC) lpWndProcOld, hwnd, message, wParam, lParam ); } return 0; }
LRESULT player_impl::win_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { PAINTSTRUCT ps; HDC hdc; switch (msg) { case WM_CREATE: { SetTimer(hwnd, ID_PLAYER_TIMER, 100, NULL); } break; case WM_TIMER: { if (wparam != ID_PLAYER_TIMER) break; // 计算显示客户区. int more_y = GetSystemMetrics(SM_CYCAPTION) + (GetSystemMetrics(SM_CYBORDER) * 2) + (GetSystemMetrics(SM_CYDLGFRAME) * 2); int more_x = (GetSystemMetrics(SM_CXDLGFRAME) * 2) + (GetSystemMetrics(SM_CXBORDER) * 2); if (!m_avplay || !m_avplay->m_video_ctx) break; if (m_avplay && m_avplay->m_video_ctx && (m_avplay->m_video_ctx->width != 0 || m_avplay->m_video_ctx->height != 0 || m_avplay->m_play_status == playing)) { RECT rc = { 0 }; GetWindowRect(hwnd, &rc); SetWindowPos(hwnd, HWND_NOTOPMOST, rc.left, rc.top, m_avplay->m_video_ctx->width + more_x, m_avplay->m_video_ctx->height + more_y, SWP_FRAMECHANGED); KillTimer(hwnd, ID_PLAYER_TIMER); } // 得到正确的宽高信息. m_video_width = m_avplay->m_video_ctx->width; m_video_height = m_avplay->m_video_ctx->height; } break; case WM_KEYDOWN: if (wparam == VK_F2) { full_screen(!m_full_screen); } break; case WM_RBUTTONDOWN: { if (m_avplay && m_avplay->m_play_status == playing) pause(); else if (m_avplay && m_avplay->m_play_status == paused) resume(); } break; case WM_LBUTTONDOWN: { RECT rc = { 0 }; GetWindowRect(hwnd, &rc); int width = rc.right - rc.left; int xpos = LOWORD(lparam); double fact = (double)xpos / width; if (m_avplay && (m_avplay->m_play_status == playing || m_avplay->m_play_status == completed) && (fact >= 0.0f && fact <= 1.0f)) ::seek(m_avplay, fact); } break; case WM_PAINT: hdc = BeginPaint(hwnd, &ps); if (m_avplay) win_paint(hwnd, hdc); EndPaint(hwnd, &ps); break; case WM_ERASEBKGND: { if (m_video && m_avplay->m_play_status == playing) return 1; else return DefWindowProc(hwnd, msg, wparam, lparam); } case WM_ACTIVATE: case WM_SYNCPAINT: break; case WM_MOVING: case WM_MOVE: case WM_SIZE: { RECT window; GetClientRect(hwnd, &window); if (m_avplay && m_avplay->m_vo_ctx && m_video->video_dev) { m_video->re_size(m_video, LOWORD(lparam), HIWORD(lparam)); } InvalidateRect(hwnd, NULL, TRUE); } break; case WM_DESTROY: PostQuitMessage(0); break; default: break; } if (m_old_win_proc) return CallWindowProc(m_old_win_proc, hwnd, msg, wparam, lparam);// m_old_win_proc(hwnd, msg, wparam, lparam); else return DefWindowProc(hwnd, msg, wparam, lparam); }
LRESULT CALLBACK ModuleButtonWindowProc2 (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){ HDC hdc ; PAINTSTRUCT ps ; RECT rect; PMODULEMANAGER pMM = GetPModuleManagerByButtonHWND(hwnd); CheckNullErrorAndQuit(pMM,15,TEXT("Can't Get ModuleManager By HWND in ModuleButtonWindowProc2()!")); static int i , totalWidth,idGot; static int cxWindow,cyWindow,cxChar; static int* intList=NULL; int lengthToLeft,buttonShift; static int blockLeft,blockRight,newLeft,newRight,oldLeft,oldRight; //用于绘制高亮区域 static int firstTimeFlag = 1; static bool toRight = true; static int currentId = 0; //"按钮窗口"的两个左右方向按钮 static HWND hLeftButton,hRightButton; //记录“按钮窗口”中按钮的开始与结束位置 static int xButtonBegin,xButtonEnd; switch(message) { case WM_CREATE: /** 注意:在子窗口类别化时,次新的回调函数的WM_CREATE 不会被调用,进入该函数的该消息是在 CreateStaticModuleManergerBoard()中使用 SendMessage(pMM.hButtonBoard,WM_CREATE,0,0); 发送的 */ //设置定时器,用于绘画可以移动的高亮区域 SetTimer (hwnd, 2, 10, NULL) ; blockLeft = blockRight = 0; xButtonBegin = 5; hLeftButton = CreateWindow(TEXT("button"),TEXT("<<"),WS_CHILD|BS_PUSHBUTTON, 0,0,0,0, // 使用 MAX_COUNT_OF_MODULE+1 作为向左移动按钮的ID hwnd, (HMENU)(MAX_COUNT_OF_MODULE+1), (HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE),NULL); hRightButton = CreateWindow(TEXT("button"),TEXT(">>"),WS_CHILD|BS_PUSHBUTTON, 0,0,0,0, // 使用 MAX_COUNT_OF_MODULE+2 作为向右移动按钮的ID hwnd, (HMENU)(MAX_COUNT_OF_MODULE+2), (HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE),NULL); break; case WM_SIZE: //获得“按钮窗口”的大小消息,和设备字体宽度 cxWindow = LOWORD(lParam); cyWindow = HIWORD(lParam); cxChar = LOWORD (GetDialogBaseUnits ()) ; //仅调用一次 if(firstTimeFlag) { //将每个按钮的字体宽度信息保存在列表中 intList = (int*)malloc(sizeof(int)*ModuleManager2.countOfModule); CheckNullErrorAndQuit(intList,19,TEXT("Memory for [intList] alloc failed in ModuleButtonWindowProc2()!")); for(i=0 ; i< ModuleManager2.countOfModule ; i++) { intList[i] = GetWindowTextLength (ModuleManager2.pToolModule[i].hButton) ; } //第一次调用时将高亮的区域指定为第一个按钮 newLeft = xButtonBegin; newRight = xButtonBegin + intList[0]*cxChar*2+30; firstTimeFlag = 0; } //根据xButtonBegin和字体宽度等设置按钮的 位置和大小 lengthToLeft =0; for(i=0 ; i< ModuleManager2.countOfModule ; i++) { MoveWindow(ModuleManager2.pToolModule[i].hButton, xButtonBegin+lengthToLeft*cxChar*2+i*30,10, intList[i]*cxChar*2+30,cyWindow-10-2,TRUE); lengthToLeft += intList[i]; } //根据xButtonBegin 和 按钮总宽度获得 xButtonEnd totalWidth = lengthToLeft*cxChar*2 + i*30; xButtonEnd = xButtonBegin + totalWidth; //由 xButtonBegin 、xButtonEnd 与 windows size 的关系决定“左右移动”按钮是否出现 if(xButtonBegin >= 5 && xButtonEnd <= cxWindow-5) { ShowWindow(hLeftButton,SW_HIDE); ShowWindow(hRightButton,SW_HIDE); } else { MoveWindow(hLeftButton,cxWindow-5-60,1,30,9,TRUE); MoveWindow(hRightButton,cxWindow-5-30,1, 30,9,TRUE); ShowWindow(hLeftButton,SW_SHOW); ShowWindow(hRightButton,SW_SHOW); } //改变大小变宽时,若左侧部分隐藏,右侧又有空余,则全部按钮拉着右边框跟着移动 if(xButtonBegin < 5 && xButtonEnd < cxWindow-5) { xButtonBegin += cxWindow- 5 - xButtonEnd; newLeft += cxWindow- 5 - xButtonEnd; newRight += cxWindow - 5-xButtonEnd; toRight = true; } break; case WM_COMMAND: //由按钮的句柄获得其Id 即得到所在模块pToolModle[]的下标 idGot = GetWindowLong ((HWND)lParam, GWL_ID) ; idOfCurrentSubModule = idGot < MAX_COUNT_OF_MODULE ? idGot : idOfCurrentSubModule; if(idGot < MAX_COUNT_OF_MODULE) //为模块按钮的消息 { for(i=0; i<pMM->countOfModule ;i++){ if(i==idOfCurrentSubModule) ShowWindow(pMM->pToolModule[i].hContentBoard,SW_SHOW); else ShowWindow(pMM->pToolModule[i].hContentBoard,SW_HIDE); } //计算点击按钮的位置,储存在newLeft 和 newRight中 lengthToLeft =0; for(i=0 ; i< ModuleManager2.countOfModule ; i++) { if(i==idOfCurrentSubModule){ newLeft= xButtonBegin+lengthToLeft*cxChar*2+i*30; newRight= newLeft + intList[i]*cxChar*2+30; break; } lengthToLeft += intList[i]; } //确定高亮移动方向 if(idOfCurrentSubModule > currentId) toRight =true; else if(idOfCurrentSubModule < currentId) toRight = false; currentId = idOfCurrentSubModule; } else //为“左右移动”按钮的消息 { if(idGot == MAX_COUNT_OF_MODULE + 1) //为“向左”按钮 { if(xButtonEnd > cxWindow-5){ buttonShift=xButtonEnd; //改变Button位置 xButtonEnd = max( cxWindow-5, xButtonEnd-30); xButtonBegin = xButtonEnd - totalWidth; //改变高亮位置 buttonShift = xButtonEnd -buttonShift; newLeft += buttonShift; newRight += buttonShift; toRight = false; } } else //为“向右”按钮 { if(xButtonBegin < 5){ buttonShift=xButtonBegin; //改变Button位置 xButtonBegin = min( 5, xButtonBegin + 30); xButtonEnd = xButtonBegin + totalWidth; //改变高亮位置 buttonShift = xButtonBegin - buttonShift; newLeft += buttonShift; newRight += buttonShift; toRight = true; } } SendMessage(hwnd,WM_SIZE,0, (cyWindow<<16)|cxWindow); InvalidateRect(hwnd,NULL,TRUE); } break; case WM_TIMER: //更新绘画高亮区域的范围 if(blockLeft != newLeft || blockRight != newRight) { oldLeft = blockLeft; oldRight = blockRight; blockLeft = blockLeft + (toRight ? 45:60)*(toRight ? 1:-1); blockRight = blockRight + (toRight ? 60:45)*(toRight ? 1:-1); blockLeft = toRight? min(blockLeft,newLeft):max(blockLeft,newLeft); blockRight = toRight? min(blockRight,newRight):max(blockRight,newRight); oldLeft = toRight? oldLeft:blockRight; oldRight = toRight? blockLeft:oldRight; InvalidateRect(hwnd,NULL,TRUE); } break; case WM_PAINT: hdc = BeginPaint (hwnd, &ps) ; //FillRect(hdc,&ps.rcPaint,(HBRUSH)GetStockObject(WHITE_BRUSH)); //绘制高亮区域 //擦除旧的区域 SetRect(&rect,oldLeft,1,oldRight,8); FillRect(hdc,&rect,(HBRUSH)GetStockObject(WHITE_BRUSH)); //绘制性的区域 SetRect(&rect,blockLeft,1,blockRight,8); FillRect(hdc,&rect,(HBRUSH)GetStockObject(BLACK_BRUSH)); EndPaint (hwnd, &ps) ; break; } return CallWindowProc (pMM->OldModuleButton, hwnd, message, wParam,lParam); }