VBA实现全局钩子的调用
之前的钩子是用C语言实现的,现在想将其改成用VBA实现,本人是菜鸟,想请教一下各位大虾,C语言代码如下:// dllCall.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <Windows.h>
#include <iostream>
#include <string>
#include <WinUser.h>
//#include <IMessage.h>
#pragma comment(lib,"..\\Release\\dlltest.lib") //静态调用dll文件,必须将上面生成的dlltest.lib和dlltest.dll文件放到主程序的运行目录下
using namespace std;
extern "C" BOOL _declspec(dllimport)startHOOK(HWND hwnd);
extern "C" BOOL _declspec(dllimport)stopHOOK();
#define WM_THREADFIREEVENT1 WM_APP+111
LRESULT CALLBACK WndProc(HWND hwnd,UINT uMsg,WPARAM wparam,LPARAM lparam); //定义窗口过程函数
int _tmain(int argc, _TCHAR* argv[])
{
MSG msg;
HINSTANCE hInstance = (HINSTANCE)GetModuleHandleW(0);//获取当前程序实例句柄
//创建窗口
HMENU hMenu = CreateMenu();
WNDCLASS wndclass;
wndclass.hbrBackground = (HBRUSH)GetStockObject(DKGRAY_BRUSH);
wndclass.hCursor = LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wndclass.hInstance =hInstance;
wndclass.lpfnWndProc = WndProc;
wndclass.lpszClassName = L"HELLO";
wndclass.lpszMenuName=NULL;
wndclass.style = CS_HREDRAW;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
RegisterClass(&wndclass);
HWND hwnd_y = CreateWindowExW(WS_ACTIVECAPTION,L"hello",L"hello",WS_ACTIVECAPTION,
960,720,CW_USEDEFAULT,CW_USEDEFAULT,NULL,hMenu,hInstance,NULL);
//隐藏窗口
ShowWindow(hwnd_y,SW_HIDE);
startHOOK(hwnd_y); //启动钩子函数
//进行消息循环
while (GetMessageW(&msg,hwnd_y,0,0))
{
if (msg.message == WM_THREADFIREEVENT1)
{
cout<<"收到消息"<<endl; //当有窗口激活消息收到,则打印该行
}
}
return 0;
}
LRESULT CALLBACK WndProc(HWND hwnd_y,UINT uMsg,WPARAM wparam,LPARAM lparam)
{
switch (uMsg)
{
case WM_QUIT:
{stopHOOK();cout<<"停止钩子函数"<<endl;break;}
default:
return DefWindowProc(hwnd_y,uMsg,wparam,lparam);
}
return 0;
}
--------------------编程问答-------------------- 菜鸟就花钱找人做吧。 --------------------编程问答-------------------- 除
补充:VB , API