2

I'm trying to create an edit box inside my Win-32 application, but am having a bit of trouble. It will only show up under the circumstances that my mouse is moving, clicking and dragging at the same time, and it wil be flickering in and out of visibility

I create my initial window like this:

m_hWnd = CreateWindow(m_wWindowName.c_str(), m_wWindowName.c_str(), 
        WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, width, height, 0, 0, m_hInstance, this); 

And then I try to create a new Edit box inside the existing window afterwards:

CreateWindowEx(WS_EX_CLIENTEDGE, 
        TEXT("Edit"), TEXT(""),
        WS_CHILD | WS_VISIBLE,
        10, 80,
        200, 20,
        m_hWnd, (HMENU)1, NULL, NULL);

EDIT: I am creating my initial window in its own class, by doing the following

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance,
                   PSTR cmdLine, int showCmd)
{
    CApplication Application;
    Application.Initialise(hInstance, MainWndProc, L"GUI Tool");

    return Application.Run();
}

The initialise function creates the window, and then directly after (still in the initialise function) I am attempting to create the edit box.

Could someone give some help as to why this is happening?

Thanks

Matt
  • 175
  • 2
  • 12
  • 1
    Can you provide a minimal complete example that reproduces this issue? – andlabs Dec 16 '14 at 02:00
  • This makes me think you are creating the windows in the wrong place of your code. – Remy Lebeau Dec 16 '14 at 02:16
  • I can edit the post to give a sense of how my code ties together. – Matt Dec 16 '14 at 02:23
  • Also, I have been using my framework for two years and not had an issue. It's done tons of 2D and 3D projects - I've just never done edit boxes without a dialog resource – Matt Dec 16 '14 at 02:29
  • 1
    Try setting the `WS_CLIPCHILDREN` style on your parent window. – Jonathan Potter Dec 16 '14 at 02:32
  • Thanks Jonathan that was all that was necessary to fix the problem :) If you mark it as an answer I can vote it as correct. Also to whoever down voted... Why? I provided all information I thought was necessary to answer the question, and showed I had attempted it first. As we can see by the answer, it was all that was needed. And even given that, I was in the process of recreating the issue in a minimalistic project as per the first comment request. Anyway, thanks again Jonathan – Matt Dec 16 '14 at 02:37

1 Answers1

3

It sounds like you're painting over the top of the control in your WM_PAINT handler (or this is being done by DefWindowProc).

The easiest solution is to set the WS_CLIPCHILDREN style on the parent window, which will automatically clip out any child windows when painting.

Jonathan Potter
  • 36,172
  • 4
  • 64
  • 79