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
انتقال کرسر به مختصات صفحه ی مشخص شده.
Moves the cursor to the specified screen coordinates. If the new coordinates are not within the screen rectangle set by the most recent ClipCursor function call, the system automatically adjusts the coordinates
.so that the cursor stays within the rectangle
در 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 ارسال میشود
کدام درست و منطقی تر است ؟
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 uFlags: SWP_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
دادن ابعاد مستطیل پنجره ی مشخص شده ( ابعاد در مختصات صفحه داده میشود ) در ClientRect عدد x و y گوشه ی بالایی صفر است
Retrieves the dimensions of the bounding rectangle of the specified window. The dimensions are given in screen coordinates that are relative to the upper-left
.corner of the screen
برای اضافه کردن باتن ازCreateWindowEx استفاده میشود . در زمان ساب کلاس کردن و قرار دادن در پیام SHOWWINDOW و استفاده از استایل WS_CHILD OR WS_VISIBLE اگر بخواهیم میتوان از BS_OWNERDRAW استفاده کرد و باتن خود را در پیام CTLCOLORBTB ( که lparam هندلی است برای هندل باتن ) ترسیم کرد .
فرضا اگر به InputBox در زیر باتن کنسل بخواهیم باتنی اضافه کنیم می توانیم با GetWindowRect موقعیت باتن کنسل را بگیریم منظور X و Y گوشه بالایی و با GetClientRect عرض و طول باتن Cancel را بدست آوریم ( همانطور که گفته شد GetClientRect گوشه بالایی هر کنترلی را صفر میدهد )
Dim WinRect As RECT
Dim BtnWinRect As RECT
Dim BtnClientRect As RECT
Dim CyFrame As Long
(CyFrame=GetSystemMetrics(SM_CYFRAME
(CyCaption=GetSystemMetrics(SM_CYCAPTION
GetWindowRect Hwnd,WinRect
GetWindowRect BtnHandle,BtnRect
GetClientRect BtnHandle,BtnClientRect
ابعاد زیر میشود پارامترهایی که باید در آرگومانهای تابع CreateWindowEx قراردهیم x1,y1 میشود مختصات گوشه ی بالایی سمت چپ و cx ( عرض ) و cy ( ارتفاع ) یا x2 و y2 میشود مختصات گوشه پایینی سمت راست
LeftBound=(BtnWinRect.Left-WinRect.Left)+CyFrame
TopBound=(BtnWinRect.Top-WinRect.Top)+CyFrame
(CyCaption/2)+
RightBound'
Width=BtnClientRect.Rigth-BtnClientRect.Left
BottomBound'
Height=BtnClientRect.Bottom-BtnClientRect.Top
SetWindowLong(Handle, GWL_STYLE, GetWindowLong(Handle, GWL_STYLE) and (not
WS_CAPTION) or WS_THICKFRAME)
WM_COMMAND
section of your callback, use ShowWindow(hwnd, SW_MAXIMIZE)
and ShowWindow(hwnd, SW_RESTORE)
. That's all there is to it.1) Do not use BeginPaint/EndPaint in WM_ERASEBKGND. Move that code in a WM_PAINT handler.
احتملا Rec در پیام WMPAINT باید Global یا Static تعیین شود. تست نشده ولی روال بدین شکل است .
SM_CYSIZEFRAME = SM_CYFRAME SM_CXSIZEFRAME = SM_CXFRAME
Option Compare Database
Public WinProcOld As LongPtr
(Public Function SubClassWnd(hwnd As LongPtr
( WinProcOld = SetWindowLongPtr(hwnd, GWL_WNDPROC, AddressOf WindProc
End Function
(Public Function UnSubclassWnd(hwnd As LongPtr
SetWindowLongPtr hwnd, GWL_WNDPROC, WinProcOld
WinProcOld = 0
End Function
'This is your subclassed window procedure
Public Function WindProc(ByVal hwnd As LongPtr, ByVal wMsg As Long, ByVal wParam As LongPtr, ByVal lParam As LongPtr) As LongPtr
'WM_COMMAND message is sent to parent window to notify of a button click
'The lParam parameter tells the hWnd of the button
'If wMsg = WM_CTLCOLORBTN Then WindProc = CreateSolidBrush(RGB(0, 0, 10))
If wMsg = WM_COMMAND Then
If lParam = GetDlgItem(hwnd, 4) Then MsgBox "Button was clicked!"
If lParam = GetDlgItem(hwnd, 1) Then MsgBox "Button was clicked!"
End If
If wMsg = WM_DESTROY Then
UnSubclassWnd hwnd
End If
WindProc = CallWindowProc(WinProcOld, hwnd, wMsg, wParam, ByVal lParam)
End Functionc
CW_USEDEFAULT = &80000000TTM_ADDTOOL = &404TTM_TRACKACTIVATE = &411TTM_UPDATETIPTEXT = &40CTTS_BALLOON = 64TTS_ALWAYSTIP = 1TTS_NOPREFIX = 2WS_POPUP = &80000000
بسته شدن پنجره زمانیکه کپشن به عدد 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
کار سختی نیست از منبعی که در انتهای صفحه آمده استفاده شده که تابع ویندوزی است
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
If PtInRect(nn, p.x, p.y) Then
" ... MsgBox "You Clicked Me
End If
.....RedrawWindow
مورد بالا تست شده
در 32 بیت
ارسال تکست به کپشن پنجره در صورت فشردن باتن Ok در صورتیکه تعداد کاراکتر داخل کنترل ادیت بیشتر از 13 باشد
WndProc
Case WM_COMMAND
Case 1
(InputDataLen=SendDlgItemMessage(hwnd,EM_LINELENGTH,0,0
if InputDataLen>14 Then
"....SetWindowTextA hwnd,"Exceed Data
Sleep 1000
End If
Case 2
Case 4900
End Select
این پیام هنگامی ارسال میشود که یوزر اقدام به تغییر متن در کنترل EDIT کرده است. ( منظور پیام EN_CHANGE )
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