绘标题栏简例
就是段小例子 其实处理绘制标题栏 涉及到很多消息代码我也是很偷懒了 不过 大家知道怎么搞 剩下的就简单了
绘制完背景还需要重绘 图标 和标题 或者 干脆直接上图片算了呵呵
有时间 把例子写完整 嘿嘿
程序代码:
.386 .Model Flat,Stdcall Option Casemap :None Include Windows.inc Include Kernel32.inc Include User32.inc Include Gdi32.inc Include /MASMPlus/Macros/Strings.Mac IncludeLib Kernel32.lib IncludeLib User32.lib IncludeLib Gdi32.lib .Data? hInstance dd ? lpOldDlgProc dd ? .Code DrawTitleBar Proc _hWnd:DWORD,_hDC:DWORD Local @hBrush,@hPen Local @stRect:RECT invoke GetWindowRect,_hWnd,addr @stRect mov eax,@stRect.left ; Window size mov @stRect.left,0 sub @stRect.right,eax mov eax,@stRect.top mov @stRect.top,0 sub @stRect.bottom,eax invoke GetSystemMetrics,SM_CXFRAME ; titlebar size mov @stRect.bottom,eax invoke GetSystemMetrics,SM_CYSIZE add @stRect.bottom,eax invoke CreateSolidBrush,00db8943h mov @hBrush,eax invoke FrameRect,_hDC,addr @stRect,@hBrush invoke DeleteObject,@hBrush invoke CreateSolidBrush,00ffebdch mov @hBrush,eax inc @stRect.left inc @stRect.top dec @stRect.right invoke FrameRect,_hDC,addr @stRect,@hBrush inc @stRect.left inc @stRect.top dec @stRect.right dec @stRect.bottom invoke FrameRect,_hDC,addr @stRect,@hBrush invoke DeleteObject,@hBrush ; invoke CreateSolidBrush,00FFBEA0h ; 可以使用图片填充 ; mov @hBrush,eax ; invoke CreatePen,PS_SOLID,0,00f4c593h ; mov @hPen,eax ; invoke SelectObject,_hDC,@hBrush ; invoke SelectObject,_hDC,@hPen ; inc @stRect.left ; inc @stRect.top ; dec @stRect.right ; dec @stRect.bottom ; invoke Rectangle,_hDC,@stRect.left,@stRect.top,@stRect.right,@stRect.bottom ; invoke DeleteObject,@hBrush ; invoke DeleteObject,@hPen ret DrawTitleBar EndP NewWndProc Proc Uses esi edi ebx _hWnd:DWORD,_uMsg:DWORD,_wParam:DWORD,_lParam:DWORD Local @stRect:RECT Local @hDC:DWORD .if _uMsg == WM_NCPAINT invoke CallWindowProc,lpOldDlgProc,_hWnd,_uMsg,_wParam,_lParam invoke GetWindowDC,_hWnd ; Draw titlebar mov @hDC,eax invoke DrawTitleBar,_hWnd,@hDC invoke ReleaseDC,_hWnd,@hDC ret .elseif _uMsg == WM_ACTIVATE invoke GetWindowDC,_hWnd ; Draw titlebar mov @hDC,eax invoke DrawTitleBar,_hWnd,@hDC invoke ReleaseDC,_hWnd,@hDC invoke CallWindowProc,lpOldDlgProc,_hWnd,_uMsg,_wParam,_lParam ret .elseif _uMsg == WM_NCACTIVATE invoke GetWindowDC,_hWnd ; Draw titlebar mov @hDC,eax invoke DrawTitleBar,_hWnd,@hDC invoke ReleaseDC,_hWnd,@hDC invoke CallWindowProc,lpOldDlgProc,_hWnd,_uMsg,_wParam,_lParam ret .else invoke CallWindowProc,lpOldDlgProc,_hWnd,_uMsg,_wParam,_lParam ret .endif xor eax,eax ret NewWndProc EndP WndProc Proc Uses ebx edi esi _hWnd:DWORD,_uMsg:DWORD,_wParam:DWORD,_lParam:DWORD .if _uMsg == WM_CLOSE ; Dialog terminate invoke EndDialog,_hWnd,NULL .elseif _uMsg == WM_INITDIALOG ; Dialog initialization invoke SetWindowLong,_hWnd,GWL_WNDPROC,offset NewWndProc ; SubClass mov lpOldDlgProc,eax .else mov eax,FALSE ret .endif mov eax,TRUE ret WndProc EndP Start Proc invoke GetModuleHandle,NULL ; Get the module handle mov hInstance,eax invoke DialogBoxParam,hInstance,1000,NULL,WndProc,NULL ; Dialog ret Start EndP End Start
Rc
程序代码:
#include <resource.h> 1000 DIALOG 0, 0, 227, 170 STYLE DS_CENTER | DS_MODALFRAME | WS_POPUP | WS_CAPTION CAPTION "Titlebar Example Works 2009" FONT 9, "宋体" { }
[ 本帖最后由 sll0807 于 2009-10-30 20:34 编辑 ]