How can I produce an OSD in Windows? - windows

I want to create an on-screen display, i.e. text or simple graphics that appear on top of everything else being displayed. I know in Linux this is achieved with xosd, but how do you do it in Windows? (Assume XP and up if it makes it easier, and I would also be interested in knowing if the method is different in Vista/7)

You can use NativeWindow to do this as described here.
The article explains how to create an
OSD window with
animation/semi-transparent effects, in
C#, using the NativeWindow class.

Use the WS_EX_LAYERED style to make the window transparent, and SetWindowPos(..., HWND_TOPMOST, ...) to make it float above other windows.

You can call SetForeGroundWindow

Related

MFC colored button with native win7 appearance

I am using MFC to create a dialog project and trying to impart color to the buttons.
I came to know that the only way you can do is to make the button owner draw. OnCtlColor() does not work for buttons.
I am able to color the button overriding OnDrawItem , but the problem is that , in the process the 3D cool look (with slightly rounded corner that you get in Win7) is lost.
Is there any way to retain the native look and color the button on top of that?
This is not a trivial task. As long as you are using themed controls (what you want), you cannot do more than the theme allows.
You would have to re-implement drawing of the button on your own, making use of the theme API as much as possible to retain themed look, yet sneak-in your color.
Though note that you can hardly achieve anything better than, what .NET WinForms do, when you set the Button.BackColor:
See also question how to set Button BackColor?
Disassembling the WinForms ButtonStandardAdapter.PaintWorker will give you some idea and API you need to use. Beware, you need to do lots of coding!
For C++/MFC code check out Vista themed Owner-Drawn and Full-Custom Push/Menu/Image Buttons on CodeProject. Which probably actually does, what you want already (the SetBackgroundColor method), so you might reuse it.

Drawing popups in X11

I would like to draw a popup in X11. Something like the slider that appears in KDE and GNOME when you press volume or brightness control buttons. This is what it looks like in GNOME:
What library should I use to create such popups (unlike normal windows they should be without borders, etc. and possibly with some transparency)? Would be nice if there were bindings for Python.
This is done in GTK+. The easiest thing may be to find the code that creates that and copy what it does (my system has a different volume notifier, I'm not easily finding the code for that one).
Roughly what you'd do is create a GtkWindow, set_decorated(FALSE), set_position(GTK_WIN_POS_CENTER), something along those lines.
I'm not sure of the best set_type_hint(). Maybe TYPE_HINT_NOTIFICATION or TYPE_HINT_SPLASHSCREEN. If you do set the type hint, it may not be necessary to set_decorated or set_position since the type hint may imply those with many window managers.

how to find type of GDI

i am beginner in win 32 api . i try use win 32 api for create an onscreen keyboard . I can give handle of window and components by click but how to realize type of these and i want set text only on text box and editable components
i try to use GetWindowInfo() and try use atomWindowType of window for realize type of that but this is not use full for this goal because this change on each restart of OS.
(click is handle of window)
WINDOWINFO pwi = new WINDOWINFO(); USER32INST.GetWindowInfo(click, pwi); if (pwi.atomWindowType != -15891) { setLastclick(click); } tnx
You are not going to be able to achieve what you desire, in full generality it is not realistically possible.
A window's type (or class) is essentially determined by its WndProc. You can use GetClassName and its ilk to help you identify some standard window classes, but as you have already discovered, most real-world apps will not use these standard classes.
So, although in theory, you could analyse the code behind the WndProc at runtime, in practice this is not remotely feasible.

How to avoid flicker while handling WM_ERASEBKGND in Windows dialog

I have a dialog that resizes. It also has a custom background which I paint in response to a WM_ERASEBKGND call (currently a simple call to FillSolidRect).
When the dialog is resized, there is tremendous flickering going on. To try and reduce the flickering I enumerate all child windows and add them to the clipping region. That seems to help a little -- now the flickering is mostly evident in all of the child controls as they repaint.
How can I make the dialog flicker-free while resizing? I suspect double-buffering must play a part, but I'm not sure how to do that with a dialog with child controls (without making all child controls owner-draw or something like that).
I should note that I'm using C++ (not .NET), and MFC, although pure Win32-based solutions are welcomed :)
NOTE: One thing I tried but which didn't work (not sure why) was:
CDC memDC;
memDC.CreateCompatibleDC(pDC);
memDC.FillSolidRect(rect, backgroundColor);
pDC->BitBlt(0, 0, rect.Width(), rect.Height(), &memDC, 0, 0, SRCCOPY);
Assuming that "FillSolidRect" is the erase of your background then return TRUE from the WM_ERASEBKGND.
To do the double buffering that you are almost doing in your code fragment, you will need to use CreateCompatibleBitmap and select that into your memDC.
Try adding the following line to your OnInitDialog function:
ModifyStyle(0, WS_CLIPCHILDREN, 0);
Do nothing in the WM_ERASEBKGND handling and do the erase as part of your main WM_PAINT. You can either paint smarter so that you only redraw the invalid areas, or more easily, double-buffer the drawing.
By not doing anything in the erase background, you have all your drawing code in one location which should make it easier for others to follow and maintain.
If you are targeting WinXP or higher, you can also use the WS_EX_COMPOSITED style to enable double-buffering by default for top-level windows with this style. Bear in mind this has its own set of limitations -- specifically, no more drawing out of OnPaint cycles using GetDC, etc.
you can set parameter of your call to InvalidateRect method as false. This will prevent you to send WM_ERASEBKGND when the window will redraw.
Double buffering is indeed the only way to make this work.
Child controls will take care of themselves so long as you make sure CLIPCHILDREN.

Changing Win32 menu colors

Is there a way to change the colors used by plain Win32 menus (background, text, and highlight) for a single process, without using SetSysColors?
(SetSysColors does a global change, which is bad, and if you crash or forget to set the colors back with SetSysColors again before exiting, they will not be restored until you logout.)
The SetMenuInfo() API is your friend. It lets you apply any brush to paint your menu's background.
Something along these lines should solve your problem:
MENUINFO mi = { 0 };
mi.cbSize = sizeof(mi);
mi.fMask = MIM_BACKGROUND|MIM_APPLYTOSUBMENUS;
mi.hbrBack = hBrush;
HMENU hMenu = ::GetMenu(hWnd);
SetMenuInfo(hMenu, &mi);
If I believe your comment to Rob, it is for a skinned application, with special look and feel. So the way to go is probably indeed, as ferek points out (in an unfriendly way...) to use owner-drawn menus: you will be able to define precisely their look.
I have to ask, why? Adopting the regular Windows look-and-feel is good; it means users can be confident that there are consistent elements in your user interface, onto which they can map their experience using other software for the platform.
[I'm probably preaching to the converted, of course, but I thought I'd make the point so anyone who reads an answer for this doesn't start making all their menus sky-blue-pink 'cause it looks pretty.]

Resources