| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1272 人关注过本帖
标题:绘按钮简例
只看楼主 加入收藏
sll0807
Rank: 3Rank: 3
等 级:论坛游侠
威 望:5
帖 子:69
专家分:123
注 册:2009-3-2
结帖率:100%
收藏
 问题点数:0 回复次数:0 
绘按钮简例
小例子

程序代码:
.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 ?
lpOldButton      dd ?
btnState         dd ?      ; Button State
                           ; --------------
                           ; Normal : FALSE  
                           ; Click  : TRUE
                           ; Hover  : TRUE
                           ; --------------

.Code

BtnHover Proc    Uses ebx  _hDC:DWORD,_lpstRect:DWORD
    Local    @hBrush,@hPen

    mov       ebx,_lpstRect
    invoke    CreateSolidBrush,00000000h                            ; 可以使用图片填充
    mov       @hBrush,eax
    invoke    CreatePen,PS_SOLID,0,00f4c593h
    mov       @hPen,eax
    invoke    SelectObject,_hDC,@hBrush
    invoke    SelectObject,_hDC,@hPen
    inc       (RECT ptr [ebx]).left
    inc       (RECT ptr [ebx]).top
    dec       (RECT ptr [ebx]).right
    dec       (RECT ptr [ebx]).bottom
    invoke    Rectangle,_hDC,(RECT ptr [ebx]).left,(RECT ptr [ebx]).top,(RECT ptr [ebx]).right,(RECT ptr [ebx]).bottom
    invoke    DeleteObject,@hBrush
    invoke    DeleteObject,@hPen
    
    ret
    
BtnHover EndP

BtnNormal Proc    Uses ebx _hDC:DWORD,_lpstRect:DWORD
    Local    @hBrush,@hPen

    mov       ebx,_lpstRect
    invoke    CreateSolidBrush,0ffffffh                            ; 可以使用图片填充
    mov       @hBrush,eax
    invoke    CreatePen,PS_SOLID,0,00f4c593h
    mov       @hPen,eax
    invoke    SelectObject,_hDC,@hBrush
    invoke    SelectObject,_hDC,@hPen
    inc       (RECT ptr [ebx]).left
    inc       (RECT ptr [ebx]).top
    dec       (RECT ptr [ebx]).right
    dec       (RECT ptr [ebx]).bottom
    invoke    Rectangle,_hDC,(RECT ptr [ebx]).left,(RECT ptr [ebx]).top,(RECT ptr [ebx]).right,(RECT ptr [ebx]).bottom
    invoke    DeleteObject,@hBrush
    invoke    DeleteObject,@hPen
    
    ret
    
BtnNormal EndP

NewBtnProc    Proc    _hWnd:DWORD,_uMsg:DWORD,_wParam:DWORD,_lParam:DWORD
    Local    @stTme:TRACKMOUSEEVENT

    .if _uMsg == WM_MOUSEMOVE                                                ; Mouse move msg
    
        .if (!btnState)
        
            lea        ebx,@stTme
            assume    ebx: ptr TRACKMOUSEEVENT
                mov    [ebx].cbSize,sizeof TRACKMOUSEEVENT
                m2m    [ebx].hwndTrack,_hWnd
                mov    [ebx].dwFlags,TME_LEAVE or TME_HOVER
                mov    [ebx].dwHoverTime,1
            assume    ebx: nothing
            invoke    TrackMouseEvent,addr @stTme                           ; Send leave and hover Msg
        
        .endif
    
    .elseif _uMsg == WM_MOUSELEAVE                                          ; Mouse leave msg
        
        mov       btnState,FALSE
        invoke    InvalidateRect,_hWnd,NULL,TRUE                            ; Redraw
    
    .elseif    _uMsg == WM_MOUSEHOVER                                       ; Mouse hover msg
    
        mov       btnState,TRUE
        invoke    InvalidateRect,_hWnd,NULL,TRUE                            ; Redraw
    
    .else
    
        invoke    CallWindowProc,lpOldButton,_hWnd,_uMsg,_wParam,_lParam
        ret
    
    .endif
    
    xor    eax,eax
    ret
    
NewBtnProc EndP

WndProc Proc Uses ebx edi esi _hWnd:DWORD,_uMsg:DWORD,_wParam:DWORD,_lParam:DWORD ; Dialog CallBack

    .if _uMsg == WM_INITDIALOG                                            ; Dialog initialization
    
        invoke    GetDlgItem,_hWnd,1001                                   ; SubCalss Button
        invoke    SetWindowLong,eax,GWL_WNDPROC,offset NewBtnProc
        mov        lpOldButton,eax
    
    .elseif _uMsg == WM_CLOSE                                             ; Dialog terminate
    
        invoke    EndDialog,_hWnd,NULL
    
    .elseif _uMsg == WM_DRAWITEM                                          ; WM_DRAWITEM message
                                                                          ; wParam Control Identifier
                                                                          ; lParam lpDRAWITEMSTRUCT
        
        .if _wParam == 1001 
        
            mov        ebx,_lParam
            assume    ebx: ptr DRAWITEMSTRUCT
        
            .if [ebx].itemState & ODS_SELECTED                            ; Button State : Selected
            
                invoke    BtnHover,[ebx].hdc,addr [ebx].rcItem
            
            .else
            
                .if (!btnState)
                
                    invoke    BtnNormal,[ebx].hdc,addr [ebx].rcItem
                
                .else
                
                    invoke    BtnHover,[ebx].hdc,addr [ebx].rcItem
                
                .endif
            
            .endif
        
            assume    ebx: nothing
        
        .endif
        
    .elseif _uMsg == WM_COMMAND
        
        mov    eax,_wParam
        and    eax,0FFFFh
        
        .if eax == 1001    ; Button 
        
            invoke    MessageBox,0,$CTA0("你点击了按钮"),0,0
        
        .endif
    
    .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 | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Button Example Works 2009"
FONT 9, "宋体"
{
   CONTROL "", 1001, BUTTON, BS_OWNERDRAW | WS_CHILD | WS_VISIBLE, 79, 63, 69, 29
}


图片附件: 游客没有浏览图片的权限,请 登录注册


图片附件: 游客没有浏览图片的权限,请 登录注册


MASMPlus Works:

DrawButton.rar (66.11 KB)


[ 本帖最后由 sll0807 于 2009-11-1 23:44 编辑 ]
搜索更多相关主题的帖子: 按钮 
2009-11-01 23:35
快速回复:绘按钮简例
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.031297 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved