Archived

This topic is now archived and is closed to further replies.

Charles Godfrey

C++ Positioning A Dialog Box

Recommended Posts

In C++, I have a Modal Dialog Box that is brought up when the user selects a Menu option. The Dialog Box appears in the middle of the screen. I want to position it in the upper left or upper right corner of the frame window, but the various functions I have tried require a pointer that I just can''t seem to figure out how to obtain. Anyone have any examples they are willing to share? Thanks. My email address is: cgodfrey7@hotmail.com

Share this post


Link to post
Share on other sites
Skibum    122
  
// all you will need is a handle to the dialog(i used hDlg),

// and the x and y position of where you want the window to be

SetWindowPos(hDlg, HWND_TOP, x-placement, y-placement,
0, 0, SWP_NOSIZE);

Share this post


Link to post
Share on other sites
EddieCai    122
try this.
CWnd::SetWindowPos
BOOL SetWindowPos( const CWnd* pWndInsertAfter, int x, int y, int cx, int cy, UINT nFlags );
Any customer dialog derives CWnd.

Share this post


Link to post
Share on other sites
I thank you for your reply. I have tried using SetWindowPos and I am unable to get the first parameter correct.
I do not know how to get a handle to the dialog box, assuming that is what I am supposed to use as the first parameter. I could use a working example, if you have the time. Thanks.

Share this post


Link to post
Share on other sites
EddieCai    122
Well, you are using MFC or straight C codes?
If you use MFC, you should have an object which is the dialog, and follow this, assuming the object is myDialog:
myDialog.SetWindowPos(NULL, 0, 0, 100, 100, SWP_SHOWWINDOW);
of course, you can specify the values as you wish.
If you use straight C, you should have a variable which gets its value from the CreateDialog function. Use this variable as the first parameter of the SetWindowPos API function.

Share this post


Link to post
Share on other sites