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

📄 main.cpp

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

#include <vcl.h>
#pragma hdrstop

#include "Main.h"
#include "dockwin.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TMainWin *MainWin;
//---------------------------------------------------------------------------
__fastcall TMainWin::TMainWin(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TMainWin::C1Click(TObject *Sender)
{
  Close();
}
//---------------------------------------------------------------------------

void __fastcall TMainWin::DockPanelDockDrop(TObject *Sender,
      TDragDockObject *Source, int X, int Y)
{
  TPanel* SenderPanel = dynamic_cast<TPanel*>(Sender);
  if (SenderPanel == NULL)
    throw EInvalidCast("");

  // OnDockDrop gets called AFTER the client has actually docked,
  // so we check for DockClientCount = 1 before making the dock panel visible.
  if (SenderPanel->DockClientCount == 1)
    ShowPanel(SenderPanel, true, NULL);
  SenderPanel->DockManager->ResetBounds(true);
  // Make DockManager repaints it's clients.
}
//---------------------------------------------------------------------------

void __fastcall TMainWin::DockPanelDockOver(TObject *Sender,
      TDragDockObject *Source, int X, int Y, TDragState State,
      bool &Accept)
{
  Accept = (dynamic_cast<TDockableForm*>(Source->Control) != NULL);
  if (Accept)
  {
    // Modify the DockRect to preview dock area.
    Windows::TPoint TopLeft = DockPanel->ClientToScreen(Point(0, 0));
    Windows::TPoint BottomRight = DockPanel->ClientToScreen(
      Point(this->ClientWidth / 3, DockPanel->Height));
    Source->DockRect = Windows::TRect(TopLeft, BottomRight);
  }
}
//---------------------------------------------------------------------------

void __fastcall TMainWin::DockPanelGetSiteInfo(TObject *Sender,
      TControl *DockClient, TRect &InfluenceRect, TPoint &MousePos,
      bool &CanDock)
{
  CanDock = (dynamic_cast<TDockableForm*>(DockClient) != NULL);
}
//---------------------------------------------------------------------------

void __fastcall TMainWin::DockPanelUnDock(TObject *Sender,
      TControl *Client, TWinControl *NewTarget, bool &Allow)
{
  TPanel* SenderPanel = dynamic_cast<TPanel*>(Sender);
  if (SenderPanel == NULL)
    throw EInvalidCast("");

  // OnUnDock gets called BEFORE the client is undocked, in order to optionally
  // disallow the undock. DockClientCount is never 0 when called from this event.
  if (SenderPanel->DockClientCount == 1)
    ShowPanel(SenderPanel, false, NULL);
}
//---------------------------------------------------------------------------


void TMainWin::ShowPanel(TPanel* APanel, bool MakeVisible, TControl* Client)
{
  // Client - the docked client to show if we are re-showing the panel.
  // Client is ignored if hiding the panel.

  // Since docking to a non-visible docksite isn't allowed, instead of setting
  // Visible for the panels we set the width to zero. The default InfluenceRect
  // for a control extends a few pixels beyond it's boundaries, so it is possible
  // to dock to zero width controls.

  // Don't try to hide a panel which has visible dock clients.
  if (!MakeVisible && (APanel->VisibleDockClientCount > 1))
    return;

  if (APanel == DockPanel)
    VSplitter->Visible = MakeVisible;
  if (MakeVisible)
  {
    APanel->Width = ClientWidth / 3;
    VSplitter->Left = APanel->Width + VSplitter->Width;
  }
  else
    APanel->Width = 0;
  if (MakeVisible && (Client != NULL))
    Client->Show();
}
void __fastcall TMainWin::CMredwindowClick(TObject *Sender)
{
  TDockableForm *redform=new TDockableForm(this);
  redform->Memo1->Color=clRed;
  redform->Show();
}
//---------------------------------------------------------------------------

void __fastcall TMainWin::CMbluewindowClick(TObject *Sender)
{
  TDockableForm *redform=new TDockableForm(this);
  redform->Memo1->Color=clBlue;
  redform->Show();
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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