Page 1 of 1

GetThemeDocumentationProperty() [Windows]

Posted: Sat Aug 20, 2011 8:36 am
by RASHAD
Regarding
http://www.purebasic.fr/english/viewto ... 3&t=30737

This is how to implement GetCurrentThemeName() and GetThemeDocumentationProperty()
Compile as Unicode

Tested with PB 4.60 Beta3 & Windows 7 x64

Code: Select all

; GetThemeDocumentationProperty Function
; Retrieves the value For a theme property from the documentation section of the specified theme file.
; 
; Syntax
; CopyHRESULT GetThemeDocumentationProperty(
;   __in   LPCWSTR pszThemeName,
;   __in   LPCWSTR pszPropertyName,
;   __out  LPWSTR pszValueBuff,
;   __in   int cchMaxValChars
; );
; Parameters
; pszThemeName [in]
; Type: LPCWSTR
; 
; Pointer To a string that contains the name of the theme file that will be opened To query For the property.
; 
; pszPropertyName [in]
; Type: LPCWSTR
; 
; Pointer To a string that contains the name of the theme property To query. Can be one of the following values.
; 
; Value Meaning 
; SZ_THDOCPROP_DISPLAYNAME Retrieves the display name of the theme. 
;  
; SZ_THDOCPROP_TOOLTIP Retrieves the tooltip associated With this theme.
;  
; SZ_THDOCPROP_AUTHOR Retrieves the name of the author of the theme.
;  
; SZ_THDOCPROP_CANONICALNAME Retrieves the name of the theme.
; 
;   SZ_THDOCPROP_DISPLAYNAME               = WideString('DisplayName');
;   SZ_THDOCPROP_CANONICALNAME             = WideString('ThemeName');
;   SZ_THDOCPROP_TOOLTIP                   = WideString('ToolTip');
;   SZ_THDOCPROP_AUTHOR                    = WideString('author');
; 
; pszValueBuff [out]
; Type: LPWSTR
; 
; Pointer To a string buffer that receives the property string value.
; 
; cchMaxValChars [in]
; Type: int
; 
; Value of type int that specifies the maximum number of characters that pszValueBuff can contain.
; 
; Return Value
; Type: HRESULT
; 
; If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
  
Import "UxTheme.lib"    
  GetCurrentThemeName(pszThemeFileName, dwMaxNameChars, pszColorBuff, cchMaxColorChars, pszSizeBuff, cchMaxSizeChars)
  GetThemeDocumentationProperty(pszThemeName, pszPropertyName, pszValueBuff, cchMaxValChars)    
EndImport

