I have never touched on such in-depth windowsui problems before. Now, I have to develop such a technology because of the need for a touch screen mouse. Now I have to write down the research results, help myself, and help others.
First, it is relatively simple to say how to always top the window.
1: setwindowpos () input parameter swp_topmost.
2: If the preceding method is called once, the window is placed in the list of top-level windows maintained by the system. The window cannot be placed on the top-level window (top-level)
The solution is to constantly call the setwindowpos () function so that it is always placed at the top layer.
3: either set a timer, call setwindowpos () at intervals, or call the setwindowpos function when the window location information changes.
When the position of the window changes, including the position change of Z-order, Windows will send the wm_windowposchanging message to the window.
4: If you want to call setwindowpos only when the window position changes, you can respond to the wm_move message.
5: If you want the window to be topped without capturing the input focus of the original window, specify the swp_noactivity variable when you call setwindowpos. (This problem has plagued me for a long time. it takes about one week)
Pixel-by-pixel alphablend transparent window
After research, we found that if you want to implement a pixel-by-pixel window, you only need to use the updatelayeredwindow function.
In other ways, you can either specify a transparent color or implement alphablend by the program itself. However, problems may occur when you mix windows with other applications.
In essence, pay attention to the following issues when using updatelayeredwindow correctly:
1) The 32 BPP (bitsperpixel) bitmap. rgba format must be used.
2) use the alphablend () function or the updatelayedredwindow function. Only these two functions support pixel-by-pixel alphablend.
3) before alphablend, you must perform the Alpha operation (premultiplyrgbchannels) on the RGB pixel values of the source image. For details, see the RGB values after the msdn operation used by alphablend () and updatelayedredwindow functions.
4) if you want to perform the premultiplyrgbchannels operation, you must get a pointer to the pixel data. How can you get a pointer to the data? The answer is given below. Use DiB.
///////////////
How can we get a pointer to hbitmap's image data?
So far, it seems that only createdibsection is supported !!!
It also returns a pointer to rawdata.
The usage is as follows:
Try using a memory HDC wich contains a 32 BPP Device
Independant bitmap. (DIB)
Here's one simple exemple to create a 32 BPP Buffer:
Bitmapinfo bi32 = {0 };
Bi32.bmiheader. bisize = sizeof (bitmapinfoheader );
Bi32.bmiheader. biwidth = 100;
Bi32.bmiheader. biheight = 100;
Bi32.bmiheader. biplanes = 1;
Bi32.bmiheader. bibitcount = 32;
Bi32.bmiheader. bicompression = bi_rgb;
Void * pbits = NULL;
HDC htarget = createcompatibledc (null); // or any compatible DC.
Hbitmap hbmp = createdibsection (null, & bi32, dib_rgb_colors,
(Void **) & pbits, null, null)
Hgdiobj hold = SelectObject (htarget, (hgdiobj) hbmp );
Etc...