C/C++ Windows API

Moderators: Lundin
Number of threads: 450
Number of posts: 1225

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Intercept mesages from a control ? Posted by vlad777 on 2 Feb 2011 at 6:52 PM

How do I intercept WM_LBUTTONDOWN of edit control?

Many thanks.
Report
Re: Intercept mesages from a control ? Posted by pseudocoder on 7 Feb 2011 at 2:10 PM
subclass the control


HWND hParent;
WNDPROC wpEdit;

LRESULT CALLBACK EditProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {

   LRESULT lRes;

   if(msg != WM_MOUSEMOVE) {
      lRes = CallWindowProc(wpEdit, hwnd, msg, wParam, lParam);
   } else {
      return DefWindowProc(hwnd, msg, wParam, lParam);
   }

   if(msg == WM_LBUTTONDOWN) {
      // code
      MessageBox(hwnd, TEXT("lbutton click test"), TEXT(""), MB_OK); 
   }
   return lRes;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {

   // bits of code
   static HWND hEdit1; // handle to edit control

   switch(msg) {

      WM_CREATE : // bits of code
                  hParent = hwnd;
                  wpEdit = (WNDPROC) SetWindowLong(hEdit1, GWL_WNDPROC, (LONG) EditProc);  
                  // bits of code
                  break;

      WM_DESTORY : // bits of code
                   SetWindowLong(hEdit1, GWL_WNDPROC, (LONG) wpEdit);
                   // bits of code
   }
   // bits of code
}


something like that, I think.




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.