کلینیک فوق تخصصی اکسس ( کاربرد vba در اکسس )

کلینیک فوق تخصصی اکسس ( کاربرد vba در اکسس )

به اشتراک گذاری اطلاعات کسب شده در اکسس از سایت آفیس و سایت های تخصصی خارجی
کلینیک فوق تخصصی اکسس ( کاربرد vba در اکسس )

کلینیک فوق تخصصی اکسس ( کاربرد vba در اکسس )

به اشتراک گذاری اطلاعات کسب شده در اکسس از سایت آفیس و سایت های تخصصی خارجی

Paint InputBox



موارد پایین تست شده ... البته اینها موارد ساده ای هستند و پیش پا افتاده


Public Function CallWindProc(ByVal hwnd As LongPtr, ByVal Msg As Long, ByVal wParam As LongPtr, ByVal lParam As LongPtr) As LongPtr

Dim hdc As LongPtr


Select Case Msg

   Case WM_PAINT

    

     Dim cc As RECT

     GetClientRect hwnd, cc

     (hdc = GetDC(hwnd

     ((FillRect hdc, cc, CreateSolidBrush(RGB(255, 0, 255

     

   Case WM_DESTROY

   SetWindowLongPtr hwnd, GWL_WNDPROC, OldWindow

      

   End Select


CallWindProc = CallWindowProc(OldWindow, hwnd,

(Msg, wParam, lParam,


End Function



(FillRect hdc, cc, GetSysColorBrush(5


(FillRect hdc, cc, GetSysColorBrush(16




TIMER

 Case WM_TIMER

GetClientRect hwnd, rcClient

hdc

(GetDC(hwnd=

      DrawText hdc, x, 2, rcClient, DT_CENTER

      SetWindowTextA hwnd, x

    x = x + 1


ترسیم مستطیل در InputBox


Case WM_TIMER

               Dim Et As LongPtr

        Dim WinRect As RECT

     Et:Edit Handle,WinRect For Edit Control'

        GetWindowRect Et, WinRect

       ( hdc = GetDC(hwnd

             

      

        rc.Left = 10

        rc.Top = 68

        rc.right = 70

        rc.bottom = 88


rcClear.Left = rc.Left: rcClear.right = GetUpdateRight

        rcClear.Top = rc.Top - 3: rcClear.bottom = rc.bottom

       

       

         rc.Left = rc.Left + x: rc.right = rc.right + x

        Fill Rectangle' 

( FillRect hdc, rcClear, GetSysColorBrush(15

           Draw Rectangle'

           Rectangle hdc, rc.Left, rc.Top, rc.right, rc.bottom

FillRect Again GetSysColorBrush(18) ' Black'

Use Offset And FillRect rc With Another Brush'

GetUpdateRight = rc.right + x

        If rc.right > WinRect.right - WinRect.Left Then x = 0








CUSTOM CAPTION





case WM_PAINT

Dim ps As PAINTSTRUCT ps
hdc =BeginPaint(hwnd,ps)
'fill the window with a color HBRUSH
hbrush=CreateSolidBrush(RGB(33, 33, 33))
FillRect hdc,ps.rcPaint,hbrush
DeleteObject(hbrush)
'get a drawing area
Dim Crect As RECT
GetClientRect hwnd,Crect
Crect.bottom=Crect.top+GetSystemMetrics(SM_CYCAPTION)+ GetSystemMetrics(SM_CYEDGE)*2
'draw a simple win9x style caption (switch out the window text while drawing)
SetWindowText hwnd,CUSTOM_CAPTION
DrawCaption hwnd, hdc, rect,DC_GRADIENT Or DC_TEXT Or DC_ACTIVE Or DC_ICON

SetWindowText hwnd,WINDOW_CAPTION

DC_ACTIVE = 1
DC_SMALLCAP = 2
DC_ICON = 4
DC_TEXT = 8
DC_INBUTTON = 16
DC_GRADIENT = 32

SM_CXSCREEN = 0
SM_CYSCREEN = 1

SM_CXSIZE = 30
SM_CYSIZE = 31

SM_CXFRAME = 32
SM_CYFRAME = 33

SM_CYCAPTION = 4

SM_CXBORDER = 5
SM_CYBORDER = 6

SM_CXICON = 11
SM_CYICON = 12

SM_CXFRAME = 32
SM_CYFRAME = 33

SM_CXEDGE = 45
SM_CYEDGE = 46





DFC_CAPTION = 1
DFC_MENU = 2
DFC_SCROLL = 3
DFC_BUTTON = 4
DFC_POPUPMENU = 5
DFCS_CAPTIONCLOSE = 0
DFCS_CAPTIONMIN = 1
DFCS_CAPTIONMAX = 2
DFCS_CAPTIONRESTORE = 3
DFCS_CAPTIONHELP = 4
DFCS_MENUARROW = 0
DFCS_MENUCHECK = 1
DFCS_MENUBULLET = 2
DFCS_MENUARROWRIGHT = 4
DFCS_SCROLLUP = 0
DFCS_SCROLLDOWN = 1
DFCS_SCROLLLEFT = 2
DFCS_SCROLLRIGHT = 3
DFCS_SCROLLCOMBOBOX = 5
DFCS_SCROLLSIZEGRIP = 8
DFCS_SCROLLSIZEGRIPRIGHT = 16
DFCS_BUTTONCHECK = 0
DFCS_BUTTONRADIOIMAGE = 1
DFCS_BUTTONRADIOMASK = 2
DFCS_BUTTONRADIO = 4
DFCS_BUTTON3STATE = 8
DFCS_BUTTONPUSH = 16
DFCS_INACTIVE = 256
DFCS_PUSHED = 512
DFCS_CHECKED = 1024
DFCS_TRANSPARENT = 2048
DFCS_HOT = 4096
DFCS_ADJUSTRECT = 8192
DFCS_FLAT = 16384
DFCS_MONO = 32768



PAINT-BUTTON

احتملا Rec   در پیام WMPAINT باید Global یا Static تعیین شود.  تست نشده ولی روال بدین شکل است .


Private Pressed As Boolean
Private FocusLost As Boolean
Private TRect As RECT



Border3D_Y, Border_Thickness, Btn_Width,Button_Width, Button_Height


(GetWindowDC(FrmMainForm.Handle
(Border3D_Y=GetSystemMetrics(SM_CYEDGE

(Border_Thickness=GetSystemMetrics(SM_CYSIZEFRAME

(Button_Width=GetSystemMetrics(SM_CXSIZE

(Button_Height=GetSystemMetrics(SM_CYSIZE

Btn_Width=Border3D_Y+Border_Thickness+Button_Height-(2 * Border3D_Y) - 1

*Rec.Left=FrmMainForm.Width-(3 
(Button_Width+Btn_Width

+Rec.Right=FrmMainForm.Width - (3 * Button_Width 
(03

Rec.Top=Border3D_Y+Border_Thickness -1

*Rec.Bottom=Rec.Top+Button_Height - (2 
(Border3D_Y

FillRect 
(MyCanvas.Handle,Rec,HBRUSH(COLOR_BTNFACE+1

If not Pressed or Focuslost Then
    DrawEdge MyCanvas.Handle, Rec, EDGE_RAISED,BF_SOFT or BF_RECT
  Else If Pressed and Not Focuslost Then
    DrawEdge MyCanvas.Handle, Rec, EDGE_SUNKEN, BF_SOFT or BF_RECT

DrawIconEX MyCanvas.Handle,Rec.Left+4,Rec.Top+3,Application.Icon.Handle,8, 8, 0, 0, DI_NORMAL



WMNCACTIVATE
(InvalidateRect FrmMainForm.Handle, Rec, True
 

WMNCPAINT
InvalidateRect FrmMainForm.Handle, Rec, True


WMNCMOUSEDOWN

PT1.X=Loword(LParam)- FrmMainForm.Left
PT1.Y=Hiword(LParam)- FrmMainForm.Top
 
  if PTInRect(Rec,PT1.x,PT1.y) Then
      Pressed=True
      FocusLost=False
   InvalidateRect FrmMainForm.Handle, Rec,True
 SetCapture TWinControl(FrmMainForm).Handle
End If


WMLBUTTONUP

  Tmp  Boolean
 
 ReleaseCapture
  Tmp=Pressed
  Pressed=False
  if Tmp and PTInRect(Rec, PT1.x,PT1.y) Then
 
    InvalidateRect FrmMainForm.Handle, Rec,True
   
WMNCHITTEST

  Tmp : Boolean

  if Pressed then
      Tmp=FocusLost
 End if
   
PT1.X=Loword(LParam)- FrmMainForm.Left
PT1.Y=Hiword(LParam)- FrmMainForm.Top
   
   if PTInRect(Rec, PT1.x,PT1.y) then
      FocusLost=False
   else
      FocusLost=True
  End if

    if FocusLost =Tmp then
      InvalidateRect FrmMainForm.Handle, Rec,True
  End If 


SM_CXSCREEN = 0
SM_CYSCREEN = 1

SM_CXSIZE = 30
SM_CYSIZE = 31

SM_CXFRAME = 32
SM_CYFRAME = 33

SM_CYCAPTION = 4

SM_CXBORDER = 5
SM_CYBORDER = 6

SM_CXICON = 11
SM_CYICON = 12

SM_CYSIZEFRAME =    SM_CYFRAME
            SM_CXSIZEFRAME =    SM_CXFRAME

SM_CXFRAME = 32
SM_CYFRAME = 33

SM_CXEDGE = 45
SM_CYEDGE = 46



WM_CTLCOLORDLG




win32api/reference/Message/WM_CTLCOLORDLG.htm



WM_CTLCOLORDLG
Static wBrush
If wBrush<>0 Then
(hBM=LoadImage(0,"tile.bmp",0,0,0,0x2010
(wBrush=CreatePatternBrush(hBM

Function=wBrush

CreateHatchBrush/ CreatePatternBrush



hatch-brush


((hBrush=CreateSolidBrush (RGB(0, 0, 255
Associate the brush with the display device context'
SelectObject  hdc, hBrush
Draw a rectangle with blue background'
Rectangle hdc, 400,40,800,400
Create a hatch brush that draws horizontal red line'
,hBrush=CreateHatchBrush(HatchStyleHorizontal
((RGB(255, 0, 0
Set the background color to yellow'
(SetBkColor hdc, RGB(255, 255, 0


HBRUSH (CreatePatternBrush ( HBITMAP hbm

برگرفته از فروم های خارجی 


 Hatch Styles'
HS_HORIZONTAL= 0
HS_VERTICAL= 1
HS_FDIAGONAL= 2
HS_BDIAGONAL =3
HS_CROSS =4
HS_DIAGCROSS =5

()Sub OnPaint
Dim Brush
CreatePatternBrush 
(Brush,HS_HORIZONTAL,RGB(232,166,153
Dim ps As PAINTSTRUCT
Dim rct As RECT
GetClientRect hwnd,rct
(dc=BeginPaint(hwnd,ps
SelectObject dc,Brush
Rectangle hdc,left,top,right,bottom'
Rectangle dc,rct?
(SetBkColor dc,RGB(232,166,153
DrawText dc,"Brush Demo",10,rct,DT_CENTER Or DT_VCENTER Or DT_SINGLELINE
EndPaint hwnd,ps








Private hbr

(Function CreatePatternBrushFromFile(pszFile
hbr=0
(hbm=LoadImage(0,pszFile,IMAGE_BITMAP,0,0,LR_LOADFROMFILE
if (hbm) Then 
(hbr=CreatePatternBrush(hbm
DeleteObject hbm
End if
CreatePatternBrushFromFile=hbr
End Function

Function PaintContent(ByVal hwnd As Long,ByRef pps As 
(PAINTSTRUCT  

BeginPath pps.hdc
Ellipse pps.hdc,0,0,200,100
EndPath pps.hdc
(hbrOld=SelectObject(pps.hdc,hbr
FillPath pps.hdc
SelectObject pps.hdc,hbrOld
End Function



SWP_NOSIZE = 0x0001
SWP_NOMOVE = 0x0002
SWP_NOZORDER = 0x0004
SWP_FRAMECHANGED = 0x0020
SWP_SHOWWINDOW = 0x0040

(GWL_STYLE = (-16

'Window Style 
WS_CLIPCHILDREN=0x02000000
WS_CLIPSIBLINGS=0x04000000


hBrush=CreateHatchBrush(HS_DIAGCROSS,ColorTranslator.ToWin32(Color.Red)

,SetWindowSubclass(textBox1.Handle
(AddressOf WindowSubClass,0,0

SetWindowPos(textBox1.Handle,0,0,0, 200,40,SWP_NOZORDER Or SWP_NOMOVE Or 
(SWP_SHOWWINDOW Or SWP_FRAMECHANGED
For main form resizing long'
(nStyle = GetWindowLong(this.Handle, GWL_STYLE

SetWindowLong(this.Handle,GWL_STYLE, nStyle And 
(WS_CLIPCHILDREN



,WindowSubClass(hWnd,uMsg,wParam
(lParam,uIdSubclass,dwRefData

Select Case  uMsg
Case WM_NCPAINT
(hDC=GetWindowDC(hWnd
Dim rct As RECT 
()rect = new RECT'
(GetClientRect(hWnd, out rect
rct.right += 20 * 2
rct.bottom += 20 * 2

if  hBrush<>0 Then 
FillRect hDC,rct,hBrush
ReleaseDC hWnd, hDC
Exit Function

case WM_NCCALCSIZE

if (wParam == (IntPtr)0'
Dim pRect As RECT
,pRect =(RECT)Marshal.PtrToStructure(lParam'
((typeof(RECT'

(Call CopyMemory(VarPtr(rct)+4,ByVal lParam+4,4

pRect.left += 10
pRect.top += 10
pRect.bottom -= 10
pRect.right -= 10

(Marshal.StructureToPtr(pRect, lParam,false'
(Call CopyMemory(lparam,VarPtr(rct),4
Exit Function
End Select
DefSubclassProc(hWnd, uMsg, wParam, lParam)

رنگ کنترل رسمی ( Custom Control) در SubClaasing



ساب کلاس کردن کنترل ترسیمی  ( تنها یک کنترل ) 

Type  cz As SIZE

cx As Long ' Width

cy As Long  ' Height

End Type 


Type CustCtrl
'Foreground text colour
crForeGnd As Long 
'Background text colour
crBackGnd As Long 
'The font
hFont As Long 
'The control's window handle
hwnd As Long 
End Type 


Painting the control

Whenever windows wants us to update the contents of our window (the client area), a WM_PAINT message will be sent. So, whenever the WM_PAINT message is received, we need to call our control’s painting routine.


case WM_PAINT
 CustCtrl_OnPaint ccp,wParam, lParam

(CustCtrl_OnPaint(ccp As CustCtrl,wParam,lParam

Dim  hdc As Long
Dim ps As PAINTSTRUCTHANDLE
Dim hOldFont As Long
Dim szText As String*200
Dim rc As RECT
Get a device context for this window'
(hdc=BeginPaint(ccp.hwnd,ps
Set the font we are going to use'
(hOldFont=SelectObject(hdc,ccp.hFont
Set the text colours'
SetTextColor hdc,ccp.crForeGnd
SetBkColor  hdc,ccp.crBackGnd
Find the text to draw'
(GetWindowText ccp.hwnd,szText, Len(szText
Work out where to draw'
GetClientRect ccp.hwnd,rc
computes the width and height of the '
.specified string of text'
GetTextExtentPoint32 hdc,szText, len(szText),sz
Center the text'
x=(rc.right-sz.cx)/2
y=(rc.bottom-sz.cy)/2
Draw the text'
ETO_OPAQUE'
The current background color should be used to fill'
the rectangle'
ExtTextOut hdc,x,y,ETO_OPAQUE,rc,szText,len(szText),0
Restore the old font when we have finished'
SelectObject hdc,hOldFont
Release the device context'
EndPaint ccp.hwnd,ps
return 0



The GWL_USERDATA area

Every window in the system has a 32bit integer which can be set to any value. This 4 byte storage area is enough to store a pointer to a structure. We set this integer using SetWindowLong, and retrieve the integer using GetWindowLong. Using this technique, our function will look like this:

(GetCustCtrl(hwnd
return=GetWindowLong(hwnd,GWL_USERDATA



(SetCustCtrl(ByVal hwnd As Long,ByRef ccp As CustCtrl
SetWindowLong hwnd,GWL_USERDATA,ccp

This method is usually used when subclassing a control




Memory allocated by HeapAlloc is not movable. The address returned by HeapAlloc is valid until the memory block is freed or reallocated; the memory 
.block does not need to be locked

To free a block of memory allocated byHeapAlloc, use 
.the HeapFree function


Our custom control will change colour whenever the user clicks the mouse on it. Therefore the next message handler will be for the 
.WM_LBUTTONDOWNmessage

case WM_LBUTTONDOWN
CustCtrl_OnLButtonDown ccp, wParam, lParam


CustCtrl_OnLButtonDown(ByRef ccp As 
(CustCtrl,wParam,lParam
(col=RGB(rnd()*256,rnd()*256,rnd()*256 
Change the foreground colour'
ccp.crForeGnd=col
Use the inverse of the foreground colour'
(ccp.crBackGnd=((col) And &Hffffff
Now redraw the control'
InvalidateRect ccp.hwnd,0,0
UpdateWindow ccp.hwnd
return 0

WM_MOUSEACTIVATE=&H21

'Activates the window, and does not discard the mouse'
.message
MA_ACTIVATE =1

case WM_MOUSEACTIVATE
    SetFocus hwnd
    return MA_ACTIVATE

CreateWindowEx


 HWND CreateWindowExA

dwExStyle

lpClassName

lpWindowName

dwStyle

X

Y

nWidth

nHeight

hWndParent

hMenu

hInstance

lpParam 


WS_EX_WINDOWEDGE=&H100
WS_EX_TOOLWINDOW=&H80

 :  Window Styles 

WS_BORDER=&H800000
WS_CHILD=&H40000000

WS_POPUP=&H80000000

 : Note 

The windows is a pop-up window. This style cannot' 

be used with the WS_CHILDstyle


Case WM_CREATE/SHOWWINDOW


create window
int style=WS_POPUP And WS_BORDER
int exstyle=WS_EX_TOOLWINDOW
int hwnd=CreateWindowEx(exstyle "xclass"0 style 10 
(10 50 50 0 0 _hinst 0


BS_OWNERDRAW

case WM_CREATE
hWndButton=CreateWindowEx(0, "BUTTON", NULL, 
WS_CHILD Or 
(BS_OWNERDRAW,10,10,80,20,hWnd,IDC_OWNERDRAW,0,0


Type SIZE
x As Long
y As Long
End Type

LPDRAWITEMSTRUCT lpdis =(DRAWITEMSTRUCT*)lParam
SIZE size
[char text[256
("sprintf(text, "%s", "Test

The GetTextExtentPoint32 function computes the'
. width and height of the specified string of text
(GetTextExtentPoint32 lpdis.hDC,text, Len(text),size
(SetTextColor lpdis.hDC,RGB(0, 0, 0
(SetBkColor lpdis.hDC,RGB(255, 255, 0


ExtTextOut lpdis.hDC, ((lpdis.rcItem.right -lpdis.rcItem.left)-size.cx)/2,((lpdis.rcItem.bottom-lpdis.rcItem.top)- size.cy)/2,ETO_OPAQUE And ETO_CLIPPED,lpdis.rcItem,text,Len(text),0)

DrawEdge lpdis.hDC,lpdis.rcItem,(lpdis.itemState & ODS_SELECTED ? EDGE_SUNKEN : EDGE_RAISED ), BF_RECT


: case WM_CREATE
      
       "hButton = CreateWindow("button","Label,
                WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON,
                100, 200, 
                50 ,20,
                hWnd,(HMENU) BUTTON_ID,
                0,0,

پیام WM_SETCURSOR برای تغییررنگ Custom Button


 




 getdlgctrlid : Retrieves the identifier of the 

.specified control




بر گرفته از فروم خارجی  ( بررسی  موقعیت ماوس در باتن موردنظر )


1-find your button rectangle

GetWindowRect BtnHwnd,BtnRect

2-transform form client coordinate in screen coordinate
ClientToScreen BtnRect,pt
(those 2 points in OnInitDialog or equivalent)
3-in OnMouseMove function check if mouse point is inside BtnRect (use PtInRect(BtnRect,pt) and if it is then do what u want to do.The mouse point u can found it this way:Dim pt As POINT
(pt.x = LOWORD(lParam
(pt.y = HIWORD(lParam


WM_SETCURSOR. Do not change anything, just detect if wParam is HWND of your button. If it is, then set a 
flag (some BOOL) and InvalidateRect(..) your button. 
#define WM_SETCURSOR                    0x0020

تست شده طبق توصیه ی دوست خارجی 
Case WM_SETCURSOR
      Dim cc As RECT
      (hdc = GetWindowDC(can
      GetClientRect can, cc ' Necessary
can is handle of Cancel Button'       
      If wParam = can Then
      ((FillRect hdc, cc, CreateSolidBrush(RGB(255, 0, 0
      ReleaseDC can, hdc
      Else
InvalidateRect' 
      InvalidateRect can, cc, False
      End If


Hook کردن MsgBox و Subclass کردن تغییر حالت باتن ها به BS_OWNERDRAW  در ENUMCHILDPROC و گرفتن  آیدی های باتن فرضا IDYES=6 و IDNO=7 و IDCANCEL=2 با GetDlgCtrlID که در مثال زیر در ناحیه کنترل Static در آخرش آیدی ها پرینت شده.
آیدی ها درمتغید تعریف شده بنام GetBtn  ذخیره شده و با تابع Split  در اکسس جدا شده ودر لوپ گذاشته شده این متد فقط با پیام DRAWITEN انجام میشود و پیام CTLCOLORBTN جواب نخواهد داد.

Case WM_DRAWITEM
  
 Dim pDIS As DRAWITEMSTRUCT
   Dim state
   Dim p As RECT
   Dim pdc As LongPtr
   Dim OldBr As LongPtr
 


   ("," ,SplitBtn = Split(GetBtn
     (For i = 0 To UBound(SplitBtn
      (CopyMemory pDIS, ByVal lParam, Len(pDIS
      DeleteObject OldBr
      
     (( BtnHwnd = GetDlgItem(lhwnd, SplitBtn(i
      p = pDIS.rcItem
      pdc = pDIS.hdc
      (hdc = GetWindowDC(pdc
      pDIS.hwndItem = BtnHwnd
      GetClientRect pDIS.hwndItem, p
      ,OldBr=SelectObject(hdc
((CreateSolidBrush(RGB(100, 0, 135
      RoundRect hdc, p.Left, p.Top, p.Right, p.Bottom, 16, 16
      ReleaseDC BtnHwnd, hdc
      DeleteObject OldBr
      (CopyMemory ByVal lParam, pDIS, Len(pDIS
          Next


 Case WM_SETCURSOR
      Dim cc As RECT
      Dim txt
      
(" ,",SplitBtn = Split(GetBtn
    (For j = 0 To UBound(SplitBtn
DeleteObject OldBr   
((BtnHwnd = GetDlgItem(lhwnd, SplitBtn(j   
(txt = GetText(BtnHwnd    
GetClientRect BtnHwnd, cc    
(hdc = GetWindowDC(BtnHwnd    
GetClientRect BtnHwnd, cc    
If wParam = BtnHwnd Then
            cc.Left = cc.Left + 2.5     
            cc.Top = cc.Top + 2.5     
            cc.Right = cc.Right - 2.5     
            cc.Bottom = cc.Bottom - 2.5     
 (( FillRect hdc, cc, CreateSolidBrush(RGB(255, 0, 0
  DrawText hdc, txt, Len(txt), cc, DT_CENTER            ReleaseDC BtnHwnd, hdc
DeleteObject OldBr 
       Else
InvalidateRect BtnHwnd, cc, False
ReleaseDC BtnHwnd, hdc
DeleteObject OldBr
      End If  
      Next
      
SetBkMode hdc,0'



پیام WM_PAINT جهت رنگ Client و WM_DRAWITEM برای باتن ساخته شده بجای باتن CANCEL


تست شده 


The WM_PAINT message is sent when the system or another application makes a request to paint a portion 

  of an application's window


The PAINTSTRUCT structure contains information that can be used to paint the.client area of a window

حاوی اطلاعاتی برای استفاده در نقاشی ناحیه ی Client پنجره.



Case WM_PAINT

Dim ps As PAINTSTRUCT

    ( hdc = BeginPaint(lhwnd, ps

     Dim rrc As RECT

     GetClientRect lhwnd, rrc 

  (( FillRect hdc, rrc, CreateSolidBrush(RGB(100, 0, 100

     SetTextColor hdc, vbRed

     TextOutA hdc, 10, 10, "sa", 2

     EndPaint lhwnd, ps

     ReleaseDC lhwnd, hdc


البته غیر از پیام زیر میشود با پیام WM_CTLCOLORBTN  هم  رنگ باتن  را تغییر داد که lParam میشود هندل باتن و wParam هم هندل DC میشود


Case WM_DRAWITEM

   Dim pDIS As DRAWITEMSTRUCT

   Dim state

   (CopyMemory pDIS, ByVal lParam, Len(pDIS

  ( hdc = GetDC(pDIS.hdc

   Dim p As RECT

   p = pDIS.rcItem

   state = pDIS.itemState

  GetClientRect can, p

   If pDIS.CtlID = 2 Then

   If state = 272 Then       

  RoundRect hdc, p.Left, p.Top, p.Right, p.Bottom, 16, 16  

ReleaseDC can, hdc  

  Else         

  RoundRect hdc, p.Left, p.Top, p.Right, p.Bottom, 4, 4       

  ReleaseDC can, hdc      

 End If     

   End If

   (CopyMemory ByVal lParam, pDIS,Len(pDIS



زمان کلیک روی باتن کنسل  مکث عمل RounRect را نمایش داده و پنجره بسته میشود.


If state = 785 Then  '272
  RoundRect hdc, p.Left, p.Top, p.Right, p.Bottom, 16, 16
  Sleep 400
  ReleaseDC can, hdc

If (pDIS.itemState And???
ODS_SELECTED)=ODS_SELECTED Then




طبق داکیومنت آفیس  (WM_CTLCOLORBTN) :

در موارد بالا حتما باید BS_OWNERDRAW تنظیم شود برای کل باتن ها که هندل میشود هندل Dlg و برای باتن خاص هندل همان باتن فقط ،   setwindowlongptra را در WIN64 ببینید.
See For Button Control button-styles
See For Static Control static-control-styles
wParam
An HDC that specifies the handle to the display context for the button
lParam
)An HWND that specifies the handle to the button
getdlgitem : Retrieves a handle to a control in the 
(specified dialog box

hdc=wParam '
Case WM_CTLCOLORBTN
if lparam=GetDlgItem(hwnd,IDCANCEL) then
.
End if
Exit Function



The idea is to add your own Windows message handler, you can do this using 
.SetWindowsHookEx function
Don't forget : Before terminating, an application must call the UnhookWindowsHookEx function to free 
system resources associated with the hook