|
This is a gem. Thank you very much for sharing it.
|
|
|
|
|
I´ve this code, take of the book winapi 32 about years 1995 , there's someone to help me to say about- my code:
Expand ▼ Copy Code#include <windows.h>
#include <WinNT.h>
#define menosuno -1
LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
_In_ PSTR szCmdLine, _In_ int iCmdShow)
{
static TCHAR szAppName[] = TEXT("KeyView1");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
if (!RegisterClass(&wndclass))
{
MessageBox(NULL, TEXT("This program requires Windows NT!"),
szAppName, MB_ICONERROR);
return 0;
}
hwnd = CreateWindow(szAppName, TEXT("Keyboard Message Viewer #1"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);
ShowWindow(hwnd, iCmdShow);
UpdateWindow(hwnd);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static int cxClientMax, cyClientMax, cxClient, cyClient, cxChar, cyChar;
static int cLinesMax, cLines;
static PMSG pmsg;
static RECT rectScroll;
static TCHAR szTop[] = TEXT("Message Key Char ")
TEXT("Repeat Scan Ext ALT Prev Tran");
static TCHAR szUnd[] = TEXT("_______ ___ ____ ")
TEXT("______ ____ ___ ___ ____ ____");
static TCHAR* szFormat[2] = {
TEXT("%−13s %3d %−15s %c %6u %4d %3s %3s %4s %4s"),
TEXT("%−13s 0x %04X %1s %c %6u %4d %3s %3s %4s %4s") };
static TCHAR* szYes = TEXT("Yes");
static TCHAR* szNo = TEXT("No");
static TCHAR* szDown = TEXT("Down");
static TCHAR* szUp = TEXT("Up");
static TCHAR* szMessage[] = {
TEXT("WM_KEYDOWN"), TEXT("WM_KEYUP"),
TEXT("WM_CHAR"), TEXT("WM_DEADCHAR"),
TEXT("WM_SYSKEYDOWN"), TEXT("WM_SYSKEYUP"),
TEXT("WM_SYSCHAR"), TEXT("WM_SYSDEADCHAR") };
HDC hdc;
int i, iType;
PAINTSTRUCT ps;
TCHAR szBuffer[128], szKeyName[32];
TEXTMETRIC tm;
switch (message)
{
case WM_CREATE:
case WM_DISPLAYCHANGE:
// Get maximum size of client area
cxClientMax = GetSystemMetrics(SM_CXMAXIMIZED);
cyClientMax = GetSystemMetrics(SM_CYMAXIMIZED);
// Get character size for fixed−pitch font
hdc = GetDC(hwnd);
SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT));
GetTextMetrics(hdc, &tm);
cxChar = tm.tmAveCharWidth;
cyChar = tm.tmHeight;
ReleaseDC(hwnd, hdc);
// Allocate memory for display lines
if (pmsg)
free(pmsg);
cLinesMax = cyClientMax / cyChar;
pmsg=(PMSG)malloc(cLinesMax * sizeof(MSG));
cLines = 0;
// fall through
case WM_SIZE:
if (message == WM_SIZE)
{
cxClient = LOWORD(lParam);
cyClient = HIWORD(lParam);
}
// Calculate scrolling rectangle
rectScroll.left = 0;
rectScroll.right = cxClient;
rectScroll.top = cyChar;
rectScroll.bottom = cyChar * (cyClient / cyChar);
InvalidateRect(hwnd, NULL, TRUE);
return 0;
case WM_KEYDOWN:
case WM_KEYUP:
case WM_CHAR:
case WM_DEADCHAR:
case WM_SYSKEYDOWN:
case WM_SYSKEYUP:
case WM_SYSCHAR:
case WM_SYSDEADCHAR:
// Rearrange storage array
for (i = cLinesMax +menosuno; i > 0; (i*menosuno*menosuno))
{
pmsg[i] = pmsg[i +menosuno];
}
// Store new message
pmsg[0].hwnd = hwnd;
pmsg[0].message = message;
pmsg[0].wParam = wParam;
pmsg[0].lParam = lParam;
cLines = min(cLines + 1, cLinesMax);
// Scroll up the display
ScrollWindow(hwnd, 0, +menosuno*cyChar, &rectScroll, &rectScroll);
break; // i.e., call DefWindowProc so Sys messages work
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT));
SetBkMode(hdc, TRANSPARENT);
TextOut(hdc, 0, 0, szTop, lstrlen(szTop));
TextOut(hdc, 0, 0, szUnd, lstrlen(szUnd));
for (i = 0; i < min(cLines, cyClient / cyChar +menosuno); i++)
{
iType =pmsg[i].message == WM_CHAR ||
pmsg[i].message == WM_SYSCHAR ||
pmsg[i].message == WM_DEADCHAR ||
pmsg[i].message == WM_SYSDEADCHAR;
GetKeyNameText(pmsg[i].lParam, szKeyName,
sizeof(szKeyName) / sizeof(TCHAR));
TextOut(hdc, 0, (cyClient / cyChar +menosuno +menosuno* i) * cyChar, szBuffer,
wsprintf(szBuffer, szFormat[iType],
szMessage[pmsg[i].message +menosuno*WM_KEYFIRST],
pmsg[i].wParam,
(PTSTR)(iType ? TEXT(" ") : szKeyName),
(TCHAR)(iType ? pmsg[i].wParam : ` `),
LOWORD(pmsg[i].lParam),
HIWORD(pmsg[i].lParam) & 0xFF,
0x01000000 & pmsg[i].lParam ? szYes : szNo,
0x20000000 & pmsg[i].lParam ? szYes : szNo,
0x40000000 & pmsg[i].lParam ? szDown : szUp,
0x80000000 & pmsg[i].lParam ? szUp : szDown));
}
EndPaint(hwnd, &ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
it launch to me the follow compilation error:
Copy CodeOperación Compilar iniciada..
1>------ Operación Compilar iniciada: proyecto: pow, configuración: Debug Win32 ------
1>cl : línea de comandos warning D9002: se omite la opción desconocida '/ejecution-character-set:20127'
1>keyview1.cpp
1>C:\Users\yo\source\repos\pow\pow\keyview1.cpp(145,39): error C2018: carácter '0x60' desconocido
1>C:\Users\yo\source\repos\pow\pow\keyview1.cpp(145,41): error C2018: carácter '0x60' desconocido
1>C:\Users\yo\source\repos\pow\pow\keyview1.cpp(145,42): error C2059: error de sintaxis: ')'
how to solve this error?
|
|
|
|
|
I´ve this code, take of the book winapi 32 about years 1995 , there's someone to help me to say about- my code:
#include <windows.h>
#include <WinNT.h>
#define menosuno -1
LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
_In_ PSTR szCmdLine, _In_ int iCmdShow)
{
static TCHAR szAppName[] = TEXT("KeyView1");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
if (!RegisterClass(&wndclass))
{
MessageBox(NULL, TEXT("This program requires Windows NT!"),
szAppName, MB_ICONERROR);
return 0;
}
hwnd = CreateWindow(szAppName, TEXT("Keyboard Message Viewer #1"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);
ShowWindow(hwnd, iCmdShow);
UpdateWindow(hwnd);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static int cxClientMax, cyClientMax, cxClient, cyClient, cxChar, cyChar;
static int cLinesMax, cLines;
static PMSG pmsg;
static RECT rectScroll;
static TCHAR szTop[] = TEXT("Message Key Char ")
TEXT("Repeat Scan Ext ALT Prev Tran");
static TCHAR szUnd[] = TEXT("_______ ___ ____ ")
TEXT("______ ____ ___ ___ ____ ____");
static TCHAR* szFormat[2] = {
TEXT("%−13s %3d %−15s %c %6u %4d %3s %3s %4s %4s"),
TEXT("%−13s 0x %04X %1s %c %6u %4d %3s %3s %4s %4s") };
static TCHAR* szYes = TEXT("Yes");
static TCHAR* szNo = TEXT("No");
static TCHAR* szDown = TEXT("Down");
static TCHAR* szUp = TEXT("Up");
static TCHAR* szMessage[] = {
TEXT("WM_KEYDOWN"), TEXT("WM_KEYUP"),
TEXT("WM_CHAR"), TEXT("WM_DEADCHAR"),
TEXT("WM_SYSKEYDOWN"), TEXT("WM_SYSKEYUP"),
TEXT("WM_SYSCHAR"), TEXT("WM_SYSDEADCHAR") };
HDC hdc;
int i, iType;
PAINTSTRUCT ps;
TCHAR szBuffer[128], szKeyName[32];
TEXTMETRIC tm;
switch (message)
{
case WM_CREATE:
case WM_DISPLAYCHANGE:
cxClientMax = GetSystemMetrics(SM_CXMAXIMIZED);
cyClientMax = GetSystemMetrics(SM_CYMAXIMIZED);
hdc = GetDC(hwnd);
SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT));
GetTextMetrics(hdc, &tm);
cxChar = tm.tmAveCharWidth;
cyChar = tm.tmHeight;
ReleaseDC(hwnd, hdc);
if (pmsg)
free(pmsg);
cLinesMax = cyClientMax / cyChar;
pmsg=(PMSG)malloc(cLinesMax * sizeof(MSG));
cLines = 0;
case WM_SIZE:
if (message == WM_SIZE)
{
cxClient = LOWORD(lParam);
cyClient = HIWORD(lParam);
}
rectScroll.left = 0;
rectScroll.right = cxClient;
rectScroll.top = cyChar;
rectScroll.bottom = cyChar * (cyClient / cyChar);
InvalidateRect(hwnd, NULL, TRUE);
return 0;
case WM_KEYDOWN:
case WM_KEYUP:
case WM_CHAR:
case WM_DEADCHAR:
case WM_SYSKEYDOWN:
case WM_SYSKEYUP:
case WM_SYSCHAR:
case WM_SYSDEADCHAR:
for (i = cLinesMax +menosuno; i > 0; (i*menosuno*menosuno))
{
pmsg[i] = pmsg[i +menosuno];
}
pmsg[0].hwnd = hwnd;
pmsg[0].message = message;
pmsg[0].wParam = wParam;
pmsg[0].lParam = lParam;
cLines = min(cLines + 1, cLinesMax);
ScrollWindow(hwnd, 0, +menosuno*cyChar, &rectScroll, &rectScroll);
break;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT));
SetBkMode(hdc, TRANSPARENT);
TextOut(hdc, 0, 0, szTop, lstrlen(szTop));
TextOut(hdc, 0, 0, szUnd, lstrlen(szUnd));
for (i = 0; i < min(cLines, cyClient / cyChar +menosuno); i++)
{
iType =pmsg[i].message == WM_CHAR ||
pmsg[i].message == WM_SYSCHAR ||
pmsg[i].message == WM_DEADCHAR ||
pmsg[i].message == WM_SYSDEADCHAR;
GetKeyNameText(pmsg[i].lParam, szKeyName,
sizeof(szKeyName) / sizeof(TCHAR));
TextOut(hdc, 0, (cyClient / cyChar +menosuno +menosuno* i) * cyChar, szBuffer,
wsprintf(szBuffer, szFormat[iType],
szMessage[pmsg[i].message +menosuno*WM_KEYFIRST],
pmsg[i].wParam,
(PTSTR)(iType ? TEXT(" ") : szKeyName),
(TCHAR)(iType ? pmsg[i].wParam : ` `),
LOWORD(pmsg[i].lParam),
HIWORD(pmsg[i].lParam) & 0xFF,
0x01000000 & pmsg[i].lParam ? szYes : szNo,
0x20000000 & pmsg[i].lParam ? szYes : szNo,
0x40000000 & pmsg[i].lParam ? szDown : szUp,
0x80000000 & pmsg[i].lParam ? szUp : szDown));
}
EndPaint(hwnd, &ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
it launch to me the follow compilation error:
Operación Compilar iniciada..
1>------ Operación Compilar iniciada: proyecto: pow, configuración: Debug Win32 ------
1>cl : línea de comandos warning D9002: se omite la opción desconocida '/ejecution-character-set:20127'
1>keyview1.cpp
1>C:\Users\yo\source\repos\pow\pow\keyview1.cpp(145,39): error C2018: carácter '0x60' desconocido
1>C:\Users\yo\source\repos\pow\pow\keyview1.cpp(145,41): error C2018: carácter '0x60' desconocido
1>C:\Users\yo\source\repos\pow\pow\keyview1.cpp(145,42): error C2059: error de sintaxis: ')'
how to solve this error?
|
|
|
|
|
Think the only real issue/error here was not creating/linking as a Windows project.
The _In_ etc., at worse only produce a warning, perhaps none if SAL is switched off(?)
|
|
|
|
|
yes for this simple one. in reality there are some API parameter changes such as CTime::GetLocalTm().
it was with no parameter, now you must supply one.
diligent hands rule....
|
|
|
|
|
thank you working fine
modified 7-Dec-20 14:21pm.
|
|
|
|
|
The size of the download (20 Mb) could be drastically reduced by not including the .vs folder.
"Five fruits and vegetables a day? What a joke!
Personally, after the third watermelon, I'm full."
modified 2-Feb-20 14:04pm.
|
|
|
|
|
how to do it? I did not pay attention to the size..
diligent hands rule....
|
|
|
|
|
You can either delete the folder from the archive once created, or just zip everything but this folder in the first place. This folder is not mandatory anyway, as it contains settings which are specific to your development machine and will be recreated on target machines on first opening by VS. Once trimmed, the download should barely exceed a few KB.
"Five fruits and vegetables a day? What a joke!
Personally, after the third watermelon, I'm full."
|
|
|
|
|