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

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

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

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

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

WM_NCHITTEST در ساب کلاس EDIT Control



تمام موارد کپی شده از داکیومنتِ موجود است  تست شده همراه با تصویر ، ثابت ها نیز از داکیومنت استخراج و قابل مشاهده برای عموم است. لینک ها شما را به مطلب داکیومنت هدایت خواهند نمود.



if the return value of the message response function of WM_NCHITTEST is HTCLIENT, indicating that the mouse clicked on the client area, Windows will send a WM_LBUTTONDOWN message to the window; if the return value of the message response function of WM_NCHITTEST is not HTCLIENT (may be HTCAPTION, HTCLOSE,

HTMAXBUTTON) Etc.), that is, when the mouse clicks on the non-client area, Windows will send a WM_NCLBUTTONDOWN message to the window.



اگر مقدار برگشتی پاسخ پیام تابع، HTCLIENT باشد، نشان می دهد که ماوس روی ناحیه Client کلیک شده . ویندوز یک پیام WM_NCLBUTTONDOWN به پنجره خواهد فرستاد اگر مقدار جواب پیام برگشتی HTCLIENT نباشد ممکن است HTCAPTION یا HTCLOSE و یا حتی HTMAXBUTTON باشد .یعنی زمان کلیک در منطقه خارج از Client ( هر پنجره ای می تواند خود باتن باشد یا کنترل ویرایش یا  دیالوگ باکس ) ویندوز یک پیام WM_NCLBUTTONDOWN به پنجره ارسال می نماید.





تصویر بالا وقتی ماوس داخل کنترل ویرایش است ( Client ) در Caption یا TitleBar عدد یک و وقتی روی بوردر است عدد 18 را مشاهده می نمائید ثابت ها در پائین ذکر شده .




Case 132 ' WM_NCHITTEST
ff = CallWindowProc(HookInputBoxprev, hWnd, uMsg, wParam, lParam)
SetWindowTextA GetParent(hWnd), ff



HTBORDER=18   '<<<<<<

HTBOTTOM=15

HTBOTTOMLEFT=16

HTBOTTOMRIGHT=17

HTCAPTION=2

HTCLIENT=1  ' <<<<<

HTCLOSE=20

HTERROR=-2

HTGROWBOX=4

HTHELP=21

HTHSCROLL=6

HTLEFT=10

HTMENU=5

HTMAXBUTTON=9

HTMINBUTTON=8

HTNOWHERE=0

HTREDUCE=8

HTRIGHT=11

HTSIZE=4

HTSYSMENU=3

HTTOP=12

HTTOPLEFT=13

HTTOPRIGHT=14

HTTRANSPARENT=-1

HTVSCROLL=7

HTZOOM=9




How to Get Border Of NonClientArea



  1. Call GetClientRect() to get the size of the client area.
  2. Call ClientToScreen() to transform client rect to screen coordinates.
  3. Call GetWindowRect() to get the rectangle of the control including NC area, in screen coordinates.
  4. Calculate difference between client rect and window rect coordinates to get size of border (e. g. leftBorderWidth = clientRect.left - windowRect.left).



how-to-set-the-size-of-the-non-client-area-of-a-win32-window-native


win32/gdi/nonclient-area



CoorDinate     ..... PtInRect





در بالا مختصات x و y با پیام WM_MOUSEMOVE و پارامتر lParam و استفاده از loword و hiword آن در Caption ذکر شده برای گرفتن Right مستطیل کنترل ویرایش از تابع GetClientRect استفاده شده.


