Toolbar looks ourselves ourselves (5)

xiaoxiao2021-03-05  20

'The last part, and the core message processing code and the main drawing process

Friend Function MsgProc (lParam As Long, MouseDown As Boolean) As Long Dim tHDR As NMHDR Dim className As String * 32 Dim retval As Long CopyMemory tHDR, ByVal lParam, Len (tHDR) If tHDR.hwndFrom <> 0 Then retval = GetClassName ( tHDR.hwndFrom, className, 33) If retval> 0 Then If Left $ (className, retval) = "msvb_lib_toolbar" Then MsgProc = OnCustomDraw (lParam, MouseDown) End If End If End IfEnd FunctionPrivate Function OnCustomDraw (lParam As Long, MouseDown As boolean) As Long Dim tTBCD As NMTBCUSTOMDRAW Dim hBrush As Long CopyMemory tTBCD, ByVal lParam, Len (tTBCD) With tTBCD.nmcd Select Case .dwDrawStage Case CDDS_ITEMPREPAINT OnCustomDraw = CDRF_SKIPDEFAULT DrawToolbarButton .hdr.hwndFrom, .hdc, .dwItemSpec, .uItemState, .rc, mousedown case cdds_prepaint oncustomDraw = cdrf_notifyitemdraw getclientRect .hdr.hwndf ROM ,.rc if mpicbk is nothing kilush = createsolidbrush (m_lngbackcolor) else hbrush =

CreatePatternBrush (mpicBk) End If FillRect .hdc, .rc, hBrush DeleteObject hBrush End Select End WithEnd FunctionPrivate Sub DrawToolbarButton (ByVal hWnd As Long, ByVal hdc As Long, itemSpec As Long, ByVal itemState As Long, tR As RECT, MouseDown As Boolean ) Dim i As Long Dim bPushed As Boolean, bDropDown As Boolean, bHover As Boolean Dim bDisabled As Boolean, bChecked As Boolean Dim bSkipped As Boolean, bBottomText As Boolean, bNoDsbIcon As Boolean Dim hIcon As Long, hImageList As Long Dim tTB As TBBUTTON Dim szText As Size, rcDrop As RECT, rcIcon As RECT Dim hOldPen As Long, hPen As Long Dim hFont As Long, hOldFont As Long Dim sCaption As String, bFirstSetBk As Boolean Dim lDropWidth As Long, lTxtColor As Long sCaption = String $ (128, vbnullchar) i = sendMessage (hwnd, tb_getbuttontexta, itemspec, byval scAption) IF i> 0 Then SCAPTION = Left $ (Scaption, I) Else Scaption = "" End If i = GetWindowLong (hWnd, GWL_STYLE) bBottomText = ((i And TBSTYLE_LIST) = 0) i = SendMessage (hWnd, TB_COMMANDTOINDEX, itemSpec, ByVal 0) SendMessage hWnd, TB_GETBUTTON, i, tTB bDisabled = (itemState And CDIS_DISABLED) bChecked = (itemState And CDIS_CHECKED) bHover = (itemState And CDIS_HOT) bPushed = (itemState And CDIS_SELECTED) If tTB.fsStyle And TBSTYLE_SEP Then 'parting line button hPen = CreatePen (PS_SOLID, 1, vb3DShadow) hOldPen = SelectObject (hdc, hPen) MoveToEx HDC, Tr.Left 2 &, Tr.Top 1 &, Byval 0 Lineto HDC, Tr.Left 2 &, Tr.Bottom - 1 &

SelectObject hdc, hOldPen DeleteObject hPen Exit Sub Else hImageList = SendMessage (hWnd, TB_GETIMAGELIST, 0, ByVal 0) If hImageList <> 0 Then 'acquired main image list If mlngImgList <> hImageList Then mlngImgList = hImageList bFirstSetBk = True mlngIconWidth = 0 End If If bDisabled Then 'made disabled image list i = SendMessage (hWnd, TB_GETDISABLEDIMAGELIST, 0, ByVal 0) If i <> 0 And i <> hImageList Then hImageList = i If mlngDsbImgList <> i Then mlngDsbImgList = i bFirstSetBk = True End If Else Bnodsbicon = true end if elseif bhover life 'getting hot image list i = sendMessage (hwnd, tb_gethotimagelist, 0, byval 0) IF i <> 0 and i <> himagelist kilist damagelist = i i f mlngHotImgList <> i Then mlngHotImgList = i bFirstSetBk = True End If End If End If If bFirstSetBk Then 'background color for the first time needs to be set If ImageList_GetBkColor (hImageList) <> Then ImageList_SetBkColor hImageList -1, CLR_NONE End If End If hIcon = ImageList_GetIcon (himagelist, ttb.ibitmap, ild_normal) ife mlngiconwidth = 0 Then geticonsize hicon end if 'Create a different brush and brush LTXTColor = according to status

