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

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

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

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

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

MOVECURSOR رسم مستطیل



WM_MOUSEMOVE 

       Dim p As POINTAPI

       GetCursorPos p

       ScreenToClient hwnd, p

    

    

      Dim ff As RECT

      Dim ff1 As RECT

       SetRect ff, p.x, p.y, p.x, p.y

       ff.Left = p.x - 15

       ff.Top = p.y - 15

       ff.right = p.x + 35

       ff.bottom = p.y + 30

              

 DrawFrameControl GetDC(hwnd), ff, DFC_BUTTON, DFCS_BUTTONPUSH

       RoundRect GetDC(hwnd), ff.Left, ff.Top, ff.right, ff.bottom, 16, 16

      ( FillRect GetDC(hwnd), ff, GetSysColorBrush(16

            

        Sleep 100

       InvalidateRect hwnd, ff, 1

       UpdateWindow hwnd

       

      

         (ReleaseDC hwnd, GetDC(hwnd

     

     

       

   






UINT SetBoundsRect( HDC hdc, const RECT *lprect, 
(UINT flags : DCB_RESET ( Clear Bounding Rectangle 


(BOOL ValidateRect( HWND hWnd, const RECT *lpRect 

validates the client area within a rectangle by removing the rectangle from the update region of the specified window.

BOOL InvalidateRect( HWND hWnd, const RECT 
(*lpRect, BOOL bErase 

The InvalidateRect function adds a rectangle to the specified window's update region. The update region represents the portion of the window's client area that must be redrawn.

(BOOL UpdateWindow( HWND hWnd 

The UpdateWindow function updates the client area of the specified window by sending a WM_PAINT message to the window if the window's update region is not empty


(HDC GetDC( HWND hWnd 

The GetDC function retrieves a handle to a device context (DC) for the client area of a specified window or for the entire screen







MOUSEMOVE


کدام درست و منطقی تر است ؟


WM_MOUSEMOVE

   Dim rc As RECT
   Din pt As POINT

   SetRect rc, 0,0,5,5
   (Pt.x=LOWORD(LParam
   (Pt.y=HIWORD(LParam

   if PtInRect(rc,pt.x,pt.y)  Then 
      Msgbox "in"
  Else 
     Msgbox "Out"
  End If 



For x = rc.Left To rc.Right
For y = rc.Top To rc.Bottom

If PtInRect(rc, x, y) Then 
Msgbox "in"
Else
Msgbox "Out"
End If 

Next y
Next x




Dim mousept As POINTAPI
Dim winrect As RECT 
with winrect
left=5.
top=0.
right=5.
bottom=5.
End With 


GetCursorPos mousept
GetWindowRect hWnd, winrect'
SetRect 5,0,5,5?'
ScreenToClient ?'

(isinside=PtInRect(winrect, mousept.x, mousept.y

If isinside = 1 Then
  Debug.Print "The mouse cursor is currently inside 
".of Form1
Else
  Debug.Print "The mouse cursor is currently outside 
".of Form1
End If



Dim pt As POINTAPI
Dim BtnRect As RECT



WM_MOUSEMOVE

GetWindowRect BtnHwnd,BtnRect
(pt.x=loword(lparam
(pt.y=hiword(lparam
ClientToScreen BtnHwnd,pt

If PtInRect(BtnRect,pt.x,pt.y) Then 


CustomButton_MouseMove



WM_MOUSEMOVE
Dim pt As POINTAPI
Dim cursorPoint As Longptr 
Dim rc As RECT
(pt.x=loword(lparam
(pt.y=hiword(lparam
(cursorPoint=ScreenToClient (hwnd,pt???
rc.left=0
rc.right=0
rc.right=rc.left+5
rc.bottom=rc.top+5
(If PtInRect(rc, cursorPoint
"SetWindowTextA hwnd,"in
End if 


wParam  : virtual keys like MK_LBUTTON(Mouse Key 
(Left 

lParam
loword از lparam یا (Clng(lparam And 65535 نشاندهنده ی مختصات x کرسر 
The low-order word specifies the x-coordinate of the cursor. The coordinate is relative to the upper-left 
.corner of the client area
Hiword از lparam یا (Clng(lparam \ 65535 نشاندهنده ی مختصات y کرسر 
The high-order word specifies the y-coordinate of the cursor. The coordinate is relative to the upper-left corner of the client area.


Return value

If an application processes this message, it should 
.return zero




Private oldUserData As LongPtr
Private oldWinProc As LongPtr


=oldUserData 
(GetWindowLongPtr(hwnd,GWLP_USERDATA
oldWinProc=SetWindowLongPtr(hwnd,GWL_WNDPROC,Addressof 
(WinProc


WinProc
Select Case uMsge


Case WM_MOUSMOVE
.
End Select

=userDataToRestore
(SetWindowLongPtr(GWL_USERDATA,oldUserData
)WinProc=CallWindowProc
(oldWinProc,hWnd,uMsg,wParam,lParam
SetWindowLongPtr(GWL_USERDATA,userDataToRestore
End Function



()OnNcPaint

static BOOL before=FALSE
 
if  not before Then 'If first time, the OnNcCalcSize function will be called

SetWindowPos 0(hwnd),0,0,0,0, SWP_FRAMECHANGED Or SWP_NOMOVE Or SWP_NOSIZE before=TRUE
DrawBorders

End if



prect
oldrect

NCCALCSIZE
Static p As RECT


Dim nccsp As NCCALCSIZE_PARAMS
(CopyMemory nccsp,ByVal lParam,Len(lParam
(prect=nccsp.rgrc(0
oldrect=prect

CallWindowProc hWnd, wMsg, wParam, lParam


p.left=prect.left - oldrect.left
p.right=oldrect.right - prect.right
p.Top=prect.top-oldrect.top
p.Bottom=oldrect.bottom-prect.bottom

(p.right=p.right-GetSystemMetrics(SM_CXVSCROLL

ret 
WinProc=WVR_VALIDRECTS


WMNCPAINT : GetButtonRect
Static btnrect

CallWindowProc hWnd, wMsg, wParam, lParam

GetWindowRect hwnd,Winrect
OffsetRect Winrect, -Winrect.left, -Winrect.top

btnrect.right=btnrect.right-p.Right
btnrect.top=btnrect.top+p.Top
btnrect.bottom=btnrect.bottom-p.Bottom
btnrect.left=btnrect.right 
(GetSystemMetrics(SM_CXVSCROLL-


(hdc=GetWindowDC(hwnd

FillRect hdc,btnrect
(GetSysColorBrush(COLOR_BTNFACE,
 

WM_NCPAINT=&H85
WM_NCCALCSIZE=&H83

 * WM_NCCALCSIZE  flags

WVR_ALIGNTOP=&H10
WVR_ALIGNLEFT=&H20
WVR_ALIGNBOTTOM=&H40
WVR_ALIGNRIGHT=&H80
WVR_HREDRAW=&H100
WVR_VREDRAW=&H200
(WVR_REDRAW=(WVR_HREDRAW+ WVR_VREDRAW
WVR_VALIDRECTS=&H400 

پیام 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_MOUSEMOVE در Custom Draw Control



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


Dim r As RECT
(HWND h=GetDlgItem(hwndDlg,IDC_YOURCTLID
GetWindowRect h, r ' get window rect of control relative to screen
POINT pt={r.left,r.top } 'new point object using rect x, y
Above means ->>>??? pt.x=r.left:pt.y=r.top '
ScreenToClient hwndDlg,pt ' convert screen co-ords to
 client based points
example if I wanted to move said control'
-MoveWindow h,pt.x,pt.y+15,r.right-r.left, r.bottom
(r.top,TRUE
 r.right - r.left, r.bottom - r.top to keep control at its '
current size


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

(void CMyButton::OnTimer(UINT nIDEvent

()DWORD GetMessagePos'
Point p(GetMessagePos
Dim p As PONIAPI And p=GetMessagePos ??? '
'BOOL ScreenToClient(HWND hWnd,LPPOINT lpPoint'
ScreenToClient hBtn ,p

(Get the bounds of the control (just the client area '
 CRect rect
(BOOL GetClientRect(HWND hWnd,LPRECT lpRect'
GetClientRect hBtn,rect

 Check the mouse is inside the control '
(BOOL PtInRect(const RECT *lprc,POINT pt'
if PtInRect(rect,p)<>0 Then
Else
 ...if not then stop looking '
m_bOverControl=FALSE
(BOOL KillTimer(HWND hWnd,UINT_PTR uIDEvent'
KillTimer lhwnd,m_nTimerID
 ...and redraw the control '
  InvalidateRect ? Or Redraw 

CButton::OnTimer(nIDEvent ??? '