Case WM_MOUSEMOVE
         GetClientRect GetDlgItem(hwnd, 1000), r1
         GetCursorPos tt
         ScreenToClient hwnd, tt
         mm.x = CLng(lParam And &HFFFF&)  'LoWord(lParam
         mm.y = CLng(lParam \ &HFFFF&)  'HiWord(lParam
        SetWindowTextA hwnd, "Coordinate :(" & mm.x & "," & mm.y & ")" & " &RectR:" & r1.Right & " &tt_X_Y(" & tt.x & "," & tt.y & ")"
           'r1.Left = 0: r1.Right = 30: r1.Top = 0: r1.Bottom = 50
           If PtInRect(r1, mm.x, mm.y) Then
            'SetWindowTextA GetDlgItem(hwnd, 1), "In"
           ElseIf Not PtInRect(r1, mm.x, mm.y) Then
            'SetWindowTextA GetDlgItem(hwnd, 1), "Out"
           End If


در تصویر پائین Right را 1263 زده چون از تابع GetWindowRect کنترل ویرایش با آیدی 4900 استفاده شده . در ضمن اگر ماوس در مختصات خاصی که که مستطیل را تعریف کردیم ( با left و top و right و bottom ) باشد در باتن Ok با آیدی 1 رشته In و اگر خارج باشد رشته Out جایگزین تکست پنجره باتن میشود.( استفاده از تابع PtInRect )


if Points moved inside the edit 's rectangle we specified  in the above code  , the window text of "Ok" button will  be changed to "In" , Otherwise "Out"



Byval StrPtr

"1604;1591;1601;1575;32;1601;1602;1591;32;1608;1575;1585;1583;32;1705;1606;1740;1583"



The InflateRect function increases or decreases the width and height of the specified rectangle. The InflateRect function adds -dx units to the left end and dx to the right end of the rectangle and -dy units to the top and dy to the bottom. The dx and dy parameters are signed values; positive values increase the width and height, and negative values decrease them.



تابع InflateRect عرض و ارتفاع مستطیل ( Rectangle )  را افزایش یا کاهش می دهد . این تابع dx- واحد به چپ و dx واحد به انتهای راست مستطیل و dy- به بالا و dy به پائین اضافه می نماید.پارامترهای dx و dy مقادیر علامت دار هستند .مقادیر مثبت عرض و ارتقاع را افزایش می دهند و مقادیر منفی آنها را کاهش می دهند.




Dim Mpos As POINTAPI
'Retrieves the position of the mouse cursor, in screen coordinates.
 Retval = GetCursorPos(MPos)
'Retrieves a handle to the window that contains the specified point.
hWnd = WindowFromPoint(MPos.x, MPos.y)
'A handle to the window to be tested.
 If CBool(IsWindow(hWnd)) = False Then
Label1.Caption = ""
Exit Sub
End If
Determines whether a window is maximized
IsMaximized = IsZoomed(hWnd)
'Determines whether the specified window is minimized (iconic).
IsMinimized = IsIconic(hWnd)
'Retrieves a handle to the specified window's parent or owner.
ParentWnd = GetParent(hWnd)

 




29 بهمن 1400 : در پی اهانت یک افسر هندی به سردار سلیمانی و رهبر انقلاب،  مردم منطقه بدگام کشمیر به خیابان‌ها ریختند و در حمایت از سردار سلیمانی شعار سردادند و با ماموران پلیس درگیر شدند و اقدام مامور هتاک را محکوم کردند. یکی از افسران هندی در حین عملیات سرشماری یکی از شهرهای کشمیر با ورود به منزل یکی از شهروندان عکس شهید سلیمانی و رهبرانقلاب را که در خانه او بود به آتش می‌کشد. 








بررسی قرار گرفتن نشانگر ماوس در ناحیه مورد نظر API



تمام این مطالب گردآوری شده از سایت های مختلف است بعضی امتحان شده و تصویر نیز در مطلب قرار داده شده و در بعضی موارد فقط مطلب Copy Paste شده است به بزرگی خودتان ببخشید دوستان 


