Fog Creek Software
g
Discussion Board




Center a PropertySheet dialog in Win32 API?

I can't find a way to center a tabbed dialog box created with PropertySheet().

I tried tweaking the resource template, moving the box on WM_INITDIALOG (even on WM_PAINT), changing the style from the callback procedure, nothing.

One example is the Network Status dialog in Windows -- it always shows up centered. Any ideas?

Alex
Saturday, May 29, 2004

From dim memory you get the resolution of the entire surface, work out the centre and use SetWindowLong to position the window before painting it.

Simon Lucy
Saturday, May 29, 2004

There should be a command like centerwindow that takes the handle of the window to be centered and the parent window. As you want to center on whole screen give the desktop as parent. I think thats the same as giving NULL as parent.

Somorn
Saturday, May 29, 2004

Somorn,

the question asked how to center the propertysheet dialog using the WIN32 API.

The suggestion you gave, CenterWindow, involves using either MFC or ATL.  (According to my help, CWnd::CenterWindow is part of MFC and CWindow:CenterWindow is part of ATL).

You should take the time to learn the differences, as you didn't answer his question.

William Campbell
Sunday, May 30, 2004

Aah why don't people just use google for these kind of questions? It's a lot faster then waiting for anwser here: http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&threadm=6qsbfd%24nmm%241%40freeside.cls.net&rnum=20&prev=/groups%3Fq%3Dwindows%2Bapi%2Bcenter%2Bwindow%26hl%3Den%26lr%3D%26ie%3DUTF-8%26start%3D10%26sa%3DN

Anyway I haven't used the MFC (I'm not even a programmer) but I know a bit about the WinAPI so I guessed there should be some function in the user32.dll that could center a window and normally the functionname descripes it's function. So what I meant was google for a win32 api that centers a Window.

I found that you can use the MoveWindow, SetWindowPos but they require you to calculate stuff as they have no flag such as CNTWIN (which is a bummer)

I do recommend that you use http://groups.google.com not because I think you bother anyone here but as motto of usenet is every possible question has been asked before.

Somorn
Sunday, May 30, 2004

Thank you, Somorn. It's a big planet, someone must have asked it before :)

Incidentally, that page doesn't answer the question, but I found a workaround since then: WM_INITDIALOG gets called for the individual pages, I use GetParent and then MoveWindow on that handle.

Alex
Sunday, May 30, 2004

*  Recent Topics

*  Fog Creek Home