M_LNGTextColor if bchecked or bpushed the alphablend hdc, tr.LEFT, TR.TOP, Tright - Tr.Left, Tr.Bottom - tr.top, mdcwhite.hdc, 0, 0, tr.right - tr.Left, TR .Bottom - trop, mlngbtndownalpha * & h10000 elseif Bhover Ten Alphablend HDC, Tr.Left, Tr.Top, Tright - Tr.LEFT, Tr.BOTTOM - Tr.TOP, MDCWHITE.HDC, 0, 0, TR. Right - tR.Left, tR.Bottom - tR.Top, mlngBtnHiAlpha * & H10000 lTxtColor = m_lngTextHiColor Else bSkipped = True End If SetTextColor hdc, lTxtColor If tTB.fsStyle And TBSTYLE_DROPDOWN Then lDropWidth = 14 bDropDown = bHover And MouseDown And Not bPushed SetRect rcDrop , tr.right - ldropwidth, tr.top, tr.right, tr.bottom tr.right = tr.right - ldropwidth End if endiffsbkmode hdc, 1 'text background transparent if bskipped = false then, according to style, painting Different borders and fill the if bchecked or bpushed the DrawRect HDC, TR, 2 else DrawRec t hdc, tR, 1 End If Else DrawRect hdc, tR, 0 End If If tTB.fsStyle And TBSTYLE_DROPDOWN Then 'small pull-down menu button processing If bSkipped = False Or m_lngBrdStyle> 0 Then If bDropDown Then AlphaBlend hdc, rcDrop.Left, rcDrop.Top, lDropWidth, rcDrop.Bottom - rcDrop.Top, mdcWhite.hdc, 0, 0, rcDrop.Right - rcDrop.Left, rcDrop.Bottom - rcDrop.Top, mlngBtnDownAlpha * & H10000 End If If bDropDown Or bPushed Then DrawRect hdc , RcDrop, 2, True elseif Bhover THEN DRAWRECT HDC, RCDROP, 1, TRUE Else DrawRect HDC, RcDrop, 0, True Mousedown =

False end if else mousedown = false end if DrawPLOY3 HDC, RCDROP, BHOVER AND NOT (BDROPDOWN OR BPUSHED) END IF 'Draw Icon and Text WITH RCICON' Calculation Icon Area .top = Tr.Top 3 if Bbottomtext = false .left = Tr.Left 3 IF mlngiconwidth <16 Then if bbottomtext damleft = tr.Left (tr.right - tr.Left - 16) / 2 .right = .left 16 else if bbottomtext damleft = TR. Left (Tright - Tr.Left - mlngiconwidth) / 2 .right = .left mlngiconwidth End if IFT MLNGICONWIDTH END IF MLNGICONHEIGHT <161 .bottom = .top 16 else .bottom = .top mlngiconheight End if if Bhover and NOT (BPUSHED or BCHECKED) Then .left = .left - 1 .top = .top - 1 .right = .right - 1 .bottom = .bottom - 1 End ififfi Himagelist <> 0 Then IF BDisabled and Bnodsbicon Then IF Hico N THEN DRAWSTATE HDC, 0, 0, HICON, 0, DST_ICON OR DSS_DISABED END IF ELSE IMAGELIST_DISABED END IF ELSE IMAGELIST_DISAGLIST, TTB.IBITMAP, HDC, .LEFT, .TOP, ILD_NORMAL END IF END IF Len (Scaption)> 0 Then HFONT = CREATEFONTINDIRECT (FONT) HOLDFONT =

SelectObject (hdc, hFont) If bBottomText Then If bDisabled Then SetTextAlign hdc, TA_LEFT GetTextExtentPoint32 hdc, sCaption, lstrlen (sCaption), szText DrawState hdc, 0, 0, StrPtr (StrConv (sCaption, vbFromUnicode)), lstrlen (sCaption), ( .Right . Left - sztext.cx) / 2, .bottom 1, 0, 0, DST_TEXT OR DSS_DISABED ELSE setTextAlign HDC, TA_Center Textout HDC, (.right .left) / 2, .bottom 1, Scaption, lstrlen (sCaption) End If Else SetTextAlign hdc, TA_LEFT If bDisabled Then 'GetTextExtentPoint32 hdc, sCaption, lstrlen (sCaption), szText DrawState hdc, 0, 0, StrPtr (StrConv (sCaption, vbFromUnicode)), lstrlen (sCaption), .Right 1, (.top .bottom - font.lfheight) / 2, 0, 0, DST_TEXT OR DSS_DISABED ELSE TEXTOUT HDC, .right 1, (.to) p .Bottom - Font.lfHeight) / 2, sCaption, lstrlen (sCaption) End If End If SelectObject hdc, hOldFont DeleteObject hFont End If End With If hIcon <> 0 Then DestroyIcon hIconEnd Sub Chushe Custom Draw message processing, ToolBar originally I used very little, so my interest is the process itself, not the application needs, it is difficult to study it in depth.

转载请注明原文地址:https://www.9cbs.com/read-36750.html

New Post(0)