|
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
LPCTSTR ProgName = "Form1";
HHOOK hHook;
LRESULT CALLBACK HookMouseProc(int nCode, WPARAM wParam, LPARAM lParam) ;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
hHook = SetWindowsHookEx(13,(HOOKPROC)::HookMouseProc,GetModuleHandle(NULL), 0);
}
//---------------------------------------------------------------------------
LRESULT CALLBACK HookMouseProc(int nCode, WPARAM wParam, LPARAM lParam)
{
HWND hwnd;
LRESULT lResult = 0;
if(nCode == HC_ACTION)
{
if(((EVENTMSG*)lParam)->message == VK_F10)
{
hwnd=FindWindow(NULL,ProgName);
SendMessage(hwnd,WM_USER+4,1,1);
return 1;
}
else if(((EVENTMSG*)lParam)->message == VK_F12)
{
hwnd=FindWindow(NULL,ProgName);
SendMessage(hwnd,WM_USER+5,1,1);
return 1;
}
else if(((EVENTMSG*)lParam)->message == VK_F8)
{
hwnd=FindWindow(NULL,ProgName);
SendMessage(hwnd,WM_USER+6,1,1);
return 1;
}
}
return CallNextHookEx(hHook, nCode, wParam, lParam);
UnhookWindowsHookEx(hHook);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::OnMyKeyEvent(TMessage &Message)
{
switch(Message.Msg)
{
case WM_USER+4:
ShowMessage("F10 press");
break;
case WM_USER+5:
ShowMessage("F12 press");
break;
case WM_USER+6:
ShowMessage("F8 press");
break;
}
}
헤더 파일
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TEdit *Edit1;
TButton *Button1;
void __fastcall Button1Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
protected:
void __fastcall OnMyKeyEvent(TMessage &Message);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_USER+4, TMessage, OnMyKeyEvent);
MESSAGE_HANDLER(WM_USER+5, TMessage, OnMyKeyEvent);
MESSAGE_HANDLER(WM_USER+6, TMessage, OnMyKeyEvent);
END_MESSAGE_MAP(TForm)
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
왜 한번 더 실행 돼는지 아세요???
|