Modify

Opened 9 months ago

Closed 9 months ago

#3993 closed Bug (No Bug)

_WinAPI_SetWindowTheme() - remove limits

Reported by: argumentum Owned by:
Milestone: Component: Standard UDFs
Version: 3.3.16.1 Severity: None
Keywords: SetWindowTheme Cc:

Description

Trying to change a color on a checkbox control I needed to remove the theme and found the limitation on the implementation of the wrapper.
The request is to remove the "string or null, only" from the func., as zero is the value that is needed in this case.

#include <WinAPITheme.au3>
Test()
Func Test()
	GUICreate(@ScriptName)

	GUICtrlCreateCheckbox("one", 10, 10, 200)

	GUICtrlCreateCheckbox("two", 10, 30, 200)
	GUICtrlSetColor(-1, 0xFF00FF)

	GUICtrlCreateCheckbox("three", 10, 50, 200)
	_WinAPI_SetWindowTheme(GUICtrlGetHandle(-1)) ;, 0, 0)
	GUICtrlSetColor(-1, 0xFF00FF)

	GUICtrlCreateCheckbox("Four", 10, 70, 200)
	_WinAPI_SetWindowTheme_mod(GUICtrlGetHandle(-1)) ;, 0, 0)
	GUICtrlSetColor(-1, 0xFF00FF)

	GUISetState()
	While GUIGetMsg() <> -3
	WEnd
	GUIDelete()
EndFunc

Func _WinAPI_SetWindowTheme_mod($hWnd, $sName = Default, $sList = Default) ; #include <WinAPITheme.au3>
;~ 	If Not IsString($sName) Then $sName = Null ; <-- this limits what can get done with it.
;~ 	If Not IsString($sList) Then $sList = Null ; also, don't ask me why "Default" works !, I was going to use 0

	Local $sResult = DllCall('UxTheme.dll', 'long', 'SetWindowTheme', 'hwnd', $hWnd, 'wstr', $sName, 'wstr', $sList)
	If @error Then Return SetError(@error, @extended, 0)
	If $sResult[0] Then Return SetError(10, $sResult[0], 0)
	Return 1
EndFunc   ;==>_WinAPI_SetWindowTheme

Attachments (0)

Change History (7)

comment:1 Changed 9 months ago by argumentum <argumentum@…>

in 3.3.14.5 it was:

Func _WinAPI_SetWindowTheme($hWnd, $sName = Default, $sList = Default)
	Local $sTypeOfName = 'wstr', $sTypeOfList = 'wstr'
	If Not IsString($sName) Then
		$sTypeOfName = 'ptr'
		$sName = 0
	EndIf
	If Not IsString($sList) Then
		$sTypeOfList = 'ptr'
		$sList = 0
	EndIf

	Local $aRet = DllCall('uxtheme.dll', 'long', 'SetWindowTheme', 'hwnd', $hWnd, $sTypeOfName, $sName, $sTypeOfList, $sList)
	If @error Then Return SetError(@error, @extended, 0)
	If $aRet[0] Then Return SetError(10, $aRet[0], 0)

	Return 1
EndFunc   ;==>_WinAPI_SetWindowTheme

maybe that's better than removing the "If Not IsString($sName) Then $sName = Null" ?

comment:2 Changed 9 months ago by argumentum <argumentum@…>

ok, close this and pardon my ignorance.
Calling $name and $list as an empty string is what I should have done.

anyone reading this in the future, here's an extended/"free style" function:

; these defaults are the most common use when calling SetWindowTheme
; to remove a theme, use name and list with "" ( empty string, do not use 0 as it is not an expected 'wstr' )
Func _WinAPI_SetWindowThemeEx($hWnd, $sName = 'Explorer', $sList = Null, $sTypeOfName = 'wstr', $sTypeOfList = 'wstr')
	Local $sTypeOfName = 'wstr', $sTypeOfList = 'wstr' ; a 'ptr' can be passed too
	Local $aRet = DllCall('uxtheme.dll', 'long', 'SetWindowTheme', 'hwnd', $hWnd, $sTypeOfName, $sName, $sTypeOfList, $sList)
	If @error Then Return SetError(@error, @extended, 0)
	If $aRet[0] Then Return SetError(10, $aRet[0], 0)
	Return 1
EndFunc   ;==>_WinAPI_SetWindowThemeEx

