我寫了一個小程序能夠把鼠標所在的位置的顔色取出來,但是遇到一個小問題?如何才能檢測到在窗體外的鼠標事件?

huahao0672 2004-04-06 10:36:20
我寫了一個小程序能夠把鼠標所在的位置的顔色取出來,但是遇到一個小問題?如何才能檢測到在窗體外的鼠標事件?

我寫了一個小程序能夠把鼠標所在的位置的顔色取出來,但是遇到一個小問題?如何才能檢測到在窗體外的鼠標事件?


在Form1當中,用什麽事件來處理這種情況呢!!!!!!
...全文
34 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
jiangchun_xn 2004-04-06
  • 打赏
  • 举报
回复
1.在Timer事件中调用
BOOL GetCursorPos(
LPPOINT lpPoint // cursor position
);获取屏幕坐标,再在GetDC(0)上取颜色

2.用鼠标钩子,直接取当前窗口的当前鼠标位置颜色


windfighter 2004-04-06
  • 打赏
  • 举报
回复
没有别的办法,只有用钩子
lovebcb 2004-04-06
  • 打赏
  • 举报
回复
看个例子,
三个Edit,1个button,1个timer(设false),1个panel

点button后,三个edit中分别显示RGB的值,panel显示颜色


//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
TPoint p;
HDC d;
DWord r;
GetCursorPos(&p);
d=GetDC(0);
r=GetPixel(d,p.x,p.y);
Panel1->Color=TColor(r);
Edit1->Text=IntToStr(GetRValue(r));
Edit2->Text=IntToStr(GetGValue(r));
Edit3->Text=IntToStr(GetBValue(r));
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
Timer1->Enabled=True;
Button1->Enabled=False;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender)
{

hotkeyid=GlobalAddAtom("UserDefined")-0xC000;
RegisterHotKey(NULL,hotkeyid,MOD_ALT,26);

}
//---------------------------------------------------------------------------



void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
UnregisterHotKey(NULL,hotkeyid);
DeleteAtom(hotkeyid);
}
//---------------------------------------------------------------------------

void TForm1::WMHotKey(TWMHotKey Msg)
{
if (Msg.HotKey==hotkeyid)
{
Msg.Result=1;
Timer1->Enabled=True;
Button1->Enabled=False;
}
}

604

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder VCL组件使用和开发
社区管理员
  • VCL组件使用和开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