Question

I have a parent window and a few child windows attached to this. With SpyXX I can see the children all have a certain style class, lets say ChildWindowClass.

When I create the window with the name of this particular class, CreateWindowEx returns a NULL handle. If I use my own class and just set the parent, the window is a child window, but - of course - has a different class as all the other children.

If I get me the style and then set it, the style is found, but not set for my child window. It still shows the style used with CreateWindowEx

HWND firstChild = FindWindowEx(MyClass::_parent, NULL, szFsxChildWindowClass, NULL);
LONG childStyle = GetWindowLong(firstChild, GWL_STYLE);
...
SetWindowLong(MyClass::_child,GWL_STYLE, childStyle);

The ChildWindowClass is not registered by me, so I can not crosscheck how it is registered. So how can I set this style for my child window?

-- Edit call as requested --

 child = CreateWindowEx( WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR,
        szWindowClass, // this is where I want to place the name of the child class
        _T("Test"),
        WS_CHILDWINDOW | WS_VISIBLE,
        x,y, // 0,0
        w, h, // 500,100
        MyClass::_parent, // parent
        NULL,
        MyClass::_hInstance, // must this be 0??
        NULL
        );
Was it helpful?

Solution

Check GetLastError. If it's nonzero, you're most probably misusing API. If it is 0, it means that window procedure explicitly failed the creation by returning FALSE from WM_NCCREATE or WM_CREATE.

When handling these messages the window procedure has access to all parameters that you pass to the function (styles, title, coordinates, parent window and menu), and that specific window class may require additional data to be passed via lpCreateParams, or even in title or coordinates, failing the creation otherwise.

Set breakpoint or hook WM_CREATE for windows of that class and examine how those existing child windows were created, what were the parameters. (Assuming you don't just have documentation on it!)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top