The following source code is fast to create an irregular form, and it can be moved. File: // ---------------------------------------------- -------------------------- File: //Unit1.h
#ifndef unit1h # Define unit1hfile: // ------------------------------------------------------------------------------------------------------------------------------------------------ ------------------------------ # include
File: //Unit1.cppfile: // ---------------------------------------- -----------------------------------
#include
#include "unit1.h" file: // -------------------------------------- ------------------------------------ # prgma package (smart_init) #pragma resource "* .dfm" TFORM1 * FORM1; File: // ------------------------------------------ ---------------------------------__ fastcall tform1 :: tform1 (tcomponent * owner): TFORM (OWNER) {} File: // ---------------------------------------------- ----------------------------- void __fastcall tform1 :: exit1click (TOBJECT * Sender) {close ();} file: // -------------------------------------------------- ------------------------- void __fastcall tform1 :: formcreate (TOBJECT * Sender) {
BMPTORGN ();} file: // ----------------------------------------- ----------------------------------
void __fastcall TForm1 :: Image1MouseDown (TObject * Sender, TMouseButton Button, TShiftState Shift, int X, int Y) {if (Button == mbLeft) {ReleaseCapture (); Perform (WM_NCLBUTTONDOWN, HTCAPTION, 0);}} file: / / --------------------------------------------------- -------------------------- void __fastcall tform1 :: bmptorgn () {image1-> autosize = true; form1-> autosear = true; Form1 -> borderstyle = bsnone; tcolor colorKey = image1-> canvas-> pixels [0] [0]; int x, y; int L, r; point * a; bool LB, RB; HRGN WNDRGN, TEMPRGN
IF ((a = (pointof)))) == null) {showMessage ("Apply for Memory Failed!"); exit (0);
L = 0; r = image1-> height * 2-1; wNDRGN = CreateRectrGN (0, 0, image1-> width, image1-> height);
For (y = 0; y
For (x = image1-> width; x> = 0; x--) if (image1-> canvas-> pixels [x] [y]! = colorKey) {a [r] .x = x; a [r ] .y = y; rb = false; Break;} if (rb) a [r] = a [R 1]; r -;
R = image1-> height * 2-1; for (y = 0; y
file: // TempRgn = CreatePolygonRgn (a, Image1-> Height * 2, ALTERNATE); TempRgn = CreatePolygonRgn (a, Image1-> Height * 2, WINDING); CombineRgn (WndRgn, WndRgn, TempRgn, RGN_AND); DeleteObject (TempRgn DELETE A; SetWindowRgn (Handle, WNDRGN, TRUE);
void __fastcall TForm1 :: Open1Click (TObject * Sender) {if (OpenPictureDialog1-> Execute ()) {Image1-> Picture-> LoadFromFile (OpenPictureDialog1-> FileName); BmpToRgn ();}} file: // ---- -------------------------------------------------- ---------------------
Yes, the background color of the picture is the same. The picture is plus in the properties of Image1, not in the running period through loadingFromFile (). .
File: // -------------------- (1) increase the gradient color (blue) for the form background ------------- --VOID __FASTCALL TFORM1 :: FormPaint (omitted) {ANSISTRING WW; INT BB; WW = ANSISTRING (Form1-> Width / 256); TRECT MyRect; MyRect.Left = 0; for (BB = 0; BB <255; BB ) {Form1-> canvas-> brush-> color = (tcolor) RGB (0, 0, bb); myRect.top = bb * (ww.toint ()); myRect.right = form1-> width; myRect. Bottom = (bb 1) * (ww.Toint ()); Form1-> canvas-> FillRect (myRect);}} file: // -------------- Transparent window Body -------------------------- void __fastcall tform1 :: button1click (Tobject * sender) {TRECT * RCTCLIENT, * RCTFRAME; HRGN HCLIENT, HFRAME ; POINT * lpTL, * lpBR; rctFrame = new TRect; rctClient = new TRect; lpTL = new POINT; lpBR = new POINT; GetWindowRect (Form1-> Handle, rctFrame); :: GetClientRect (Form1-> Handle, rctClient); LPTL-> x = rctframe-> left; lptl-> y = rctframe-> top; lpbr-> x = rctframe-> right; lpbr-> y = rctframe-> bottom;
:: ScreenToClient (Form1-> Handle, LPTL); :: ScreenToClient (Form1-> Handle, LPBR); RctFrame-> LEFT = LPTL-> X; RctFrame-> TOP = lptl-> y; rctframe-> Right = LPBR -> x; rctframe-> bottom = lpbr-> y; rctclient-> left = abs (rctframe-> left); rctclient-> top = ABS (rctframe-> top); rctclient-> right = rctclient-> Right ABS (rctFrame-> Left); rctClient-> Bottom = rctClient-> Bottom abs (rctFrame-> Top); rctFrame-> Right = rctFrame-> Right abs (rctFrame-> Left); rctFrame-> Bottom = rctFrame-> Bottom abs (rctFrame-> top); rctFrame-> Top = 0; rctFrame-> Left = 0; hClient = CreateRectRgn (rctClient-> Left, rctClient-> Top, rctClient-> Right, rctClient-> Bottom); hFrame = CreateRectRgn (RctFrame-> LEFT, RCTFRAME-> TOP, RCTFRAME-> Right, RctFrame-> Bottom; Combinergn (HFrame, Hclient, HFrame, RGN_XOR); setWindowRgn (Form1-> Handle, HFrame, true);
Delete rctframe; delete rctclient; delete lptl, lpbr;
}