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

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

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

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

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

Hook ؛ کنترل یا رهگیری Mouse Action




Responding To Mouse Click mouse-click




hook  is a mechanism by which an application can intercept events, such as

 messages, mouse actions, and keystrokes



(HHOOK SetWindowsHookExA( int idHook, HOOKPROC lpfn, HINSTANCE hmod, DWORD dwThreadId 

WH_MOUSE_LL=14


CALLBACK LowLevelMouseProc( _In_ int    nCode, _In_ WPARAM wParam, _In_ LPARAM lParam

HC_ACTION=0


wParam [in]
Type: WPARAM

The identifier of the mouse message. This parameter can be one of the following messages: WM_LBUTTONDOWN, WM_LBUTTONUP, WM_MOUSEMOVE, WM_MOUSEWHEEL, WM_MOUSEHWHEEL, WM_RBUTTONDOWN, or WM_RBUTTONUP.

If nCode is less than zero, the hook procedure must return the value returned by CallNextHookEx.

(CallNextHookEx( HHOOK hhk, int nCode, WPARAM wParam, LPARAM lParam

باتن چپ ماوس در محیط 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






مشخص کردن حالت نمایش پنجره


ShowWindow   showwindow


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


Declare PtrSafe Function ShowWindow Lib "user32" (ByVal lhwnd As LongPtr, ByVal nCmdShow As Long) As Long







غیرفعال کردن 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

SubClassing



SetWindowSubclass hwnd,SubClassProc&,1,0


 SubClassProc(Byval hwnd as Longptr,Byval uMsg As Long,Byval wParam as LongPtr,Byval lParam As LongPtr,Byval uId As Long,Byval dwRef as Long) As LongPtr


DefSubClassProc Hwnd,uMsg,wParam,lParam


RemoveWindowSubClass hwnd,SubClassProc&,1



GWL_WNDPROC=-4


lpfnOld=SetWindowLongA(hwnd,GWL_WNDPROC,Address

( Of WndProc






(Of WNDProc



   ( GetPropA hwnd,lPstring       (Retrieve A Data Handle 


SetPropA hwnd,lPstring,hData


RemovePropA hwnd,lPstring 



WndPro(Byval hwnd as LongPtr,Byval uMsg

 as Long,Byval wParam as LongPtr,Byval lParam as LongPtr) As LongPtr

Select Case uMsg

Case WM_NCDESTROY ' &H82

  Call UnSubClass( hwnd)   'Built-In Function

End Select

)WndProc=CallWindowProcA

((GetPropA(hwnd,OldWndProc),hwnd,uMsg,wParam,lParam





مسیج های ویندوزی



' { W
' WH_* constants used for SetWindowsHookEx {
'
public const WH_CBT = 5
public const WH_KEYBOARD_LL = 13 ' Low level keyboard events
public const WH_SHELL = 10 ' Notification of shell events, such as creation of top level windows.
' }
' { WM_*: Window messsages
public const WM_CHAR = &h0102
public const WM_DESTROY = &H0002
public const WM_CLOSE = &H0010
public const Wm_CREATE = &H0001
public const WM_PAINT = &H000F
public const WM_KEYDOWN = &h0100
public const WM_KEYUP = &h0101
public const WM_SYSKEYUP = &h0105
public const WM_SETTEXT = &h000C public const WM_SETTINGCHANGE = &H001A
public const WM_SYSKEYDOWN = &h0104
public const WM_SIZE = &h0005 ' } ' { WS_* / Window styles
public const WS_THICKFRAME = &H40000
public const WS_VISIBLE = &H10000000
public const WS_VSCROLL = &H200000
public const WS_MAXIMIZE = &H1000000
public const WS_TABSTOP = &H10000
public const WS_BORDER = &H800000
public const WS_MAXIMIZEBOX = &H10000
public const WS_MINIMIZE = &H20000000
public const WS_MINIMIZEBOX = &H20000
public const WS_DLGFRAME = &H400000
public const WS_SYSMENU = &H80000
public const WS_CLIPSIBLINGS = &H4000000
public const WS_CAPTION = WS_BORDER or WS_DLGFRAME
public const WS_CHILD = &H40000000
public const WS_CLIPCHILDREN = &H2000000
public const WS_CHILDWINDOW = WS_CHILD public const WS_DISABLED = &H8000000
public const WS_GROUP = &H20000
public const WS_EX_ACCEPTFILES = &H10&
public const WS_EX_DLGMODALFRAME = &H1&
public const WS_EX_STATICEDGE = &H20000
public const WS_EX_NOPARENTNOTIFY = &H4& public const WS_EX_TOPMOST = &H8&
public const WS_POPUP = &H80000000
public const WS_EX_TRANSPARENT = &H20& public const WS_HSCROLL = &H100000
public const WS_ICONIC = WS_MINIMIZE
public const WS_OVERLAPPED = &H0&
public const WS_OVERLAPPEDWINDOW = WS_OVERLAPPED or WS_CAPTION or WS_SYSMENU or WS_THICKFRAME or WS_MINIMIZEBOX or WS_MAXIMIZEBOX
public const WS_TILEDWINDOW = WS_OVERLAPPEDWINDOW
public const WS_POPUPWINDOW = WS_POPUP or WS_BORDER or WS_SYSMENU
public const WS_SIZEBOX = WS_THICKFRAME
public const WS_TILED = WS_OVERLAPPED

ارسال اسکی کد به پنجره ی کلاس Edit


VK_CONTROL=&H11
VK_RETURN=&HD        '  Enter       Key 
VK_PRIOR=&H21          '  PAGE UP Key
VK_NEXT=&H22           '  PAGE DOWN Key
قسمت بالا در WM_KeyDown کاربرد دارند 
H31                             '  1                     Key&



WM_KEYDOWN=&H100

WM_CHAR = &H102



asciiChar مثل &H32   ارسال عدد 32


(SendMessageA(hwndEdit, WM_CHAR, asciiChar, 0    



You can unhide the menu bar in Acrobat itself by pressing the “F9” key on Windows


AVPageView در Acrobat.Exe

 

if GetClassNameTxt(pHwnd)="AVL_AVView" And GetWindowText(pHwnd)="AVPageView" Then

((TEdit=GetWindowTxt(FindWindowEx(pHwnd,0,"RICHEDIT50W",VbNullString 

End If


تغییر کپشن نویگیشن فرم





که بجای  کلمه ی Record  لغت Item در کپشنش قرار خواهد گرفت 

رنگ خطوط بصورت یک در میان در گزارش Alternative Color



البته در نسخه های ۲۰۰۷ و بالاتر Alternative Color در پراپرتی شیت گزارش وجود دارد   در سکشن Page Header یا Detail و روش زیر لازم نیست 





Report Effect




    Table 14.1. Interaction of MoveLayoutNextRecord, and PrintSection. 
MoveLayout

NextRecord

PrintSection

Effect

True

True

True

Move to the next position, get the next record, and print the data.

True

False

True

Move to the next position, remain on the same record, and print the data.

True

True

False

Move to the next position, get the next record, and don't print the data. This has the effect of skipping a record and leaving a blank space.

True

False

False

Move to the next position, remain on the same record, and don't print. This causes a blank space to appear without moving to the next record.

False

True

True

Remain in the same position, get the next record, and print the data. This has the effect of overlaying one record on another.

False

False

True

Not allowed.

False

True

False

Remain in the same position, get the next record, and refrain from printing. This has the effect of skipping a record without leaving a blank space.

False

False

False

Not allowed.

FormatCount 

The FormatCount property is used to evaluate the number of times the Format event has occurred for the current section of the report. The Format event occurs more than once whenever the Retreat event occurs. By checking the FormatCount property, you can ensure that complex code placed within the Format event is executed only once. 

PrintCount 

The PrintCount property is used to identify the number of times the Print event has occurred for the current section of the report. The Print event occurs more than once whenever the Retreat event occurs. By checking the value of the PrintCount property, you can ensure that logic within the Print event is executed only once. 




Private Sub Report_Activate()
' Used by Solutions to show toolbar that includes Show Me button.
' Hide built-in Print Preview toolbar.
DoCmd.ShowToolbar "Print Preview", acToolbarNo
' Show Custom Print Preview toolbar.

DoCmd.ShowToolbar "Custom Print Preview", acToolbarYes

End Sub

Top پراپرتی در Report



For reports, the Top property setting is the amount that the current section is offset from the top of the page. This property setting is expressed in twips. You can use this property to specify how far down the page you want a section to print in the section's Format event 

procedure


مقدار جابجایی سکشن جاری از بالای صفحه را نشان میدهد سکشن میتواند Detail باشد یا Report Footer  و  به twips که مقدار در 1440 ضرب میشود بیان شده است. ( خیلی مهم است )


Page Footer که محل قرار گرفتن شماره صفحه یا تاریخ است در تمام صفحات و پائین آن می آید ولی Report Footer در صفحه  آخر و بعد از آخرین رکورد می آید ( مهم : بعد از آخرین رکورد نه بعد از Page Footer ، جای رکورد در کجاست ؟ در رکوردست و لیست شدن در دیتیل ) و قابلیت اینکه بعد از Page Footer یا قبل از شروع آن باشد را ندارد.


قسمت آخر متن انگلیسی در بالا منظور این است که فرضا اگر دیتیل شما تمام صفحه را پر نکرده باشد میشود تا جایی که این آفست یا جابجایی (  طبق گفته ی بالا این مقدار در  پراپرتی Top تنظیم شده )  کوچکتر از ارتفاع صفحه باشد رکورد آخر آن سکشن  را در صفحه پرینت کرد ( NextRecord=False ) و برای عدم پرینت  رکوردهای تکرارشده  PrintSection باید فالز شود.( در رویداد Format )  یا مثلا  میخواهید Report Footer  که بعد از رکورد آخر در دیتیل شروع میشود تقریبا در پایین صفحه ( بعد از Page Footer قرار نخواهد گرفت )  بیاید.


اگر دیتیل تا قبل از Page Footer پیشروی کند (Advance ) ، صفحه جدید ایجاد شده و Report Footer در آن صفحه ی خالی قرار خواهد گرفت  ( در هر صورت در صفحه ی آخر و قبل از Page Footer قرار خواهد گرفت )



Acrobat Child Window



AVScrollView
AVTaskPanelAccordionScrollView
AVTableContainerView
AVTaskPaneBarView
AVFlipContainerView
AVTableContainerView
AVTabStripView
AVSplitterView
AVDockableHostView
AVBookmarkView
AVScrollView
AVTreeViewClass
AVTreeNodeSimpleView
AVTreeNodeSimpleView
AVTreeNodeSimpleView
AVTreeNodeSimpleView
AVTreeNodeSimpleView
AVTreeNodeSimpleView
AVSplitationPageView
AVSplitterView
AVScrolledPageView
AVScrollView
AVTableContainerView
8.50 x 11.00 in
AVSplitterDragView
AVPageView
AVTopBarView
1


>>>> Hidden Text <<<<
AVTableContainerView
AVDockableHostView
AVCornerView
AVRulerView
55.3%
AVRNAFilesScrollContainerView
AVScrollView
AVTableContainerView

پارامترهای هنگام باز کردن Pdf با A/

برای باز کردن فایل pdf از تابع Shell استفاده کنید یا تابع Shell Execute  اگر Shell بکار ببرید  در ابتدا مسیر Acrobat.exe که در سیستم های 32 و 64 بیت فرق میکند را باید حتما ذکر کنید حتی مسیر اپلیکیشن اصلی Word یا Access ؛  از ساخت آبجکت Shell.Application هم به احتمال زیاد می توانید بهره ببرید 


ObjShell.Shell.Open fileName


<Acrobat path> /A "<parameter>=<value>" "<PDF path>



Navpanes=1|0Turns the navigation panes and tabs on or off
Scrollbar=1|0Turns scrollbars on or off
Statusbar=1|0Turns the status bar on or off
Messages=1|0Turns the document message bar

باید بین  معرفی مسیر فایل اجرایی ،  پارامتر و نام فایل از 
  استفاده کرد  Chr(34) 

 "Zoom=%100&navpanes=0&toolbar=0"












Open a PDF file:

    AcroRd32.exe PdfFile

Open a PDF file in a new instance of Adobe Reader:

    AcroRd32.exe /N PdfFile

Open a PDF file at page 7:

    AcroRd32.exe /A "page=7=OpenActions" PdfFile

Open a PDF file with navigation pane active, zoom out to 50%, and search for and highlight the word "batch":

    AcroRd32.exe /A "zoom=50&navpanes=1=OpenActions&search=batch" PdfFile

Print a PDF file with dialog:

    AcroRd32.exe /P PdfFile

Print a PDF file silently:

    AcroRd32.exe /N /T PdfFile PrinterName [ PrinterDriver [ PrinterPort ] ]

پرینت فایل ذکر شده بصورت هیدن یا ریموت 

"C:\Program Files\Adobe\Acrobat 5.0\Reader\AcroRd32.exe" /p /h "c:\filename.pdf"


ShellExecute Method

  • با ساخت آبجکت Shell.Application

Key
   application   The file to execute (required)
   parameters    Arguments for the executable
   dir           Working directory
   verb          The operation to execute (runas/open/edit/print)
   window        View mode application window (normal=1, hide=0, 2=Min, 3=max, 4=restore, 5=current, 7=min/inactive, 10=default)

تابع GetClassNameA و GetWindowTextA از توابع API


User32.dll  64 Bit 



نحوه ی اظهار توابع عنوان این مطلب  در ویندوز 32 و 64 بیت یا در Vb6 یا Vb7 فرق میکند که در اینترنت جستجو کنید تابع صحیح برای موارد بالا وجود دارد.


تابع زیر نام یا کلاس را در بافر ایجاد و برمی گرداند 



برای گرفتن کلاس یا نام (  پنجره  )بکار برده میشود فرضا گرفتن  تکست  نوار عنوان پنجره ی اکسس جایی که اسم دیتابیس و نام اپلیکشن و حتی مسیر نمایان میشود


(Public Function GetClassName(h as LongPtr

Dim Buff As String*256

Dim BuffLen As Long 

((Buff=String(256,Chr(0

(BuffLen=getclassnamea(h,Buff,BuffLen

If BuffLen>0 Then 

(GetClassName=Left$(Buff,BuffLen

End If

Set Buff=Nothing 

End Function 



(Public Function GetWindowText(h as LongPtr

Dim Buff As String*256

Dim BuffLen As Long 

((Buff=String(256,Chr(0

(BuffLen=getwindowtexta(h,Buff,BuffLen

If BuffLen>0 Then 

(GetWindowText=Left$(Buff,BuffLen

End If 

Set Buff=Nothing

End Function 




تابع SetParent

.

DLL


User32.dll