如何监视剪贴板
2008-03-08 12:46:04 来源:WEB开发网核心提示:在Form1的.h的PRivate加上:void __fastcall ClipboardChanged(TMessage& Msg);在Form1的.h的public加上:BEGIN_MESSAGE_MAPMESSAGE_HANDLER(WM_DRAWCLIPBOARD,TMessage,ClipboardChang
在Form1的.h的PRivate加上:
void __fastcall ClipboardChanged(TMessage& Msg);
在Form1的.h的public加上:
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_DRAWCLIPBOARD,TMessage,ClipboardChanged)
END_MESSAGE_MAP(TForm)
在Form1的.cpp内加上:
void __fastcall TForm1::ClipboardChanged(TMessage& Msg)
{
POINT MousePos;
GetCursorPos(&MousePos);
PopupMenu4->PopupComponent=Form1;
PopupMenu4->Popup(MousePos.x,MousePos.y); //一有变化,就弹出一个菜单,复制,剪切或清除都能引发此函数
}
在Form1的.cpp内有一个ToolButton
void __fastcall TForm1::ToolButton9Click(TObject *Sender)
{
static HWND LastHandle;
static bool clip=false;
if(clip==true)
{
ToolButton9->Down=false;
ChangeClipboardChain(Form1->Handle,LastHandle); //结束监视
}
else
{
ToolButton9->Down=true;
Clipboard()->Clear();
application->Minimize();
LastHandle=SetClipboardViewer(Form1->Handle); //启动监视
}
clip=!clip;
}
更多精彩
赞助商链接