comment:3 Changed 9 months ago by argumentum <argumentum@…>

This would work for ... no clue, but is not a bad idea either:

Func _WinAPI_SetWindowTheme($hWnd, $sName = Default, $sList = Default) ; #include <WinAPITheme.au3>
	If Not IsString($sName) Then $sName = Null
	If Not IsString($sList) Then $sList = Null
	Local $sResult = _WinAPI_SetWindowThemeEx($hWnd, $sName, $sList)
	Return SetError(@error, @extended, $sResult)
EndFunc   ;==>_WinAPI_SetWindowTheme

Func _WinAPI_SetWindowThemeEx($hWnd, $sName = 'Explorer', $sList = Null, $sTypeOfName = 'wstr', $sTypeOfList = 'wstr')
	Local $sTypeOfName = 'wstr', $sTypeOfList = 'wstr' ; a 'ptr' can be passed too
	Local $aRet = DllCall('uxtheme.dll', 'long', 'SetWindowTheme', 'hwnd', $hWnd, $sTypeOfName, $sName, $sTypeOfList, $sList)
	If @error Then Return SetError(@error, @extended, 0)
	If $aRet[0] Then Return SetError(10, $aRet[0], 0)
	Return 1
EndFunc   ;==>_WinAPI_SetWindowThemeEx

comment:4 Changed 9 months ago by Jpm

I don't knowif it is so useful to extend this function as coloring checkbox can be done with the current implementation

#include <GUIConstantsEx.au3>
#include <WinAPITheme.au3>

Test()

Func Test()
	GUICreate(@ScriptName, 410, 150)

	GUICtrlCreateCheckbox("No Color", 10, 10, 400)

	GUICtrlCreateCheckbox("Set color by AutoIt", 10, 30, 400)
	GUICtrlSetColor(-1, 0xFF0000)

	GUICtrlCreateCheckbox("Set Window Theme Default, Default", 10, 50, 400)
	_WinAPI_SetWindowTheme(GUICtrlGetHandle(-1))
	GUICtrlSetColor(-1, 0xFF0000)

	GUICtrlCreateCheckbox('Set Window Theme "", ""', 10, 70, 400)
	_WinAPI_SetWindowTheme(GUICtrlGetHandle(-1), "", "")
	GUICtrlSetColor(-1, 0xFF0000)

	_WinAPI_SetThemeAppProperties(0)
	GUICtrlCreateCheckbox("Set color by AutoIt with _WinAPI_SetThemeAppProperties(0)", 10, 90, 400)
	GUICtrlSetColor(-1, 0xFF0000)

	GUICtrlCreateCheckbox("Set Window Theme modified no Default checking", 10, 110, 400)
;~ 	_WinAPI_SetWindowThemeEx(GUICtrlGetHandle(-1), "", "") ; same as _WinAPI_SetWindowTheme()
	_WinAPI_SetWindowThemeEx(GUICtrlGetHandle(-1), Default, Default)
;~ 	_WinAPI_SetWindowThemeEx(GUICtrlGetHandle(-1), 0, 0)
	GUICtrlSetColor(-1, 0xFF00FF)

	GUISetState()

	While GUIGetMsg() <> $GUI_EVENT_CLOSE
		Sleep(50)
	WEnd

	GUIDelete()
EndFunc   ;==>Test

Func _WinAPI_SetWindowThemeEx($hWnd, $sName = 'Explorer', $sList = Null, $sTypeOfName = 'wstr', $sTypeOfList = 'wstr')
	Local $aRet = DllCall('uxtheme.dll', 'long', 'SetWindowTheme', 'hwnd', $hWnd, $sTypeOfName, $sName, $sTypeOfList, $sList)
	If @error Then Return SetError(@error, @extended, 0)
	If $aRet[0] Then Return SetError(10, $aRet[0], 0)

	Return 1
EndFunc   ;==>_WinAPI_SetWindowThemeEx

comment:5 Changed 9 months ago by argumentum <argumentum@…>

I went overboard. You are right.
Ok, this modification will take 0 as it did in prior versions.
So it returns the expectation that ",0,0)" would do, without having to "'ptr',0" each field.

#include <GUIConstantsEx.au3>
#include <WinAPITheme.au3>

