ش | ی | د | س | چ | پ | ج |
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
BOOL IsWindowEnabled( [in] HWND hWnd
Declare PtrSafe Functuon IsWindowEnabled lib "user32" (ByVal hWnd As LongPtr) As Boolean
If idHook = HCBT_ACTIVATE Then
If IsWindowEnabled(GetParent(wParam)) ThenUnhookWindowsHookEx lHookMsgBox "You can't format a Modeless Userform.", vbCriticalExit FunctionEnd If
'Put Inside WindowProc
Dim tPt As POINTAPI, tClientRect As RECT
Dim loword As Long, hiword As Long
GetClientRect hwnd, tClientRect
Select Case Msg
Case WM_NCLBUTTONDOWN SetWindowPos hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE + SWP_NOMOVE Case WM_ACTIVATE
If wParam = 0 Then
SetWindowPos hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE + SWP_NOMOVE
SetWindowLong hwnd, GWL_STYLE, (GetWindowLong(hwnd, GWL_STYLE) And Not WS_SYSMENU)
DrawTitleBar(hwnd, lTitleBarColor)
InvalidateRect hwnd, tClientRect, 0
Case WM_EXITSIZEMOVE
DrawTitleBar(hwnd, lTitleBarColor)
InvalidateRect hwnd, tClientRect, 0
Case WM_NCPAINT
If bDrawn = False Then bDrawn = True: DrawTitleBar(hwnd, lTitleBarColor)
Exit Function
Case WM_SYSCOMMAND
GetHiLoword CLng(lParam), loword, hiword
tPt.x = loword : tPt.y = hiword
Dim lngPtr As LongPtr
CopyMemory lngPtr, tPt, LenB(tPt)
If PtInRect(tUpdatedCloseButtonRect, lngPtr) Then
If PtInRect(tUpdatedCloseButtonRect, tPt.x, tPt.y) Then
If PtInRect(tUpdatedCloseButtonRect, tPt.x, tPt.y) Then
DrawTitleBar(hwnd, lTitleBarColor, True) Do DoEvents
Loop Until GetAsyncKeyState(vbKeyLButton) = 0
GetCursorPos tPt
CopyMemory lngPtr, tPt, LenB(tPt)
If PtInRect(tUpdatedCloseButtonRect, lngPtr) Then
If PtInRect(tUpdatedCloseButtonRect, tPt.x, tPt.y) Then
If PtInRect(tUpdatedCloseButtonRect, tPt.x, tPt.y) Then
If bCloseButtonPressed Then Sleep 200 Unload oForm
End If
End If
If bCloseButtonPressed Then
DrawTitleBar hwnd, lTitleBarColor InvalidateRect hwnd, tClientRect, 0
End If
Case WM_DESTROY
SetWindowLong hwnd, GWL_WNDPROC, lPrevWinProc
SetClassLong hwnd, GCL_STYLE, GetClassLong(hwnd, GCL_STYLE) And Not CS_DROPSHADOW
'DrawTitleBar function
Dim p1 As POINTAPI, p2 As POINTAPI
Dim tFormRect As RECT, tFillRect As RECT
Dim tPs As PAINTSTRUCT
BeginPaint hwnd, tPs
hdc = GetWindowDC(hwnd)
Color = CaptionColor
hBrush = CreateBrushIndirect(Color)
Call GetWindowRect(hwnd, tFormRect)
bCloseButtonPressed = PressedCloseButton
If Not PressedCloseButton Then
SetRect tFormRect, 0, 0, tFormRect.Right, tFormRect.Bottom
SetRect tFillRect, 0, 5, GetSystemMetrics(SM_CXSIZE), GetSystemMetrics(SM_CYSIZE) + tFormRect.Bottom
OffsetRect tFillRect, tWinRect.Right - tWinRect.Left - GetSystemMetrics(SM_CXSIZE), 0
FillRect hdc, tFormRect, hBrush
DeleteObject(hBrush)
DrawFrameControl hdc, tCloseRect, DFC_CAPTION, DFCS_CAPTIONCLOSE Else
DrawFrameControl hdc, tCloseRect, DFC_CAPTION, DFCS_CAPTIONCLOSE + DFCS_PUSHED
End If
If bDropShadow Then
SetClassLong hwnd, GCL_STYLE, GetClassLong(hwnd, GCL_STYLE) Or CS_DROPSHADOW
End If
SetBkMode hdc, 1
SetTextColor hdc, lFontColor
CreateFont(hdc) 'CreateFontIndirect
TextOut hdc, 4, 4, sCaptionText, Len(sCaptionText)
GetClientRect hwnd, tCloseRect
With tCloseRect
.Bottom = GetSystemMetrics(SM_CYCAPTION)
.Left = .Right - 20
.Right = .Right + 3
.Top = .Top + 4
End With
With tCloseRect
p1.x = .Left - 2: p1.y = .Top - 2
p2.x = .Right: p2.y = .Bottom - GetSystemMetrics(SM_CYCAPTION) - 2 End With
ClientToScreen hwnd, p1
ClientToScreen hwnd, p2
With tUpdatedCloseButtonRect
.Left = p1.x: .Top = p1.y - GetSystemMetrics(SM_CYCAPTION)
.Right = p2.x: .Bottom = p2.y
End With
ReleaseDC hwnd, hdc
EndPaint hwnd, tPs