如何在窗体中捕获控件的消息

mbzdh 2003-09-02 07:30:44
如题
...全文
44 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
mbzdh 2003-09-03
  • 打赏
  • 举报
回复
有点眉目了,但还是不太清楚,解决了另外开贴给分!
mbzdh 2003-09-03
  • 打赏
  • 举报
回复
tmessage和tmsg有何区别,
上边的意思是LPARM指某个控件,那WPARM指什么,谢谢!!
XXSingle 2003-09-03
  • 打赏
  • 举报
回复
up,同意楼上
上海老李 2003-09-03
  • 打赏
  • 举报
回复
Determines whether an application message requires hiding the hint window.

type

TMsg = packed record
hwnd: HWND;
message: UINT;
wParam: WPARAM;
lParam: LPARAM;
time: DWORD;
pt: TPoint;

end;

function IsHintMsg(var Msg: TMsg): Boolean; virtual;

Description

Call IsHintMsg to determine whether the message specified by the Msg parameter requires hiding the hint window. Upon seeing a mouse, keyboard, command, or activation message, IsHintMsg returns True. The global Application object calls IsHintMsg to check messages while the hint window is on the screen, and hides the window if IsHintMsg returns True.
上海老李 2003-09-03
  • 打赏
  • 举报
回复
或者说,你的windowproc(msg:Tmsg);
msg.message就是如左键呀等
msg.lparam就是具体的某个控件
上海老李 2003-09-03
  • 打赏
  • 举报
回复
function WindowProc(hWnd, uMsg, wParam, lParam: Integer): Integer; stdcall;
begin
Result := DefWindowProc(hWnd, uMsg, wParam, lParam);
{ Checks for messages }
if (lParam = Button1) and (uMsg = WM_COMMAND) then
CheckPassword;
if uMsg = WM_DESTROY then
Halt;
end;
mbzdh 2003-09-03
  • 打赏
  • 举报
回复
我的意思是在窗体上有控件,比如BUTTON,我在它上面击鼠标左键,如何捕获这一消息。
上海老李 2003-09-03
  • 打赏
  • 举报
回复
你看看DELPHI中的DEMOS中的APPEVENTS这个讲得挺好了
上海老李 2003-09-03
  • 打赏
  • 举报
回复
对了,在DELPHI的DEMOS中有个APPEVENTS这个例子,你看看就会明白了!
上海老李 2003-09-03
  • 打赏
  • 举报
回复
这个呀,我给你一段我写的C的代码,你看吧,其实DELPHI只是封装了一些消息处理或其它的东西罢了:
LRESULT CTopEisKeyboardCtrl::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class