این تابع تعیین می کند آیا نقطه داخل ناحیه مشخص شده است یا خیر .فرضا یک ناحیه بیضوی درست کرده اید در WM_PAINT و می خواهید زمانیکه Mouse را داخل آن منطقه بردید کاری را برای شما انجام دهد ، lParam در WM_MOUSEMOVE قسمت loword آن xmouse و قسمت hiword آن ymouse است .


The PtInRegion function determines whether the specified point is inside the specified region.


SetRect R, 0, 0, 50, 50
'Create an elliptical region
mRGN = CreateEllipticRgnIndirect(R)

For x = R.Left To R.Right
For y = R.Top To R.Bottom
'If the point is in the region, draw a green pixel
If PtInRegion(mRGN, x, y) <> 0 Then
'Draw a green pixel

setpixel  ' Lib "gdi32"

SetPixel Me.hdc, x, y, vbGreen
ElseIf PtInRect(R, x, y) <> 0 Then
'Draw a red pixel
SetPixel Me.hdc, x, y, vbRed
End If






SubClassing The Window : win64


Private OldWindowProc As LongPtr

Const WM_CONTEXTMENU=&H7b

List_Of_Windows_Messages


Public Function NewWindowProc(ByVal hwnd As LongPtr, ByVal msg  As Long, ByVal wParam As LongPtr, ByVal lParam As LongPtr) As LongPtr
Const WM_NCDESTROY = &H82
Debug print Hex$(msg)
If msg = WM_NCDESTROY Then

SetWindowLonPtr hwnd,GWL_WNDPROC,OldWindowProc End If

NewWindowProc=CallWindowProc(OldWindowProc,hwnd,msg,wParam,lParam)

End Function







.









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 


PtInRect در کنترل Edit مربوط به پنجره InputBox



کار سختی نیست از منبعی که در  انتهای صفحه آمده استفاده شده که تابع ویندوزی است 





Declare PtrSafe Function PtInRect Lib "user32" (lpRect As RECT, pt As POINTAPI) As Long'

Use Belows Only

Declare PtrSafe Function PtInRect Lib "user32" (lpRect As RECT, ByVal x As Long, ByVal y As Long) As Long


 _  ,  Public Function EditSubclass(ByVal hwnd As LongPtr, ByVal Msg As Long, ByVal wParam As LongPtr
                            ByVal lParam As LongPtr, ByVal Uid As LongPtr, ByVal dwData As LongPtr) As Long

Static r As RECT
در پیام Paint  
      DefSubclassProc hwnd, Msg, wParam, ByVal lParam
      
       GetWindowRect hwnd, r
       OffsetRect r, -r.left, -r.top
       r.left = r.right - 20
       r.right = r.right
       r.bottom = r.bottom - 0.9
       r.top = r.top + 0.9
 Case WM_LBUTTONDOWN
      Dim p As POINTAPI
       Dim  nn As RECT
