Jump to content
  • Advertisement
Sign in to follow this  
Fish Fishes

Tab controls and dialogs

This topic is 4846 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How to insert transparent dialog in the tab control. Well, I have the tab control w/ the light silver color and I want controls to appear on it transparently. But when I place the dialog - the light silver colour is changed w/ dialogs' gray colour.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Fish Fishes
How to insert transparent dialog in the tab control.
Well, I have the tab control w/ the light silver color and I want controls to appear on it transparently. But when I place the dialog - the light silver colour is changed w/ dialogs' gray colour.


You mean getting the XP theming to work?

Presumably you've already set up a manifest file as described here, otherwise the tab itself wouldn't look themed.

Which means that the problem is that the dialog message handler isn't using the correct brushes to draw everything. I had a similar problem with an application a while back - there may be an 'easy' way of dealing with it, but I never found it, and ended up writing some functions to get the theme's tab background bitmap as a brush, and overriding the WM_CTLCOLORDLG, WM_CTLCOLORSTATIC, WM_CTLCOLORSCROLLBAR and WM_CTLCOLORBTN messages to return that brush to the system. (in the case of the latter three, you have to use SetBrushOrgEx to change the origin of the brush to make it blend properly)

This link should contain most of the info you need on the Windows XP theme API, if you're really stuck on the theming I could probably dig up a bit of code to help.

Share this post


Link to post
Share on other sites
Code would be great...

Well, I want to make a tranpsparent control. E.g. I have child dialog which is brushed w/ gray color. I want to make it transparent.
One solvation of this task was to override WM_ERASEBKGRN and return TRUE.
But the next time I load that child dialog, I had some old backgrounds.

I had manifest. The tab control is drawn XP-stylish, but the child dialog over it fill tab control w/ its background.

Want just to make controls (or dialogs) transparent...

I have read smth about layers (in NT500) but I think its not the great solvement.

Quote:
Original post by Sandman
Quote:
Original post by Fish Fishes
How to insert transparent dialog in the tab control.
Well, I have the tab control w/ the light silver color and I want controls to appear on it transparently. But when I place the dialog - the light silver colour is changed w/ dialogs' gray colour.


You mean getting the XP theming to work?

Presumably you've already set up a manifest file as described here, otherwise the tab itself wouldn't look themed.

Which means that the problem is that the dialog message handler isn't using the correct brushes to draw everything. I had a similar problem with an application a while back - there may be an 'easy' way of dealing with it, but I never found it, and ended up writing some functions to get the theme's tab background bitmap as a brush, and overriding the WM_CTLCOLORDLG, WM_CTLCOLORSTATIC, WM_CTLCOLORSCROLLBAR and WM_CTLCOLORBTN messages to return that brush to the system. (in the case of the latter three, you have to use SetBrushOrgEx to change the origin of the brush to make it blend properly)

This link should contain most of the info you need on the Windows XP theme API, if you're really stuck on the theming I could probably dig up a bit of code to help.


Share this post


Link to post
Share on other sites
The following code generates an HBRUSH which can be used to draw the tab theme on a dialog box or other control.



// ** not fully tested ** //

#include <uxtheme.h>
#include <tmschema.h>

typedef HRESULT (__stdcall *DrawThemeBackgroundFunc)(HTHEME,HDC,int,int,LPRECT,LPRECT);
typedef HTHEME (__stdcall *OpenThemeDataFunc)(HWND,LPCWSTR);
typedef HRESULT (__stdcall *CloseThemeDataFunc)(HTHEME);
typedef HRESULT (__stdcall *GetThemePartSizeFunc)(HTHEME,HDC,int,int, RECT*,THEMESIZE,SIZE*);

// CreateThemedTabBrush /////////////////////////////////////
//
// Finds the tabbed dialog background in the current theme and
// returns it as a brush
//
// Parameters:
// hThemeBrushOut (output) a handle to the resulting brush
// Return Values:
// true if successful, false if the function fails.
//
bool CreateThemedTabBrush(HBRUSH& hThemeBrushOut)
{
// load libraries and theme functions..
HMODULE hModXP = LoadLibrary("uxtheme.dll");
if(!hModXP)
{
return false;
}
// Import the required functions...
OpenThemeDataFunc pOpenThemeData = (OpenThemeDataFunc) GetProcAddress(hModXP,"OpenThemeData");
CloseThemeDataFunc pCloseThemeData = (CloseThemeDataFunc) GetProcAddress(hModXP,"CloseThemeData");
DrawThemeBackgroundFunc pDrawThemeBackground = (DrawThemeBackgroundFunc) GetProcAddress(hModXP,"DrawThemeBackground");
GetThemePartSizeFunc pGetThemePartSize = (GetThemePartSizeFunc) GetProcAddress(hModXP,"GetThemePartSize");

// make sure they all exist:
if(!pOpenThemeData || !pCloseThemeData || !pDrawThemeBackground || !pThemeGetPartSize)
{
FreeLibrary(hModXP);
return false;
}
// Open a theme handle
HTHEME hTheme = pOpenThemeData(hWnd,L"TAB");

if(!hTheme)
{
// no theme enabled
FreeLibrary(hModXP);
return false;
}

HDC hdc = 0;
HDC hdcMain = GetDC(GetDesktopWindow());

RECT rc;
GetClientRect(hWnd,&rc);
SIZE sz;

// figure out how big the theme background bitmap is
pGetThemePartSize(hTheme,hdcMain,TABP_BODY,0,&rc,TS_TRUE,&sz);

hbm = CreateCompatibleBitmap(hdcMain,sz.cx,sz.cy);
hdc = CreateCompatibleDC(hdcMain);

ReleaseDC(GetDesktopWindow(),hdcMain);

// prepare the destination bitmap for drawing.
SelectObject(hdc,hbm);

// Draw the theme background to the compatible dc, thus
// copying it to the compatible bitmap we just selected into it.
RECT rc;
SetRect(&rc,0,0,sz.cx,sz.cy);
pDrawThemeBackground(hTheme,hdc,TABP_BODY,0,&rc,0);

// now hbm contains the theme background, turn it into a brush
hThemeBrushOut = CreatePatternBrush(hbm);

// clear up all the crap
DeleteObject(hbm);
DeleteDC(hdc);
pCloseThemeData(hTheme);
FreeLibrary(hModXP);

return hThemeBrushOut != 0;
}







Override the window messages I mentioned earlier to return this brush to the system and the child dialog should appear themed. Note that you may still need to fiddle with the origin of the brush for some child controls or the background will appear misaligned - used SetBrushOrgEx with offsets calculated from the child's window rect relative to the parent window rect, e.g


...
case WM_CTLCOLORSTATIC:
case WM_CTLCOLORSCROLLBAR:
case WM_CTLCOLORBTN:
// need to align the brush correctly..
HWND hWndControl = (HWND)lParam;

RECT rcControl,rcParent;
GetWindowRect(hWndControl,&rcControl);
GetWindowRect(GetParent(p->hWndMain),&rcParent);

int yOffset = rcControl.top - rcParent.top;
int xOffset = rcControl.left - rcParent.left;

SetBrushOrgEx((HDC)wParam,-xOffset,-yOffset,0);

return (INT_PTR)hThemeBrush; // brush generated with CreateThemedTabBrush function
...




Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!