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

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

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

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

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

تنظیم رنگ پس زمینه ی EDIT CONTROL


EM_SETBKGNDCOLOR

The EM_SETBKGNDCOLOR message sets the background color for a rich edit control.


wParam

Specifies whether to use the system color. If this parameter is a nonzero value, the background is set to the window background system color. Otherwise, the 
.background is set to the specified color

lParam

A COLORREF structure specifying the color if wParam 
.is zero. To generate a COLORREF, use the RGB macro




GWL_USERDATA



When you send a WM_CLOSE message to a window, it tries to close the window as if the X button were pressed.You cannot know whether the application was closed externally or by clicking the X button

But there is an easy alternative. When you are closing the window externally using WM_CLOSE, you can initialize its 32-bit user data value using the SetWindowLong function before sending the message. In the target application (being closed) you will query this user data using GetWindowLong function and execute your code accordingly.

The user data value is set to 0 by default. You can set it to any non-zero value before sending the WM_CLOSE 
.message


Set the user data value of the target window to -1'
(originally 0)'
WIN32'
SetWindowLong CurrApp,GWL_USERDATA,-1

send closing messgae'
CurrApp is a Handle to the window
&SendMessage CurrApp,WM_CLOSE, 0,ByVal 0

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    If GetWindowLong(hwnd, GWL_USERDATA) = 0 Then
        MsgBox "Closing from X."
    Else '(if -1)
        MsgBox "Closing externally using WM_CLOSE."
    End If
End Sub

تنظیم عنوان یا تکست کنترل در دیالوگ باکس #32770









GetDlgCtrlIDRetrieves the identifier of the specified control. 
GetDlgItemRetrieves a handle to a control in the specified dialog box. 








MENUBARINFO



Type rect
      Left As Long
      Top As Long
      Right As Long
      Bottom As Long
End Type

Type MENUBARINFO
     cbSize As Long
     rcBar As rect
     hMenu As Long
     hwndMenu As Long
     fBarFocused As Boolean
     fFocused As Boolean
End Type

Public Const OBJID_MENU As Long = &HFFFFFFFD
Pubic Const OBJID_SYSMENU As Long = &HFFFFFFFF


Dim mbi as MENUBARINFO
mbi.cbSize=LenB(mbi)
GetMenuBarInfo Me.hWnd,OBJID_MENU, lMenuNumber, mbi

Where "lMenuNumber" is 1 for the first (e.g. "File"), 2 for the second (e.g. "Edit"), etc.

rcBar.Left

تغییر کپشن و ترتیب چیدمان ( راست ) منوی سیستمی

MIIM_STRING = 64

MIIM_FTYPE = 256

MFT_RIGHTORDER = 0x2000

MF_BYPOSITION = 0x00000400



For j = 0 To MenuCount - 1

With mii

