Create an irregular window with Win32 API

zhaozj2021-02-08  252

Win32 API supports creation of irregular windows, now many software uses this technology, such as QuickTime, Windows Media Player 7, etc.

AB uses API to create an irregular window mainly have two ways, namely vector shape superposition (Boolean operation) and bitmap area. In any case, the effect of the above two figures can be realized. Before writing such a window code, we must clear whether the shape of the window to create is complicated. If the window B's window is complicated, it is very irregular window, it is difficult to create the vector shape overlay, then the area can be used. The transparent color implementation of the specified bitmap; and the picture A is a rounded rectangle, which is superimposed using a simple vector shape. This is the reason for operating efficiency, and the vectors are faster for ordinary irregular windows. Of course, the bitmap area can create any shape of the window, if you don't need to consider running efficiency (the actual two speed difference is small), you don't have to consider the vector shape superimposed method, you can directly see the example of the location area.

A. Vector superimposed mode Create an irregular window Example 1: Simple window area setting, using rounded rectangle 1, HRGN HRGN = CreateroundRectrGN (0, 0, 200, 200, 20); // Create a rounded rectangular area 2, setWindowRgn HRGN, TRUE); // Set the area created as window area 2: Multiple zones superimposed (Boolean operation) 1, hrgn hrgn1 = CreateroundRectrGN (0, 0, 0, 200, 20, 20); // Create a rounded rectangular area 2, HRGN HRGN2 = CreateRectrGN (10, 10, 20, 20); // Create a rectangular area 3, HRGN HRGN; Combinergn (hRGN, HRGN1, HRGN2, RGN_DIFF); // Using region 1 reduction zone 2, generate new zone hRGN (The optional parameters are added, minimal, etc. Download Bitmaptoregion function code RGN.Zip:1.95 KB (2,002 bytes) 1, hbitmap hbmp = (hbitmap) loadImage (application handle, bitmap file name, image_bitmap, width, height, lr_loadfromfile); // Load a bitmap A particular color in this bitmap will be processed as a transparent area 2, hrgn hrgn = bitmaptoregion (HBMP, RGB (255, 0), 0); // Call bitmap converted to the region function, transparent color For red, the third parameter is tolerance, and only red is set to transparent color. If the tolerance is 1, it means that the colors of the gap between the red green blue three-color value of the given transparent color will also be treated as transparent color. 3, setWindowRGN (HRGN, TRUE); // Set the area to window area Description: About the Bitmaptoregion function, its function is to convert bitmaps into zones, principle from API: ExtcreateRegion, which uses the RGndata structure Data creation RGN, this function is to analyze the number of pixel points of the bitmap, fill the RGNDATA structure according to them, and then create RGN.

Due to the relatively simple in the irregular window, there is no complete example, the key to the B method is the Bitmaptoregion function, so only the code is provided. If you still have an unclear place or want a complete example, please contact me.

转载请注明原文地址:https://www.9cbs.com/read-2249.html

New Post(0)