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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
| // neurocom.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "neurocom.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CNeurocom
#define MY_WM_NOTIFYICON WM_USER+1
BEGIN_MESSAGE_MAP(CNeurocom, CWinApp)
END_MESSAGE_MAP()
HHOOK hHook; // Handle du hook global
LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM){
return 0;
}
LRESULT CALLBACK HookProc (int nCode, WPARAM wParam, LPARAM lParam)
{
// Si une touche a été pressée
if ((nCode == HC_ACTION) && (wParam == WM_KEYDOWN))
{
// Structure de récupération d'infos sur la touche tapée
// MOUSEHOOKSTRUCT - HARDWAREHOOKSTRUCT - DESKTOP_HOOKCONTROL - SHELLHOOKINFO - DEBUGHOOKINFO
KBDLLHOOKSTRUCT hookstruct = *((KBDLLHOOKSTRUCT*)lParam);
// Si la touche pressée est la touche PrintScreen
if(hookstruct.vkCode == VK_LSHIFT)
{
MessageBox(NULL, _T("VK_LSHIFT Pressed"), _T("alert"), MB_OK);
}
if(hookstruct.vkCode == VK_ESCAPE){
PostQuitMessage(0);
}
}
// Renvoi des messages au sytème pour permettre d'autres hooks
return CallNextHookEx(hHook, nCode, wParam, lParam);
}
// CNeurocom construction
CNeurocom::CNeurocom()
{
}
CNeurocom theApp;
BOOL CNeurocom::InitInstance()
{
// InitCommonControlsEx() is required on Windows XP if an application
// manifest specifies use of ComCtl32.dll version 6 or later to enable
// visual styles. Otherwise, any window creation will fail.
INITCOMMONCONTROLSEX InitCtrls;
InitCtrls.dwSize = sizeof(InitCtrls);
// Set this to include all the common control classes you want to use
// in your application.
InitCtrls.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&InitCtrls);
if(!CWinApp::InitInstance()){
DWORD error = GetLastError();
return FALSE;
}
if (!AfxSocketInit())
{
AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
return FALSE;
}
m_hIcon = LoadIcon(IDR_MAINFRAME);
// Standard initialization
SetRegistryKey(_T("Neurocom"));
m_WndClass.style = 0;
m_WndClass.lpfnWndProc = MainWndProc;
m_WndClass.cbClsExtra = 0;
m_WndClass.cbWndExtra = 0;
m_WndClass.hInstance = m_hInstance;
m_WndClass.hIcon = m_hIcon;
m_WndClass.hCursor = LoadStandardCursor(IDC_ARROW);
m_WndClass.hbrBackground = (HBRUSH)(1 + COLOR_BTNFACE);
m_WndClass.lpszMenuName = NULL;
m_WndClass.lpszClassName = _T("Neurocom Network");
if(!RegisterClass(&m_WndClass)) return FALSE;
if(BuildHWnd()){
hHook = SetWindowsHookEx(WH_KEYBOARD_LL, HookProc, m_hInstance, NULL);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
UnhookWindowsHookEx(hHook);
}
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}
bool CNeurocom::BuildHWnd()
{
int a = 0;
m_hWnd = CreateWindow( _T("Neurocom"), _T("Neurocom"), WS_MINIMIZE, 0, 0, 100, 50,
NULL, NULL, m_hInstance, m_hIcon );
if(m_hWnd){
ZeroMemory(&TrayIcon, sizeof(NOTIFYICONDATA));
TrayIcon.cbSize = sizeof(NOTIFYICONDATA);
TrayIcon.hWnd = m_hWnd;
TrayIcon.uID = 0;
TrayIcon.hIcon = m_hIcon;
TrayIcon.uCallbackMessage = MY_WM_NOTIFYICON;
TrayIcon.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
char* name = "Neurocom Network";
char c;
for(int i = 0; i < 16; i++){
c = name[i];
TrayIcon.szTip[i] = c;
}
Shell_NotifyIcon(NIM_ADD,&TrayIcon);
return true;
}else{
DWORD error = GetLastError();
return false;
}
} |
Partager