//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Main.h"
#include "About.h"
//---------------------------------------------------------------------------
#pragma resource "*.dfm"
//定义全局变量
HHOOK hMsgHook;//钩子句柄
int iClientHeight, iClientWidth;//待画的客户区高和宽
Graphics::TBitmap *BackBmp;
HBITMAP hFaceBitmap;//位图句柄
HWND hClientHandle, hMdiHandle;//MDI主窗口和MDI客户窗口句柄
TMainForm *MainForm;
//在指定的窗口中,画位图,填充整个用户窗口,Ture为绘制成功,false为绘制失败
BOOL DrawBitmap(HWND Handle, HBITMAP hBitmap, int iClientHeight, int iClientWidth)
{
if(hBitmap==NULL)
return false;
BITMAP Bmp;
int iBitmapH, iBitmapW;
GetObject( hBitmap, sizeof( BITMAP), &Bmp);
iBitmapH = Bmp.bmHeight;
iBitmapW = Bmp.bmWidth;
HDC hClientDC, hMemDC;
hClientDC = GetDC(Handle);
if(hClientDC==NULL)
return false;
hMemDC = CreateCompatibleDC( hClientDC );
if(hMemDC==NULL)
{
DeleteDC(hClientDC);
return false;
}
SelectObject(hMemDC,hBitmap);
int x=0, y=0;
while(x<iClientWidth )
{
y = 0;
while(y<iClientHeight)
{
MainForm->Canvas->Draw(x, y, BackBmp);
BitBlt(hClientDC, x, y,iBitmapW, iBitmapH, hMemDC, 0, 0,SRCCOPY );
y = y + iBitmapH;
}
x = x + iBitmapW;
}
DeleteDC( hMemDC );
DeleteDC( hClientDC );
return true;
}
//钩子函数,处理系统WM_PAINT和WM_ERASEBKGND消息
LRESULT CALLBACK GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam )
{
LRESULT lReturn=0;
MSG *cwMessage;
cwMessage=(MSG*)lParam;
if(cwMessage->hwnd==hClientHandle||cwMessage->hwnd==hMdiHandle)
//是发送给子窗口的消息则处理
{
if(cwMessage->message==WM_PAINT||cwMessage->message==WM_ERASEBKGND)
{//重画用户窗口
DrawBitmap(hClientHandle, hFaceBitmap, iClientHeight, iClientWidth);
}
}
if(hMsgHook != NULL) //将消息继续下传
lReturn = CallNextHookEx(hMsgHook, nCode, wParam, lParam );
return lReturn;
}
//---------------------------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent *Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::CreateMDIChild(String Name)
{
TMDIChild *Child;
//--- create a new MDI child window ----
Child = new TMDIChild(Application);
Child->Caption = Name;
if (FileExists (Name))
Child->Memo1->Lines->LoadFromFile(Name);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FileNew1Execute(TObject *Sender)
{
CreateMDIChild("NONAME" + IntToStr(MDIChildCount + 1));
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FileOpen1Execute(TObject *Sender)
{
if (OpenDialog->Execute())
CreateMDIChild(OpenDialog->FileName);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::HelpAbout1Execute(TObject *Sender)
{
AboutBox->ShowModal();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FileExit1Execute(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FormPaint(TObject *Sender)
{
iClientHeight = ClientHeight;
iClientWidth = ClientWidth;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FormShow(TObject *Sender)
{//从文件中调入位图
BackBmp = new Graphics::TBitmap();
BackBmp->LoadFromFile("Show.bmp");
hFaceBitmap = BackBmp->Handle;
//保存位图句柄
hClientHandle = ClientHandle;
//保存窗口句柄
hMdiHandle = Handle;
//保存MDI主窗口句柄
//安装截取程序消息的钩子函数
hMsgHook = SetWindowsHookEx(WH_GETMESSAGE, (HOOKPROC)GetMsgProc, NULL, GetCurrentThreadId());
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FormClose(TObject *Sender, TCloseAction &Action)
{//卸载钩子函数
if ( hMsgHook != NULL)
UnhookWindowsHookEx( hMsgHook );
if ( BackBmp != NULL )
delete BackBmp;
}
//---------------------------------------------------------------------------
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
C++ Builder 精彩编程实例集锦 源代码 第一部分 界面设计.rar (417个子文件)
ShowBmp.bmp 509KB
LUOBIN11.BMP 448KB
LUOBIN10.BMP 445KB
LUOBIN15.BMP 444KB
Show.bmp 400KB
Show.bmp 394KB
Show.bmp 393KB
Show.bmp 393KB
Show.bmp 389KB
Show.bmp 359KB
Show.bmp 330KB
Show.bmp 305KB
Show.bmp 277KB
001.BMP 261KB
Show.bmp 252KB
Show.bmp 248KB
Show.bmp 235KB
Show.bmp 226KB
Show.bmp 226KB
Show.bmp 212KB
Show.bmp 204KB
Screen.bmp 187KB
LUOBIN10.BMP 112KB
0024.BMP 14KB
0030.BMP 14KB
0023.BMP 14KB
0022.BMP 14KB
0024.BMP 14KB
0030.BMP 14KB
0023.BMP 14KB
0022.BMP 14KB
TaskbarSwitch.bpr 4KB
DynamicForm.bpr 4KB
Splash.bpr 4KB
Controls.bpr 4KB
SDIAPP.BPR 3KB
CustomCaption.bpr 3KB
Flash.bpr 3KB
CustomIcon.bpr 3KB
Move.bpr 3KB
HideProgram.bpr 3KB
Transparent.bpr 3KB
Transparent.bpr 3KB
ShowWindow.bpr 3KB
Progress.bpr 3KB
Controls.bpr 3KB
Position.bpr 3KB
Minimize.bpr 3KB
Caption.bpr 3KB
ListBox.bpr 3KB
Taskbar.bpr 3KB
ListBox.bpr 3KB
Radiant.bpr 3KB
Scroll.bpr 3KB
System.bpr 3KB
Rotate.bpr 3KB
Tray.bpr 3KB
System.bpr 3KB
BKBmp.bpr 3KB
Pixel.bpr 3KB
Limit.bpr 3KB
Hide.bpr 3KB
Memo.bpr 3KB
Edit.bpr 3KB
Amp.bpr 3KB
Avi.bpr 3KB
Tab.bpr 3KB
Hit.bpr 3KB
Str.bpr 3KB
Top.bpr 3KB
MDIAPP.BPR 3KB
MDIAPP.BPR 3KB
MDIAPP.BPR 3KB
MAIN.CPP 4KB
Mainform.cpp 2KB
Mainform.cpp 2KB
MAIN.CPP 2KB
SDIMAIN.CPP 2KB
Mainform.cpp 2KB
Mainform.cpp 2KB
MAIN.CPP 2KB
Mainform.cpp 2KB
Mainform.cpp 2KB
Mainform.cpp 1KB
TaskbarSwitch.cpp 1KB
Mainform.cpp 1KB
Mainform.cpp 1KB
Mainform.cpp 1KB
Taskbar.cpp 1KB
MainForm.cpp 1KB
MainForm.cpp 1KB
CustomCaption.cpp 1KB
Tray.cpp 1KB
DynamicForm.cpp 1KB
Mainform.cpp 1KB
Mainform.cpp 1KB
Mainform.cpp 1KB
Scroll.cpp 1KB
System.cpp 1KB
Rotate.cpp 1KB
共 417 条
- 1
- 2
- 3
- 4
- 5
资源评论
- siva202013-12-31很好,适合初学者参考.
- pdy_132014-04-21不错,资料很详细
SoulKeeer
- 粉丝: 10
- 资源: 119
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功