Zdravím, snažím se zachytit klávesu enter, když má editbox focus. Strýček google napovídá subclassing, se kterým nemám žádné zkušenosti, takže vůbec netuším, jak by to mohlo fungovat. Snad mi někdo z vás poradí ;-)
Předem díky :)
Tady je můj kód:
#include <windows.h>
#include <winuser.h>
HDC hdc;
HWND edit;
HWND edit2;
#define ID_TEXTBOX 105
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow);
LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_DESTROY:
{
PostQuitMessage(0);
}
break;
case WM_CLOSE:
{
DestroyWindow(hwnd);
}
break;
case WM_CREATE:
{
edit = CreateWindow(
TEXT("EDIT"),
TEXT(""),
WS_VISIBLE | WS_CHILD | WS_BORDER,
5, 5,
200, 20,
hwnd,
(HMENU)ID_TEXTBOX,
NULL,
NULL,
);
edit2 = CreateWindow(
TEXT("EDIT"),
TEXT(""),
WS_VISIBLE | WS_CHILD | WS_BORDER,
5, 30,
200, 20,
hwnd,
(HMENU)ID_TEXTBOX,
NULL,
NULL,
);
}
break;
case WM_LBUTTONDOWN:
{
SendMessage(hwnd, WM_NCLBUTTONDOWN, HTCAPTION, NULL);
SetFocus(hwnd);
}
break;
case WM_KEYDOWN:
{
if(GetKeyState(VK_RETURN))
{
char buffer[255];
SendMessage(edit, WM_GETTEXT, 255, LPARAM(buffer));
SendMessage(edit2, WM_SETTEXT, NULL, (LPARAM)buffer);
}
}
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
TCHAR CLASS_NAME[] = TEXT("Title");
WNDCLASSEX wc = {};
wc.cbSize = sizeof(wc);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = CLASS_NAME;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = NULL;
wc.hIconSm = NULL;
wc.hCursor = (HCURSOR)LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)CreateSolidBrush(RGB(255, 255, 255));
wc.lpszMenuName = NULL;
RegisterClassEx(&wc);
HWND hwnd = CreateWindowEx
(
NULL,
CLASS_NAME,
CLASS_NAME,
WS_OVERLAPPED | WS_SYSMENU,
640,
300,
640,
480,
NULL,
NULL,
hInstance,
NULL);
if(!hwnd)
{
return FALSE;
}
ShowWindow(hwnd, iCmdShow);
UpdateWindow(hwnd);
MSG msg;
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}