通过窗口句柄截获消息

来源:互联网 发布:淘宝会员卡在哪里查看 编辑:程序博客网 时间:2024/05/16 06:51
#include <vcl.h>#pragma hdrstop#include "Unit1.h"#pragma package(smart_init)#pragma resource "*.dfm"TForm1 *Form1;typedef LRESULT (CALLBACK* WNDPROC) (HWND, UINT, WPARAM, LPARAM);WNDPROC g_pOldProc;LRESULT CALLBACK NewWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){   switch (message)   {    case WM_LBUTTONUP:        ShowMessage("ok");        break;    default :       //继续调用原来的窗口过程函数        return CallWindowProc((FARPROC)g_pOldProc, hwnd, message, wParam, lParam);    }}//---------------------------------------------------------------------------__fastcall TForm1::TForm1(TComponent* Owner)        : TForm(Owner){    g_pOldProc = (WNDPROC)GetWindowLong(this->Handle, GWL_WNDPROC);//获取旧的窗口过程函数指针保存    SetWindowLong(this->Handle, GWL_WNDPROC, long(NewWndProc));//设置新的窗口过程函数}//---------------------------------------------------------------------------__fastcall TForm1::~TForm1(){    SetWindowLong(this->Handle , GWL_WNDPROC, (long)g_pOldProc);//恢复旧的过程函数}

0 0
原创粉丝点击