自画标题栏的一个例子
2008-02-23 05:36:52来源:互联网 阅读 ()
//---------------------------------------------------------------------------
#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();
}
}
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇: 纯sdk创建能接收文档拖放的窗体
下一篇: 工具栏中的主菜单实现自定义快捷键的方法
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash