Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Confirm and Notify Window Position

Recommended Posts

It would be really nice to be able to set the Notify and Confirm window positions! Currently they pop up in the middle of the screen and I would like them to pop up in the middle of my application.

  • Thanks 1
Link to post
Share on other sites

I checked to make sure the messagebox was properly parented to the active window and it is. This is the default behavior of Win32, so I believe this should be how our API works.

I was curious to see if it was possible to change the position of dialogs and I found this:


I created this example but the call to SetWindowPos seems to have no effect on the messagebox position:

#include "UltraEngine.h"

using namespace UltraEngine;


// global hook procedure
HHOOK hhookCBTProc = 0;

LRESULT CALLBACK pfnCBTMsgBoxHook(int nCode, WPARAM wParam, LPARAM lParam)
    if (nCode == HCBT_CREATEWND)
        CREATESTRUCT* pcs = ((CBT_CREATEWND*)lParam)->lpcs;

        if ((pcs->style & WS_DLGFRAME) || (pcs->style & WS_POPUP))
            HWND hwnd = (HWND)wParam;

            // At this point you have the hwnd of the newly created 
            // message box that so you can position it at will

            RECT rect;
            GetWindowRect(hwnd, &rect);
            int w = rect.right - rect.left;
            int h = rect.bottom - rect.top;

            HWND phwnd = GetActiveWindow();
            if (phwnd)
                GetWindowRect(phwnd, &rect);
                int x = ((rect.right - rect.left) - w) / 2;
                int y = ((rect.bottom - rect.top) - h) / 2;

                //Neither of these seem to have any effect:
                //MoveWindow(hwnd, x, y, w, h, true);
                SetWindowPos(hwnd, NULL, x, y, 0, 0, SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER);
    return (CallNextHookEx(hhookCBTProc, nCode, wParam, lParam));

int main(int argc, const char* argv[])
    //Get the displays
    auto displays = GetDisplays();

    //Create a window
    auto window = CreateWindow("Ultra Engine", 0, 0, 800, 600, displays[0]);

    HWND hwnd = window->GetHandle();

    hhookCBTProc = SetWindowsHookEx(WH_CBT, pfnCBTMsgBoxHook, 0, GetCurrentThreadId());

    //Create User Interface
    auto ui = CreateInterface(window);
    while (true)
        const Event ev = WaitEvent();
        switch (ev.id)
            return 0;
    return 0;


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...