Edit: Nevermind! the code below doesn't work but when I copy and paste it from the website, it works fine.
I tried what this website told me but it didn't work. Anywhay, probably doing something pretty nooby.
int editid = 5654;
HWND edit;
//int WINAPI wWinMain
WNDCLASS wc;
wc.lpfnWndProc = WindowProc;
wc.lpszClassName = L"class name";
HWND hwnd = CreateWindowEx(
0,
L"Class name",
L"Copy N Paste",
WS_OVERLAPPEDWINDOW | WS_THICKFRAME | WS_VISIBLE,
CW_USEDEFAULT, 10,
885, 484,
NULL,
NULL,
hInstance,
NULL
);
edit = CreateWindowEx(
0,
L"EDIT",
NULL,
WS_CHILD | WS_VISIBLE | ES_LEFT,
20, 12,
480, 22,
hwnd,
(HMENU)editid,
hInstance,
NULL
);
// LRESULT CALLBACK WindowProc
switch(uMsg) {
case WM_COMMAND:
if(HIWORD(wParam) == EN_CHANGE && LOWORD(wParam)==editid) { // this is
//supposed to detect a change event in the edit 开发者_运维知识库control
MessageBox(0, L"Doesnt Work!", L"failure", 0);
}
}
You can handle WM_COMMAND, check the lparam for the HWND of your control and see if the HIWORD of your wparam isn't a focus command.
case WM_COMMAND:
if((HWND)lparam == hwndmycontrol) {
if(HIWORD(wparam) != EN_SETFOCUS && HIWORD(wparam) != EN_KILLFOCUS) {
//triggered on keypress
}
}
edit: Make sure you check if wparam is IDOK (which means the user hit enter).
The notification is sent to the parent of the edit. You are probably listening to the notification in the edit control's window proc.
精彩评论