In Windows Sometimes because you need to create a shaped form, we can use the Windows API function setWindowRGN () to achieve the purpose, which is declared in the Window unit:
Int setWindowRgn
HWND hWnd, / / To change the handle of the window
HRGN HRGN, // Window display area
Bool BredRaw // Indicates whether the window needs to be regenerated after changing the display area (generally set to true)
);
The SetWindowRGN function can set the window to any shape. Now let's build a small sun form. Create a blank form, the Color property of the form is CLRED (red), borderstyle is: bsnone. Add the following code in the formcreate event:
Procedure TFORM1.FormCreate (Sender: TOBJECT);
VAR
HRGN: longint;
Begin
/ / Create a round form, if you want to create a form of other shapes, simply call the function of different establishment zones
HRGN: = CreateroundRectrGN (0,0,200,200,200,200);
SetwindowRgn (Handle, HRGN, TRUE);
END;
Now let's add the code to move the movement of the title form, here we have to block the WM_NCHITTEST message, this message is when the cursor moves, the mouse is pressed or released. When you press MOUSE in the customer area, we deceive Windows think that the title bar is pressed:
Procedure TFORM1.WMNCHITTEST (VAR Msg: Twmnchittest); Message WM_NCHITEST;
Begin
inherited;
// If mouse presses the customer area of the form, assign the value as the title area.
IF (Msg.Result = HTCLIENT) THEN
Msg.result: = htcaption;
END;
In this way, we have achieved the creation and movement of an exception form without a title, plus several codes, we can create a practical hour clock program.