Thread: Center Window inside another Window?

  1. #1
    Registered User
    Join Date
    Nov 2018
    Posts
    25

    Question Center Window inside another Window?

    I can calculate how to center a window on the desktop screen.

    But I'm not able to center a window inside another window! That's because the Window can be in any position on the Screen.

    Does anyone know the calculation to do that?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,176
    > Does anyone know the calculation to do that?
    Pencil, paper - and a bit of geometry.

    > I can calculate how to center a window on the desktop screen.
    Try doing the same, but introduce a left=0 and top=0 into the terms.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Nov 2018
    Posts
    25
    Quote Originally Posted by Salem View Post
    >
    > I can calculate how to center a window on the desktop screen.
    Try doing the same, but introduce a left=0 and top=0 into the terms.
    Left and Top are already zero. I already do that to calculate the Desktop Center!
    I calculate based on the Desktop Screen Size, but the Desktop screen does not change its x,y position.

    I need to know how to calculate from the Center of the x,y position where the main window is! that is not ZERO
    And the main window isn't in the center of the desktop, it could be anywhere. And it's exactly this x, y of this Window that I have no idea where to put in this calculation!
    Soon I didn't understand what you wanted to explain!

  4. #4
    Registered User
    Join Date
    Nov 2018
    Posts
    25
    Quote Originally Posted by Salem View Post
    > Try doing the same, but introduce a left=0 and top=0 into the terms.
    Thanks for trying to help, but this calculation you didn't know how to do! left and top could never be ZERO because the main window would never be in this position!

    I managed to solve the problem because I found where I should put the position of the main window that I had no idea where to put in the calculation, it was by trying and error!

  5. #5
    Registered User
    Join Date
    Feb 2019
    Posts
    722
    Ask yourself: "What is the origin for a 'child' window?" Is it the "desktop" or its parent window? And what if you have multiple monitors?

  6. #6
    Registered User
    Join Date
    Nov 2018
    Posts
    25
    Quote Originally Posted by flp1969 View Post
    Ask yourself: "What is the origin for a 'child' window?" Is it the "desktop" or its parent window? And what if you have multiple monitors?
    I understand your point. But this is a warning window! And it needs to be shown on top of the Window that called it!

    So even if you have multiple monitors, it will only be displayed on the monitor where the Window that called you is!

    But don't worry, I already solved the problem!
    Thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 02-12-2019, 04:48 PM
  2. How do you center a window?
    By Queatrix in forum Windows Programming
    Replies: 4
    Last Post: 05-28-2005, 06:25 PM
  3. Showing a window from inside a DLL
    By Rare177 in forum Windows Programming
    Replies: 0
    Last Post: 10-08-2004, 11:39 AM
  4. Child window inside child window
    By Magos in forum Windows Programming
    Replies: 13
    Last Post: 04-20-2004, 06:51 AM
  5. opening a dialog window from inside a dialog window
    By uvacow in forum C++ Programming
    Replies: 1
    Last Post: 12-02-2002, 09:27 AM

Tags for this Thread