abnormalwin.~cpp

来自「C++Builder程序员编程手记《配书光盘》」· ~CPP 代码 · 共 73 行

~CPP
73
字号
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "AbnormalWin.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TAbnormalWindow *AbnormalWindow;
//---------------------------------------------------------------------------
__fastcall TAbnormalWindow::TAbnormalWindow(TComponent* Owner)
  : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void TAbnormalWindow::SetAbnormalWin(HWND Window)
{
  TPoint *Side;
  HRGN WinRect;
  int x,y,leftscan,rightscan;

  Image1->Picture->LoadFromFile(".\\abnormal.bmp");
  Width=Image1->Width;
  Height=Image1->Height;
  Invalidate();
  leftscan=0;
  if((Side=(TPoint *)malloc(800*4*(sizeof(POINT))))==NULL)
  {
    ShowMessage("未获得有效空间!");
    exit(0);
  }
  for(y=0;y<Image1->Height;y++)
  {
    for(x=0;x<Image1->Width;x++)
      if(Image1->Canvas->Pixels[x][y]!=clWhite)
      {
        Side[leftscan].x=x;
        Side[leftscan].y=y;
        leftscan++;
        break;
      }
  }
  rightscan=leftscan;
  for(y=Image1->Height-2;y>0;y--)
  {
    for(x=Image1->Width-2;x>0;x--)
      if(Image1->Canvas->Pixels[x][y]!=clWhite)
      {
        Side[rightscan].x=x;
        Side[rightscan].y=y;
        rightscan++;
        break;
      }
  }
  WinRect=CreatePolygonRgn(Side,rightscan,ALTERNATE);
  if(WinRect==0)
    ShowMessage("创建窗体过程失败");
  else
    if(!SetWindowRgn(Window,WinRect,true))
      ShowMessage("设置窗口失败!");
}
void __fastcall TAbnormalWindow::FormShow(TObject *Sender)
{
  SetAbnormalWin(Handle);
}
//---------------------------------------------------------------------------
void __fastcall TAbnormalWindow::Image1Click(TObject *Sender)
{
  Close();
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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