Member Avatar for Thew

Hello, can you help me with this problem:
I'm extending the TListView to enable notifying me about the column resize. I've found the code written in Delphi, but I needed to use it in C++, so I decided to rewrite this code to C++. But first problem occurs when I overload this function:
virtual void __fastcall CreateWnd(void);
In Delphi, this code was required to enable functionality of column resize notification:

procedure TListViewEx.CreateWnd;
var
  wnd: HWND;
begin
  inherited;
  wnd := GetWindow(handle, GW_CHILD);
  SetWindowLong(wnd, GWL_STYLE, GetWindowLong(wnd, GWL_STYLE) and not HDS_FULLDRAG);
end;

I have rewritten Delphi code to this:

virtual void __fastcall CreateWnd(void)
{
    TListView::CreateWnd();
    HWND wnd = GetWindow(Handle, GW_CHILD);
    SetWindowLongA(wnd, GWL_STYLE, GetWindowLong(wnd, GWL_STYLE) & !HDS_FULLDRAG);
}

The problem comes with calling to this function. GetWindow(Handle, GW_CHILD) returns NULL. Why?

From msdn [link]

The retrieved handle identifies the child window at the top of the Z order, if the specified window is a parent window; otherwise, the retrieved handle is NULL. The function examines only child windows of the specified window. It does not examine descendant windows.

If the function succeeds, the return value is a window handle. If no window exists with the specified relationship to the specified window, the return value is NULL. To get extended error information, call GetLastError.

Try to find out more about the problem using the GetLastError function.

Hope this helps.

Member Avatar for Thew

Try to find out more about the problem using the GetLastError function.

Hope this helps.

I have already tried it. GetLastError returns 0, and I don't understand if the same example works in Delphi, why it doesn't work in C++, I know I'm missing something or I did some mistake...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.