Func _WinAPI_SetWindowTheme_TakesZero($hWnd, $sName = Default, $sList = Default)
	If Not IsString($sName) Then $sName = ($sName = 0 ? "" : Null)
	If Not IsString($sList) Then $sList = ($sName = 0 ? "" : Null)
	Local $sResult = DllCall('uxtheme.dll', 'long', 'SetWindowTheme', 'hwnd', $hWnd, 'wstr', $sName, 'wstr', $sList)
	If @error Then Return SetError(@error, @extended, 0)
	If $sResult[0] Then Return SetError(10, $sResult[0], 0)
	Return 1
EndFunc   ;==>_WinAPI_SetWindowTheme


Test()

Func Test()
	GUICreate(@ScriptName, 410, 180)

	GUICtrlCreateCheckbox("No Color", 10, NextHeight(10), 400)

	GUICtrlCreateCheckbox("Set color by AutoIt", 10, NextHeight(), 400)
	GUICtrlSetColor(-1, 0xFF0000)

	GUICtrlCreateCheckbox("Set Window Theme Default, Default", 10, NextHeight(), 400)
	_WinAPI_SetWindowTheme_TakesZero(GUICtrlGetHandle(-1))
	GUICtrlSetColor(-1, 0xFF0000)

	GUICtrlCreateCheckbox('Set Window Theme "", ""', 10, NextHeight(), 400)
	_WinAPI_SetWindowTheme_TakesZero(GUICtrlGetHandle(-1), "", "")
	GUICtrlSetColor(-1, 0xFF0000)

	GUICtrlCreateCheckbox("Set Window Theme mod. _TakeZero() with "" 0, 0)"" <<<<< ", 10, NextHeight(), 400)
;~ 	_WinAPI_SetWindowThemeEx(GUICtrlGetHandle(-1), "", "") ; same as _WinAPI_SetWindowTheme()
	_WinAPI_SetWindowTheme_TakesZero(GUICtrlGetHandle(-1), 0, 0)
;~ 	_WinAPI_SetWindowThemeEx(GUICtrlGetHandle(-1), 0, 0)
	GUICtrlSetColor(-1, 0xFF00FF)

	_WinAPI_SetThemeAppProperties(0)
	GUICtrlCreateCheckbox("Set color by AutoIt with _WinAPI_SetThemeAppProperties(0)", 10, NextHeight(), 400)
	GUICtrlSetColor(-1, 0xFF0000)

	GUICtrlCreateCheckbox("Set Window Theme modified no Default checking", 10, NextHeight(), 400)
;~ 	_WinAPI_SetWindowThemeEx(GUICtrlGetHandle(-1), "", "") ; same as _WinAPI_SetWindowTheme()
	_WinAPI_SetWindowTheme_TakesZero(GUICtrlGetHandle(-1), Default, Default)
;~ 	_WinAPI_SetWindowThemeEx(GUICtrlGetHandle(-1), 0, 0)
	GUICtrlSetColor(-1, 0xFF00FF)

	GUISetState()

	While GUIGetMsg() <> $GUI_EVENT_CLOSE
		Sleep(50)
	WEnd

	GUIDelete()
EndFunc   ;==>Test

Func NextHeight($iInit = Default)
	Local Static $iNext = 0
	If $iInit = Default Then
		$iNext += 20
	Else
		$iNext = $iInit
	EndIf
	Return $iNext
EndFunc

comment:6 Changed 9 months ago by argumentum <argumentum@…>

Func _WinAPI_SetWindowTheme($hWnd, $sName = Default, $sList = Default)
	If Not IsString($sName) Then $sName = ($sName = 0 ? "" : Null)
	If Not IsString($sList) Then $sList = ($sList = 0 ? "" : Null) ; <<< mistake in the prior post
	Local $sResult = DllCall('uxtheme.dll', 'long', 'SetWindowTheme', 'hwnd', $hWnd, 'wstr', $sName, 'wstr', $sList)
	If @error Then Return SetError(@error, @extended, 0)
	If $sResult[0] Then Return SetError(10, $sResult[0], 0)
	Return 1
EndFunc   ;==>_WinAPI_SetWindowTheme

comment:7 Changed 9 months ago by Jpm

  • Resolution set to No Bug
  • Status changed from new to closed

Hi,
there is no bug as 0, 0 will use Null in the current implementation
you must us "", "" if if you want to siable as stated in the doc
Cheers

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The ticket will remain with no owner.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.