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

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

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

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

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

WM_SETCURSOR



Case &H20 ' WM_SETCURSOR

 

(If GetClassName(wParam) = "Button" Then MsgBox GetWindowText(wParam

  ( SetWindowTextA Et, "Class : " & GetClassName(wParam) & "  Text : " & GetWindowText(wParam







 

ثابت های Cursor



static APPSTARTING := 32650
HAND := 32649
ARROW := 32512
CROSS := 32515
IBEAM := 32513
NO := 32648
SIZE := 32646
SIZENESW := 32643
SIZENS := 32645
SIZENWSE := 32642
SIZEWE := 32644
UPARROW := 32516
WAIT := 32514
SIZEWE_BIG := 32653
SIZEALL_BIG := 32654
SIZEN_BIG := 32655
SIZES_BIG := 32656
SIZEW_BIG := 32657
SIZEE_BIG := 32658
SIZENW_BIG := 32659
SIZENE_BIG := 32660
SIZESW_BIG := 32661
SIZESE_BIG := 32662
	

ExcludeClipRect




wnd_proc  Windowproc/////

case WM_CTLCOLOREDIT

dc = (HDC)wparam
hwnd =(HWND)lparam
RECT r

GetClientRect hwnd,r
excluding the margin, but not the border; this assumes '
a one pixel wide border '

r.left =r.right-some_margin'
--r.right'
r.left=r.left+2
r.right=r.right+16
r.top=r.top+2
r.bottom=r.bottom-2

ExcludeClipRect dc,r.left,r.top,r.right,r.bottom

(Function=GetStockObject(DC_BRUSH


edit_wnd_proc   DefSubclassProc/////

case WM_PAINT
(dc=GetDC(h)
'draw an icon 
ReleaseDC hwnd, dc
Exit Function 





DC_BRUSH  Solid color brush. The default color is white

Public Enum StockObjects
    WHITE_BRUSH = 0
    LTGRAY_BRUSH = 1
    GRAY_BRUSH = 2
    DKGRAY_BRUSH = 3
    BLACK_BRUSH = 4
    NULL_BRUSH = 5
    HOLLOW_BRUSH = NULL_BRUSH
    WHITE_PEN = 6
    BLACK_PEN = 7
    NULL_PEN = 8
    OEM_FIXED_FONT = 10
    ANSI_FIXED_FONT = 11
    ANSI_VAR_FONT = 12
    SYSTEM_FONT = 13
    DEVICE_DEFAULT_FONT = 14
    DEFAULT_PALETTE = 15
    SYSTEM_FIXED_FONT = 16
    DEFAULT_GUI_FONT = 17
    DC_BRUSH = 18
    DC_PEN = 19
End Enum



BOOL ExtTextOutA( HDC hdc, int x, int y, UINT options, const RECT *lprect, LPCSTR lpString, UINT c, const INT *lpDx

options :
ETO_CLIPPED : The text will be clipped to the rectangle.

ETO_OPAQUE  : The current background color should be used to fill the rectangle.

If the lpDx parameter is NULL, the ExtTextOut function uses the default spacing between characters


Public ENUM  ExtTextOutOptions
ETO_OPAQUE = &H2 
ETO_CLIPPED = &H4
ETO_GLYPH_INDEX = &H10
ETO_RTLREADING = &H80
ETO_NO_RECT = &H100
ETO_SMALL_CHARS = &H200
ETO_NUMERICSLOCAL = &H400
ETO_NUMERICSLATIN = &H800
ETO_IGNORELANGUAGE = &H1000
ETO_PDY = &H2000
ETO_REVERSE_INDEX_MAP =&H10000
End ENUM






EDIT : PARTS & STATES




// EDITSTYLE class parts and states
//
#define VSCLASS_EDITSTYLE L"EDITSTYLE"
#define VSCLASS_EDIT L"EDIT"
enum EDITPARTS {
EP_EDITTEXT = 1,
EP_CARET = 2,
EP_BACKGROUND = 3,
EP_PASSWORD = 4,
EP_BACKGROUNDWITHBORDER = 5,
EP_EDITBORDER_NOSCROLL = 6,
EP_EDITBORDER_HSCROLL = 7,
EP_EDITBORDER_VSCROLL = 8,
EP_EDITBORDER_HVSCROLL = 9,
};
#define EDITSTYLEPARTS EDITPARTS;
enum EDITTEXTSTATES {
ETS_NORMAL = 1,
ETS_HOT = 2,
ETS_SELECTED = 3,
ETS_DISABLED = 4,
ETS_FOCUSED = 5,
ETS_READONLY = 6,
ETS_ASSIST = 7,
ETS_CUEBANNER = 8,
};
enum BACKGROUNDSTATES {
EBS_NORMAL = 1,
EBS_HOT = 2,
EBS_DISABLED = 3,
EBS_FOCUSED = 4,
EBS_READONLY = 5,
EBS_ASSIST = 6,
};
enum BACKGROUNDWITHBORDERSTATES {
EBWBS_NORMAL = 1,
EBWBS_HOT = 2,
EBWBS_DISABLED = 3,
EBWBS_FOCUSED = 4,
};

استفاده در OpenThemaData و DrawThemBackground




عملگر واگذاری تفریق و جمع در C#









case WM_NCCALCSIZE

if wparam Then 
ncsp--> lparam 

GetWindowRect HWND,rc

rc.right -= rc.left
pnccs->rgrc[0].right-=rc.right
MoveWindow HWND,pnccs->rgrc[0].right, pnccs->rgrc[0].top,rc.right, pnccs->rgrc[0].bottom - pnccs->rgrc[0].top, TRUE
End if 
break 

case WM_NCHITTEST

if (lResult == HTNOWHERE) Then 

GetWindowRect HWND,rc) 

POINTSTOPOINT(pt, lParam)

  if(PtInRect(rc,pt)) Then 
   lResult = HTTRANSPARENT
End if 

   break --> Exit Function 

case WM_MOVE 

SetWindowPos hWnd, nullptr, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED
break --> Exit Function 


The button's width has to to be correct, the height gets adjusted afterwards. When handling WM_INITDIALOG, 

:call a single function



;(EmbedButton(hWndEdit, hWndButton

BOOL EmbedButton(HWND hWndEdit, HWND hWndButton) noexcept
}
if(!SetWindowSubclass(hWndEdit, EmbedButton_SubclassProc, 

,reinterpret_cast<UINT_PTR>(hWndButton)

((((reinterpret_cast<DWORD_PTR>(hWndButton

return(FALSE); // Enforce WM_NCCALCSIZE

return(SetWindowPos(hWndEdit, nullptr, 0, 0, 0, 0

| SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER, 

;((SWP_FRAMECHANGED

{



Change Size?



Public Type Margins 
cyTopHeight As Long 
cxLeftWidth As Long 
cyBottomHeight As Long 
cxRightWidth As Long 
End Type

Private dwmMargins As  MARGINS

' Adjust (shrink) the client rectangle to accommodate' 
the border'

'about rgrc --> 0 new 1 old 2 window 'client rectangle '
'before moved or resized '
       
nccsp.rgrc0.Top=0
nccsp.rgrc0.Bottom= 0
nccsp.rgrc0.Left=0
nccsp.rgrc0.Right=0
       

dwmMargins.cyTopHeight=nccsp.rgrc0.Top-nccsp.rgrc0.Top

dwmMargins.cxLeftWidth=nccsp.rgrc0.Left-nccsp.rgrc0.Left

dwmMargins.cyBottomHeight=nccsp.rgrc0.Bottom-nccsp.rgrc0.Bottom

dwmMargins.cxRightWidth=nccsp.rgrc0.Right-nccsp.rgrc0.Right




WVR_VALIDRECTS0x0400


This value indicates that, upon return from WM_NCCALCSIZE, the rectangles specified by the rgrc[1] and rgrc[2] members of the NCCALCSIZE_PARAMSstructure contain valid destination and source area rectangles
    

(cxfr=GetSystemMetrics(SM_CXSIZEFRAME

(cyfr= GetSystemMetrics(SM_CYSIZEFRAME
InflateRect lpncsp.rgrc,cxfr-1,cyfr-1

The InflateRect function increases or decreases the 
.width and height of the specified rectangle





کلاس Combo در api



Dim items() As String
 
"FreeBSD", "OpenBSD", "NetBSD", "Solaris", "Arch" }; 



Case WM_CREATE,WM_SHOWWINDOW

for i = 0 To 4 

SendMessageW hwndCombo,CB_ADDSTRING, 0,(LPARAM) items(i)

Next


case WM_COMMAND

if  HIWORD(wParam)=BN_CLICKED Then 

SendMessage(hwndCombo, CB_SHOWDROPDOWN,(WPARAM)TRUE, 0)

End If 

if  HIWORD(wParam)=CBN_SELCHANGE)

sel=SendMessage hwndCombo,CB_GETCURSEL,0, 0 

(SetWindowTextW hwndStatic,items(sel

End if 






MIN/MAX IN FORM





hwnd = GetActiveWindow

SetWindowLong hwnd,GWL_STYLE,GetWindowLong(hwnd,GWL_STYLE) Or p_str_Minimize_Maximize_Box

SetWindowPos hwnd, 0, 0, 0, 0,0,SWP_FRAMECHANGED Or SWP_NOMOVE Or
SWP_NOSIZE






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 

GWL_USERDATA/GWL_ID



hIcon2=CreateWindow('Static', nil, WS_VISIBLE or WS_CHILD or SS_ICON or WS_CLIPSIBLINGS, 507,2,3,120,hForm1,0,hInstance,nil)

I put WS_CLIPSIBLINGS in these 2 Icons to prevent them from drawing on each other, remove the WS_CLIPSIBLINGS and resize the form making it wider or narrow and see what the Icons do} 

SendMessage(hIcon2, STM_SETIMAGE, IMAGE_ICON,LoadIcon(0,IDI_QUESTION)); 
to put a NON-Resource Icon in a Static Icon you SendMessage,STM_SETIMAGE} 


hIcon3=CreateWindow('Static', '', WS_VISIBLE or WS_CHILD or SS_ICON or WS_CLIPSIBLINGS,475,2,7,11,hForm1,0,hInstance,nil) 

SendMessage(hIcon3,STM_SETIMAGE,IMAGE_ICON,LoadIcon(0,IDI_QUESTION))

hLabel2=CreateWindow('Static', 'Enter the Folder you want to list the File Names for below', WS_VISIBLE or WS_CHILD or SS_LEFT,10,40,290,16,hForm1,0,hInstance,nil)

SendMessage(hLabel2,WM_SETFONT,Font1,0)

if possible leave some extra room on controls, width and heigth, in case the font mapper picks a different font than the one you named}

hExitBut=CreateWindow('Button','Exit', WS_VISIBLE or WS_CHILD or BS_PUSHBUTTON or BS_TEXT or BS_BOTTOM or WS_TABSTOP, 285, 108, 64, 28, hForm1, 0, hInstance,nil)

SendMessage(hExitBut, WM_SETFONT, GetStockObject(SYSTEM_FIXED_FONT),0)

because the IsDialogMessage( ) is in the GetMessage loop below, you can put WS_TABSTOP in a control's style to have that control be a Tab Stop. Tab Stop Order is set by the creation order of the Tab Stop controls Since this is the first control with a WS_TABSTOP it is FIRST in the Tab Stop Order, hEdit1 will be next}


SetWindowLong(hExitBut, GWL_USERDATA, 1)

Every window has 4 bytes (integer) of "User Data", which you can set and read with SetWindowLong and GetWindowLong, you might think of this user data integer like the "Tag" property of controls in the VCL. Here I will use the Exit buttons user data as a boolean to signify if the button is visible, see the ChangeStyle procedure above


SetWindowLong(hExitBut, GWL_ID, ID_ExitBut)

control ID numbers are sometimes used in system messages, like the WM_DRAWITEM message, ID can also be used in the WM_COMMAND. . Normaly you would just put this ID number in the hMenu parameter of the CreateWindow function, I do this here to show methods for the SetWindowLong



WS_CLIPSIBLINGS 
0x04000000L






ترسیم خط با Polyline




Const NUM =1000
(Const TWOPI = (2 * 3.14159


WndProc 

static int cxClient,cyClient
Dim apt(NUM) As POINTAPI

WM_PAINT 

(MoveToEx hdc, 0, cyClient / 2, NULL
(LineTo  hdc,cxClient,cyClient / 2

i=0
Do
apt(i).x = i * cxClient / NUM
(((apt(i).y =(cyClient / 2 * (1 - sin (TWOPI * i / NUM
i=i+1
Loop Until I<NUM

Polyline  hdc, apt, NUM

SETMARGINS IN EDIT CONTROL




EC_LEFTMARGIN =&H1
            EC_RIGHTMARGIN =&H2

EM_SETMARGINS=&HD3


  :  lParam


The HIWORD specifies the new width of the right margin, in pixels. This value is ignoredif wParam does 

.notinclude EC_RIGHTMARGIN






EM-SETMARGINS







ExcludeClipRect



ExcludeClipRect(aMessage.WParam, fButton.Left,
                                                              top + 1,
                                                              fButton.Left + fButton.Width,
                                                              fButton.Height);
       

زاویه


عدد پی تقسیم بر سینوس یک درجه 


3.141592/0.01745240643?

 180.009101472661 



?2*(3.141592)/0.01745240643
 360.018202945323 
 180.009101472661 

ترسیم خط LineTo




تمام منابع خارجی 









Dim px As POINTAPI

           GetCursorPos px

           'ClientToScreen hwnd, px

        

         MoveToEx hdc, 120, 30, px

         LineTo hdc, 140, 30

          

         MoveToEx hdc, 120, 30, px

         LineTo hdc, 135, 15

         ' Quarter

         MoveToEx hdc, 120, 30, px

         LineTo hdc, 134, 44

         

         

         MoveToEx hdc, 120, 30, px

         LineTo hdc, 120, 50

         

         ' Quarter

         MoveToEx hdc, 120, 30, px

         LineTo hdc, 105, 44

         

               

         MoveToEx hdc, 120, 30, px

         LineTo hdc, 120, 10

         

          ' Quarter

         MoveToEx hdc, 120, 30, px

         LineTo hdc, 105, 14

         

         

         MoveToEx hdc, 120, 30, px

         LineTo hdc, 100, 30






Rotate

using WM_TIMER

Dim tt As RECT

Static Deg

       Deg = Deg + 5

         If Deg > 360 Then Deg = 0

         Dim xl, yt

        xl = 120: yt = 30

  

          tt.Left = 99: tt.Top = 5: tt.right = 141: tt.bottom = 55

   (FillRect hdc, tt, GetSysColorBrush(15

طول خط 20 

                 

   در ربع اول            If 0 < Deg < 90 Then ' Quarter 

                      Newx = xl + Sin(Deg * Sin1) * 20

                      Newy = yt - Cos(Deg * Sin1) * 20

                 End If

                  

  در ربع دوم                  If 90 < Deg < 180 Then

                      Newx = xl + Cos(Deg * Sin1) * 20

                      Newy = yt + Sin(Deg * Sin1) * 20

                End If

                

در ربع سوم                   If 180 < Deg < 270 Then

                      Newx = xl - Sin(Deg * Sin1) * 20

                      Newy = yt + Cos(Deg * Sin1) * 20

                 End If

                 

در ربع چهارم                 If 270 < Deg < 360 Then

                      Newx = xl - Cos(Deg * Sin1) * 20

                      Newy = yt - Sin(Deg * Sin1) * 20

               End If

                     

              MoveToEx hdc, 120, 30, px

              LineTo hdc, Newx, Newy

                      

                   






 xl = 120: yt = 30

       

          tt.Left = 100: tt.Top = 5: tt.right = 140: tt.bottom = 55

          (FillRect hdc, tt, GetSysColorBrush(15

                      

                      Arc hdc, 100, 10, 140, 50, 0, 0, 0, 0

                      SelectObject hdc, HoldPen

                      Arc hdc, 115, 25, 125, 35, 0, 0, 0, 0

                      SelectObject hdc, HoldPen1

                      Newx = xl + Sin(Deg * Sin1) * 16

                      Newy = yt - Cos(Deg * Sin1) * 16

                      

                      MoveToEx hdc, 120, 30, px

                      LineTo hdc, Newx, Newy

                      

                      Deg = Deg + 10

       

       

       DeleteObject HoldPen

       DeleteObject HoldPen1







       


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