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

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

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

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

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

SWP_FRAMECHANGED



Const SWP_FRAMECHANGED=&H20



Applies new frame styles set using the SetWindowLong function. 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_NCCALCSIZE is sent only when the window's size is being changed.



اعمال سبک یا استایل های قاب و چهارچوب جدید که با استفاده از تابع SetWindowLong تنظیم میشود .ارسال پیام WM_NCCALCSIZE به پنجره حتی اگر سایز پنجره تغییر نکند. اگر این flag مشخص نشود WM_NCCALCSIZE فقط زمانی ارسال می شود که سایز پنجره تغییر داده شود.


پس زمانیکه بخواهید از پیام WM_NCCALCSIZE برای محاسبه طول و عرض یا مختصات پنجره ای استفاده کنید در صورتیکه پنجره سایزش تغییر نمی کند از تابع SetWindowLong و استایل SWP_FRAMECHANGED استفاده می کنید که هگزار دسیمال آن 20 است و دسیمال برابر 14  ( 20 تقسیم بر 16 خارج تقسیم و مانده کنار هم قرار می گیرند اگر مانده بیشتر و خود 10 شد به ترتیب A تا F جایگزین مانده میشود ) 


Type RECT

Left As Long

Right As Long

Top As Long

Bottom As Long

End Type


Type WINDOWPOS

hwnd As Long 'LongPtr ( 64 bit )

hWndInsertAfter As Long 'LongPtr ( 64 bit )

x As Long ' Left 

y As Long ' Top

cx As Long ' Width in pixle

cy As Long ' Height in pixle

flags As Long

End Type


Type NCCALCSIZE_PARAMS

rgrc(3) As RECT

lppos As WINDOWPOS

END TYPE



the first rectangle contains the new coordinates of a window that has been moved or resized, that is, it is the proposed new window coordinates. The second contains the coordinates of the window before it was moved or resized. The third contains the coordinates of the window's client area before the window was moved or resized



در آرایه rgrc : ( حاوی اطلاعات زیر است ) 

اولین مستطیل حاوی مختصات پنجره جدید است که تغییر سایز یا جابجا شده ( Move )  ... مختصات جدید است 

دومین  مختصات پنجره قبل از تغییر سایز یا جابجایی است.

سومین  حاوی مختصات پنجره ناحیه Client قبل از تغییر سایز یا جابجا شدن است.


در پیام WM_NCCALCSIZE اگر wParam فالز باشد lParam به ساختار RECT اشاره می کند و اگر True باشد به ساختار NCCALCSIZE_PARAMS.



Dim ncc AS NCCALCSIZE_PARAMS

Debug.Print wParam

CopyMemory ncc,lParam,ByVal Len(ncc)

Debug.Print ncc.rgrc(1).Right

CopyMemory lParam,ncc,ByVal Len(ncc) 


پیام WM_SETFOCUS : 


پس از اینکه فوکوس صفحه کلید را به دست آورد ، این پیام به پنجره ارسال میشود و wParam حاوی هندلی به پنجره ای است که فوکوس کیبورد را از دست داده ( با Tab یا ماوس به کنترل دیگری می روید ) و lParam هم صفر است .


می توانید در این پیام با تابع SetFocus ، فوکِس یا فوکوس را به کنترل مورد نظر برده تا WM_NCCALCSIZE ارسال شود و بتوانید مختصات پنجره مورد نظر را بگیرید.












ScrollBar



At the picture below you can see what I've already done. Left scrollbar is a system scrollbar, right one - custom scrollbar.




FVertBar: Boolean; FPressedBtn1, FPressedBtn2, FSelectedBtn1, FSelectedBtn2: Boolean; FBarBmp, FBtn1Bmp, FBtn2Bmp: TBitmap; MainDC: hDC; 


FBarBmp.Free; FBtn1Bmp.Free; FBtn2Bmp.Free;


Case WM_ENABLE ' WM_SHOWWINDOW
Width=100
Height=80

FSelectedBtn1=false
FSelectedBtn2=false
FPressedBtn1=false
FPressedBtn2=false

