use WM_LBUTTONDOWN case in textbox

I want to use WM_LBUTTONDOWN case in WndProc function. This works when click on window area but dont work click in textbox. How do work when I click in textbox?
Thank you
I suspect that there are two windows in your implementation, one generic window and one dialog window.
The textbox is in dialog window and thus you cannot access the window message of the textbox through WndProc function. You should add the implementation for textbox processing in the "WndProc" function (it should have another name) of the dialog window.

If I understand wrong, please clarify your issue.

As a tip, you could set breakpoint to understand what is the code flow when the target event happens.
Thank you for your answer. In the following example, I want to throw a messagebox when I click or press the text box.


#include < Windows.h >

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int nCmdShow)
{
TCHAR appname[] = TEXT("Mouse/Key Events");
MSG msg;

WNDCLASS wndclass;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hInstance = hInstance;
wndclass.lpfnWndProc = WndProc;
wndclass.lpszClassName = appname;
wndclass.lpszMenuName = NULL;
wndclass.style = CS_HREDRAW | CS_VREDRAW;

if (!RegisterClass(&wndclass))
{
MessageBox(NULL, TEXT("Class not registered"), TEXT("Error...."), MB_OK);
}

HWND hwnd = CreateWindow(appname,appname,WS_OVERLAPPEDWINDOW, 100, 100, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
HWND Lbl1 = CreateWindowW(TEXT("static"), TEXT("Key press or left click in textbox"), WS_VISIBLE | WS_CHILD | WS_TABSTOP, 10, 70, 300, 20, hwnd, (HMENU)2, NULL, NULL);
HWND textBox1 = CreateWindowW(TEXT("edit"), TEXT(""), WS_VISIBLE | WS_CHILD | WS_BORDER, 300, 70, 100, 20, hwnd, NULL, hInstance, NULL);

ShowWindow(hwnd, nCmdShow);

while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}


LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_LBUTTONDOWN:
MessageBox(NULL, TEXT("Mouse Button Down"), TEXT("Mouse Button Down"), MB_OK);
break;
case WM_KEYDOWN:
MessageBox(NULL, TEXT("Key Down"), TEXT("Key Down"), MB_OK);
break;
case WM_DESTROY:
PostQuitMessage(EXIT_SUCCESS);
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}

Topic archived. No new replies allowed.