News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Centering a window on another window

Started by NoCforMe, April 09, 2012, 01:56:13 AM

Previous topic - Next topic

hfheatherfox07

Quote from: dedndave on April 11, 2012, 10:20:14 PM
well, first, you have to get the window width and height
i am guessing you want to center it on the desktop, so you can use GetSystemMetrics for those
        INVOKE  CenterWindow,hWnd,width,height

I thought this centers the window within another window .....not in the center of the desktop ...I just use poponcenter in the rsrc.rc with MASMeD

dedndave

oh - well it will center any window in any other window, i think
the desktop is a window   :P
HWND_DESKTOP = 0

hfheatherfox07

Quote from: dedndave on April 11, 2012, 10:20:14 PM
well, first, you have to get the window width and height
i am guessing you want to center it on the desktop, so you can use GetSystemMetrics for those
        INVOKE  CenterWindow,hWnd,width,height


I tried all this Last night on the example that I posted above and no go ...the window is not centered on my main window ...and it goes to the upper left corner of the desktop .... also no window just a title bar?????


I have another way that I do this but it does not keep the window proportion with regards to the window size ...you have to set left right top bottom and window height and width....

maybe I think this will do something that It does not..... what I thought this does is.... for the child window to pop up on center in relation to the parent window  even if I move the parent window anywhere on the desktop before I execute the child window

dedndave

well - show us your example
what you may be dealing with is a coordinate reference issue
i.e., screen coordinates vs client coordinates

hfheatherfox07

Quote from: dedndave on April 12, 2012, 04:49:44 PM
well - show us your example
what you may be dealing with is a coordinate reference issue
i.e., screen coordinates vs client coordinates

the example that does not work is the one above that I want to work using this authors way .....  I have no problem with the other one it works great ... I am not at home at my personal PC ...but If you want to see that one let me know and I will grab it with me on a flash drive and upload it ...I have no questions about that one ....
I am trying to make this one work

http://www.masm32.com/board/index.php?PHPSESSID=fc2c702b1f62df3f61be07c96a25b83f&action=dlattach;topic=18662.0;id=10550

I did not re-upload it with the modifications suggested last night

dedndave

ok
that example doesn't tell us which window you want centered on which other window   :P
remember - the parms for CenterWindow are missing - so we cannot see what you want to do

on another note...
looking again at the code,
it seems logical that the function could be passed 2 window handles, rather than a handle, width, and height
i dunno - a matter of application, i suppose

Heather...
this is a simple thing   :P
if you can handle bitmaps, you should be able to handle this

hfheatherfox07

Quote from: dedndave on April 12, 2012, 05:02:38 PM
ok
that example doesn't tell us which window you want centered on which other window   :P
remember - the parms for CenterWindow are missing - so we cannot see what you want to do

on another note...
looking again at the code,
it seems logical that the function could be passed 2 window handles, rather than a handle, width, and height
i dunno - a matter of application, i suppose

Heather...
this is a simple thing   :P
if you can handle bitmaps, you should be able to handle this

LOL the child window ... so say I execute my main window .... than I move it to the button corner of the screen ...I thought this proc makes sure that the child window opens in the center of the parent window
I know that I should be able to handle this but I want to use his proc the way he intended it ...and I do not know how ....
for example my way  the "INVOKE GetWindowRect, winHandle, ADDR gpRect" is not in the proc it gets invoked Like so:

.IF wParam == IDC_WINDOWBUTTON
INVOKE GetWindowRect,hWnd, addr rect
invoke DialogBoxParam,hInstance,IDC_WINDOW,hWnd,addr WindowProc,0

and the rect is not defined LOCAL ....

SO I do not know were to place his "invoke CenterWindow", and were do I place "invoke SetWindowPos"

I just thought I would try his proc that's all  :(

dedndave

we'll make it fly   :U

gimme a while - i am playing with the enumeration thingy

dedndave

yah - little snafu with coordinates
GetWindowRect returns screen coordinates
MoveWindow uses client coordinates for child windows, screen coordinates for top-level windows
SetWindowPos uses client coordinates

so - the routine works ok for centering the main window of a program
we can use ScreenToClient to straighten things out, i think

hfheatherfox07

Quote from: dedndave on April 12, 2012, 07:59:36 PM
yah - little snafu with coordinates
GetWindowRect returns screen coordinates
MoveWindow and SetWindowPos use client coordinates for child windows, screen coordinates for top-level windows

so - the routine works ok for centering the main window of a program
we can use ScreenToClient to straighten things out, i think

The authors original post said that it does what I thought it would ..????
I have an example that does that .... I just thought he had a better way..... oh well ......
not that important ...... I am sure the author might respond and explain or give a demo of how he uses this proc

look at the first proc  quote "Centers window (by w. & h.) on another window"

dedndave

maybe i am missing something
at the end of each section in the code, he adds the left or top screen position back onto the result

hfheatherfox07

who knows I am sure he will post an example of how he meant this to be used

Thank you for all your help with every thing so far  :bg

dedndave

ok - i must have misunderstood something or other - lol

give this a try...

hfheatherfox07

Quote from: dedndave on April 12, 2012, 08:44:00 PM
ok - i must have misunderstood something or other - lol

give this a try...


Yes that is what I wanted to do :U 
but that is not the way that the author described using the proc .....the original post made it seem like all you have to do is call CenterWindow and than SetWindowPos

I was on this for the most part of the day and still would not get it to work .......
you had to add a bunch of stuff that makes the CenterWindow proc almost irrelevant your way can be  modified so you do not  need to use that proc
It is very similar to an example that I had
As I promised yesterday that I will bring my example on a flash drive and upload it .....  this gives you the ability to Control the final Child window size  and the position

Thank you for all your hard work ... :bg I hope one day that I will be good enough to start helping people too

dedndave

#44
well - normally, you know what size the inside window will be ahead of time - the height and width would be constants
no need to call GetWindowRect before the CenterWindow call to get the size
that was just some example code i tossed together

for example - you want to center a "standard sized" button in hWin...
        INVOKE  CenterWindow,hWin,86,26
        INVOKE  MoveWindow,hButton,ecx,edx,86,26,TRUE


a trick that Edgar (donkey) taught me a couple years ago...

main window - WM_CREATE handler - create all your controls
the initial sizes and positions can be all 0's
then let the WM_SIZE handler set their sizes and positions   :P
(works especially well for scroll bars and status bars - whose sizes and positions depend on the window size)