C ++无法停靠AppBar

时间:2018-07-20 15:09:17

标签: c++ winapi codeblocks dock appbar

我试图将AppBar停靠在桌面屏幕的右侧。因此,我只包括正确的代码。我不想移动AppBar或启用自动隐藏功能。下面是代码:

    #include <windows.h>
    #include <commctrl.h>
    #include "resource.h"
    #include <stdio.h>

    #define Tool_Width 300

    HINSTANCE hInst;
    RECT desktop;
    BOOL fBarRegistered;
    UINT uCallBack;

    void RegisterBar(HWND);
    void ABSetPos(HWND);

    BOOL CALLBACK DlgMain(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam){
        switch(uMsg){
            case WM_INITDIALOG:{
                SystemParametersInfo(SPI_GETWORKAREA,0, &desktop, 0);
                RegisterBar(hwndDlg);
            }
            return TRUE;

            case WM_CLOSE:{
                RegisterBar(hwndDlg);
                EndDialog(hwndDlg, 0);
            }
            return TRUE;

        }
        return FALSE;
    }

    int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd){
        hInst=hInstance;
        InitCommonControls();
        return DialogBox(hInst, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)DlgMain);
    }

    void RegisterBar(HWND hwndDlg){
        APPBARDATA abd;
        abd.cbSize = (DWORD) sizeof(APPBARDATA);
        abd.hWnd = hwndDlg;
        if (!fBarRegistered){
            uCallBack = RegisterWindowMessage("AppBarMessage");
            abd.uCallbackMessage = uCallBack;

            SHAppBarMessage((DWORD)ABM_NEW, &abd);
            fBarRegistered = true;

            ABSetPos(hwndDlg);
        }
        else{
            SHAppBarMessage((DWORD)ABM_REMOVE, &abd);
            fBarRegistered = false;
        }
    }

    void ABSetPos(HWND hwndDlg){
        APPBARDATA abd;
        abd.cbSize = (DWORD) sizeof(APPBARDATA);
        abd.hWnd = hwndDlg;
        abd.uEdge = (UINT)ABE_RIGHT;

        abd.rc.top = 0;
        abd.rc.bottom = desktop.bottom;
        abd.rc.right = desktop.right;
        abd.rc.left = abd.rc.right - Tool_Width;

        SHAppBarMessage((DWORD)ABM_QUERYPOS, &abd);
        abd.rc.left= abd.rc.right - Tool_Width;
        SHAppBarMessage((DWORD)ABM_SETPOS, &abd);

        MoveWindow(hwndDlg, abd.rc.left, abd.rc.top, abd.rc.right - abd.rc.left, abd.rc.bottom - abd.rc.top, false);
    }

运行此代码时,在右侧分配了空间,但是MoveWindow不会将窗口停靠在该空间中。如果我评论ABM_SETPOS,则MoveWindow会在右侧移动和调整大小对话框,但不会停靠。

我从此网站C# sample code引用了代码

0 个答案:

没有答案