Jump to content
  • Advertisement
Sign in to follow this  
mind in a box

[Win32, C++] Popup window position!

This topic is 2862 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
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;


Share this post


Link to post
Share on other sites
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....

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!