C++ WinAPI - How to make button appear pressed? - c++

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).

Related

Needed: A popup window without a taskbar icon

I am designing a UI engine that needs to render into popup (WS_POPUP) windows. As these windows cannot be children of other windows, each instance is given its own taskbar icon.
I need a way to prevent the taskbar icons from appearing for certain windows that are created as "dialogs". I cannot use an OS-provided dialog because they all have frames (and I can't figure out how to render into them) or a tool-created custom dialog (which seem to require the CLR).
I am not an expert with the windows API and I feel that I have missed something obvious...
Also: Anything involving CLI/CLR is not an option.
EDIT:
The WS_EX_NOACTIVATE style can be used for this purpose as well, though the activation behavior would need to be emulated by the program.
If you set the WS_EX_TOOLWINDOW extended style for your window, it won't be shown in the task bar or Alt+Tab list. This does cause the window to be rendered slightly differently, however (thinking floating tool palette).

Image to display while dragging

I am implementing drag and drop of button on windows application.During dragging I want to display some dragging effect. I think image of the button would be appropriate to display during dragging.
Also I think cursor should be changed during dragging.
My doubts are:
How to capture the image of button and display while dragging.
What type of cursor should be displayed during dragging.
Application is in C++, win32.
Drag image:
If it is a standard button control then you should be able to use WM_PRINT or WM_PRINTCLIENT to ask it to draw itself to a GDI HDC (i.e. into a bitmap that you then use as the drag-image).
Note that not all controls support those messages and some of them support them in slightly different ways. Sometimes you have to experiment a bit or have custom code-paths for different controls.
Another way is to draw the button yourself using the visual styles (themes) API, with a fallback on DrawFrameControl for when themes are disabled. But that is much more tedious than using WM_PRINT/WM_PRINTCLIENT if you don't need it.
Cursor:
Depends what the operation is doing, really. Note that you get the copy and move cursors for free with the shell drag object, if you want them. Sometimes it makes sense to use a custom cursor, though.

What is the most correct way to hide an autocomplete popup?

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 )

Styles of buttons on win32 C++

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.

TAB control background in ATL App, XP styles

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.