Search the Community
Showing results for tags 'NonClientArea'.
-
Hello! I made a cool script to draw text to the caption bar, but I have some questions. How do I get the position of the icon? How do I get the position of the syscommand buttons (close, minimize, maximize)? How can i avoid flickering while resizing the window? There is a problem with drawing the standard title when there are 2 GUIs. Can this be fixed? TIA ;Coded by funkey!!!! ;2011, Oct 20 #include <Constants.au3> #include <GUIConstantsEx.au3> #include <WinAPIEx.au3> #include <WindowsConstants.au3> Global Const $SPI_GETNONCLIENTMETRICS = 41 Global Const $SPI_SETNONCLIENTMETRICS = 42 Global Const $SPIF_SENDCHANGE = 2 Global Const $SPIF_UPDATEINIFILE = 1 Global Const $tagNONCLIENTMETRICS = "uint cbSize;int iBorderWidth;int iScrollWidth;int iScrollHeight;int iCaptionWidth;int iCaptionHeight;" & _ "byte lfCaptionFont[92];int iSmCaptionWidth;int iSmCaptionHeight;byte lfSmCaptionFont[92];int iMenuWidth;int iMenuHeight;" & _ "byte lfMenuFont[92];byte lfStatusFont[92];byte lfMessageFont[92]";int iPaddedBorderWidth" Global $sTitle1 = "This is a special caption! - This is a special caption! - This is a special caption!" Global $sTitle2 = "Something interessting" Global $ghProcSpecialTitle, $ghWndSpecialTitle Global $nonclientmetrics = DllStructCreate($tagNONCLIENTMETRICS) DllStructSetData($nonclientmetrics, "cbSize", sizeof($nonclientmetrics)) Global $LogFontCaption = DllStructCreate($tagLOGFONT, DllStructGetPtr($nonclientmetrics, "lfCaptionFont")) _WinAPI_SystemParametersInfo($SPI_GETNONCLIENTMETRICS, sizeof($nonclientmetrics), DllStructGetPtr($nonclientmetrics), 0) Global $CaptionFontSize = Abs(DllStructGetData($LogFontCaption, "Height")) Global $CaptionHeight = _WinAPI_GetSystemMetrics(4) Global $BorderWidth = _WinAPI_GetSystemMetrics(5) Global $hForm1 = GUICreate($sTitle1, 400, 400, 100, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX)) _RemoveTheme($hForm1) Global $nBtn1 = GUICtrlCreateButton("Switch-Button", 50, 50, 100, 30) Global $hForm2 = GUICreate($sTitle2, 400, 400, 700, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX)) _RemoveTheme($hForm2) Global $nBtn2 = GUICtrlCreateButton("Switch-Button", 50, 50, 100, 30) _SpecialTitle($hForm1, 1, 0) GUISetState(@SW_SHOW, $hForm1) GUISetState(@SW_SHOW, $hForm2) Local $msg Do $msg = GUIGetMsg() If $msg = $nBtn1 Then _SpecialTitle($hForm1, 0) _SpecialTitleColor(0, 0xFFFFFF, 0xFFFF00, 0xFFFF00) _SpecialTitle($hForm2, 1) ElseIf $msg = $nBtn2 Then _SpecialTitle($hForm2, 0) _SpecialTitleColor(0, 0x0, 0x0, 0x0000FF) _SpecialTitle($hForm1, 1) EndIf Until $msg = $GUI_EVENT_CLOSE _SpecialTitle($ghWndSpecialTitle, 0, 0) Func _SpecialTitle($hWnd, $acitive = 1, $redraw = 1) Static $TitleOn = 0, $hHook, $pHook If $TitleOn = 0 And $acitive = 1 Then $hHook = DllCallbackRegister('_WinProc', 'ptr', 'hwnd;uint;long;ptr') $pHook = DllCallbackGetPtr($hHook) $ghProcSpecialTitle = _WinAPI_SetWindowLongEx($hWnd, -4, $pHook); GWL_WNDPROC = -4 If $redraw Then _WinAPI_RedrawWindow($hWnd, 0, 0, BitOR(1024, 256, 1)) $TitleOn = 1 $ghWndSpecialTitle = $hWnd ElseIf $TitleOn = 1 And $acitive = 0 Then If $hWnd <> $ghWndSpecialTitle Then Return _WinAPI_SetWindowLongEx($hWnd, -4, $ghProcSpecialTitle); GWL_WNDPROC = -4 DllCallbackFree($ghProcSpecialTitle) If $redraw Then _WinAPI_RedrawWindow($hWnd, 0, 0, BitOR(1024, 1)) $TitleOn = 0 $hHook = 0 $pHook = 0 $ghWndSpecialTitle = 0 EndIf EndFunc ;==>_SpecialTitle Func _SpecialTitleColor($iSwitch, $ColorText = 0x0, $ColorPen = 0x0, $ColorBrush = 0x0000FF) Static $sColorText = $ColorText, $sColorPen = $ColorPen, $sColorBrush = $ColorBrush Switch $iSwitch Case 0 $sColorText = $ColorText $sColorPen = $ColorPen $sColorBrush = $ColorBrush Case 1 Return $sColorText Case 2 Return $sColorPen Case 3 Return $sColorBrush EndSwitch EndFunc Func _WinProc($hWnd, $iMsg, $wParam, $lParam) Local $hDC, $hFont, $hFont_orig, $hPen, $hPen_orig, $hBrush, $hBrush_orig, $tRect, $yCaption, $sTitle, $iRectRight Local $Res = _WinAPI_CallWindowProc($ghProcSpecialTitle, $hWnd, $iMsg, $wParam, $lParam) Switch $iMsg Case $WM_NCACTIVATE, $WM_NCPAINT Switch $iMsg Case $WM_NCACTIVATE $hDC = _WinAPI_GetWindowDC($hWnd) Case $WM_NCPAINT $hDC = _WinAPI_GetDCEx($hWnd, $wParam, BitOR(1, 128)) EndSwitch $sTitle = WinGetTitle($hWnd) $hFont = _WinAPI_CreateFontIndirect($LogFontCaption) $hFont_orig = _WinAPI_SelectObject($hDC, $hFont) _WinAPI_SetTextColor($hDC, _SpecialTitleColor(1)) ;TextFarbe _WinAPI_SetBkMode($hDC, $TRANSPARENT) $hPen = _WinAPI_CreatePen($PS_SOLID, 1, _SpecialTitleColor(2)) ;Rahmenfarbe $hPen_orig = _WinAPI_SelectObject($hDC, $hPen) $hBrush = _WinAPI_CreateSolidBrush(_SpecialTitleColor(3)) ;Farbe Füllung $hBrush_orig = _WinAPI_SelectObject($hDC, $hBrush) $tRect = DllStructCreate($tagRect) DllStructSetData($tRect, "Left", 20) ;how do I get this value? DllStructSetData($tRect, "Top", $BorderWidth + ($CaptionHeight - $CaptionFontSize) / 2) DllStructSetData($tRect, "Right", 0) DllStructSetData($tRect, "Bottom", 0) _WinAPI_DrawText($hDC, " " & $sTitle & " ", $tRect, $DT_CALCRECT) DllStructSetData($tRect, "Bottom", DllStructGetData($tRect, "Bottom") + 1) $iRectRight = WinGetPos($hWnd) $iRectRight = $iRectRight[2] - 58 If DllStructGetData($tRect, "Right") > $iRectRight Then DllStructSetData($tRect, "Right", $iRectRight) ;how do I get this value? _WinAPI_RoundRect($hDC, $tRect, 8, 8) _WinAPI_DrawText($hDC, " " & $sTitle, $tRect, $DT_LEFT + $DT_END_ELLIPSIS) _WinAPI_SelectObject($hDC, $hBrush_orig) _WinAPI_DeleteObject($hBrush) _WinAPI_SelectObject($hDC, $hPen_orig) _WinAPI_DeleteObject($hPen) _WinAPI_SelectObject($hDC, $hFont_orig) _WinAPI_DeleteObject($hFont) _WinAPI_ReleaseDC($hWnd, $hDC) EndSwitch Return $Res EndFunc ;==>_WinProc Func sizeof($struct) Return DllStructGetSize($struct) EndFunc ;==>sizeof Func _RemoveTheme($hCtrl) If Not IsHWnd($hCtrl) Then $hCtrl = GUICtrlGetHandle($hCtrl) If IsHWnd($hCtrl) Then Local $aR = DllCall("UxTheme.dll", "Long", "SetWindowTheme", "HWND", $hCtrl, "Ptr", 0, "WStr", " ") If Not @error And $aR[0] = 0 Then Return True EndIf Return False EndFunc ;==>_RemoveTheme