winapi: removing decoration

418 views Asked by At

This looks like a duplicate but hear me first. This is more on the debugging side. I'm trying to remove the borders of my window using the method here.

What are some things that will make these functions not work? Hiding windows using ShowWindow(Handle, SW_HIDE) doesn't work also. I've made my own Window class with many functions so I don't wanna paste my whole code here.

Here's my Initialization function for the window:

HRESULT SampleWindow::InitializeSimple(SampleWindow* win)
{
    HRESULT         hr;
    HWND            hWnd;
    SampleWindow*   sampleWin;

    sampleWin = new SampleWindow();

    aMWindowProps->Center();
    hWnd = CreateWindowEx(
        NULL,
        aMWindowProps->aWindowClass,
        aMWindowProps->aWindowTitle,
        WS_OVERLAPPEDWINDOW,
        aMWindowProps->aRealLeft,
        aMWindowProps->aRealTop,
        aMWindowProps->GetRelativePosWidth(),
        aMWindowProps->GetRelativePosHeight(),
        HWND_DESKTOP,
        NULL,
        *aMWindowProps->aHInstance,
        sampleWin);

    aMWindowProps->aHwnd = &hWnd;

    hr = hWnd ? S_OK : E_FAIL;

    win->aHwnd = &hWnd;
    //ShowWindow(hWnd, SW_SHOWNORMAL);

    return hr;
}

WindowProps as you can see contains various info about the window being created. I also have a HWND pointer variable in my class which points to the window handler.

Here are some things I've tried on my main, where sw2 is a pointer to my window class:

    ShowWindow(*sw2->aHwnd, SW_SHOW);
    //ShowWindow(*sw2->aHwnd, nCmdShow);
    LONG lStyle = GetWindowLong(*sw2->aHwnd, GWL_STYLE);
    lStyle &= WS_POPUP;
    //lStyle &= ~(WS_CAPTION | WS_THICKFRAME | WS_MINIMIZE | WS_MAXIMIZE | WS_SYSMENU);
    SetWindowLong(*sw2->aHwnd, GWL_STYLE, lStyle);
    //ShowWindow(*sw2->aHwnd, SW_MINIMIZE);
    //ShowWindow(*sw2->aHwnd, SW_HIDE);
    //ShowWindow(*sw2->aHwnd, SW_HIDE);
    //SetWindowLong(*sw2->aHwnd, GWL_STYLE, GetWindowLong(*sw2->aHwnd, GWL_STYLE) && ~ WS_BORDER && ~ WS_SIZEBOX && ~ WS_DLGFRAME);
    SetWindowPos(*sw2->aHwnd, HWND_TOP, sw2->aMWindowProps->aRealLeft, sw2->aMWindowProps->aRealTop, sw2->aMWindowProps->aRealWidth, sw2->aMWindowProps->aRealHeight, SWP_FRAMECHANGED);
    //LONG lExStyle = GetWindowLong(*sw2->aHwnd, GWL_EXSTYLE);
    //lExStyle &= ~(WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE);
    //SetWindowLong(*sw2->aHwnd, GWL_EXSTYLE, lExStyle);
    //SetWindowPos(*sw2->aHwnd, NULL, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER);

I'd just like some suggestions on where to debug my code. I know the functions work as I've tested it on a much simpler window project (sample project from Microsoft).

1

There are 1 answers

2
Martin Schlott On BEST ANSWER

As Jonathan Potter already pointed out in his comment, your mistake is:

aMWindowProps->aHwnd = &hWnd;

hr = hWnd ? S_OK : E_FAIL;

win->aHwnd = &hWnd;

where HWND hWnd is only valid in the scope of the current methode. I guess that you defined aHwnd in your class as something like:

HWND *aHwnd;

which is at least unnecessary. You seem to mistake a HANDLE (a HWND is nothing else) as a kind of instance/object itself. It isn't, it is more like a pointer or reference. You can always safely write:

HWND myAttribute=hWnd;

As long as you use it in the same process. (Window handles are even valid across process boundaries, but do not tell anyone about that).

I fact I know no situation where you keep a pointer to a handle instead of the handle itself.

Notice, I explicit wrote about handles, as HWND are a kind of standard window handles.