(p.x = CLng(lParam And 65535)  'LoWord(lParam
        (p.y = CLng(lParam \ 65535)  'HiWord(lParam
        GetClientRect hwnd, nn
        
        nn.left = r.left - 2
        nn.right = r.right + 2 


If  PtInRect(nn, p.x, p.y) Then 

    "  ... MsgBox "You Clicked Me

      End If

  .....RedrawWindow 






مورد بالا تست شده 





در 32 بیت 


Declare Function PtInRect Lib "user32.dll" (lpRect As RECT, ByVal x As Long, ByVal y As Long) As Long

Example
مثال زیر چک میکند کرسر ماوس داخل یا خارج از پنجره ی فرم یک است 

 Determine if the mouse cursor is inside or outside 
of  window Form1
که اینکار بوسیله ی چک کردن موقعیت کرسر ماوس به واحد Point در صفحه با مستطیل پنجره انجام شده.
This is done by checking the point of the mouse
.cursor with the rectangle of the window
دریافت مختصات ماوس در صفحه
Dim mousept As POINT_TYPE ' receives mouse 
coordinate
دریافت مستطیل فرم یک 
Dim winrect As RECT ' receives rectangle of Form1
دریافت عدد یک اگر داخل مستطیل باشد و صفر اگر در آن نباشد
Dim isinside As Long ' receives 1 if inside or 0 if outside
Dim retval As Long ' return value for other functions
تعیین موقعیت کرسر ماوس
retval = GetCursorPos(mousept) ' determine the  mouse cursor's position
گرفتن مختصات بالایی سمت چپ و مختصات پایینی سمت راست مستطیل فرم یک اگر کلاین رکت استفاده شود left و topرا صفرمی دهد.
retval = GetWindowRect(Form1.hWnd, winrect) ' determine Form1's rectangle
چک می کند تا ببینیم آیا کرسر ماوس داخل مستطیل فرم یک قرار دارد.
 Check to see if the mouse cursor is located inside'
of the Form1 rectangle

(isinside = (winrect, mousept.x, mousept.y
اگر کرسر ماوس داخل آن مستطیل باشد در پنجره ی دیباک یا  Ctrl+G چاپ میکند که کرسر ماوس در حال حاضر داخل فرم ۱ است و اگر داخل آن مختصات نباشد چاپ میکند کرسر ماوس هم اکنون بیرون از فرم یک است 
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




در کل PtInRect  چک میکند Point در داخل Rectangle هست یاخیر اگر باشد جوابش عدد غیر صفر است طبق داکیونت --->> ptinrect
منبع 


محصور کردن کرسر به منطقه مستطیل شکل در صفحه




ClipCurSor 
.Confines the cursor to a rectangular area on the screen

Parameters

lpRect

Type: const RECT*

A pointer to the structure that contains the screen coordinates of the upper-left and lower-right corners of the confining rectangle. If this parameter is NULL, 
.the cursor is free to move anywhere on the screen



Dim ptClientUL As POINTAPI  'client area upper lef corner 
Dim ptClientLR As POINTAPI 'client area lower right corner 
Static rcBmp As RECT 

WM_CREATE

(hdc=GetDC(hwnd
(hdcCompat=CreateCompatibleDC(hdc
SelectObject hdcCompat, hbmp
((hpenDot=CreatePen(PS_DOT,1,RGB(0, 0, 0
SetRect rcBmp, 1, 1, 34, 34

WM_PAINT

BeginPaint hwnd,ps
Rectangle ps.hdc,rcBmp.left,rcBmp.top,rcBmp.right, rcBmp.bottom
StretchBlt ps.hdc,rcBmp.left+1,rcBmp.top+1,(rcBmp.right-rcBmp.left)-2,(rcBmp.bottom-rcBmp.top)-2, hdcCompat,0,0,32,32,SRCCOPY
EndPaint hwnd,ps

WM_MOVE,WM_SIZE

'Convert the client coordinates of the client-area rectangle to screen coordinates and save them in a rectangle.The rectangle is passed to the ClipCursor function during WM_LBUTTONDOWN processing. 

GetClientRect hwnd,rcClient
ptClientUL.x = rcClient.left
ptClientUL.y = rcClient.top
ptClientLR.x = rcClient.right
ptClientLR.y = rcClient.bottom ClientToScreen hwnd,ptClientUL ClientToScreen hwnd,ptClientLR
SetRect rcClient,ptClientUL.x, ptClientUL.y,ptClientLR.x,ptClientLR.y)

WM_LBUTTONDOWN

ClipCursor rcClient
pt.x = (LONG) LOWORD(lParam) 
pt.y = (LONG) HIWORD(lParam)
if (PtInRect(&rcBmp, pt)) Then 
hdc=GetDC(hwnd)
SelectObject hdc,hpenDot
Rectangle hdc,rcBmp.left,rcBmp.top, rcBmp.right,rcBmp.bottom)
fDragRect=TRUE
ReleaseDC hwnd,hdc

WM_LBUTTONUP

' Release the mouse cursor.
ClipCursor  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'