⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 polygonwin.cpp

📁 C++Builder程序员编程手记《配书光盘》
💻 CPP
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "PolygonWin.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
Tpolygon *polygon;
//---------------------------------------------------------------------------
__fastcall Tpolygon::Tpolygon(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void Tpolygon::SetPolygonWin(HWND Window)
{
  HRGN PolygonWin;
  TPoint vertexes[6];
  TRect RectWin;

  if(!SetWindowRgn(Window,0,false))
    ShowMessage("窗口初始化失败!");
  if(!GetWindowRect(Window,&RectWin))
    ShowMessage("取窗口信息失败!");
  vertexes[0].x=(RectWin.Right-RectWin.Left)/2-((RectWin.Bottom-RectWin.Top)/4)/cosl(pai/6);
  vertexes[0].y=0;
  vertexes[1].x=vertexes[0].x-((RectWin.Bottom-RectWin.Top)/2)*tanl(pai/6);
  vertexes[1].y=(RectWin.Bottom-RectWin.Top)/2;
  vertexes[2].x=vertexes[0].x;
  vertexes[2].y=RectWin.Bottom-RectWin.Top;
  vertexes[3].x=vertexes[0].x+(RectWin.Bottom-RectWin.Top)/2/cosl(pai/6);
  vertexes[3].y=vertexes[2].y;
  vertexes[4].x=vertexes[3].x+((RectWin.Bottom-RectWin.Top)/2)*tanl(pai/6);
  vertexes[4].y=vertexes[1].y;
  vertexes[5].x=vertexes[0].x+(RectWin.Bottom-RectWin.Top)/2/cosl(pai/6);
  vertexes[5].y=0;

  PolygonWin=CreatePolygonRgn(vertexes,6,WINDING);
  if(PolygonWin==0)
    ShowMessage("创建窗体过程失败");
  else
    if(!SetWindowRgn(Window,PolygonWin,true))
      ShowMessage("设置窗口失败!");
}
void __fastcall Tpolygon::FormShow(TObject *Sender)
{
  SetPolygonWin(Handle);
}
//---------------------------------------------------------------------------

void __fastcall Tpolygon::FormResize(TObject *Sender)
{
  SetPolygonWin(Handle);
  Invalidate();
}
//---------------------------------------------------------------------------

void __fastcall Tpolygon::FormClose(TObject *Sender, TCloseAction &Action)
{
  SetWindowRgn(Handle,0,false);
}
//---------------------------------------------------------------------------

void __fastcall Tpolygon::FormClick(TObject *Sender)
{
  Close();
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -