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

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

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

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

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

ListBox در InputBox




vb Uses Unicode for text string so use SendMessageW instead Of SendMessageA Function 



The list box has the LBS_OWNERDRAWFIXED and LBS_HASSTRINGS styles, in addition to the standard list box styles.


LBS_HASSTRINGS


Specifies that a list box contains items consisting of strings. The list box maintains the memory and addresses for the strings so that the application can use the LB_GETTEXT message to retrieve the text for a particular item. By default, all list boxes except owner-drawn list boxes have this style. You can create an owner-drawn list box either with or without this style.


کاملا به دو نکته ی زیر توجه شود : 

To obtain the exact length of the text, use the WM_GETTEXTLB_GETTEXT, or CB_GETLBTEXT messages, or the GetWindowText function



LB_GETTEXT


The return value is the length of the string, in TCHARs, excluding the terminating  

(null character  ( hence buff+1


If the list box has an owner-drawn style but not the LBS_HASSTRINGS style, the buffer pointed to by the lParam parameter receives the value associated  with the item the item data

Means Use Byval


If the list box has WS_HSCROLL style and you insert a string wider than the list box, send an LB_SETHORIZONTALEXTENT message to ensure the horizontal scroll bar appears.




Case WM_MEASUREITEM



Case WM_DRAWITEM

   

 

    Dim pdis As DRAWITEMSTRUCT

    Dim tm As TEXTMETRIC

    Dim hDCMem As LongPtr


 CopyMemory pdis, ByVal lParam, 40

Select Case pdis.itemAction

          Case ODA_SELECT, ODA_DRAWENTIRE



Dim p As RECT

         GetClientRect pdis.hwndItem, pdis.rcitem


BitBlt pdis.hdc


SetBkMode pdis.hdc, 0

                        SetTextColor pdis.hdc, vbRed

                        TextOutA pdis.hdc, pdis.rcitem.Left,pdis.rcitem.Top, buffer$, 5


CopyMemory lParam, pdis,40

End Select 






گرفتن  تعداد آیتم ها در لیست باکس 



LB_GETCOUNT message

Gets the number of items in a list box


wParam,lParam

Not used; must be zero


Dim index As Integer
Dim textBuff As String
(textBuff = Space(255
(NumItems=SendMessage(hWndList,LB_GETCOUNT,0,0


index use GETCURSEL'

Gets the index of the currently selected item)'

(if any, in a single-selection list box'


SendMessageW hWndList, LB_GETTEXT,index, textBuff
MsgBox textBuff 




docs.microsoft.com/enmeasureitemstruct


مثالی از کشیدن نقطه چین دور آیتم سلکت شده به زبان دیگر 



if  lpdis->itemState & ODS_SELECTED


* Set RECT coordinates to surround only the'

* bitmap.


rcBitmap.left=lpdis->rcItem.left

rcBitmap.top=lpdis->rcItem.top

rcBitmap.right=lpdis->rcItem.left+XBITMAP

rcBitmap.bottom=lpdis->rcItem.top + YBITMAP


* Draw a rectangle around bitmap to indicate'

* the selection.


DrawFocusRect lpdis->hDC, &rcBitmap




استفاده در مثال شکل بالا  به زبان دیگر 


 Display the text associated with the item'

SendMessage lpdis->hwndItem

LB_GETTEXT,lpdis->itemID, (LPARAM) tchBuffer,

GetTextMetrics lpdis->hDC, &tm

GetClientRect lpdis.hwnditem,lpdis.rcItem'


-y=(lpdis->rcItem.bottom+lpdis->rcItem.top

tm.tmHeight) / 2


6+TextOutA lpdis->hDC,XBITMAP

(y,tchBuffer,len(tchBuffer,


SelectObject hdcMem, hbmpOld

DeleteDC hdcMem






The GetTextMetrics function fills the specified buffer with the metrics for the currently selected font

BOOL GetTextMetrics( HDC hdc, LPTEXTMETRIC lptm );

Parameters

hdc

A handle to the device context

lptm

A pointer to the TEXTMETRIC structure that receives the text metrics.


Type TEXTMETRICA
tmHeight As Long
tmWeight As Long
tmItalic As Long
tmMaxCharWidth As Long
tmUnderlined As Long
tmCharSet As Long
End Type




 : case WM_MEASUREITEM
;lpmis = (LPMEASUREITEMSTRUCT) lParam
;lpmis->itemHeight=20
;return TRUE

(DrawEntire(LPDRAWITEMSTRUCT lpDStruct

;(CRect rect(lpDStruct->rcItem
;HDC dc =lpDStruct->hDC
;MYLISTITEM *a = (MYLISTITEM*)lpDStruct->itemData

TextOut(dc,rect.left+20,rect.top+2,a->title,strlen(a-

;((title<

(if (lpDStruct->itemState & ODS_FOCUS
}

;(DrawFocusRect(dc,rect

{

clean up //

;(SelectObject(dc,hOldFont

;(SelectObject(dc,oldpen

;(SelectObject(dc,oldbrush



;logFont.lfHeight = 16
;logFont.lfWeight = FW_BOLD

;("strcpy(logFont.lfFaceName,"courier

;(hFont = CreateFontIndirect(&logFont

(hOldFont = (HFONT)SelectObject(dc,hFont








DateTime




msctls_progress32     ProgressBar

SysDateTimePick32   Custom

PostMessage(hWnd, WM_CHAR, '3', 0); (where '3' is the actual key typed in) –


Private Const DTS_SHORTDATEFORMAT As Long = &H0
Private Const DTS_SHOWNONE As Long = &H2
Private Const DATETIMEPICK_CLASS As String = SysDateTimePick32



Dim hDT As Long 
WS_EX_CLIENTEDGE Or WS_EX_LEFT Or WS_EX_LTRREADING Or WS_EX_RIGHTSCROLLBAR

WS_CHILD Or WS_OVERLAPPED Or WS_VISIBLE Or DTS_SHORTDATEFORMAT Or DTS_SHOWNONE

,


Type SYSTEMTIME
wYear                    ' 1601 To 30827
wMonth                ' 1 To 12 
wDayOfWeek       ' 0 To 6
wDay                    ' 1 To 31
wHour                  ' 0 To 23
wMinute              ' 0 To 59
wSecond             ' 0 To 59
wMilliseconds    ' 0 To 999
End Type 


DTS_TIMEFORMAT 
"The display will look like: "5:31:42 PM


DTM_SETFORMAT message

Sets the display of a date and time picker (DTP) control based on a given format string


wParam

Must be zero

lParam

A pointer to a zero-terminated format stringthat defines the desired display. Setting this parameter to NULL will reset the control to the default format string for the current style

For example, the format string "'Today is: 'hh':'m':'s ddddMMMdd', 'yyy" would produce output like "Today is: 04:22:31 Tuesday Mar 23, 1996".


DTS_UPDOWN

Places an up-down control to the right of the DTP control to modify date-time values. This style can be used in place of the drop-down month calendar, which is the default style.





Public Const DTM_SETFORMATA = &H1005

   '"SendMessageA hdtp, DTM_SETFORMATA, 0, ByVal "yyyy/M/d












ProgressBar نوار پیشرفت




PBM_SETRANGE=&H401
PBM_SETPOS=&H402
PBM_DELTAPOS=&H403
PBM_SETSTEP=&H404
PBM_STEPIT=&H405
PBM_SETRANGE32=&H406
PBM_GETRANGE=&H407
PBM_GETPOS=&H408
PBM_SETBARCOLOR=&H409
PBM_SETMARQUEE=&H40A


PBS_SMOOTH=&H1
PBS_VERTICAL=&H4
PBS_MARQUEE=&H8
PBS_SMOOTHREVERSE=&H10

PBST_NORMAL=&H1
PBST_ERROR=&H2
PBST_PAUSED=&H3


PBM_GETPOS message

Retrieves the current position of the progress bar


Parameters

wParam

Must be zero

lParam

Must be zero




PBM_SETPOS message

Sets the current position for a progress bar and redraws the bar to reflect the new position

Parameters

wParam

Signed integer that becomes the new position

lParam

Must be zero


PBM_SETSTEP message


Specifies the step increment for a progress bar. The step increment is the amount by which the progress bar increases its current position whenever it receives a PBM_STEPITmessage. By default, the step increment is set to 10

Parameters

wParam

New step increment

lParam

Must be zero



case UDN_DELTAPOS

lpnmud = (LPNMUPDOWN)lParam

iPosIndicated =SendMessage(hwndProgBar
(PBM_GETPOS,(WPARAM)0, (LPARAM)0,

SendMessage(hwndProgBar, PBM_SETPOS,(WPARAM)(iPosIndicated + lpnmud->iDelta,0


lParam

Pointer to an NMUPDOWN structure that contains information about the position change. The iPos member of this structure contains the current position of the control. The iDelta member of the structure is a signed integer that contains the proposed change in position


If the user has clicked the up button, this is a positive value

If the user has clicked the down button, this  is a negative value







زمان ساختن  کنترل نوار پیشرفت 

SendMessage(hControl,
((PBM_SETRANGE,0,MAKELPARAM(0, 100,

SendMessage(hControl, PBM_SETSTEP, (WPARAM) 1,
(0,

Parameters

wParam

State of the progress bar that is being set. One of the following values.

ValueMeaning
PBST_NORMAL
In progress.
PBST_ERROR
Error.
PBST_PAUSED
Paused.

lParam

Must be zero.





Case WM_COMMAND
    Dim iPosIndicated As LongPtr
     If lParam = hbtn Then 
    " SetWindowTextA hbtn, "JK
     SendMessageA hprog, PBM_SETSTEP, 1, 0

     Do While pp < 102
     'SetWindowTextA hwnd, nmp.iPos
            SendMessageA hprog, PBM_SETPOS,  pp, 0
       pp = pp + 1
       Loop
     End If









SetWindowLongPtr hprog, GWL_STYLE, GetWindowLongPtrA(hprog, GWL_STYLE) Or PBS_VERTICAL









EM_SETMARGINS پیامی برای تنظیم حاشیه در EDIT BOX



تنظیم حاشیه در کنترل EDIT


 : wparam

EC_LEFTMARGIN=&H1

EC_RIGHTMARGIN=&H2

:  Msg

    EM_SETMARGINS=211 '&HD3

 

دسیمال 211 تبدیل به هگزا - ->> عدد دسیمال تقسیم بر 16 میشود 13 معادل آن D و حاصل تفریق عدد211 و حاصلضرب 13 در 16 میشود 3 .... نهایتا از کنار هم گذاشتن آنها D3 بدست می آید ، در  تابع زیر پارامتر هندل Et ذکر شده و منظور گرفتن هندل Edit است که با FindWindowEx انجام شده.


SendMessageA Et, 211, &H1, ByVal  25

       SendMessageA Et, 211, &H2, ByVal 65536 * 50



تست شده طبق شکل زیر که تمام تکست داخل EDIT BOX با Ctrl+A انتخاب شده در نتیجه مارجین یا حاشیه مشخص است . البته باید دید تغییر فونت چه تاثیری خواهد گذاشت .





SWP_FRAMECHANGED  0x0020


Applies new frame styles set using the SetWindowLongfunction. Sends a WM_NCCALCSIZE message to the window, even if the window's size is not being changed. If this flag is not specified, WM_NCCALCSIZEis sent only when the window's size is being changed.


SWP_FRAMECHANGED = &H20

Fully redraw the window in its new 

.position


SWP_FRAMECHANGED   Sends a WM_NCCALCSIZEmessage to the window, even if the window's size is not being changed. If this flag is not specified, WM_NCCALCSIZE is sent only when the window's size is being changed.



ارسال آیکون به باتن با پیام BM_SETIMAGE و تابع ارسال پیام به دیالوگ باکس و آیدی باتن که یک است.  image_icon=1 , un1=1 

CreatePen ساخت قلم برای ترسیم



HPEN CreatePen( int iStyle, int cWidth, COLORREF color );


()Edit::OnNcPaint

pDC=GetDC( ) ? GetWindowDC
GetWindowRect Edithwnd,Crect 
OffsetRect Crect,-rect.left,-rect.top
'Draw a single line around the outside
(brush=RGB( 255, 0, 0
FrameRect pDC,Crect,brush ReleaseDC hwnd,pDC


Const PS_SOLID = 0
Const PS_DASH = 1
Const PS_DOT = 2
Const PS_DASHDOT = 3
Const PS_DASHDOTDOT = 4
Const PS_NULL = 5
Const PS_INSIDEFRAME = 6



((hPen=CreatePen(PS_DASH,0,RGB(0,255, 0
(hOldPen=SelectObject(hDC,hPen
Ellipse hDC, 100, 150, 350, 300
SelectObject hDC, hOldPen
DeleteObject hPen




مورد زیر طبق شکل تست شده 


حتما در WndProc در پیام SHOWWINDOW تابع زیر اعمال گردد
SetWindowPos hwnd,0,0,0,0,0,SWP_FRAMECHANGED 

ساب کلاس کردن  کنترل  Edit 

Public Function SubClassEdit(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
Dim nccsp As NCCALCSIZE_PARAMS
Select Case Msg

Case WM_NCPAINT
     (hdc = GetDC(hwnd
     Dim rClient As RECT
     GetClientRect hwnd, rClient
    ( hpen = CreatePen(ps_solid, 2, vbRed
    ( holdpen = SelectObject(hdc, hpen
     RoundRect hdc, rClient.Left - 2, rClient.Top - 2, rClient.right + 2, rClient.bottom + 2, 6, 6
     ReleaseDC hwnd, hdc
     DeleteObject holdpen
Case WM_DESTROY
      RemoveWindowSubclass hwnd, SubClassEdit, 0
      End Select
      
(SubClassEdit = DefSubclassProc(hwnd, Msg, wParam, ByVal lParam
                            
End Function


SWP_FRAMECHANGED 0x0020

Applies new frame styles set using the SetWindowLongfunction. Sends a WM_NCCALCSIZE message to the window, even if the window's size is not being changed. If this flag is not specified, WM_NCCALCSIZEis sent only when the window's size 
.is being changed







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








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







BUTTON_CLICK ( ترسیم لبه در پنجره کلاس 32770# )



در BS_OWNERDRAW یا خود Button  کار نمی کند نتیجتا ترسیم شد ( منظور ناحیه ای که در تصویر پایین داخلش  تکست Inside ترسیم شده) .   DrawEdge و DrawTextA


dim rr as RECT

If wMsg = WM_PAINT Then


        z1.Left = 285 + GetSystemMetrics(SM_CYFRAME) * 3 ' 296

        z1.right = 348 + GetSystemMetrics(SM_CYFRAME) * 2 ' 355

        z1.Top = 63 + GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYFRAME) * 2 ' 95

        z1.bottom = 86 + GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYFRAME) + 2 ' 115

     

    (WindProc = DrawEdge(GetWindowDC(hwnd), z1, EDGE_RAISED, BF_RECT + BF_ADJUST

End If


If wMsg = WM_LBUTTONDOWN Then 'WM_MOUSEMOVE

       

       Dim cp As POINTAPI

SetRect rr, 285, 63, 348, 86

      

      GetCursorPos cp

      ScreenToClient hwnd, cp


rr.Left = rr.Left + 2

       rr.right = rr.right - 2

       rr.Top = rr.Top - cp.y + 2

       rr.bottom = rr.bottom - cp.y - 2



If PtInRect(rr, cp.x, cp.y) Then


End If 



اگر شکل را مشاهده کنید زمان فشردن باتن سمت چپ ماوس در مستطیل موردنظر با مختصات صفحه در قسمت کپشن ویندو هم IN ارسال میشود 

















تایمر بستن پنجره با کلاس 32770#



بسته شدن پنجره زمانیکه کپشن به عدد 10 رسید.

 : 64BIT

Declare PtrSafe Function SetTimer Lib "user32" Alias "SetTimer" (ByVal hWnd As LongPtr, ByVal nIDEvent As LongPtr, ByVal uElapse As Long, ByVal lpTimerFunc As LongPtr) As LongPtr
Declare PtrSafe Function KillTimer Lib "user32" Alias "KillTimer" (ByVal hwnd As LongPtr, ByVal nIDEvent As LongPtr) As Long


Private Const TIMER1 = 1001

SetTimer hWndMainWnd,TIMER1,1000,0


(WndProc(HWND hWnd,UINT uMsg,WPARAM 

Static xtimer

    Select Case uMsg

      xtimer=xtimer+1

    case WM_TIMER

        if wParam = TIMER1

          SetWindowTextA hwnd, xtimer

           If xtimer = 10 Then SendMessageA hwnd, WM_CLOSE, 0, 0: xtimer = 0

        End if 

عدم نمایش شورتکات در ادیت کنترل در ساب کلاس کردن  Case WM_CONTEXTMENU 

            Exit Function

    Case WM_DESTROY, WM_NCDESTROY

          KillTimer hwnd, TIMER1

          xtimer = 0



مورد بالا تست شده و طبق منبع اعمال گردیده


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
منبع 


EDIT CONTROL اعلان ( Notification) / محدودیت تکست / ارسال تکست Edit به کپشن پنجره اصلی



EN_CHANGE 


wParam

The LOWORD contains the identifier of the edit control. The HIWORD specifies the notification code.

lParam

A handle to the edit control.


Edit styles const'
ES_LEFT = 0x0000
ES_CENTER = 0x0001
ES_RIGHT = 0x0002
ES_MULTILINE = 0x0004
ES_UPPERCASE = 0x0008
ES_LOWERCASE = 0x0010
ES_PASSWORD = 0x0020
ES_AUTOVSCROLL = 0x0040
ES_AUTOHSCROLL = 0x0080
ES_NOHIDESEL = 0x0100
ES_OEMCONVERT = 0x0400
ES_READONLY = 0x0800
ES_WANTRETURN = 0x1000
ES_NUMBER = 0x2000
  Edit notifications const' 
EN_SETFOCUS = 0x0100
EN_KILLFOCUS = 0x0200
EN_CHANGE = 0x0300
EN_UPDATE = 0x0400
EN_ERRSPACE = 0x0500
EN_MAXTEXT = 0x0501
EN_HSCROLL = 0x0601 
EN_VSCROLL = 0x0602
EN_ALIGN_LTR_EC = 0x0700
EN_ALIGN_RTL_EC = 0x0701
  Edit messages const'
EM_GETSEL = 0x00B0
EM_SETSEL = 0x00B1
EM_GETRECT = 0x00B2
EM_SETRECT = 0x00B3
EM_SETRECTNP = 0x00B4
EM_SCROLL = 0x00B5
EM_LINESCROLL = 0x00B6
EM_SCROLLCARET = 0x00B7
EM_GETMODIFY = 0x00B8
EM_SETMODIFY = 0x00B9
EM_GETLINECOUNT = 0x00BA
EM_LINEINDEX = 0x00BB
EM_SETHANDLE = 0x00BC
EM_GETHANDLE = 0x00BD
EM_GETTHUMB = 0x00BE
EM_LINELENGTH = 0x00C1
EM_REPLACESEL = 0x00C2
EM_GETLINE = 0x00C4
EM_LIMITTEXT = 0x00C5
EM_CANUNDO = 0x00C6
EM_UNDO = 0x00C7
EM_FMTLINES = 0x00C8
EM_LINEFROMCHAR = 0x00C9
EM_SETTABSTOPS = 0x00CB EM_SETPASSWORDCHAR = 0x00CC EM_EMPTYUNDOBUFFER = 0x00CD EM_GETFIRSTVISIBLELINE = 0x00CE EM_SETREADONLY = 0x00CF EM_SETWORDBREAKPROC = 0x00D0 EM_GETWORDBREAKPROC = 0x00D1 EM_GETPASSWORDCHAR = 0x00D2 EM_SETMARGINS = 0x00D3
EM_GETMARGINS = 0x00D4
EM_SETLIMITTEXT = EM_LIMITTEXT EM_GETLIMITTEXT = 0x00D5
EM_POSFROMCHAR = 0x00D6
EM_CHARFROMPOS = 0x00D7
EM_SETIMESTATUS = 0x00D8
EM_GETIMESTATUS = 0x00D9
EM_SETCUEBANNER = 0x1501
EM_GETCUEBANNER = 0x1502



EM_LIMITTEXT message 

.Sets the text limit of an edit control

wParam

The maximum number of TCHARs the user can enter. For ANSI text, this is the number of bytes; for Unicode text, this is the number of characters. This number does
.  not include the terminating null character

lParam

.This parameter is not used

) LRESULT WINAPI SendDlgItemMessage
_In_ HWND   hDlg,
_In_ int    nIDDlgItem,
_In_ UINT   Msg,
_In_ WPARAM wParam,
_In_ LPARAM lParam
;(


در InputBox  زیر با کلاس 32770#  که تست شده  در کنترل Edit آن با آیدی 4900 نمی توان بیشتر از 10 کاراکتر واردنمود



Case WM_SHOWWINDOW     
          SendDlgItemMessageA hwnd, 4900, EM_LIMITTEXT, 0, 10

پیام 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'