[Win32, C++] Popup window position!

Started by
6 comments, last by LessBread 13 years, 8 months ago
Hi,
I recently stumbled over a problem that is bogging me from time to time:


The black rectangle will be a button later, it's just a placeholder for now.
The problem is the new window I create for showing the options the button provides. I just don't know how to position it under my "button"! Currently it lays over the left half of my "button". It is supposed to be right under it.

Right now I use this code:
void SF_PopupControl::RepositionWindow(){	D3DXVECTOR2 AbsPos;	GetAbsolutePosition(&AbsPos);	RECT r;	GetWindowRect(D2DObjects->RenderTarget->GetHwnd(),&r);	SetWindowPos(Popup.GetHWND(),HWND_TOP,AbsPos.x+r.left,AbsPos.y+r.top+ItemSize.y,0,0,SWP_NOSIZE);}


But since GetWindowRect includes the window's frame, this can't work and produces the output I've shown above.


Making the popup a child won't work either, because then it starts to fight with Direct2D.
Advertisement
well HWND_TOP sends the window to the top, you might wanna change that, or send the button to the top afterwards.
or if your z-order is correct at startup, just add SWP_NOZORDER to the flags.
Quote:
well HWND_TOP sends the window to the top, you might wanna change that, or send the button to the top afterwards.
or if your z-order is correct at startup, just add SWP_NOZORDER to the flags.


The Button is drawn using Direct2D with my own GUI-System. The only "real" window is the window of the Popup.

However! This is not my problem. My problem is, that I can't position the popup's window right.

(The window must go over the bounds of the other windows, so making it a child won't work either)
If GetWindowRect doesn't work for you, have you tried GetClientRect?

Which window is D2DObjects->RenderTarget->GetHwnd()?

Have you confirmed that all units in the addition are the same units?

AbsPos.x+r.left, AbsPos.y+r.top+ItemSize.y, 0,0

Have you considered using a popup menu instead?

For example:

    case WM_CONTEXTMENU:        {            HMENU hmenu = LoadMenu(GetModuleHandle(NULL), "context");            HMENU hsub  = GetSubMenu(hmenu, 0);            SetForegroundWindow(hwnd);            TrackPopupMenuEx(hsub,                    TPM_LEFTALIGN | TPM_TOPALIGN | TPM_LEFTBUTTON,                    LOWORD(lparam), HIWORD(lparam), hwnd, NULL);            DestroyMenu(hsub);            DestroyMenu(hmenu);        }        return 0;
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
Quote:
If GetWindowRect doesn't work for you, have you tried GetClientRect?


GetClientRect() will not work for me as I don't need the client coordinates of the owning window.
The Popup window is it's own window, without any parent. Because of this I need something that gives me the client rect, but aligned to the left upper corner of the desktop.
GetWindowRect() gives a rectangle of the whole window, including title bar.

Quote:
Which window is D2DObjects->RenderTarget->GetHwnd()?


The one in the background with the black button.

Quote:
Have you confirmed that all units in the addition are the same units?


As I said above, I isolated the problem already. It's the fact that GetWindowRect() gives me everything, including title bar and stuff.

Quote:
Have you considered using a popup menu instead?


I would like to handle and draw this myself [smile]
It's just GetWindowRect() that needs to be replaced....
Sounds like you need to use GetClientRect and then ClientToScreen. Then you have the full screen coordinates of the client area (e.g. without borders and caption).

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

mind in a box told me: It works! Thank you :)

(he can not load the gamedev page at the moment :( )
Quote:Original post by mind in a box
Quote:
Have you considered using a popup menu instead?

I would like to handle and draw this myself [smile]


OK. Glad to hear that you've got it worked out.

Just for reference, you can draw your own menus too. See Using Menus: Creating Owner-Drawn Menu Items and Owner-Draw Menus.

"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man

This topic is closed to new replies.

Advertisement