#define WINVER 0x0500
#define _WIN32_IE 0x0500
#define _WIN32_WINNT 0x0500
#include <windows.h>
#include <string.h>
#include <stdlib.h>
//---
#define WINDOW_WIDTH 150
#define WINDOW_HEIGHT 100
//---
#define TRAY_MESSAGE (WM_APP + 123)
#define IDC_BUTTON1 1001
#define IDC_STATIC 1002
#define IDC_BUTTON2 1003
#define IDM_TIMER 1004
//---
#define IDC_STATIC_1 1200
#define IDC_STATIC_2 1201
#define IDC_TIMER_1 1202
HHOOK KeyboardHook;
HINSTANCE InstanceHandle;
int Trans;
HBRUSH TextBrush;
POINT MyPos;
void Minimize(HWND hwndDlg);
void UnMinimize(HWND hwndDlg);
void SetBaloonTip(HWND hwndDlg);
HICON HIcon;
LRESULT LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if(nCode == HC_ACTION)
{
KBDLLHOOKSTRUCT *HookStruct = (KBDLLHOOKSTRUCT *)lParam;
if(HookStruct->vkCode == VK_LWIN || HookStruct->vkCode == VK_RWIN)
{
return TRUE;
}
}
return CallNextHookEx(KeyboardHook, nCode, wParam, lParam);
}
LRESULT CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CREATE:
{
CreateWindow("BUTTON",
"Activate!",
WS_CHILD | WS_VISIBLE,
5, 22, 160, 34,
hwndDlg,
(HMENU)(IDC_BUTTON1),
InstanceHandle,
0);
CreateWindow("STATIC",
"Version 1.0",
WS_CHILD | WS_VISIBLE,
45, 5, 75, 16,
hwndDlg,
(HMENU)(IDC_STATIC),
InstanceHandle,
0);
CreateWindow("BUTTON",
"Close",
WS_CHILD | WS_VISIBLE,
87, 58, 78, 16,
hwndDlg,
(HMENU)(IDC_BUTTON2),
InstanceHandle,
0);
CreateWindow("STATIC",
"Some multi line\\r\\nText",
WS_CHILD | WS_VISIBLE | SS_CENTER,
5, 5, WINDOW_WIDTH - 10, 45,
hwndDlg,
(HMENU)(IDC_STATIC_1),
InstanceHandle,
0);
CreateWindow("STATIC",
"Text in red",
WS_CHILD | WS_VISIBLE | SS_CENTER,
5, 50, WINDOW_WIDTH - 10, 45,
hwndDlg,
(HMENU)(IDC_STATIC_2),
InstanceHandle,
0);
SetWindowPos(hwndDlg, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_ASYNCWINDOWPOS);
LONG OldState;
LONG NewState;
OldState = GetWindowLong(hwndDlg, GWL_STYLE);
NewState = OldState & ~WS_CAPTION;
SetWindowLong(hwndDlg, GWL_STYLE, NewState);
OldState = GetWindowLong(hwndDlg, GWL_EXSTYLE);
NewState = OldState | WS_EX_LAYERED | WS_EX_TRANSPARENT | WS_EX_TOOLWINDOW;
SetWindowLong(hwndDlg, GWL_EXSTYLE, NewState);
SetLayeredWindowAttributes(hwndDlg, 0, 0, LWA_ALPHA);
SetTimer(hwndDlg, IDC_TIMER_1, 100, 0);
TextBrush = CreateSolidBrush(RGB(255, 255, 255));
break;
}
case TRAY_MESSAGE:
if(lParam == WM_LBUTTONDOWN)
{
UnMinimize(hwndDlg);
}
break;
case WM_CTLCOLORSTATIC:
{
HDC dc = (HDC )wParam;
SetBkMode(dc, TRANSPARENT);
int Id = GetDlgCtrlID((HWND )lParam);
if(Id == IDC_STATIC_1)
SetTextColor(dc, RGB(0, 0, 0));
else
SetTextColor(dc, RGB(255, 0, 0));
return (LRESULT )TextBrush;
}
case WM_TIMER:
{
Trans += 4;
if(Trans >= 0x200)
PostQuitMessage(0);
else if(Trans < 0x100)
SetLayeredWindowAttributes(hwndDlg, 0, Trans, LWA_ALPHA);
else
SetLayeredWindowAttributes(hwndDlg, 0, 255 - (Trans - 0x100), LWA_ALPHA);
break;
case WM_COMMAND:
if(HIWORD(wParam) == BN_CLICKED &&
LOWORD(wParam) == IDC_BUTTON1)
{
Minimize(hwndDlg);
}
break;
}
}
return DefWindowProc(hwndDlg, msg, wParam, lParam);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, INT)
{
InstanceHandle = hInstance;
HBRUSH BackBrush = CreateSolidBrush(RGB(0xA0, 0xA0, 0xFF));
WNDCLASS wc;
HIcon = LoadIcon(0, IDI_WINLOGO);
HIcon = (HICON )LoadImage(0, "KeyIcon.ico", IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE);
memset(&wc, 0, sizeof(WNDCLASS));
wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
wc.lpfnWndProc = DialogProc;
wc.hInstance = InstanceHandle;
wc.hbrBackground = BackBrush;
wc.hbrBackground = (HBRUSH )(COLOR_BTNFACE + 1);
wc.lpszClassName = "WhateverClass";
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
if(!RegisterClass(&wc))
return FALSE;
int Width = GetSystemMetrics(SM_CXFULLSCREEN);
int Height = GetSystemMetrics(SM_CYFULLSCREEN);
HWND WindowHandle = CreateWindow("WhateverClass",
"Windows KeyKiller", // Caption text
WS_VISIBLE | WS_CLIPSIBLINGS |
WS_CLIPCHILDREN | WS_CAPTION |
WS_BORDER | WS_SYSMENU,
450, 300, 175, 124, // Position
0,
0,
InstanceHandle,
0);
MSG Msg;
while(GetMessage(&Msg, WindowHandle, 0, 0xFFFF) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return 0;
}
void InstallHook(void)
{
if(KeyboardHook)
return;
KeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, (HOOKPROC )LowLevelKeyboardProc, GetModuleHandle(0), 0);
if(!KeyboardHook)
{
}
}
void UnInstallHook(void)
{
if(KeyboardHook)
UnhookWindowsHookEx(KeyboardHook);
KeyboardHook = 0;
}
void Minimize(HWND hwndDlg)
{
NOTIFYICONDATA NotifyIconData;
ShowWindow(hwndDlg, SW_HIDE);
memset(&NotifyIconData, 0, sizeof(NotifyIconData));
NotifyIconData.cbSize = sizeof(NotifyIconData);
NotifyIconData.uID = 123;
NotifyIconData.hWnd = hwndDlg;
NotifyIconData.hIcon = HIcon;
NotifyIconData.uFlags = NIF_ICON | NIF_MESSAGE;
NotifyIconData.uCallbackMessage = WM_APP + 123;
strcpy(NotifyIconData.szTip, "TrayTip");
Shell_NotifyIcon(NIM_ADD, &NotifyIconData);
SetTimer(hwndDlg, IDM_TIMER, 2000, 0);
InstallHook();
}
void UnMinimize(HWND hwndDlg)
{
NOTIFYICONDATA NotifyIconData;
ShowWindow(hwndDlg, SW_SHOW);
memset(&NotifyIconData, 0, sizeof(NotifyIconData));
NotifyIconData.cbSize = sizeof(NotifyIconData);
NotifyIconData.uID = 123;
NotifyIconData.hWnd = hwndDlg;
NotifyIconData.hIcon = HIcon;
NotifyIconData.uFlags = NIF_ICON | NIF_MESSAGE;
NotifyIconData.uCallbackMessage = TRAY_MESSAGE;
strcpy(NotifyIconData.szTip, "TrayTip");
Shell_NotifyIcon(NIM_DELETE, &NotifyIconData);
UnInstallHook();
}
void SetBaloonTip(HWND hwndDlg)
{
NOTIFYICONDATA NotifyIconData;
memset(&NotifyIconData, 0, sizeof(NOTIFYICONDATA));
NotifyIconData.cbSize = sizeof(NOTIFYICONDATA);
NotifyIconData.uID = 123;
NotifyIconData.hWnd = hwndDlg;
NotifyIconData.hIcon = HIcon;
NotifyIconData.uFlags = 0x10;
NotifyIconData.uTimeout = 15000;
NotifyIconData.uCallbackMessage = TRAY_MESSAGE;
strcpy(NotifyIconData.szInfoTitle, "KeyKiller");
strcpy(NotifyIconData.szInfo, "Your windows keys shouldn't work!");
strcpy(NotifyIconData.szTip, "TrayTip");
Shell_NotifyIcon(NIM_MODIFY, (NOTIFYICONDATA *)&NotifyIconData);
}
Jeg ved ikke hvorfor, den sidder sammen, men jeg skal have den til at skrive 'Activated' når man trykker på knappen 'Activate' i en fade box.
Jeg håber i kan hjælpe mig.