switch(message)
{
case WM_ACTIVATE:
MSG msg;
wParam=WA_INACTIVE;
msg.wParam=wParam;
msg.lParam=wParam;
msg.message=message;
msg.hwnd=hwnd;
DispatchMessage(&msg);
break;
case WM_MOUSEACTIVATE:

return MA_NOACTIVATE;

break;
case WM_SETFOCUS:
{

::PostMessage(hwnd,WM_KILLFOCUS,0,0);
CWnd *wnd=::AfxGetMainWnd();
HWND hwndwnd=wnd->m_hWnd;
lihao=hwndwnd;
::SetFocus(hwndwnd);

//&&gFocus!=NULL
/*if (hwndwnd!=gFocus)
{
::SetFocus(gFocus);
char buffer[9];
long l=(long)gFocus;
_ltoa(l,buffer,16);
//MessageBox(buffer);
}*/
}
break;
case WM_KILLFOCUS:
{
//::SetFocus(lihao);
/*if (hwndwnd!=hwnd)
b=::PostMessage(hwndwnd,WM_MOUSEACTIVATE,0,0);
if (b)
{
::SetFocus(hwndwnd);
lihao=hwndwnd;
}9*/


}
case WM_DESTROY:
if (gShift==true)
{
keybd_event(0x20,0,KEYEVENTF_KEYUP,0);
}
break;
case WM_CREATE:

CWnd *wnd;
//MSG msg;
hwnd=CWnd::m_hWnd;
wnd=AfxGetMainWnd();
hInst=AfxGetResourceHandle();

//HANDLE hmutex;
//LPCTSTR szAppName;
//CreateMutex
/*while (GetMessage(&msg,NULL,0,0))
{
HWND hwndx=::GetForegroundWindow();
//BringWindowToTop(hwndMain);
if (IsWindow(hwndx))
{
if (hwndx!=hwnd)
{
if (gFocus!=hwndx)
{
if (IsWindow(gFocus))
{
AttachThreadInput(GetWindowThreadProcessId(hwnd,NULL),GetWindowThreadProcessId(gFocus,NULL),false);
}
gFocus=hwndx;
AttachThreadInput(GetWindowThreadProcessId(hwnd,NULL),GetWindowThreadProcessId(gFocus,NULL),true);
}
}
}
if (!hwnd||!::IsDialogMessage(hwnd,&msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

//ReleaseMutex(hMutex);
return(msg.wParam );*/


//AfxGetInstanceHandle();
/*char buffer[20];
long l=(long)hInst;
_ltoa(l,buffer,16);
//MessageBox(buffer);
/*MessageBox("next");
HINSTANCE hin=AfxGetInstanceHandle();
l=(long)hin;
_ltoa(l,buffer,16);
MessageBox(buffer);*/

/*HDC hdc;
HDC hMemdc;
HBITMAP hbitmap;
BITMAP bm;
hbitmap=LoadBitmap(hInst,"IDB_KEYBOARD");
GetObject(hbitmap,sizeof(BITMAP),&bm);
hdc=::GetDC(hwnd);
hMemdc=CreateCompatibleDC(hdc);

GetClientRect(&rect);
StretchBlt(hdc,0,0,rect.right,rect.bottom,hMemdc,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);
DeleteDC(hMemdc);
::ReleaseDC(hwnd,hdc);

DeleteObject(hbitmap);

/*char buff[20];
_itoa(rect.top,buff,10);
MessageBox(buff);
_itoa(rect.left,buff,10);
MessageBox(buff);
_itoa(rect.bottom,buff,10);
MessageBox(buff);
_itoa(rect.right,buff,10);
MessageBox(buff);*/
break;
case WM_LBUTTONDOWN:
int x,y;
RECT rect;
x=LOWORD(lParam);
y=HIWORD(lParam);
POINT p;
p.x=x;
p.y=y;
//the '~'
rect=CRect(0,0,25,27);
if (PtInRect(&rect,p))
{
keybd_event(0xC0,0,0,0);
keybd_event(0xC0,0,KEYEVENTF_KEYUP,0);
if (gShift==true)
{
keybd_event(0x20,0,KEYEVENTF_KEYUP,0);
}
}
//'1'
rect=CRect(25,0,50,27);
if (PtInRect(&rect,p))
{
keybd_event(0x31,0,0,0);
keybd_event(0x31,0,KEYEVENTF_KEYUP,0);
if (gShift==true)
{
keybd_event(0x20,0,KEYEVENTF_KEYUP,0);
}
}
//'2'
rect=CRect(50,0,75,27);
if (PtInRect(&rect,p))
{
keybd_event(0x32,0,0,0);
keybd_event(0x32,0,KEYEVENTF_KEYUP,0);
if (gShift==true)
{
keybd_event(0x20,0,KEYEVENTF_KEYUP,0);
}
}
//'3'
rect=CRect(75,0,100,27);
if (PtInRect(&rect,p))
{
keybd_event(0x33,0,0,0);
keybd_event(0x33,0,KEYEVENTF_KEYUP,0);
if (gShift==true)
{
keybd_event(0x20,0,KEYEVENTF_KEYUP,0);
}
}
//'4'
rect=CRect(100,0,125,27);
if (PtInRect(&rect,p))
{
keybd_event(0x34,0,0,0);
keybd_event(0x34,0,KEYEVENTF_KEYUP,0);
if (gShift==true)
{
keybd_event(0x20,0,KEYEVENTF_KEYUP,0);
}
}
-------------
//'5'
}}
就是处理它的窗口的消息处理函数,我给你写一个DELPHI的
blackbeetle 2003-09-03
  • 打赏
  • 举报
回复
说的不清初啊,太抽象了。还是问具体点。
mbzdh 2003-09-02
  • 打赏
  • 举报
回复
谢谢!
lw549 2003-09-02
  • 打赏
  • 举报
回复
顶一下。
mbzdh 2003-09-02
  • 打赏
  • 举报
回复
这么没人缘

5,386

社区成员

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

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