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

📄 neowin.~cpp

📁 新颖按钮控件
💻 ~CPP
📖 第 1 页 / 共 2 页
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "NeoWin.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TNeoForm *NeoForm;
//---------------------------------------------------------------------------
__fastcall TNeoForm::TNeoForm(TComponent* Owner)
        : TForm(Owner)
{
  Sizeable = true;
  FPopedMenuIndex = -1;
  FLastPopedMenuIndex = -1;
  FBorderMouseDown = false;
  FCaptionMouseDown = false;

  Color = (TColor)0x00CFCFCF;
  CaptionLabel->Caption = TForm::Caption;
  MinImage->Visible = (BorderIcons.Contains(biMinimize));
  MaxImage->Visible = (BorderIcons.Contains(biMaximize));
}
//---------------------------------------------------------------------------
void __fastcall TNeoForm::FormCreate(TObject *Sender)
{
//
}
//---------------------------------------------------------------------------
void __fastcall TNeoForm::FormShow(TObject *Sender)
{
//
}
//---------------------------------------------------------------------------
void __fastcall TNeoForm::FormResize(TObject *Sender)
{
//
}
//---------------------------------------------------------------------------
void __fastcall TNeoForm::FormCanResize(TObject *Sender, int &NewWidth,
      int &NewHeight, bool &Resize)
{
  if (NewWidth < 200 || NewHeight < 60) Resize = false;
  else
  {
    TRect R;
    R = GetWorkAreaRect();
    if (NewWidth > R.Width()){ NewWidth = R.Width(); }//Resize = false; }
    if (NewHeight > R.Height()){ NewHeight = R.Height(); }//Resize = false; }
  }
}
//---------------------------------------------------------------------------
void __fastcall TNeoForm::WndProc(Messages::TMessage &Message)
{
  inherited::WndProc(Message);
  switch (Message.Msg)
  {
    case WM_SIZE:
      switch (Message.WParam)
      {
        case SIZE_MAXIMIZED:
        {
          if (BorderIcons.Contains(biMaximize))
          {
            MaxImage->Visible = false;
            RestoreImage->Visible = true;
          }
          SetSizeableCursor(false);
          break;
        }
        case SIZE_MINIMIZED:
          break;
        case SIZE_RESTORED:
        {
          if (BorderIcons.Contains(biMaximize))
          {
            MaxImage->Visible = true;
            RestoreImage->Visible = false;
          }
          SetSizeableCursor(FSizeable);
          break;
        }
      }//switch (Message.wParam)
      break;

    case WM_ACTIVATE:
      switch (Message.WParamLo)
      {
        case WA_ACTIVE:
        case WA_CLICKACTIVE:
        {
          TopLeftImage->Picture = GetFTopLeftImage->Picture;
          TopCenterImage->Picture = GetFTopCenterImage->Picture;
          TopRightImage->Picture = GetFTopRightImage->Picture;
          TopPanel->Refresh();
          break;
        }
        case WA_INACTIVE:
        {
          MenuTimer->Enabled = false;
          TopLeftImage->Picture = LostFTopLeftImage->Picture;
          TopCenterImage->Picture = LostFTopCenterImage->Picture;
          TopRightImage->Picture = LostFTopRightImage->Picture;
          break;
        }
      }
    break;
  }
}
//---------------------------------------------------------------------------
/*
void __fastcall TForm1::WMSize(TWMSize& M)
{
  DefaultHandler(&M);
  switch (M.SizeType)
  {
    case SIZE_MAXIMIZED:
      {
        if (BorderIcons.Contains(biMaximize))
        {
          MaxImage->Visible = false;
          RestoreImage->Visible = true;
        }
        break;
      }
    case SIZE_MINIMIZED:
      break;
    case SIZE_RESTORED:
      {
        if (BorderIcons.Contains(biMaximize))
        {
          MaxImage->Visible = true;
          RestoreImage->Visible = false;
        }
        break;
      }
  }
}
*/
//---------------------------------------------------------------------------
void __fastcall TNeoForm::SetSizeable(bool Value)
{
  FSizeable = Value;
  SetSizeableCursor(Value);
}
//---------------------------------------------------------------------------
void __fastcall TNeoForm::SetSizeableCursor(bool Value)
{
  if (Value)
  {
    TopImage->Cursor = crSizeNS;
    LeftImage->Cursor = crSizeWE;
    BottomLeftImage->Cursor = crSizeNESW;
    BottomCenterImage->Cursor = crSizeNS;
    BottomRightImage->Cursor = crSizeNWSE;
    RightImage->Cursor = crSizeWE;
  }
  else
  {
    TopImage->Cursor = crDefault;
    LeftImage->Cursor = crDefault;
    BottomLeftImage->Cursor = crDefault;
    BottomCenterImage->Cursor = crDefault;
    BottomRightImage->Cursor = crDefault;
    RightImage->Cursor = crDefault;
  }
}
//---------------------------------------------------------------------------
TSpeedButton* __fastcall TNeoForm::GetNeoMenuButton(int Index)
{
  int i;
  TSpeedButton *sb;

  for (i = 0; i < this->ComponentCount; i++)
  {
    if ((AnsiString)(this->Components[i]->ClassName()) == "TSpeedButton")
    {
      sb = (TSpeedButton *)(this->Components[i]);
      if ((AnsiString)(sb->Name).SubString(1, 10) == "MenuButton" && sb->Tag == Index)
        return sb;
    }
  }
  return NULL;
}
//---------------------------------------------------------------------------
void __fastcall TNeoForm::SetNeoMenu(int Index, TPopupMenu *Menu, AnsiString Caption)
{
  TSpeedButton *sb;

  FNeoMenu[Index] = Menu;
  sb = GetNeoMenuButton(Index);
  sb->Visible = true;
  sb->Caption = Caption;
}
//---------------------------------------------------------------------------
TRect __fastcall TNeoForm::GetWorkAreaRect()
{
  TRect R;
  SystemParametersInfo(SPI_GETWORKAREA, 0, &R, 0);
  return R;
}
//---------------------------------------------------------------------------
void __fastcall TNeoForm::SetCaption(AnsiString Value)
{
  CaptionLabel->Caption = Value;
}
//---------------------------------------------------------------------------
AnsiString __fastcall TNeoForm::GetCaption()
{
  return CaptionLabel->Caption;
}
//---------------------------------------------------------------------------
void __fastcall TNeoForm::TopPanelResize(TObject *Sender)
{
  CaptionLabel->Left = 85;
  CaptionLabel->Top = 11;
  CaptionLabel->Width = Width - 175;
  CaptionLabel->SendToBack();
  TopRightImage->Left = TopPanel->Width - TopRightImage->Width;
  TopCenterImage->SendToBack();
  TopCenterImage->Left = TopLeftImage->Left + TopLeftImage->Width;
  MinImage->Left = TopPanel->Width - 60;
  MaxImage->Left = TopPanel->Width - 41;
  RestoreImage->Left = TopPanel->Width - 41;
  CloseImage->Left = TopPanel->Width - 22;
  TopPanel->Update();
}
//---------------------------------------------------------------------------
void __fastcall TNeoForm::BottomPanelResize(TObject *Sender)
{
  BottomRightImage->Left = BottomPanel->Width - BottomRightImage->Width;
  BottomPanel->Update();
}
//---------------------------------------------------------------------------
void __fastcall TNeoForm::RightImageMouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
  FBorderMouseDown = true;
  FBorderMouseX = X;
  FBorderMouseY = Y;
}
//---------------------------------------------------------------------------
void __fastcall TNeoForm::RightImageMouseUp(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
  FBorderMouseDown = false;
}
//---------------------------------------------------------------------------
void __fastcall TNeoForm::RightImageMouseMove(TObject *Sender,
      TShiftState Shift, int X, int Y)
{
  TPoint MousePos;
  TRect WinRect;

  if (!FSizeable) return;
  if (WindowState == wsMaximized) return;
  if (FBorderMouseDown)
  {
    GetCursorPos(&MousePos);
    WinRect = this->BoundsRect;
    WinRect.Right = MousePos.x + (RightImage->Width - FBorderMouseX);
    this->BoundsRect = WinRect;
  }
}
//---------------------------------------------------------------------------
void __fastcall TNeoForm::BottomLeftImageMouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
  FBorderMouseDown = true;
  FBorderMouseX = X;
  FBorderMouseY = Y;
}
//---------------------------------------------------------------------------
void __fastcall TNeoForm::BottomLeftImageMouseUp(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
  FBorderMouseDown = false;
}
//---------------------------------------------------------------------------
void __fastcall TNeoForm::BottomLeftImageMouseMove(TObject *Sender,

⌨️ 快捷键说明

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