(BuffLen = GetMenuStringA(hMenu, j, Buff, Len(Buff) + 1, &H400

(txt = Left$(Buff, BuffLen

       (cbSize = Len(mii

    fMask = 64 Or 256

     fTyp = &H2000

      dwtypedata = arr(j) 'txt

      cch = Len(.dwtypedata) + 1

      .fState = &H3 'mfs_disabled

End With

SetMenuItemInfoA hSysMenu, GetMenuItemID(hMenu, j), 0, mii

Next







"InsertMenuA hSysMenu, 6, MF_BYPOSITION Or MF_STRING Or &H2000, 10200, ByVal "Salam

For j = 0 To (hc + 1) - 1






بعضی ازکلاس های فرم اکسس


البته  هندل  همه کنترل ها را نمیشود بدست آورد فقط چیزی که فعال باشد یا Active ولی در برنامه های ساخته شده ویندوزی هر کدام از کنترل ها دارای آیدی خودش است مثل دیالوگ باکس دیباگ اکسس  ( که کلاس سیستم را داراست ) که تمام باتن ها آیدی خودشون رو دارا هستند.


class name for Edit controls in Access=Okttbx

class name for an Access form's client window=OFormSub

(ComboParent=FindWindow("ODCombo",vbNullString
(DropDown=GetWindow(ComboParent, GW_CHILD
if DropDown="OGrid" Then 
if GetWindowLongPtrA(ComboParent,GWL_STYLE) And WS_VISIBLE Then
ComboOpen=True
End If
End If 

نمایش Bitmap کنار منو ( پیوند BitMap مشخص شده به آیتم منو )

Type: HBITMAP

A handle to the bitmap to be displayed, or it can be one of the values in the following table. It is used when the MIIM_BITMAP flag is set in the fMask member


uflags: MF_BYCOMMAND

hBitmap:LoadBitmap,LoadIcon,LoadImage







Dim mim As MENUITEMINFOA

(mim.cbSize = Len(mim

   mim.fMask = MIIM_BITMAP

mim.hbmpitem=1

SetMenuItemInfoA hSysMenu, 6, 1, mim


Use the GetSystemMetrics function with the CXMENUCHECK and CYMENUCHECK values to retrieve the bitmap dimensions.


تصویر بالا با استفاده از تابع زیر ( foo هندلی برای Bitmap ) و   loadimagea ( در آرگومان Type حتما IMAGE_BITMAP  استفاده شود ) بدست آمده  ضمنا  Bitmap ها در Shell32  در اینترنت وجود دارد و می توانید در سیستم خود لود نمایید و مانند زیر استفاده کنید .


windows_7_shell32_dll.shtml


SetMenuItemBitmaps hMenu, 1,MF_BYPOSITION, foo, foo


گرفتن استرینگ آیتم های SystemMenu


در تصویر بالا تعداد آیتم ها عدد 6 است 


szItem As String*100
((szItem=String$(100,Chr(0
(hSysMenu=GetSystemMenu(hwnd
(hSysMenuItmCount=GetMenuItemCount(hSysMenu,0
For i=0 To hSysMenuItmCount
(ItemId=GetMenuItemId(hSysMenu,i
(Length=GetMenuString(hSysMenu,i,szItem,Len(szItem)+1,MF_BYPOSITION
(txt=Left$(szItem,Length
Debug.Print txt,ItemId,i
Next

درباره ی تابع GetMenuString 

If the function succeeds, the return value specifies the number of characters copied to the buffer, not including the terminating null character.

If the function fails, the return value is zero.

If the specified item is not of type MIIM_STRING or MFT_STRING, then the return value is zero.

Remarks

The nMaxCount parameter must be one larger than the number of characters in the text string to accommodate the terminating null character.

If nMaxCount is 0, the function returns the length of the menu string.



درباره تابع  GetMenuItemCount 


Return Value

Type: int

اگر عملکرد موفقیت آمیزباشدمقداربرگشتی تعداد آیتم های منو خواهدبود.

If the function succeeds, the return value specifies the number of items in the menu.

If the function fails, the return value is -1


درباره  تابع  GetMenuItemId


Return Value

Type: UINT

مقدار برگشتی شناسه ی آیتم منوی مشخص شده خواهد بود اگر شناسه ی آیتم منو نال یا شامل ساب منو باشد عدد برگشتی 1- است که اثبات و تست شده.  

The return value is the identifier of the specified menu item. If the menu item identifier is NULL or if the specified item opens a submenu, the return value is -1.


درباره تابع ModifyMenu



(idItem=GetMenuItemID(hmenu, uItemPos

ModifyMenu hmenu,idItem,MF_BYCOMMAND+MF_STRING,idItem, szItem


Return Value

Type: BOOL

اگر تابع ( عملکرد ) موفقیت آمیز باشد مقدار برگشتی عددی غیرصفر است خواه مثبت یا منفی  و در صورت عدم موفقیت صفر را برخواهد گرداند.

If the function succeeds, the return value is nonzero

If the function fails, the return value is zero

EnableMenuItem در VB



(WndProc(ref Message m
    if  m.Msg = WM_INITMENUPOPUP
  (((int)m.LParam & 0x10000) != 0) 
   (EnableMenuItem(WParam,SC_MOVE,MF_DISABLED
End If

   

   

Handle Menu در VB


Private Const windowsMenuClassName As String= "#32768

(externalMenu=FindWindowEx(GetDesktopWindow,0,windowsMenuClassName,VbNullString
(PostMessage(externalMenu,WM_CLOSE, 0,0
End If 
End Sub

()Private Sub Timer1_Timer


Dim hMenuWnd As Long
(hMenuWnd = FindWindow ("# 32768", vbNullString
If hMenuWnd <> 0 Then
(( Me.Caption = CStr (SendMessage
(hMenuWnd, MN_GETHMENU, 0, 0
End If
End Sub

Mouse Hook

در سیستم 64 بیت



Public Function LowLevelMouseProc(ByVal nCode As Long, ByVal wParam As LongPtr, ByVal lParam As LongPtr) As LongPtr

If nCode > 0 Then

    Select Case wParam

         Case WM_NCDESTROY, WM_DESTROY

             UnhookWindowsHookEx hhk

         Case WM_RBUTTONDOWN, WM_RBUTTONUP

           LowLevelMouseProc = 1

        Exit Function

         Case Else

          ( LowLevelMouseProc = CallNextHookEx(hhk, nCode, wParam, lParam

     End Select

 End If

CallNextHookEx hhk, nCode, wParam, lParam

End Function





پیام اعلام راست کلیک توسط User به پنجره Right Clicked








Public Function MouseHookProc(ByVal nCode As Long,ByVal wParam As LongPtr,ByVal lParam As LongPtr) As LongPtr

      Dim MyMouseHookStruct As New
 ()MOUSEHOOKSTRUCT

Dim ret As Integer = 0

If (nCode < 0) Then
,Return CallNextHookEx(hHook, nCode, wParam
 (lParam

End If
If wParam = WM_RBUTTONDOWN Or wParam = WM_RBUTTONUP Then
Return -1
End If
,Return CallNextHookEx(hHook, nCode, wParam
 (lParam
End Function


باتن چپ ماوس در محیط NonClient پنجره




lparam موقعیتی درستی از کرسر نمیدهد پس رو ش حساب باز نکنیدچرا ؟ چون داکیومنتش داره میگه








    windows-data-type


WORD  :  A 16-bit unsigned integer. The range is 0 through 65535 decimal.
WPARAM : message parameter.
LPARAM : message parameter.
HWND : A handle to a window.


لود کردن آیکون ، کرسر یا بیتمپ



LoadImageA   loadimagea


نحوه ی اظهار یا فراخوانی در سیستم 64 بیتی : 


Declare PtrSafe Function LoadImageA Lib "user32 (ByVal hInst As LongPtr, ByVal lpsz As String, ByVal ImgType As Long, ByVal cx  As Long, ByVal cy As Long, ByVal ufLoad As Long) As LongPtr


(hIcon=LoadImageA(0,"D:\ico1.ico",IMAGE_ICON,16,16,LR_LOADFROMFOLE



: (LR_LOADFROMFILE(&H10

Loads the stand-alone image from the file specifiedLby lpszName(icon,cursor, or bitmap file










نمایش آیکون در حالت  بزرگ  زمانیکه ALT+TAB 

را می فشارید و در مد کوچک در عنوان یا کپشن پنجره و ارسال با تابع ویندوزی SendMessageA که Msg همان WM_SETICON میشود wParam که در تصویر پائین ذکر شده  ICON_BIG یا ICON_SMALL  و  lParam هم  همان hIcon ذکر شده در بالا 


Declare PtrSafe Function SendMessageA Lib "User32" (ByVal hwnd As LongPtr,ByVal uMsg As Long,ByVal wParam As LongPtr,ByVal lParam As LongPtr) As LongPtr






غیرفعال کردن SysMenu




#Get System menu of windows handled
(hMenu=GetSystemMenu(hwnd, 0
 
#Window Style : TOOLWINDOW
SetWindowLongPtrA(hwnd, GWL_EXSTYLE 
WS_EX_TOOLWINDOW) | Out-Null,

#Disable X Button and window itself
Enablemenuitem(hMenu, SC_CLOSE, MF_DISABLED)| Out-Nul
EnableWindow(hwnd, 0) | Out-Nul

ثابت های استایل پنجره برای تغییر یا ساخت



window-styles


استفاده در SetWindowLongPtrA در 64 بیت یا SetWindowLongA در 32 بیت 


'\ Window Style
Public Enum enWindowStyles
    WS_BORDER = &H800000
    WS_CAPTION = &HC00000
    WS_CHILD = &H40000000
    WS_CLIPCHILDREN = &H2000000
    WS_CLIPSIBLINGS = &H4000000
    WS_DISABLED = &H8000000
    WS_DLGFRAME = &H400000
    WS_EX_ACCEPTFILES = &H10&
    WS_EX_DLGMODALFRAME = &H1&
    WS_EX_NOPARENTNOTIFY = &H4&
    WS_EX_TOPMOST = &H8&
    WS_EX_TRANSPARENT = &H20&
    WS_EX_TOOLWINDOW = &H80&
    WS_GROUP = &H20000
    WS_HSCROLL = &H100000
    WS_MAXIMIZE = &H1000000
    WS_MAXIMIZEBOX = &H10000
    WS_MINIMIZE = &H20000000
    WS_MINIMIZEBOX = &H20000
    WS_OVERLAPPED = &H0&
    WS_POPUP = &H80000000
    WS_SYSMENU = &H80000
    WS_TABSTOP = &H10000
    WS_THICKFRAME = &H40000
    WS_VISIBLE = &H10000000
    WS_VSCROLL = &H200000

فرآیند پیام ارسال شده به پنجره WindowProc

Subclassing Controls



Declare PtrSafe Function CallWindowProcA Lib "user32" (ByVal lpPrevWndFunc As LongPtr, ByVal hwnd As LongPtr, ByVal Msg As Long, ByVal wParam As LongPtr, ByVal lParam As LongPtr) As Long

Declare PtrSafe Function SetWindowLongPtrA Lib "user32" (ByVal hwnd As LongPtr, ByVal nIndex As Long,ByVal dwNewLong As LongPtr) As Long

(Public Const GWL_WNDPROC = (-4

Global oldwndproc As LongPtr
Global wndHW As LongPtr




: Form_Load

wndHw=Me.Hwnd

(oldwndproc = SetWindowLongPtrA(Me.hwnd, GWL_WNDPROC, AddressOf WndProc


Form_Unload

SetWindowLongPtrA wndHw, GWL_WNDPROC, oldwndproc



Public Function WndProc(ByVal lhwnd As LongPtr, ByVal uMsg As Long, ByVal wParam As LongPtr, ByVal lParam As LongPtr) As Long

If uMsg = 516 Then 'WM_RBUTTONDOWNU           

        'Debug.Print "Intercepted WM_CONTEXTMENU at " & Now                        

       " MsgBox "Mouse Right Button Was Clicked                       

          WndProc=-1                      

ElseIf uMsg = WM_KEYDOWN Then        

           MsgBox wParam                    

             WndProc = True                    

     Else ' Send all other messages to the default message handler     

        (WndProc = CallWindowProcA(oldwndproc, lhwnd, uMsg, wParam, lParam

     End If

     

End Function



Public Const WM_KEYDOWN = &H100
Public Const WM_KEYUP = &H101
Public Const WM_CHAR = &H102
Public Const VK_RETURN = &HD
Public Const VK_UP = &H26
Public Const VK_DOWN = &H28
Public Const VK_HOME = &H24
Public Const VK_LEFT = &H25
Public Const VK_PRIOR = &H21
Public Const VK_LBUTTON = &H1  ' Left mouse button
Public Const VK_RBUTTON = &H2  ' Right mouse button
Public Const VK_MBUTTON = &H4  ' Middle mouse button (three-button mouse)

Public Const SC_SIZE = &HF000&
Public Const SC_MOVE = &HF010&
Public Const SC_MINIMIZE = &HF020&
Public Const SC_MAXIMIZE = &HF030&
Public Const SC_NEXTWINDOW = &HF040&
Public Const SC_PREVWINDOW = &HF050&
Public Const SC_CLOSE = &HF060&














Const WM_NCLBUTTONDOWN As Integer = 161
Const WM_SYSCOMMAND As Integer = 274
Const HTCAPTION As Integer = 2
Const SC_MOVE As Integer = 61456

If (Msg = WM_SYSCOMMAND) And (WParam = SC_MOVE) Then
Return
End If

If (Msg = WM_NCLBUTTONDOWN) And (WParam = HTCAPTION) Then
Return
If (Msg = WM_RBUTTONDOWN) And (WParam = WM_RBUTTONDOWN) Then
Return
End If


وقتی دابل کلیک روی قسمت تایتل بار انجام میشود یا بعبارتی  قسمت کپشن پنجره عمل ماکسیمایز پنجره انجام خواهد گرفت

If umsg = WM_NCLBUTTONDBLCLK And wParam = 2 Then Exit Function

SYsMenu عمل نکردن منوهای تایتل بار یا 

If umsg = WM_SYSCOMMAND And ((wParam = SC_CLOSE) Or (wParam = SC_MINIMIZE) Or (wParam = SC_MAXIMIZE)) Then
Exit Function

مثال دیگر :
    wm-ncdestroy   &H82
If Msg = WM_NCDESTROY Then 
SetWindowLong hWnd,GWL_WNDPROC,OldWindowProc
End If 
If Msg <> WM_CONTEXTMENU Then
NoPopupWindowProc = CallWindowProc(OldWindowProc,hWnd
,Msg,wParam,lParam)

----------------------------------------

 اگر از HOOK  استفاده شود و آیدی WH_MOUSE یا WH_MOUSE_LL


If Wparam=WM_NCLBUTTONDBLCLK Then 
     MouseHookProc=NoneZero
End If



WM_RBUTTONDOWN   wm-rbuttondown   &H204

(20×16)×1.6+4=516 ( DECIMAL )


516÷16=32  

516-(32×16)=4

(516÷16)×10=320

320÷16=20



List Of Windows Message  SendMessageList

ویندوزمسیج( ScrollBar ) حرکت اسکرول در واحد Unit

SendMessageA HandleWindow,WindowseMessage,Wparam(ScrollBar

Constants),lparam:Null