Thread: Windows XP visual themes and style changing

  1. #1
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401

    Windows XP visual themes and style changing

    I thought I'd make this a new thread to focus on this particular problem.

    My question is: is anyone familiar with the way that Windows XP visual themes work, as well as programs such as Windows Blinds, and if so, could they direct me as to where to find a detailed resource on this topic?

    Also, I would like to know why I can only change top-level window styles when using the default XP visual style. When any other theme/style is present, the window style cannot be changed. For example, I cannot add/remove the caption bar or sizing border. This is the code if anyone wants:

    Code:
    style=GetWindowLong(hwnd,GWL_STYLE);//get current window style
    				
    if (style&WS_CAPTION) //if we have caption
    {
    	style&=(~WS_CAPTION); //remove caption and thickframe
    	style&=(~WS_SIZEBOX);
    	style&=(~WS_SYSMENU);
    	style&=(~WS_BORDER);
    }
    else //otherwise
    {
    	style|=WS_CAPTION; //put em in
    	style|=WS_SIZEBOX;
    	style|=WS_SYSMENU;
    	style|=WS_BORDER;
    }
    
    SetWindowLong(hwnd,GWL_STYLE,style); //change window style
    SetWindowPos(hwnd,NULL,rc.left-1,rc.top, rc.right-rc.left,rc.bottom-rc.top,SWP_NOZORDER); //move to update
    SetWindowPos(hwnd,NULL,rc.left, rc.top,rc.right-rc.left,rc.bottom-rc.top,SWP_NOZORDER); //move back
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  2. #2
    Master of the Universe! velius's Avatar
    Join Date
    Sep 2003
    Posts
    219
    The following link should be of use to the topic and explain some things.
    http://www.codeproject.com/useritems...%7Cxp%7Cthemes
    While you're breakin' down my back n'
    I been rackin' out my brain
    It don't matter how we make it
    'Cause it always ends the same
    You can push it for more mileage
    But your flaps r' wearin' thin
    And I could sleep on it 'til mornin'
    But this nightmare never ends
    Don't forget to call my lawyers
    With ridiculous demands
    An you can take the pity so far
    But it's more than I can stand
    'Cause this couchtrip's gettin' older
    Tell me how long has it been
    'Cause 5 years is forever
    An you haven't grown up yet
    -- You Could Be Mine - Guns N' Roses

  3. #3
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Thanks velius, I've found out how to disable visual themes for my application. I haven't however, actually done it yet. Doing so requires a header file, uxtheme.h, that I do not have on my computer. I haven't found it anywhere by itself, and I do not feel like downloading the 180mb core SDK from MSDN. Could somebody please post up that header file?

    I was thinking about this problem, and I realized what must be happening. Using any visual theme except the XP style, any subsequent repaints of a window (after window creation) do not actually check for a style change. Ie, at window creation, the window style is recorded, and that same style is used throughout the windows entire lifetime. Thus, changing the style through SetWindowLong() will have no effect on that whatsoever. Could anyone shed some light on this behavior?

    EDIT: I also need uxtheme.lib.
    Last edited by bennyandthejets; 10-01-2003 at 09:23 PM.
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  4. #4
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    I managed to download a 40mb version of the SDK, so now I can use the API functions for visual themes. I still can't disable themes for my application however. This is my code:

    Code:
    int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR cmd,int shCmd)
    {
    	//------------------Prevent visual styles-------------------------
    	SetThemeAppProperties(NULL);
    Any windows created in my application still use the visual theme selected (Classic style). Shouldn't they default to XP style now?
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  5. #5
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    I just found something else awry. When I add that line, SetThemeAppProperties(NULL), changing the window style doesn't work AT ALL, even when using the default Windows XP style. I just don't understand what's going on.
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  6. #6
    Master of the Universe! velius's Avatar
    Join Date
    Sep 2003
    Posts
    219
    Remember that all of the theme drawing code is handled with the WM_NCPAINT message. Your program does not normally handle it and it is therefore passed on to DefalutWindowProc() which then draws it. There is mostlikely a bug in that feature.
    While you're breakin' down my back n'
    I been rackin' out my brain
    It don't matter how we make it
    'Cause it always ends the same
    You can push it for more mileage
    But your flaps r' wearin' thin
    And I could sleep on it 'til mornin'
    But this nightmare never ends
    Don't forget to call my lawyers
    With ridiculous demands
    An you can take the pity so far
    But it's more than I can stand
    'Cause this couchtrip's gettin' older
    Tell me how long has it been
    'Cause 5 years is forever
    An you haven't grown up yet
    -- You Could Be Mine - Guns N' Roses

  7. #7
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Do you think that I should handle the WM_NCPAINT message myself and make an owner drawn caption and border? I'd prefer working out how to use the system functions properly. Surely there is a way to get them to work.
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  8. #8
    Master of the Universe! velius's Avatar
    Join Date
    Sep 2003
    Posts
    219
    I dunno, I actually have no intrest in using that feature myself. I just wanted to help you out. So anyways I'd consider patching Windows XP with SP 1 if you haven't yet and then if your using a Microsoft IDE to program with, I'd check for patches for that too. Beyond that it seems you need to use the .Net C++ extention for Manifesting the XP controls.
    While you're breakin' down my back n'
    I been rackin' out my brain
    It don't matter how we make it
    'Cause it always ends the same
    You can push it for more mileage
    But your flaps r' wearin' thin
    And I could sleep on it 'til mornin'
    But this nightmare never ends
    Don't forget to call my lawyers
    With ridiculous demands
    An you can take the pity so far
    But it's more than I can stand
    'Cause this couchtrip's gettin' older
    Tell me how long has it been
    'Cause 5 years is forever
    An you haven't grown up yet
    -- You Could Be Mine - Guns N' Roses

  9. #9
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    I have dialup so it's really hard for me to get a hold of those things. Could someone else who has Windows XP sp1, and maybe Visual Studio .NET compile this file and see if it works please?

    Note: press alt-c to change window style, alt-q to exit. You'll have to link with comclt32.lib and uxtheme.lib.
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  10. #10
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    From MSDN:
    If you apply a region to a top-level window and later remove the region, a visual style is not automatically applied to the window. To apply a visual style to the window, you must create a new window.
    Is that what is causing this problem? If it is, it means I WILL have to draw everything myself. What a bother.
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  11. #11
    Master of the Universe! velius's Avatar
    Join Date
    Sep 2003
    Posts
    219
    You might just need to. One of the things I know for sure is that if you wan the same menu style from Office XP then you must draw it all yourself. So it would stand to reason that that would mean this feature is the same.
    While you're breakin' down my back n'
    I been rackin' out my brain
    It don't matter how we make it
    'Cause it always ends the same
    You can push it for more mileage
    But your flaps r' wearin' thin
    And I could sleep on it 'til mornin'
    But this nightmare never ends
    Don't forget to call my lawyers
    With ridiculous demands
    An you can take the pity so far
    But it's more than I can stand
    'Cause this couchtrip's gettin' older
    Tell me how long has it been
    'Cause 5 years is forever
    An you haven't grown up yet
    -- You Could Be Mine - Guns N' Roses

  12. #12
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Should I use the DrawThemeText() and DrawThemeEdge() functions? I guess if I did that, my window would look like all the others on my screen.
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  13. #13
    Master of the Universe! velius's Avatar
    Join Date
    Sep 2003
    Posts
    219
    No. What I'd do is come up with 'style' of your own. Then you can use LineTo() and various other functions for rectangles and the such. Just experiement with it.
    While you're breakin' down my back n'
    I been rackin' out my brain
    It don't matter how we make it
    'Cause it always ends the same
    You can push it for more mileage
    But your flaps r' wearin' thin
    And I could sleep on it 'til mornin'
    But this nightmare never ends
    Don't forget to call my lawyers
    With ridiculous demands
    An you can take the pity so far
    But it's more than I can stand
    'Cause this couchtrip's gettin' older
    Tell me how long has it been
    'Cause 5 years is forever
    An you haven't grown up yet
    -- You Could Be Mine - Guns N' Roses

  14. #14
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Do you think that this problem would be addressed by future versions of Windows?
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  15. #15
    Master of the Universe! velius's Avatar
    Join Date
    Sep 2003
    Posts
    219
    Let's hope it comes after security.
    While you're breakin' down my back n'
    I been rackin' out my brain
    It don't matter how we make it
    'Cause it always ends the same
    You can push it for more mileage
    But your flaps r' wearin' thin
    And I could sleep on it 'til mornin'
    But this nightmare never ends
    Don't forget to call my lawyers
    With ridiculous demands
    An you can take the pity so far
    But it's more than I can stand
    'Cause this couchtrip's gettin' older
    Tell me how long has it been
    'Cause 5 years is forever
    An you haven't grown up yet
    -- You Could Be Mine - Guns N' Roses

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. win xp look&feel
    By aym_7 in forum Windows Programming
    Replies: 9
    Last Post: 05-11-2002, 08:28 PM