ThemeFileName=AllocateMemory(2*(#MAX_PATH+1))
AnsiBuff_1=AllocateMemory(#MAX_PATH)
pszValueBuff=AllocateMemory(2*(#MAX_PATH+1))
AnsiBuff_2=AllocateMemory(#MAX_PATH)

CoInitialize_(0)
  GetCurrentThemeName(ThemeFileName,#MAX_PATH,ColorBuff,#MAX_PATH,0,0)
  pszThemeName.s = PeekS(ThemeFileName)
  Debug pszThemeName.s
  GetThemeDocumentationProperty(@pszThemeName.s,@"ThemeName",pszValueBuff,#MAX_PATH)
CoUninitialize_()
  
Debug PeekS(pszValueBuff)  

Re: GetThemeDocumentationProperty() [Windows]

Posted: Sun Aug 21, 2011 2:55 am
by IdeasVacuum
Brilliant stuff Rashad - I see that uxtheme.lib is in the PB PureLibraries folder too.

For performance-critical applications, some of the fancy windows effects just have to go - swapping themes is a quick way, and of course one could define a custom theme to match the app, something which Users may find a bit more reassuring.

Re: GetThemeDocumentationProperty() [Windows]

Posted: Sun Aug 21, 2011 7:55 am
by RASHAD
Thanks mate
Next is a revised version
- Ascii & Unicode compatible
- Qrganized
- Tested with XP,Win 7 x86,x64

Code: Select all

; GetThemeDocumentationProperty Function
; Retrieves the value For a theme property from the documentation section of the specified theme file.
; 
; Syntax
; CopyHRESULT GetThemeDocumentationProperty(
;   __in   LPCWSTR pszThemeName,
;   __in   LPCWSTR pszPropertyName,
;   __out  LPWSTR pszValueBuff,
;   __in   int cchMaxValChars
; );
; Parameters
; pszThemeName [in]
; Type: LPCWSTR
; 
; Pointer To a string that contains the name of the theme file that will be opened To query For the property.
; 
; pszPropertyName [in]
; Type: LPCWSTR
; 
; Pointer To a string that contains the name of the theme property To query. Can be one of the following values.
; 
; Value Meaning 
; SZ_THDOCPROP_DISPLAYNAME Retrieves the display name of the theme. 
;  
; SZ_THDOCPROP_TOOLTIP Retrieves the tooltip associated With this theme.
;  
; SZ_THDOCPROP_AUTHOR Retrieves the name of the author of the theme.
;  
; SZ_THDOCPROP_CANONICALNAME Retrieves the name of the theme.
; 
;   SZ_THDOCPROP_DISPLAYNAME               = WideString('DisplayName');
;   SZ_THDOCPROP_CANONICALNAME             = WideString('ThemeName');
;   SZ_THDOCPROP_TOOLTIP                   = WideString('ToolTip');
;   SZ_THDOCPROP_AUTHOR                    = WideString('author');
; 
; pszValueBuff [out]
; Type: LPWSTR
; 
; Pointer To a string buffer that receives the property string value.
; 
; cchMaxValChars [in]
; Type: int
; 
; Value of type int that specifies the maximum number of characters that pszValueBuff can contain.
; 
; Return Value
; Type: HRESULT
; 
; If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
  
Import "UxTheme.lib"    
  GetCurrentThemeName(*pszThemeFileName, dwMaxNameChars, *pszColorBuff, cchMaxColorChars, *pszSizeBuff, cchMaxSizeChars)
  GetThemeDocumentationProperty(*pszThemeName, *pszPropertyName, *pszValueBuff, cchMaxValChars)    
EndImport

*MemoryBuffer_1=AllocateMemory(2*(#MAX_PATH+1))
*MemoryBuffer_2 = AllocateMemory(#MAX_PATH)
*ValueBuff=AllocateMemory(#MAX_PATH)
*AnsiBuff=AllocateMemory(#MAX_PATH)

CoInitialize_(0)
  GetCurrentThemeName(*MemoryBuffer_1,#MAX_PATH,0,#MAX_PATH,0,0)
  PokeS(*AnsiBuff,PeekS(*MemoryBuffer_1,-1,#PB_Unicode), -1, #PB_Ascii)
  ;WideCharToMultiByte_(#CP_ACP,#WC_COMPOSITECHECK,*MemoryBuffer_1,-1,*AnsiBuff,#MAX_PATH,0,0)
  
  CompilerIf #PB_Compiler_Unicode
    pszThemeName.s = PeekS(*MemoryBuffer_1)    
  CompilerElse
    pszThemeName.s = PeekS(*AnsiBuff)
  CompilerEndIf  
  
  Debug pszThemeName
  
  Query.s = "ThemeName"
  
  CompilerIf #PB_Compiler_Unicode
    GetThemeDocumentationProperty(@pszThemeName.s,@Query,*ValueBuff,#MAX_PATH)
    pszValueBuff.s = PeekS(*ValueBuff)    
  CompilerElse
    PokeS(*MemoryBuffer_1, PeekS(@pszThemeName.s), -1, #PB_Unicode)    
    PokeS(*MemoryBuffer_2, Query.s, -1, #PB_Unicode)
    GetThemeDocumentationProperty(*MemoryBuffer_1,*MemoryBuffer_2,*ValueBuff,#MAX_PATH)
    PokeS(*AnsiBuff,PeekS(*ValueBuff,-1,#PB_Unicode), -1, #PB_Ascii)
    ;WideCharToMultiByte_(#CP_ACP,#WC_COMPOSITECHECK,*ValueBuff,-1,*AnsiBuff,#MAX_PATH,0,0)
    pszValueBuff.s = PeekS(*AnsiBuff)
  CompilerEndIf
  
  Debug pszValueBuff
  
CoUninitialize_()


Re: GetThemeDocumentationProperty() [Windows]

Posted: Sun Aug 21, 2011 11:09 am
by Tomi
very nice :D :D :D :D :D Thanks

Re: GetThemeDocumentationProperty() [Windows]

Posted: Wed Aug 24, 2011 8:39 am
by Kwai chang caine
Hello RASHAD :wink:

I try your code and not see something ... :(
The debbuger return nothing :shock:
I have VISTA SP1 is it the reason ???

What your code must be do ??

Re: GetThemeDocumentationProperty() [Windows]

Posted: Wed Aug 24, 2011 12:52 pm
by RASHAD
@Tomi Hi
Thank you very much

@KCC hi
Long time no see why?
This subject is related to

http://www.purebasic.fr/english/viewto ... 3&t=30737

and

http://www.purebasic.fr/english/viewto ... 5&t=47173

But yes I just noticed that there is some problems with Vista x86 SP1 Classic Theme
It works fine with Aero Theme
Please confirm
And thanks mate

Re: GetThemeDocumentationProperty() [Windows]

Posted: Wed Aug 24, 2011 4:23 pm
by Kwai chang caine
It works fine with Aero Theme
It's surely that the problem
It's a vista with no aero (Computer of my job)

it does not matter, thanks to your answer 8)