Jump to content

Confirm and Notify Window Position


CodeChomper
 Share

Recommended Posts

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:

https://stackoverflow.com/questions/1530561/set-location-of-messagebox

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

#include "UltraEngine.h"

using namespace UltraEngine;

//https://stackoverflow.com/questions/1530561/set-location-of-messagebox

// 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());
    Notify("test");
    UnhookWindowsHookEx(hhookCBTProc);

    //Create User Interface
    auto ui = CreateInterface(window);
    
    while (true)
    {
        const Event ev = WaitEvent();
        switch (ev.id)
        {
        case EVENT_WINDOWCLOSE:
            return 0;
            break;
        }
    }
    return 0;
}

 

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
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.

Guest
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.

 Share

×
×
  • Create New...