Implement irregular window with VC ++

zhaozj2021-02-08  312

Author: Zeng Jinfeng With the launch of Windows95, there has been an increasing number of applications using non-rectangular exterior form, or simulated reality of things, like bells, eyes, etc. in a PC system; or to create a three-dimensional look and feel Non-realistic objects, such procedures are represented by various MP3 players, even some big wrist old applications (such as Norton), and this window has begun to have such windows. One is because the Windows operating system and various development tools are greatly improved; second, the developers hope to emphasize the first image when using distinctive appearance, in order to achieve the purpose of attracting users. After all, the current PC is a world full of graphics (images), which makes full use of this feature, can also improve the operability of the program interface to a certain extent. Moreover, for the same type of application, in the case of function, performance, users are often willing to choose beautiful appearance. Thus, many articles are introducing how to create an irregular window, but almost a thousand will be described based on VB. And the author has been developing based on the C / C language, and therefore, the author has studied the method of implementing irregular windows in VC 5, and the main method implemented will be described. VC 5 provides a CRGN class and a setwindowrgn () function to implement an irregular program window. The process of creating an irregular window is: First define a CRGN class and create a specific area of ​​the CRGN class with a variety of initialization functions, and then call the CWnd: SetWindowRGN () function to create an irregular window. CRGN is a class derived from CGDiobject to determine a polygon, ellipse or range of polygons and ellipse, which is mainly used in the program to use CreateRectrGNInderct (), createLipTicRGNDirect (), createPolygonRGN () three functions. The CreateRectrGnIndirect (LPCRect LPRECT) function creates a rectangular area, and the parameter lprect specifies the Create of the rectangular area created in the window user area, left, TOP (on), Right (right), Bottom (below) coordinate. For example: CRgn MyRgn; RECT m_rect; m_rect.left = 0; m_rect.top = 0; m_rect.right = 500; m_rect.bottom = 300; MyRgn.CreateRectRgnIndirect (& m_rect); CreateEllipticRgnIndirect (LPCRECT lpRect) function creates an elliptical area The parameter LPRECT specifies the created elliptical area in the window user area, left, TOP (below) coordinates, if the difference between the Right coordinates and the LEFT coordinate is equal to BOTTOM coordinates The difference in TOP coordinates is a circle.

For example: CRgn MyRgn; RECT m_rect; m_rect.left = 0; m_rect.top = 0; m_rect.right = 500; m_rect.bottom = 300; MyRgn.CreateEllitpticRgnIndirect (& m_rect); CreatePolygonRgn (LPPOINT lpPoints, int nCount, int nMode) The function creates a polygon area, and the parameter LPPoints points to a Point structure array, each Point structure item in the Point structure array, used to determine the coordinate of the multilateral vertex in the window user area; Ncount Description Point structure in the Point structure item, That is, the number of polygonal vertices; nmode specifies the fill mode of the polygon, generally uses Alternate mode. For example, create a triangle: CRGN MyRGN; Point Points [3]; Points [0] .x = points [0] .y = 0; Points [1] .x = 10; Points [1] .y = 30; Points [ 2] .x = 5; Points [2] .y = 60; MyRgn.createPolygonRgn (Points, 3, Alternate); After using the above function to create a zone, you can call CWnd :: setWindowRgn (HRGN HRGN, BOOL BREDRAW) Create a non-rectangular window. SetWindowRGN () function parameter description: hrgn is a handle of a CRGN class; BredRAW If set to true, then when the window order changes, the system will send WM_WindowPosChange and WM_WindowPoschanged messages to the window. If you want to create a more complex window, such as a play interface of the MP3 player Soniq, the two circular portions are coincidentally formed. For such windows, you have to use another extremely important function of the CRGN class --combinergn (). The first thing to explain is: In the online help of VC 5, the function is set to the initialization type. Initially, if the defined CRGN class calls this function before being initialized using other initialization functions, If the program will fail, so this function seems to be more appropriate to enter the Operation class. Combinergn (CRGN * PrGN1, CRGN * prgn2, int ncombinemode "function is used to create an irregular area synthesized by multiple polygons and ellipse. PRGN1, PRGN2 points to polygons or ellipses involved in the synthesis irregular region; NcombineMode illustrates the method of synthesis: RGN_and's last area is the overlapping portion of PRGN1 and PRGN2; RGN_DIFF last area is a portion of PRGN1 does not contain PRGN2; RGN_OR Last The area also includes PRGN1 and PrGN2; RGN_XOR last regions contain both PRGN1 and PRGN2, but does not include portions of PRNG1 and PRNG2 overlap.

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

New Post(0)