How to create a shaped window using the setWindowRGN function

zhaozj2021-02-08  221

How to create a shaped window using the setWindowRGN function

Time: 2000/10/11 21: 06ENET Technology

Many games and tools software use a shaped window to come out. In fact, it is difficult to create a shaped window from a technical difficulty, but is there any effect that is mainly due to whether or not the creativity is surprising. The following is a simple introduction to how to make a shaped window using SETWINDOWRGN.

SetwindowRGN is a new SDK function. This function defines the drawing message and the mouse message in a specified area of ​​the window, in fact, enables the window to become the specified irregular shape.

First use AppWizard to create a dialog-based application and use the resource editor from the resource from the resource from the resource. Some default controls, titles, and boundaries.

Add a CRGN data member to the dialogue to create a window area using the data member.

Class Ctestdlg: Public CDIALOG

{...

Private:

CRGN M_RGN; // WINDOW Region

...}

Modify the OnInitDialog function of the dialog, create an ellipse area and call SETWINDOWRGN to assign the area to the window:

Bool ctestdlg :: oninitdialog ()

{

CDIALOG :: OnInitdialog ()

// Get the size of the dialog

CRECT RCDIALOG;

GetClientRect (rcdialog)

// Create an elliptical area and use the SETWINDOWRGN reset dialog.

m_rgn.createelllipticRGN (0, 0, rcdialog.width (),

RcDialog.height ()); setwindowRgn (GetsafehWnd (), (hrgn) m_ rgn, true);

Return True;

}

A simple shaped window has been generated, if compiled running project, an elliptical window will appear. The following code is processed in the OnPAint message, making the dialog have a stereoscopic effect.

Void ctestdlg :: onpaint ()

{

CPAINTDC PAINTDC (THIS);

// Get the device // set the border when drawing oval

PainTDC. SelecstockObject (null_pen);

/ / Get the color of the sphere

ColorRef Ballcolor = RGB (0, 0, 255);

Byte Byred = GtrValue (ballcolor);

Byte bygreen = getGvalue (ballcolor);

Byte Byblue = getBValue (ballcolor);

// Get the range of the sphere.

Rect rcdialog;

GetClientRect (rcdialog);

// Licen the minimum unit of painting sphere

INT NUNITS = MIN (rcdialog.right, rcdialog.bottom);

// Calculate the line unit in the horizontal direction and the vertical direction.

Float fltstepharz = (float) rcdialog.right / NUnits;

Float fltstepvert = (float) rcdialog.bottom / NUnits;

INT NELLIPSE = NUNITS / 3;

// Start drawing multiple ellipses to achieve visually stereoscopic.

CBRUSH brush;

// Painting brush using BallColor's color.

CBRUSH * PBRUSHOLD;

// Store old painting brush

For (Nindex = 0; Nindes

{

Creatsolidbrush (RGB ((Nindex * Byred) / Nellipse;

((Nindex * Bygreen) / Nellipse, ((NINDEX * BYBLUE) / Nellipse)))))); PBRUSHOLD = PainTDC .SelectObject (& brhsh);

Paintdc .ellipse ((int) Fltstepharz * 2, (int) Fltstepvert * Nindex,

Right - ((int) Fltstephaz * Nindex) 1, Rect. Bottom - (INT)

Fltstepvert * (NINDEX * 2)) 1);

Brush.delecteObject ();

}

}

The shaped window is not only applicable to the dialog, the same applies to a single document, a multi-document type application. If the reader is interested, you can try it yourself. If you have any questions, you can send Mail to the Academy mailbox.

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

New Post(0)