| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 733 人关注过本帖
标题:WIN32取颜色值
取消只看楼主 加入收藏
Captains
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2009-7-30
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:0 
WIN32取颜色值
刚才看帖子有人问STATIC控件取颜色的问题
正好我之前有写过,拿出来请大家指教
;转换成R、G、B
_RGB            proc    _hColor
    
            mov     eax, _hColor
            shr     eax, 16
            and     eax, 0FFh
            mov    hB,eax
            
            mov     eax, _hColor
            shr     eax, 8
            and     eax, 0FFh
            mov    hG,eax
            
            mov     eax, _hColor
            and     eax, 0FFh
            mov    hR,eax
    ret

_RGB endp
            
_GetColor        proc    _hWnd
            
            LOCAL    @buffer[128]:byte
            LOCAL    rect:RECT
            LOCAL    pi:POINT
            
            invoke    GetCursorPos,addr pi                ;取当前坐标
            
            invoke    wsprintf,addr @buffer,addr szFmt,pi.x
            invoke    SetDlgItemText,_hWnd,IDC_X,addr @buffer
            invoke    wsprintf,addr @buffer,addr szFmt,pi.y
            invoke    SetDlgItemText,_hWnd,IDC_Y,addr @buffer        
            
            invoke GetWindowDC, NULL                ;获取窗口HDC
            invoke GetPixel, eax, pi.x, pi.y            ;获取颜色值
            mov hColor,eax

            invoke    _RGB,hColor                    ;转换RGB
            
            invoke    SetDlgItemInt,_hWnd,IDC_R,hR,0
            invoke    SetDlgItemInt,_hWnd,IDC_G,hG,0
            invoke    SetDlgItemInt,_hWnd,IDC_B,hB,0
            
            invoke SetDlgItemInt,_hWnd,IDC_COLOR,hColor,0
            invoke InvalidateRect,hStatic,NULL,TRUE            ;重绘客户区
            
            
    ret

_GetColor endp
            
_ProcDlgMain        proc    uses ebx edi esi hWnd,wMsg,wParam,lParam
            
            mov    eax,wMsg
            
            .if    eax    ==    WM_CLOSE
            
                invoke    UnregisterHotKey,hWnd,HotKey
                invoke    KillTimer,hWnd,1
                invoke    EndDialog,hWnd,NULL
                
            .elseif    eax    ==    WM_INITDIALOG
                invoke    LoadIcon,hInstance,ICO_MAIN
                invoke    SendMessage,hWnd,WM_SETICON,ICON_BIG,eax
                
                
                invoke    GetDlgItem,hWnd,IDC_STATIC1
                mov    hStatic,eax
                invoke    GetDlgItem,hWnd,IDC_STATIC2
                mov    hStatic2,eax
                
                invoke    RegisterHotKey,hWnd,HotKey,NULL,VK_HOME        ;注册HOME热键
                invoke    SetTimer,hWnd,1,50,NULL                ;设置时间
                
            .elseif    eax    ==    WM_TIMER
                
                invoke    _GetColor,hWnd
                
            .elseif    eax    ==    WM_HOTKEY
                invoke InvalidateRect,hStatic2,NULL,TRUE        ;保存最后一次指向的颜色
                invoke DeleteObject,hBrush                ;删除刷子
                
            
            .elseif    eax    ==    WM_CTLCOLORSTATIC
                mov    eax,lParam
                .if    eax    ==    hStatic
                    invoke CreateSolidBrush,hColor        ;创建指定颜色的刷子
                    mov hBrush,eax
                    ret                    ;一定要返回hBrush值
                
                .elseif    eax    ==    hStatic2
                    invoke CreateSolidBrush,hColor
                    mov hBrush,eax
                    ret
                .endif
            
            .else
                mov    eax,FALSE
                ret
            .endif
            mov    eax,TRUE
    ret

_ProcDlgMain endp


取颜色值.rar (4.76 KB)
搜索更多相关主题的帖子: 取颜色 
2009-08-18 23:11
快速回复:WIN32取颜色值
数据加载中...
 
   



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

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