Some techniques for implementing interface effects in C ++ Builder. . Irregular forms, etc. .

zhaozj2021-02-17  68

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 #include #include #include #include #include #include #include #include file: // -------------------------------------------------- ----------------------- Class TFORM1: Public TForm {__ Published: // Ide-Managed Components TIMAGE * Image1; TPopupMenu * PopupMenu1; TPENUITEM * EXIT1; TOPENPICTUREDIALOG * OpenPictureDialog1; TMenuItem * Open1; void __fastcall Exit1Click (TObject * Sender); void __fastcall FormCreate (TObject * Sender); void __fastcall Image1MouseDown (TObject * Sender, TMouseButton Button, TShiftState Shift, int X, int Y); void __fastcall Open1Click ( TOBJECT * Sender); private: // user declarations void __fastcall bmptorgn (); public: // user declarations __fastc All TForm1 (Tcomponent * Owner;}; File: // ------------------------------------ --------------------------------------- EXTERN PACKAGE TFORM1 * FORM1; File: // -------------------------------------------------- ------------------------ # Endif

File: //Unit1.cppfile: // ---------------------------------------- -----------------------------------

#include #pragma HDRSTOP

#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 height; y ) {lb = true; for (x = 0; x width 1; x ) if (image1-> canvas-> pixels [x] [ Y]! = colorKey) {a [l] .x = x; a [l] .y = y; lb = false; break;} if (lb) a [l] = a [l-1]; l ; RB = True;

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 height-1; y ) {for (x = a [y] .x; x <= a [r] .x; X ) IF (image1-> canvas-> pixels [x] [y] == colorKey) {tempRGN = creterecTrGN (x, y, x 1, y 1); Combinergn (WNDRGN, WNDRGN, TEMPRGN, RGN_XOR); DELETEOBJECT (TEMPRGN);} r -;

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;

}

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

New Post(0)