1) Do not use BeginPaint/EndPaint in WM_ERASEBKGND. Move that code in a WM_PAINT handler.
2) Use SetWindowLong and the GWL_USERDATA index for storing the button state (UP or DOWN) and use GetWindowLong for retrieving the current state.
3) Use SetCapture for capturing the mouse, starting with WM_LBUTTONDOWN. Update the state of the button (UP or DOWN) according to mouse position
4) Use RedrawWindow when you need painting to occur
SubClassEditControl
replace the old window procedure with our new one'
oldproc=SetWindowLong(hwnd,GWL_WNDPROC,Address
(Of InsButProc
associate our button state structure with the window'
SetWindowLong hwnd,GWL_USERDATA,pbut
force the edit control to update its non-client area'
SetWindowPos hwnd,0,0,0,0,0, SWP_FRAMECHANGED Or SWP_NOMOVE Or SWP_NOSIZE Or SWP_NOACTIVATE Or SWP_NOZORDER
get the button state structure'
, InsBut *pbut = (InsBut *)GetWindowLong(hwnd
(GWL_USERDATA
case WM_NCPAINT
let the old window procedure draw the borders / other'
non-client // bits-and-pieces for us.'
CallWindowProc oldproc,hwnd,msg, wParam, lParam
get the screen coordinates of the window. // adjust '
the coordinates so they start from 0,0
GetWindowRect hwnd,Wrect
OffsetRect Wrect, -Wrect.left,-Wrect.top
BM_SETIMAGE = 247
BST_UNCHECKED = 0
BST_CHECKED = 1
BST_INDETERMINATE = 2
BST_PUSHED = 4
BST_FOCUS = 8 ' KeyBoard Focus
SetWindowLongPtr hwnd,GWL_USERDATA,0