1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
// MainHamsterDlg.cpp : implementation file
#include "stdafx.h"
#include "MainHamsterDlg.h"
// MainHamsterDlg dialog
IMPLEMENT_DYNAMIC(MainHamsterDlg, CDialogEx)
MainHamsterDlg::MainHamsterDlg(CWnd* pParent)
: CDialogEx(MainHamsterDlg::IDD, pParent)
{}
void MainHamsterDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(MainHamsterDlg, CDialogEx)
ON_WM_TIMER()
END_MESSAGE_MAP()
HHOOK _hook;
KBDLLHOOKSTRUCT kbdStruct;
LRESULT __stdcall HookCallback(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode >= 0)
{
if (wParam == WM_KEYUP)
{
kbdStruct = *((KBDLLHOOKSTRUCT*)lParam);
if (kbdStruct.vkCode == VK_INSERT)
{
//I want start timer there
}
}
}
return CallNextHookEx(_hook, nCode, wParam, lParam);
}
void SetHook()
{
if (!(_hook = SetWindowsHookEx(WH_KEYBOARD_LL, HookCallback, NULL, 0)))
{
MessageBox(NULL, "Failed to install hook!", "Error", MB_ICONERROR);
}
}
void ReleaseHook()
{
UnhookWindowsHookEx(_hook);
}
BOOL MainHamsterDlg::OnInitDialog()
{
SetHook();
//SetTimer(0, 0, NULL); <<<------- this starts timer
CDialogEx::OnInitDialog();
return TRUE;
}
void MainHamsterDlg::OnTimer(UINT nIDEvent)
{
//do something
CDialog::OnTimer(nIDEvent);
}
|