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
_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)