当前位置:七道奇文章资讯编程技术VC/C++编程
日期:2011-03-22 13:55:00  来源:本站整理

自画标题栏的一个例子[VC/C++编程]

赞助商链接



  本文“自画标题栏的一个例子[VC/C++编程]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:

.h File

//---------------------------------------------------------------------------
#ifndef wmncH
#define wmncH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <Buttons.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
     TBitBtn *BitBtn1;
     void __fastcall FormPaint(TObject *Sender);
     void __fastcall FormResize(TObject *Sender);
     void __fastcall BitBtn1Click(TObject *Sender);
private:// User declarations
     void __fastcall OnNcHitTest(TMessage &Message);
public: // User declarations
     __fastcall TForm1(TComponent* Owner);
     BEGIN_MESSAGE_MAP
      VCL_MESSAGE_HANDLER(WM_NCHITTEST,TMessage,OnNcHitTest);
     END_MESSAGE_MAP(TForm);
protected:
     virtual void __fastcall WndProc(TMessage &Message);
     virtual void __fastcall CreateParams(TCreateParams &Params);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
.cpp File
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "wmnc.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
  : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::CreateParams(TCreateParams &Params)
{
  TForm::CreateParams(Params);
  Params.Style|=WS_POPUP;
  Params.Style^=WS_DLGFRAME;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::OnNcHitTest(TMessage &Message)
{
  TPoint PT;
  PT.x=LOWORD(Message.LParam);
  PT.y=HIWORD(Message.LParam);
  PT=ScreenToClient(PT);
  RECT rect;
  ::SetRect(&rect,0,0,20,ClientHeight);
  if(PtInRect(&rect,PT))
  {
   Message.Result=HTCAPTION;
   //ShowMessage("How are you");
  }
  else
  {
   DefaultHandler(&Message);
  }
}
void __fastcall TForm1::FormPaint(TObject *Sender)
{
  RECT rect;
  ::SetRect(&rect,0,0,ClientWidth,ClientHeight);
  Canvas->Pen->Color=clBlue;
  Canvas->Brush->Color=clBlue;
  Canvas->Rectangle(0,0,20,ClientHeight);
  char *msg="My Fellow Citizens!";
  LOGFONT fontRect;
  memset(&fontRect,0,sizeof(LOGFONT));
  fontRect.lfHeight=-13;
  fontRect.lfWeight=FW_NORMAL;
  fontRect.lfEscapement=900;
  lstrcpy(fontRect.lfFaceName,"宋体");
  HFONT hFont=CreateFontIndirect(&fontRect);
  HFONT hOld=::SelectObject(Canvas->Handle,hFont);
  ::SetRect(&rect,0,0,20,ClientHeight);
  ::SetTextColor(Canvas->Handle,RGB(255,255,255));
  ::SetBkColor(Canvas->Handle,RGB(255,0,0));
  ::TextOut(Canvas->Handle,3,ClientHeight-3,msg,lstrlen(msg));
  ::SelectObject(Canvas->Handle,hOld);
  ::DeleteObject(hFont);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::WndProc(TMessage &Message)
{
  if(Message.Msg==WM_SYSCOMMAND)
  {
   if(Message.WParam==SC_MAXIMIZE || Message.WParam==61490)
   {
    Invalidate();
   }
  }
  TForm::WndProc(Message);
}
void __fastcall TForm1::FormResize(TObject *Sender)
{
  Invalidate(); 
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
  int button;
  button=Application->MessageBox("Do you want to exit thisform?", \
   "Confirmation",MB_YESNO+MB_ICONQUESTION);
  if(button==IDYES)
  {
   Application->Terminate();
  }
}


  以上是“自画标题栏的一个例子[VC/C++编程]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
  • 自画标题栏的一个例子
  • 本文地址: 与您的QQ/BBS好友分享!
    • 好的评价 如果您觉得此文章好,就请您
        0%(0)
    • 差的评价 如果您觉得此文章差,就请您
        0%(0)

    文章评论评论内容只代表网友观点,与本站立场无关!

       评论摘要(共 0 条,得分 0 分,平均 0 分) 查看完整评论
    Copyright © 2020-2022 www.xiamiku.com. All Rights Reserved .