GetThemeDocumentationProperty() [Windows]

Share your advanced PureBasic knowledge/code with the community.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

GetThemeDocumentationProperty() [Windows]

Post 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)  
Egypt my love
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: GetThemeDocumentationProperty() [Windows]

Post 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.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: GetThemeDocumentationProperty() [Windows]

Post 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_()

Egypt my love
User avatar
Tomi
Enthusiast
Enthusiast
Posts: 270
Joined: Wed Sep 03, 2008 9:29 am

Re: GetThemeDocumentationProperty() [Windows]

Post by Tomi »

very nice :D :D :D :D :D Thanks
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: GetThemeDocumentationProperty() [Windows]

Post 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 ??
ImageThe happiness is a road...
Not a destination
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: GetThemeDocumentationProperty() [Windows]

Post 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
Egypt my love
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: GetThemeDocumentationProperty() [Windows]

Post 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)
ImageThe happiness is a road...
Not a destination
Post Reply