简体   繁体   English

winapi:删除装饰

[英]winapi: removing decoration

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. 使用ShowWindow(Handle, SW_HIDE)隐藏窗口也不起作用。 I've made my own Window class with many functions so I don't wanna paste my whole code here. 我已经创建了自己的具有许多功能的Window类,所以我不想在这里粘贴整个代码。

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. 如您所见, WindowProps包含有关正在创建的窗口的各种信息。 I also have a HWND pointer variable in my class which points to the window handler. 我的类中还有一个HWND指针变量,它指向窗口处理程序。

Here are some things I've tried on my main, where sw2 is a pointer to my window class: 这是我在主设备上尝试过的一些东西,其中sw2是指向我的窗口类的指针:

    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). 我知道这些功能可以正常工作,因为我已经在一个更简单的窗口项目(Microsoft的示例项目)中对其进行了测试。

As Jonathan Potter already pointed out in his comment, your mistake is: 正如乔纳森·波特(Jonathan Potter)在评论中指出的那样,您的错误是:

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. 其中HWND hWnd仅在当前方法的范围内有效。 I guess that you defined aHwnd in your class as something like: 我猜您在类中将aHwnd定义为:

HWND *aHwnd; 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. 您似乎将HANDLE(HWND别无其他)误认为是一种实例/对象本身。 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. 注意,由于HWND是一种标准的窗口句柄,因此我明确地写了有关句柄的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM