CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
英特尔®游戏设计大赛100美元现金周周送 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Delphi >  VCL组件开发及应用

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

楼主mbzdh(一天一个进步)2003-09-02 19:30:44 在 Delphi / VCL组件开发及应用 提问

如题 问题点数:20、回复次数:13Top

1 楼mbzdh(一天一个进步)回复于 2003-09-02 19:56:35 得分 0

这么没人缘Top

2 楼lw549(那个孩子他爹)回复于 2003-09-02 19:59:05 得分 0

顶一下。Top

3 楼mbzdh(一天一个进步)回复于 2003-09-02 19:59:39 得分 0

谢谢!Top

4 楼blackbeetle(票房毒药)回复于 2003-09-03 09:33:09 得分 0

说的不清初啊,太抽象了。还是问具体点。Top

5 楼lihao_ningxia(耗子)回复于 2003-09-03 09:41:55 得分 0

这个呀,我给你一段我写的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的Top

6 楼lihao_ningxia(耗子)回复于 2003-09-03 09:57:53 得分 0

对了,在DELPHI的DEMOS中有个APPEVENTS这个例子,你看看就会明白了!Top

7 楼lihao_ningxia(耗子)回复于 2003-09-03 09:59:18 得分 0

你看看DELPHI中的DEMOS中的APPEVENTS这个讲得挺好了Top

8 楼mbzdh(一天一个进步)回复于 2003-09-03 10:01:15 得分 0

我的意思是在窗体上有控件,比如BUTTON,我在它上面击鼠标左键,如何捕获这一消息。Top

9 楼lihao_ningxia(耗子)回复于 2003-09-03 10:36:25 得分 0

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;Top

10 楼lihao_ningxia(耗子)回复于 2003-09-03 10:44:46 得分 0

或者说,你的windowproc(msg:Tmsg);  
  msg.message就是如左键呀等  
  msg.lparam就是具体的某个控件Top

11 楼lihao_ningxia(耗子)回复于 2003-09-03 10:45:08 得分 20

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.Top

12 楼XXSingle(心无了然)回复于 2003-09-03 11:03:27 得分 0

up,同意楼上Top

13 楼mbzdh(一天一个进步)回复于 2003-09-03 11:24:28 得分 0

tmessage和tmsg有何区别,  
  上边的意思是LPARM指某个控件,那WPARM指什么,谢谢!!Top

14 楼mbzdh(一天一个进步)回复于 2003-09-03 11:50:27 得分 0

有点眉目了,但还是不太清楚,解决了另外开贴给分!Top

相关问题

  • 如何捕获窗体下面的控件的一些消息?
  • 怎么样捕获窗体下面的控件的一些消息?
  • 郁闷好几天了,大虾快救我啊![ActiveX控件中捕获不到TWAIN消息,而做成应用,在窗体中可捕获消息]
  • 捕获窗体的最小化消息
  • 窗体移动时,窗体上的控件会收到什么消息呢?
  • 如何在A窗体中处理子窗体某个控件的消息/事件?
  • 如何不让控件捕获消息??
  • 捕获控件的双击消息!!!!!!!!!!!!!!!1
  • 关于窗体移动消息捕获的问题?
  • 如何让窗体截获发给控件的消息?

关键词

  • 控件
  • 消息
  • hwndwnd
  • ishintmsg
  • gfocus
  • lihao
  • wparam
  • tmsg
  • setfocus
  • lparam

得分解答快速导航

  • 帖主:mbzdh
  • lihao_ningxia

相关链接

  • Delphi类图书
  • Delphi类源码下载
  • Delphi控件下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo