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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
#include <windows.h>
#include <strsafe.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int nWinMode)
{
const TCHAR szWinName[] = TEXT("WIN0204");
WNDCLASSEX wc;
UINT OrgDblClkTime; // holds original double-click interval
wc.cbSize = sizeof(WNDCLASSEX);
wc.hInstance = hInstance;
wc.lpszClassName = szWinName;
wc.lpfnWndProc = WndProc;
// enable double-clicks
wc.style = CS_DBLCLKS;
wc.hIcon = (HICON) LoadImage(NULL, IDI_APPLICATION, IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
wc.hIconSm = (HICON) LoadImage(NULL, IDI_APPLICATION, IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
wc.hCursor = (HCURSOR) LoadImage(NULL, IDC_ARROW, IMAGE_CURSOR, 0, 0, LR_SHARED);
wc.lpszMenuName = NULL;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
if (RegisterClassEx(&wc) == 0)
{
MessageBox(NULL, TEXT("Couldn't Register the Window Class!"), TEXT("ERROR"), MB_OK | MB_ICONERROR);
return E_FAIL;
}
const TCHAR szAppTitle[] = TEXT("Processing Double-Click Messages");
HWND hwnd = CreateWindow(szWinName, szAppTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);
if (hwnd == NULL)
{
MessageBox(NULL, TEXT("Couldn't Create the Main Window!"), TEXT("ERROR"), MB_OK | MB_ICONERROR);
return E_FAIL;
}
// save the original double-click time
OrgDblClkTime = GetDoubleClickTime();
ShowWindow(hwnd, nWinMode);
UpdateWindow(hwnd);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
// restore original double-click interval
SetDoubleClickTime(OrgDblClkTime);
return (int) msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
const size_t strSize = 255;
static TCHAR str[strSize] = TEXT("");
static size_t strLen = 0;
HDC hdc;
UINT interval;
switch(message)
{
case WM_CHAR:
// does the user want to increase the interval? (Slower)
if (toupper((TCHAR) wParam) == TEXT('S'))
{
// increase the interval
interval = GetDoubleClickTime();
interval += 100;
SetDoubleClickTime(interval);
}
// does the user want to decrease the interval? (Faster)
else if (toupper((TCHAR) wParam) == TEXT('F'))
{
// decrease the interval
interval = GetDoubleClickTime();
interval -= 100;
if (interval < 0)
{
interval = 0;
}
SetDoubleClickTime(interval);
}
else
{
// leave the interval the same
interval = GetDoubleClickTime();
}
hdc = GetDC(hwnd);
StringCchPrintf(str, strSize, TEXT("Interval is %u milliseconds. "), interval);
StringCchLength(str, (int) strSize, &strLen);
TextOut(hdc, 4, 1, str, (int) strLen);
ReleaseDC(hwnd, hdc);
return S_OK;
case WM_LBUTTONDOWN:
hdc = GetDC(hwnd);
StringCchPrintf(str, strSize, TEXT("Left button is down at %d x %d"), LOWORD(lParam), HIWORD(lParam));
StringCchLength(str, (int) strSize, &strLen);
TextOut(hdc, LOWORD(lParam), HIWORD(lParam), str, (int) strLen);
ReleaseDC(hwnd, hdc);
return S_OK;
case WM_RBUTTONDOWN:
hdc = GetDC(hwnd);
StringCchPrintf(str, strSize, TEXT("Right button is down at %d x %d"), LOWORD(lParam), HIWORD(lParam));
StringCchLength(str, (int) strSize, &strLen);
TextOut(hdc, LOWORD(lParam), HIWORD(lParam), str, (int) strLen);
ReleaseDC(hwnd, hdc);
return S_OK;
case WM_LBUTTONDBLCLK:
interval = GetDoubleClickTime();
hdc = GetDC(hwnd);
StringCchPrintf(str, strSize, TEXT("Left Button Double-Click is %u milliseconds. "), interval);
StringCchLength(str, (int) strSize, &strLen);
TextOut(hdc, LOWORD(lParam), HIWORD(lParam), str, (int) strLen);
ReleaseDC(hwnd, hdc);
return S_OK;
case WM_RBUTTONDBLCLK:
interval = GetDoubleClickTime();
hdc = GetDC(hwnd);
StringCchPrintf(str, strSize, TEXT("Right Button Double-Click is %u milliseconds. "), interval);
StringCchLength(str, (int) strSize, &strLen);
TextOut(hdc, LOWORD(lParam), HIWORD(lParam), str, (int) strLen);
ReleaseDC(hwnd, hdc);
return S_OK;
case WM_DESTROY:
PostQuitMessage(0);
return S_OK;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
| |