Button background transparency using Win32 and Visual Styles - c

Edit: If anyone's tried this in win32 before, am I going in the right direction by using DrawThemeBackground()?
I'v recently enabled Visual Styles using a manifest for version 6 of ComCtl32.dll. Example of Visual Styles in Win32: Visual Styles
The buttons look great, but I can't figure out how to make the background around the buttons transparent. Please see example image: http://www.freeimagehosting.net/image.php?2bdeff33ba.jpg
My main window background color is set to dark grey with:
a.hbrBackground = GetStockObject(DKGRAY_BRUSH);
The common controls are initialized with:
INITCOMMONCONTROLSEX stylesStruct;
stylesStruct.dwSize = sizeof(stylesStruct);
stylesStruct.dwICC = ICC_STANDARD_CLASSES;
InitCommonControlsEx(&stylesStruct);
And I create the button windows with:
j = CreateWindow(L"BUTTON", L"hello",
WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 100, 100,
100, 100, h, 0, hInst, 0);
Buttons look fine over a white background, but the border becomes visible over anything else. Is it possible to make the border around buttons transparent?

Have you tried WS_EX_TRANSPARENT?
I think you can set it in the resource editor in Visual Studio, if you're using that.

Related

gtk3 TreeView has a different default background color

The Issue
This is how my gtk3 app currently look like on Ubuntu 20.04:
The tree view on the left has a slightly brighter background color than the others. I created the tree view by:
tree_view = gtk_tree_view_new();
gtk_widget_set_margin_bottom(tree_view, 12);
gtk_widget_set_margin_top(tree_view, 12);
gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(tree_view), FALSE);
All my other widgets are created similarly with modifying any styles.
Desired Behavior
I want all the bright backgrounds to match each other. I don't mind if they all become the brighter white or the darker white. An example is gtk3-demo, where all backgrounds become the brighter white, as in the tree view:
(Its stack header is still the darker white, but I don't mind that as long as the major regions match.)
Attempted Solutions
It's tempting to set it with CSS and make them match. But I realize those backgrouds can change with different themes. I still want my app to respond to theme changes. That is, if the user is using a dark theme, I still want my app to become dark (the same dark color).
Is there a way to do this? Thank you!
EDIT:
I noticed that gtk3-demo got its bright background color because it used GtkNotebook. I tried but GtkNotebook only gives a light color when it has its tabs enabled, which I don't want. Once it disable show-tabs, its background returns to the darker white.
I manually queried the background of the GtkTreeView and applied it to other widgets. This solution is much more ugly than I want it to be, but I guess it works.
context = gtk_widget_get_style_context(GTK_WIDGET(tree_view));
GdkRGBA *c;
gtk_style_context_get(context, GTK_STATE_FLAG_NORMAL, "background-color", &c,
NULL);
GdkDisplay *display;
GdkScreen *screen;
display = gdk_display_get_default();
screen = gdk_display_get_default_screen(display);
GtkCssProvider *provider;
provider = gtk_css_provider_new();
gtk_style_context_add_provider_for_screen(
screen, GTK_STYLE_PROVIDER(provider),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
char css[128];
snprintf(css, 128, ".custom_bg { background-color: rgba(%d, %d, %d, 1) }",
(int)(c->red * 255), (int)(c->green * 255), (int)(c->blue * 255));
gtk_css_provider_load_from_data(provider, css, -1, NULL);
g_object_unref(provider);
gdk_rgba_free(c);

transparent background on tooltip control

I was able to do custom painting on the tooltip control, by disable its visual style.
I am curious that if we can make the tooltip control to be "Layered" (i.e transparent).
I tried to add WS_EX_LAYERED style on it and call
SetLayeredWindowAttributes(hwndTooltip, 0, 50, LWA_ALPHA);
But it doesn't become transparent.
I did this for the manin window and the main window become transparent.
After searching, there is no further information about how to make tooltip transparent.
So How to make tooltip control transparent background?
p.s: hwndTooltip is a child of Desktop, not of main window.
Cannot be done. Reference and explanation:
http://tech.dir.groups.yahoo.com/group/wtl/message/14214

flicker on tab control - WIN32

I have a WIN32 application. Its main window is hwndMain, one of its child is hwndView. There is one tab control hwndTab on hwndView.
When I resize hwndMain, hwndView is resized and so is hwndTab. It flicker a little, but not much.
I have tried to use WS_EX_COMPOSITED style ( for hwndView or hwndTab), but it just gave me blank window. I tried to use WS_EX_TRANSPARENT and it solves flicker, but when the windows is resized to be larger, the childs are updated very slow, e.g I see black region for one second, then the region is updated.
I have successfully sloved the flicker issue for TreeView by using WS_CHIPCHILDREN style. (See remark below). But using WS_CHIPCHILDREN stlye for hwndView doesn't fix the flicker issue for tab control.
I have paid attention to WM_ERASEBKGND and Not set hbrBackground also.
I want to use double buffer for tab control, but I can't find a tutorial for this purpose. All the tutorial I found is: In WM_PAINT, after creating CompatibleDC and CompatibleBitmap, draw what you want in memdc and.....; But I don't want to do any custom drawing in WM_PAINT for hwndTab. I just want to leave the tab control do this job, but shows the final result only.
Could someone show me a small example how to double buffer a tab control (if you think this will fix the flicker issue of tab control), in the language c + winapi, since I don't have the knowledge of C#, Net,..etc.
Remark: For my TreeView, it is a child of a window hwndContainer. It is created as:
win->hwndContainer = CreateWindowEx(
WS_CLIPCHILDREN,
_T("SUMATRA_PDF_TOCBOX"), NULL,
WS_CHILD,
0, 0, gGlobalPrefs.sidebarDx, 0,
win->hwndPanel, NULL,
ghinst, NULL);
Using WS_CLIPCHILDREN fix the flicker, even if I don't use double buffer. But it is strange to put
WS_CLIPCHILDREN in the first parameter position. If I put it after WS_CHILD, i.e
win->hwndContainer = CreateWindowEx(
NULL,
_T("SUMATRA_PDF_TOCBOX"), NULL,
WS_CHILD | WS_CLIPCHILDREN,
0, 0, gGlobalPrefs.sidebarDx, 0,
win->hwndPanel, NULL,
ghinst, NULL);
,then the flicker still occurs.
So I also tried to use the first way when I created hwndView, but it just gave blank white window.
I am really confused with these stuff.
Here is the blank window picture when I used WS_EX_COMPOSITED for hwndView.
There is no such problem when I used it for hwndContainer.
hwndView in fact has two child: a Tab Control hwndTab and a child which has its own double buffer and drawing. I am not sure if this cause the problem for using WS_EX_COMPOSITED.
You are using the WS_EX_COMPOSITED style. When you pass WS_CLIPCHIDREN as the first argument to the CreateWindowEx, it's interpreting the value of WS_CLIPCHILDREN as an extended window style. Since the value of WS_CLIPCHILDREN is 0x02000000L, the same as WS_EX_COMPOSITED, you've just created a composited window.
And a composited window, according to the documentation, has all of its descendants painted in a bottom-to-top painting order using double-buffering.
I'm not sure what you mean when you say:
I have tried to use WS_EX_COMPOSITED style ( for hwndView or hwndTab), but it just gave me blank window.
You'll have to post code the reproduces this problem. But your second-to-last code snippet is producing a composited window.

Silverlight OOB-Application - set backgroundcolor of main window to transparent

I create a Silverlight OOB application in which I try to change the background color of the window transparent. I would like to use as wallpaper its own image. This is not square and therefore interferes with the white background color of the main window.
In the OutOfBrowserSettings I can put as the "Window Style" to "none ".
In WPF there are the two following window properties:
AllowsTransparency = "True"
Background = "Transparent"
Unfortunately, this does not seem to know about Silverlight, though! Does anyone know how I get the background color of the main window transparent?
Have you tried to set beackground to {x:Null}? Or maybe to set the alpha in color to 0 which means transparent. For example #00FFFFFF or #00000000.
This is not possible with the current version (4) of Silverlight.

How do you place sub controls inside a group box?

When I enable common control visual style support (InitCommonControls()) and I am using any theme other then Windows Classic Theme, buttons inside a group box appear with a black border with square corners.
Windows Classic Theme appears normal, as well as when I turn off visual styling.
I am using the following code:
group_box = CreateWindow(TEXT("BUTTON"), TEXT("BS_GROUPBOX"),
WS_CHILD | WS_VISIBLE | BS_GROUPBOX | WS_GROUP,
10, 10, 200, 300,
hwnd, NULL, hInstance, 0);
push_button = CreateWindow(TEXT("BUTTON"), TEXT("BS_PUSHBUTTON"),
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
40, 40, 100, 22,
group_box, NULL, hInstance, 0);
EDIT: The issue occurs with radio buttons as well
EDIT: I am not using any dialogs/resources, only CreateWindow/Ex.
I am compiling under Visual C++ 2008 Express SP1, with a generic manifest file
Screenshot http://img.ispankcode.com/black_border_issue.png
The problem is having the groupbox as the controls' parent. Groupboxes are not supposed to have any children and using them as parents will cause all kinds of errors (including painting, keyboard navigation and message propagation). Just change the parent in the buttons' CreateWindow call from group_box to hwnd (i.e. the dialog).
I'm guessing you used the groupbox as the parent in order to position the other controls easily inside it. The proper way to do this is to get the position of the groupbox client area and map it to the client area of the dialog. Everything placed in the resulting RECT will then appear inside the groupbox. Since groupboxes don't actually have a client area, it can be calculated with something like this:
// Calculate the client area of a dialog that corresponds to the perceived
// client area of a groupbox control. An extra padding in dialog units can
// be specified (preferably in multiples of 4).
//
RECT getClientAreaInGroupBox(HWND dlg, int id, int padding = 0) {
HWND group = GetDlgItem(dlg, id);
RECT rc;
GetWindowRect(group, &rc);
MapWindowPoints(0, dlg, (POINT*)&rc, 2);
// Note that the top DUs should be 9 to completely avoid overlapping the
// groupbox label, but 8 is used instead for better alignment on a 4x4
// design grid.
RECT border = { 4, 8, 4, 4 };
OffsetRect(&border, padding, padding);
MapDialogRect(dlg, &border);
rc.left += border.left;
rc.right -= border.right;
rc.top += border.top;
rc.bottom -= border.bottom;
return rc;
}
Note that the same applies to Tab controls. They too are not designed to be parents and will exhibit similar behavior.
Just a guess here, but it looks like you are inheriting either the Static Edge or Client Edge style from you theme. I create most of my dialogs from the resource editor and set these properties there.
In your case, you can replace your CreateWindow with a CreateWindowEx to set these extended styles, which are probably being defaulted in CreateWindow. Specifically check out WS_EX_STATICEDGE, WS_EX_WINDOWEDGE and WS_EX_CLIENTEDGE
Edit: I'm assuming that this is not happening because you button is the default control in the dialog, which would also give a black edge.
Apparently group boxes are not meant to group controls (be a parent hwnd)
So in order to get rid of the black borders/painting issues I would have to subclass group box and implement WM_PAINT and WM_PRINTCLIENT
Ahh yes the black background with radio buttons and group boxes. Although I'm not sure if this will work for VC++ 2008, but back-in-the-day the solution for VB6 themed apps was to put the radio controls on a PictureBox (a generic container really) first and then add that to the group box.
Its worth a shot!

Resources