i know there are some styles you can put on a button in C++ win32 exa. like BS_DEFPUSHBUTTON BS_RADIOBUTTON but i do not know all of them and also how would i go about making a user drawn button
You can find the reference of all button styles on MSDN (as usual). And an overview of the Button control in general.
To create an owner drawn button, you need to specify the BS_OWNERDRAW flag and pocess the WM_DRAWITEM notification in the button parent window.
And if you only want to tweak the button drawing algorithm, you should look at the DrawThemeBackground API - that allows you to draw the button using the same visuals that the standard Windows Theme engine uses.
You do need to be careful to handle the case when theming is disabled (when OpenTheme fails) however - in that case you're on your own unfortunately.
Related
Since there is no way to deep customizing (a gradient background for example) win32 controls (such as buttons, menu items e.t.c) many people advise to create an own custom control.
And if I need a custom button I will use WM_MOUSEMOVE, WM_LBUTTONDOWN and a shadow buffer. I will draw all controls on the shadow buffer and then use BitBlt(hDC, ...) for my window.
But if I want to create a custom menu I must to foresee that menu can be drawn outside of the client area.
At first I need to mouse tracking outside of the client area. SetCapture(hWnd) seems to be a bad solution as it blocks mouse tracking for windows below.
Then I need to draw/erase items outside of my window. Erasing with InvalidateRect(NULL, NULL, TRUE/FALSE) seems to be a bad solution too as it cause of blinking.
What is the best approach to create custom menu with WinAPI?
Runtime menus that can appear anywhere on the screen can be shown with TrackPopupMenu() function. Create the menu with CreateMenu(), AppendMenu() etc, then show it with TrackPopupMenu().
I have in my editor few editing modes. I can choose specific mode using buttons that are placed on a toolbar. I want to indicate which mode is currently on. When I press appropriate button - I want to make the clicked button remain pushed. How do I do that in WinAPI? My toolbar uses bitmaps for icons if that's relevant.
There used to be a way to get something like the look and feel of a toolbar by using a normal check box with the BS_PUSHLIKE style set. But that got broken a bit with Windows XP because of mouse hover effects, so it's not widely used any more.
If you want to create your own toolbar, without the help of MFC, there is an MSDN article that covers the creation and management of a toolbar window (actually a dedicated window class as part of the Common Controls Library).
We have some C++ Win32 code that applies a background colour to certain controls by responding to the WM_CTLCOLOR... messages.
This works fine when Windows UX theming is not in operation.
Under Windows 7 with the default theme, comboboxes with CBS_DROPDOWNLIST style just display with the theme's grey background. CBS_DROPDOWN comboboxes respond correctly to the background colour change with the theme enabled.
I know I could remove the theme for the affected controls, but this makes them look odd.
Anyone have any idea of the official way to change the background color of individual themed controls now that MS seem to have broken the WM_CTLCOLOR... stuff.
Thanks
JF
You might check to see if you can accomplish what you want with NM_CUSTOMDRAW notifications. Those are sent to the parent (like WM_CTLCOLOR... messages). Some controls work better than others with these notifications. You don't always get all the notifications you'd expect.
The other option would be to subclass the control and override WM_PAINT. That would be a lot of work, but it's do-able. There is documentation on painting with the themes.
If you want to change the color for themed controls you need to custom draw it using the theme API. That's a pretty tricky task that is essentially undocumented. Good luck!
I'm developing a custom autocomplete control in pure WinApi, and the problem that I've encountered is that I don't know how to hide the popup window when clicked outside of the control (e.g. emulate the combobox dropdown behavior). How is it usually implemented? Should I use mouse capture? Thanks.
UPD: Tracking keyboard focus doesn't fit the bill since dragging the parent window around should also hide the dropdown.
UPD: Mouse capture doesn't work because it "captures mouse input either when the mouse is over the capturing window, or when the mouse button was pressed while the mouse was over the capturing window and the button is still down".
After reading this article I now believe that using SetWindowsHookEx and a WH_MOUSE hook is the way to go.
But maybe there is a simpler solution?
Autocomplete is native in Win32 api (Shell)
You don't need code.
(For source code of Windows Shell Autocomplete, see on Win32 group )
I have an ATL application with a dialog containing a TAB control. The App uses a common controls manifest.
Under XP with visual styles, the tab control background is a different color than the dialog and the controls (mostly checkboxes), so it looks quite ugly.
Screenshot
How can I fix that?
There is - apparently - one thing to do to get tab control pages colored correctly using XP visual styles.
In the WM_INITDIALOG handler for each page, call the uxtheme API EnableThemeDialogTexture
With the ETDT_ENABLETAB flag this automatically changes the background color of the dialog and all its child controls to paint appropriately on a tab.
The dialog pages do not need any kind of transparent flag, or indeed any style bit set differently from previously. If you have overridden WM_ERASEBKGND or WM_CTLCOLORDLG in your pages DialogProc you will need to revert to default handling (return FALSE).
Here you could find answer to your question.
The check boxes will post WM_CTLCOLORBTN notifications to their parent. If, for the checkbox control IDs, the parent window's message handler returns the result of
GetStockObject(HOLLOW_BRUSH)
then the check boxes should be drawn with a transparent background, which should give you the look you want.