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

📄 main.cpp

📁 C++通讯录源代码
💻 CPP
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Main.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
#pragma resource "myres.res"
TFormMain *FormMain;
//---------------------------------------------------------------------------
__fastcall TFormMain::TFormMain(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------

// == 界面代码 ==============================================================
void __fastcall TFormMain::ImageTitleMouseDown(TObject *Sender,
    TMouseButton Button, TShiftState Shift, int X, int Y)
{
    Refresh();
    if(Button == mbLeft)
    {
        ReleaseCapture();
        Perform(WM_SYSCOMMAND, 0xf017, 0);
    }
}
//--------------------------------------------------------------------------

void __fastcall TFormMain::OnWMActive(TMessage &Msg)
{
    TForm::Dispatch(&Msg);
    switch(Msg.WParamLo)
    {
        case WA_ACTIVE:
        case WA_CLICKACTIVE:
            ImageTitle->Picture->Bitmap = bmpTitleAct;
            LabelTitle->Font->Color = clGreen;
            ShapeClient->Pen->Color = clGreen;
            ImageSystem->Picture->Bitmap = bmpSysAct;
            ImageMinimize->Picture->Bitmap = bmpMinimize;
            ImageZoom->Picture->Bitmap = bmpZoom;
            ImageClose->Picture->Bitmap = bmpClose;
            break;
        case WA_INACTIVE:
            ImageTitle->Picture->Bitmap = bmpTitleInact;
            LabelTitle->Font->Color = clMoneyGreen;
            ShapeClient->Pen->Color = clMoneyGreen;
            ImageSystem->Picture->Bitmap = bmpSysInact;
            ImageMinimize->Picture->Bitmap = bmp_Inact;
            ImageZoom->Picture->Bitmap = bmp_Inact;
            ImageClose->Picture->Bitmap = bmp_Inact;
            break;
    }
}

void __fastcall TFormMain::ImageSystemMouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
//    HMENU hMenu = GetSystemMenu(Handle,FALSE);
//    TrackPopupMenu(hMenu,TPM_LEFTALIGN,X,Y,NULL,Handle,NULL);
}
//---------------------------------------------------------------------------

void __fastcall TFormMain::ImageSystemDblClick(TObject *Sender)
{
    Close();
}
//---------------------------------------------------------------------------

void __fastcall TFormMain::ImageSystemClick(TObject *Sender)
{
    static bool bUp = false;
    TImage *p = dynamic_cast<TImage *>(Sender);
    switch(p->Tag)
    {
        case 100:   // System Button
            break;
        case 101:   // Minimize Button
            Application->Minimize();
            break;
        case 102:   // Zoom Button
            bUp = !bUp;
            Height = (bUp)?(ImageTitle->Height + 2):FORMHEIGHT;
            p->Hint = (bUp)?"还原":"上卷"; 
            break;
        case 103:   // Close Button
            Application->Terminate();
            break;
        default: break;
    }
}
//---------------------------------------------------------------------------

void __fastcall TFormMain::LoadBitmaps()
{
    HBITMAP h;
    // Active Title
    bmpTitleAct = new Graphics::TBitmap();
    h = LoadBitmap(HInstance,"TITLE_ACTIVE");
    bmpTitleAct->Handle = h;
    // Inactive Title
    bmpTitleInact = new Graphics::TBitmap();
    h = LoadBitmap(HInstance,"TITLE_INACTIVE");
    bmpTitleInact->Handle = h;
    // Active System Button
    bmpSysAct = new Graphics::TBitmap();
    h = LoadBitmap(HInstance,"SYSTEM_ACITVE");
    bmpSysAct->Handle = h;
    // Inactive System Button
    bmpSysInact = new Graphics::TBitmap();
    h = LoadBitmap(HInstance,"SYSTEM_INACTIVE");
    bmpSysInact->Handle = h;
    // Close Button
    bmpClose = new Graphics::TBitmap();
    h = LoadBitmap(HInstance,"CLOSE_ACTIVE");
    bmpClose->Handle = h;
    // Minimize Button
    bmpMinimize = new Graphics::TBitmap();
    h = LoadBitmap(HInstance,"MINIMIZE_ACTIVE");
    bmpMinimize->Handle = h;
    // Zoom Button
    bmpZoom = new Graphics::TBitmap();
    h = LoadBitmap(HInstance,"ZOOM_ACTIVE");
    bmpZoom->Handle = h;
    // Inactive Button
    bmp_Inact = new Graphics::TBitmap();
    h = LoadBitmap(HInstance,"_INACTIVE");
    bmp_Inact->Handle = h;
}

void __fastcall TFormMain::FreeBitmaps()
{
    delete bmpTitleAct;
    delete bmpTitleInact;
    delete bmpSysAct;
    delete bmpSysInact;
    delete bmpClose;
    delete bmpMinimize;
    delete bmpZoom;
    delete bmp_Inact;
}
// == 界面代码 结束 =========================================================

void __fastcall TFormMain::FormCreate(TObject *Sender)
{
    DoubleBuffered = true;
    LoadBitmaps();

    // change ImageTitle's size
    ImageTitle->Width = Width - 2;
    // adjust ImageClose,ImageZoom and ImageMinimize's position
    ImageClose->Left = Width - 16;              // 16 = Image->Width + 4
    ImageZoom->Left = ImageClose->Left - 13;    // 13 = Image->Width + 1 
    ImageMinimize->Left = ImageZoom->Left - 13; // 13 = Image->Width + 1
}
//---------------------------------------------------------------------------

void __fastcall TFormMain::FormDestroy(TObject *Sender)
{
    FreeBitmaps();
}
//---------------------------------------------------------------------------


⌨️ 快捷键说明

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