0

I'm having an issue with WinAPI Edit controls in a child window - they don't respond to mouse clicks, but work fine when placed in the main window. Other controls like buttons work normally in both windows.

I have a main window with a ListView and buttons, and a child window that contains an Edit control and a Button.

This is how the application looks

The Edit control in the child window:

  1. Doesn't get focus when clicked
  2. Doesn't show text cursor when clicked
  3. Doesn't allow text selection with mouse
  4. However: The Edit control works perfectly if I place it in the main window instead of the child window
  5. The Button in the child window works fine and responds to clicks
  6. Calling SetFocus() on the Edit control works

Here's the code: Pastebin

Main Window Creation

Window::Window(int WIDTH, int HEIGHT) {
 // ... window class registration
 hwnd = CreateWindowEx(/* ... main window params */);
 
 // Edit control in main window (THIS WORKS FINE)
 // But I need it in the child window
}

Child Window Creation

ChildWindow::ChildWindow(HWND parentHwnd) {
 // ... child window class registration
 hwnd = CreateWindowExW(
 0,
 CHILD_CLASS_NAME,
 L"Child Window",
 WS_CAPTION | WS_SYSMENU | WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
 LV_WIDTH, 0, windowWidth, windowHeight,
 parentHwnd, // parent is main window
 NULL, hInstance, NULL
 );
 // Problematic Edit control in child window
 passEditHwnd = CreateWindowW(
 L"EDIT", L"",
 WS_BORDER | WS_VISIBLE | WS_CHILD | WS_TABSTOP | ES_AUTOHSCROLL,
 (windowWidth / 2) - (buttonWidth / 2),
 (windowHeight / 4) * 3,
 buttonWidth, buttonHeight,
 hwnd, // parent is child window
 (HMENU)CHILD_EDIT_ID, hInstance, NULL
 );
 // This button in the same child window works fine
 testHwnd = CreateWindowW(
 L"BUTTON", L"test",
 WS_BORDER | WS_TABSTOP | WS_VISIBLE | WS_CHILD,
 // ... same parameters
 hwnd, (HMENU)CHILD_TEST_BTN_ID, hInstance, NULL
 );
}

Message Processing

bool Window::ProcessMessages() {
 MSG msg = {};
 while (PeekMessageW(&msg, nullptr, 0, 0, PM_REMOVE) > 0) {
 if (msg.message == WM_QUIT || msg.message == WM_DESTROY) {
 return false;
 }
 TranslateMessage(&msg); // This is present
 DispatchMessage(&msg);
 }
 return true;
}

What I've Tried

  1. Different Edit control styles: WS_TABSTOP, ES_AUTOHSCROLL, ES_CLIENTEDGE
  2. Explicit focus setting: SetFocus(passEditHwnd) works when called from button click
  3. EnableWindow(): Tried enabling/disabling - no effect
  4. TranslateMessage(): Already present in message loop
  5. Window z-order: Tried BringWindowToTop(), SetWindowPos(), doesn't work
  6. Different parent relationships: Same issue

Thank you for help!

asked 2 days ago
New contributor
kanashiii is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
5
  • 2
    I hope I'm understanding correctly. I believe your Edit control isn’t responding to mouse clicks because the child window can’t receive activation. It’s created with top-level styles (WS_CAPTION, WS_SYSMENU) that block focus when combined with WS_CHILD. You should try to: remove WS_CAPTION and WS_SYSMENU from the child window style. Add WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN (and WS_BORDER if you want a frame). Handle WM_MOUSEACTIVATE in the child window procedure. (Optional) Add WS_EX_CONTROLPARENT in CreateWindowEx to enable Tab navigation. Commented 2 days ago
  • Have you compared the sequence of messages that arrive after a physical click between working and non-working? Either use Spy++ or add logging in your message loop. Commented 2 days ago
  • 1
    @ninadepina removing WS_CAPTION did help, thank you so much, this problem was so much pain. Post this as an answer so i can accept it. Commented 2 days ago
  • @BenVoigt no, didn't really think of that, ill try that if a similar problem appears, thanks for help. Commented 2 days ago
  • Why was @ninadepina's answer deleted? Does someone think it was auto-generated? Would someone flag this for moderator attention please? Commented yesterday

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.