(FBarBmp=LoadImageA(0,"D:\...bmp",0,16,16,&H10
=FBtn1Bmp
=FBtn2Bmp

Case WM_DESTROY

DeleteObject FBarBmp
DeleteObject FBtn1Bmp
DeleteObject FBtn2Bmp


Case WM_NCCALCIZE

decrease width to create non-client area'
(Dec(Message.CalcSize_Params.rgrc(0).Right,17
FVertBar= true


Case WM_NCPAINT

(MainDC=GetWindowDC(Hwnd

(if FVertBar then PaintScrollBarVert(MainDC

if FVertBar then 
PaintButtonVert1 MainDC
PaintButtonVert2 MainDC
End if 
Enf if 
ReleaseDC Handle, MainDC


Case WM_NCMOUSEMOVE

GetCursorPos pt
ScreenToClient hwnd,pt

Top Vert Button'
(Rect(Width - 17 - 2, ClientRect.Top, Width - 2, 17
if PtInRect(Crect,pt) then
FSelectedBtn1= true
else
FSelectedBtn1=false
End If 
bottom vert button '
Rect(Width - 17 - 2, ClientRect.Bottom - 17, Width - 2,
(ClientRect.Bottom + 17,
if PtInRect(Crect,pt)   then
FSelectedBtn2=true
else
FSelectedBtn2=false
End if 
SendMessageA hwnd,WM_NCPAINT,1, 0



Cas WM_NCLBUTTONDOWN

GetCursorPos pt 
ScreenToClient hwnd,pt
'Top Vert Button
Rect(Width - 17 - 2, ClientRect.Top, Width - 2, 17)
if PtInRect(Crect,pt) then
FPressedBtn1=true
End If 
'bottom vert button 
Rect(Width - 17 - 2, ClientRect.Bottom - 17, Width - 2, ClientRect.Bottom + 17)
if PtInRect(Crect,pt)   then
FPressedBtn2=true
End if 
SendMessageA hwnd,WM_NCPAINT,1, 0


Case WM_NCLBUTTONUP
FPressedBtn1=false
FPressedBtn2 =false 
SendMessageA hwnd,WM_NCPAINT,1, 0


(PaintScrollBarVert(hDC

FBarBmp.Width= 17
FBarBmp.Height=ClientRect.Bottom
FBarBmp.Canvas.Brush.Color=clLime FBarBmp.Canvas.FillRect(FBarBmp.Canvas.ClipRect)
BitBlt(MainDC,Width-17-2,ClientRect.Top + 2,FBarBmp.Width,FBarBmp.Height, FBarBmp.Canvas.Handle,0, 0,SRCCOPY) 


(PaintButtonVert1(hDC


FBtn1Bmp.Width=17
FBtn1Bmp.Height=17

if not FSelectedBtn1 then FBtn1Bmp.Canvas.Brush.Color=clRed
End if 

if FSelectedBtn1 then FBtn1Bmp.Canvas.Brush.Color =clBlue
End if 

if FSelectedBtn1 and FPressedBtn1 then FBtn1Bmp.Canvas.Brush.Color=clPurple
FBtn1Bmp.Canvas.FillRect(FBtn1Bmp.Canvas.ClipRect)
BitBlt(DC, Width - 17 - 2, ClientRect.Top + 2, FBtn1Bmp.Width, FBtn1Bmp.Height, FBtn1Bmp.Canvas.Handle, 0, 0, SRCCOPY)
End if 



(PaintButtonVert2(hDC


FBtn2Bmp.Width=17
FBtn2Bmp.Height=17

if not FSelectedBtn2 then FBtn1Bmp.Canvas.Brush.Color=clRed
End if 

if FSelectedBtn2 then FBtn1Bmp.Canvas.Brush.Color=clBlue
End if 

if FSelectedBtn2 and FPressedBtn2 then FBtn1Bmp.Canvas.Brush.Color=clPurple
FBtn1Bmp.Canvas.FillRect(FBtn1Bmp.Canvas.ClipRect)
BitBlt(DC, Width - 17 - 2, ClientRect.Bottom - 17 + 2, FBtn1Bmp.Width,FBtn1Bmp.Height, FBtn1Bmp.Canvas.Handle, 0, 0, SRCCOPY)
End if 





مربوط به مثال بالا نیست 






SETWINDOWPOS




SWP_FRAMECHANGED  &H20

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


If you have changed certain window data using SetWindowLong, you must call SetWindowPos for the changes to take effect. Use the following combination for uFlagsSWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED.



(GWL_USERDATA  (-21

Sets the user data associated with the window. This data is intended for use by the application that created the window. Its value is initially zero.



(SetWindowLong(hWnd,GWL_USERDATA,Value

(Value=GetWindowLong(hWnd, GWL_USERDATA



NCCALCSIZE TO MAKE A SPACE





WVR_ALIGNBOTTOM = 64
WVR_ALIGNLEFT = 32
WVR_ALIGNRIGHT = 128
WVR_ALIGNTOP = 16
WVR_HREDRAW = 256
WVR_REDRAW = WVR_HREDRAW + WVR_VREDRAW
WVR_VALIDRECTS = 1024
WVR_VREDRAW = 512


Type RECT

left As Long

right As Long

top As Long

bottom As Long

End Typd


Type NCCALCSIZE_PARAMS

rgrc(3) As RECT

lppos As WINDOWPOS

End Type 


Type WINDOWPOS

x As Long

y As Long

cx As Long    ' width

cy As Long    ' heigth

End Type



Dim tNCR As NCCALCSIZE_PARAMS 
Dim tWP As WINDOWPOS
If wParam <> 0 Then
 lParam containts a pointer to the'
 NCCALCSIZE_PARAMS structure: 
(CopyMemory tNCR,ByVal lParam, Len(tNCR
 the NCCALCSIZE_PARAMS structure contains'
 a pointer to the WINDOWPOS structure: 
(CopyMemory tWP,ByVal tNCR.lppos, Len(tWP
 Set the first rectangle to the WINDOWPOS ' size'
(With tNCR.rgrc(0
Left=tWP.x.
Top=tWP.y.
Right=tWP.x+tWP.cx.
Bottom = tWP.y + tWP.cy.
End With

Now modify the rectangle if we're showing tabs'
 to allow space for the tab strip itself'
If (m_bShowTabs) Then 
tNCR.rgrc(0).Left=tNCR.rgrc(0).Left+2
tNCR.rgrc(0).Right=tNCR.rgrc(0).Right-2
If (m_eTabAlign=TabAlignBottom) Then
tNCR.rgrc(0).Top=tNCR.rgrc(0).Top+2
tNCR.rgrc(0).Bottom=tNCR.rgrc(0).Bottom-m_lTabHeight
Else
tNCR.rgrc(0).Top=tNCR.rgrc(0).Top+m_lTabHeight
tNCR.rgrc(0).Bottom=tNCR.rgrc(0).Bottom-2 
End If 
End If


 Set the second rectangle to equal the first'
(tNCR.rgrc(1)=tNCR.rgrc(0
CopyMemory ByVal lParam,tNCR, Len(tNCR) ' Tell 
 :Windows we've modified the size'
ISubclass_WindowProc=WVR_VALIDRECTS

Once this is done, there will be a space for the tabs




Case WM_NCPAINT 
 Ensure the standard mon-client drawing is' 
:completed
(ISubclass_WindowProc=CallOldWindowProc(hWnd,iMsg,wParam,lParam
 Do custom drawing: first get a DC to the non-client' 
:area
Dim lhDC As Long 
(lhDC=GetWindowDC(hWnd
'.... Now can draw in the area we've cleared'
  Clear up DC '
ReleaseDC lHDC, hWnd


Check the actual source code for the details of drawing the tabs. The code uses an EnumWindowsProc callback function to determine all of the windows within the MDIClient area, and the WM_MDIGETACTIVEmessage to determine which 
.(window is the currently selected MDI child (if any

Finally, we need to intercept the user clicking on a tab or button within the tab control. There are two messages Windows sends to the non-client area to allow you to 
:check for mouse events

WM_NCHITTEST
This message allows you to tell Windows that a non-client area should be treated in a particular way, such as title bar or size gripper.
WM_SETCURSOR
This message is used by Windows to determine which cursor to display, however, since it provides the type of mouse action being performed you can use it to determine mouse movement and button presses in the 
.area





CreateHatchBrush/ CreatePatternBrush



hatch-brush


((hBrush=CreateSolidBrush (RGB(0, 0, 255
Associate the brush with the display device context'
SelectObject  hdc, hBrush
Draw a rectangle with blue background'
Rectangle hdc, 400,40,800,400
Create a hatch brush that draws horizontal red line'
,hBrush=CreateHatchBrush(HatchStyleHorizontal
((RGB(255, 0, 0
Set the background color to yellow'
(SetBkColor hdc, RGB(255, 255, 0


HBRUSH (CreatePatternBrush ( HBITMAP hbm

برگرفته از فروم های خارجی 


 Hatch Styles'
HS_HORIZONTAL= 0
HS_VERTICAL= 1
HS_FDIAGONAL= 2
HS_BDIAGONAL =3
HS_CROSS =4
HS_DIAGCROSS =5

()Sub OnPaint
Dim Brush
CreatePatternBrush 
(Brush,HS_HORIZONTAL,RGB(232,166,153
Dim ps As PAINTSTRUCT
Dim rct As RECT
GetClientRect hwnd,rct
(dc=BeginPaint(hwnd,ps
SelectObject dc,Brush
Rectangle hdc,left,top,right,bottom'
Rectangle dc,rct?
(SetBkColor dc,RGB(232,166,153
DrawText dc,"Brush Demo",10,rct,DT_CENTER Or DT_VCENTER Or DT_SINGLELINE
EndPaint hwnd,ps








Private hbr

(Function CreatePatternBrushFromFile(pszFile
hbr=0
(hbm=LoadImage(0,pszFile,IMAGE_BITMAP,0,0,LR_LOADFROMFILE
if (hbm) Then 
(hbr=CreatePatternBrush(hbm
DeleteObject hbm
End if
CreatePatternBrushFromFile=hbr
End Function

Function PaintContent(ByVal hwnd As Long,ByRef pps As 
(PAINTSTRUCT  

BeginPath pps.hdc
Ellipse pps.hdc,0,0,200,100
EndPath pps.hdc
(hbrOld=SelectObject(pps.hdc,hbr
FillPath pps.hdc
SelectObject pps.hdc,hbrOld
End Function



SWP_NOSIZE = 0x0001
SWP_NOMOVE = 0x0002
SWP_NOZORDER = 0x0004
SWP_FRAMECHANGED = 0x0020
SWP_SHOWWINDOW = 0x0040

(GWL_STYLE = (-16

'Window Style 
WS_CLIPCHILDREN=0x02000000
WS_CLIPSIBLINGS=0x04000000


hBrush=CreateHatchBrush(HS_DIAGCROSS,ColorTranslator.ToWin32(Color.Red)

,SetWindowSubclass(textBox1.Handle
(AddressOf WindowSubClass,0,0

SetWindowPos(textBox1.Handle,0,0,0, 200,40,SWP_NOZORDER Or SWP_NOMOVE Or 
(SWP_SHOWWINDOW Or SWP_FRAMECHANGED
For main form resizing long'
(nStyle = GetWindowLong(this.Handle, GWL_STYLE

SetWindowLong(this.Handle,GWL_STYLE, nStyle And 
(WS_CLIPCHILDREN



,WindowSubClass(hWnd,uMsg,wParam
(lParam,uIdSubclass,dwRefData

Select Case  uMsg
Case WM_NCPAINT
(hDC=GetWindowDC(hWnd
Dim rct As RECT 
()rect = new RECT'
(GetClientRect(hWnd, out rect
rct.right += 20 * 2
rct.bottom += 20 * 2

if  hBrush<>0 Then 
FillRect hDC,rct,hBrush
ReleaseDC hWnd, hDC
Exit Function

case WM_NCCALCSIZE

if (wParam == (IntPtr)0'
Dim pRect As RECT
,pRect =(RECT)Marshal.PtrToStructure(lParam'
((typeof(RECT'

(Call CopyMemory(VarPtr(rct)+4,ByVal lParam+4,4

pRect.left += 10
pRect.top += 10
pRect.bottom -= 10
pRect.right -= 10

(Marshal.StructureToPtr(pRect, lParam,false'
(Call CopyMemory(lparam,VarPtr(rct),4
Exit Function
End Select
DefSubclassProc(hWnd, uMsg, wParam, lParam)

NCCALCSIZE ( محاسبه ی اندازه در Non Client )


اولین  مستطیل یا Rectangle حاوی مختصات جدید پنجره که جابجا یا تغییر سایز شده است طبق داکیومنت زیر 


When the window procedure receives

 the WM_NCCALCSIZE message, the first rectangle contains the new coordinates of a window that has been moved or resized, that is, it is the proposed new window coordinates. The second contains the coordinates of the window before it was moved or resized. The third contains the coordinates of the window's client area before the window was moved or resized


افزایش عرض یا طول مستطیل ( Rectangle )

InflateRect lprc,dx,dy


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



InvalidateRect hWnd,lpRect,bErase



Also Read   offsetrect


WM_NCCALCSIZE'
(private WmNCCalcSize(ByRef m Ss Message 
Get Window Rect RECT'
Dim formRect As RECT
GetWindowRect m.HWnd,formRect
Check WPARAM'
 if m.WParam<>0 Then 
When TRUE, LPARAM Points to a'
NCCALCSIZE_PARAMS structure'
Dim nccsp As NCCALCSIZE_PARAMS

We're adjusting the size of the client area 'here. Right' 
now, the client area is the whole form

Adding to the Top, Bottom, Left, and Right will size the '
client area.

nccsp.rgrc0.top= formRect.top+30
 Thirty pixel top border'
nccsp.rgrc0.bottom=formRect.bottom-4
Four pixel bottom (resize) border'
nccsp.rgrc0.left=formRect.left+4
Four pixel left (resize) border'

Else 'FALSE
When FALSE,LPARAM Points to a RECT structure'
Dim clnRect As RECT
'Like before, we're adjusting the rectangle...
'Adding to the Top, Bottom, Left, and Right will size the client area. 
(CopyMemory clnRect,Byval lParam,Len(lParam
clnRect.top+=30
Thirty-pixel top border'
clnRect.bottom-=4
Four-pixel bottom (resize) border'
clnRect.left+=4
Four-pixel left (resize) border'
clnRect.right-=4
Four-pixel right (resize) border'
CopyMemory lParam,clnRect,Len
 Ret=0


()Private Sub InvalidateNC

 'refresh or invalidate don't work for the nonclient-area.
 'this sub forces a refresh for NC.    

SetWindowPos(Me.Handle,0,0,0,0,0,SWP_NOMOVE Or SWP_NOSIZE Or SWP_NOZORDER Or SWP_NOACTIVATE Or
SWP_FRAMECHANGED)
End Sub 'invalidateNC



WM_NCCALCSIZE return flags
Global Const WVR_ALIGNTOP = &H0010
Global Const WVR_ALIGNLEFT = &H0020
Global Const WVR_ALIGNBOTTOM = &H0040
Global Const WVR_ALIGNRIGHT = &H0080
Global Const WVR_HREDRAW = &H0100
Global Const WVR_VREDRAW = &H0200
Global Const WVR_REDRAW = (WVR_HREDRAW Or WVR_VREDRAW)
Global Const WVR_VALIDRECTS = &H0400

WM_NCCALCSIZE parameter structure'
Type NCCALCSIZE_PARAMS
rgrc As Long
lppos As Long
End Type

Global Const MA_NOACTIVATEANDEAT = 4

Type WINDOWPOS
hwndInsertAfter As Long
hwnd As Long
x As Long
y As Long
cx As Long
cy As Long
flags As Long
End Type

Dim nccs  As NCCALCSIZE_PARAMS
Dim WndPos  As WINDOWPOS
MAGICNUMBER=23

Case WM_NCCALCSIZE


' Adjust the client area size calculation to allow for our tabstrip

 If (wParam <> 0) Then
'nccs->NCCALCSIZE Structure
(CopyMemory nccs,ByVal lParam,Len(nccs

(CopyMemory WndPos,ByVal nccs.lppos,Len(WndPos

  (With nccs.rgrc(0
     Left=nccsPos.x+2.
     Top=nccsPos.y+MAGICNUMBER.
     Right=(nccsPos.x+nccsPos.cX)-2.
     Bottom=nccsPos.y+nccsPos.cY)-2.
End With


(Set nccs.rgrc(1)=nccs.rgrc(0

(CopyMemory ByVal lParam,nccs,Len(nccs

 WndProc=WVR_VALIDRECTS

 
Else

WndProc =CallWindowProc(mlpfnOldWindowProc
(hWnd,uMsg,wParam,lParam,

End If

Case WM_NCPAINT

  GetWindowRect hWnd,WndRect
  GetDCEx(hWnd,wparan,DCX_WINDOW or'
DCX_INTERSECTRGN'
  ( lhDC = GetWindiwDC(hWnd
....  BitBlt
  ReleaseDC hWnd, lhDC
WndProc =CallWindowProc(mlpfnOldWindowProc
(hWnd,uMsg,wParam,lParam

I was about to reply that I had been trying GetWindowDC and GetDCEx also until it occured to me that of course the coordinates are different... it works now Thanks so much



You can respond to the WM_NCCALCSIZEmessage, modify WndProc's default behaviour to remove the invisible border.

As this document and this documentexplain, when wParam > 0, On request wParam.Rgrc[0] contains the new coordinates of the window and when the procedure returns, Response wParam.Rgrc[0] contains the coordinates of the new client rectangle.

:The golang code sample



params.Rgrc(0).Top=params.Rgrc(2).Top params.Rgrc(0).Left=params.Rgrc(0).Left + 1
params.Rgrc(0).Bottom=params.Rgrc(0).Bottom-1
params.Rgrc(0).Right=params.Rgrc(0).Right-1
return 0x0300


Case WM_NCLBUTTONDOWN
            'pt = PointToClient(New Point(m.LParam.ToInt32()))
            'pt.Offset(I.BorderWidthLeft, I.BorderWidthTop)
       

منبع خارجی