Help Center

CWindow.Centermethod

Centers a window on the screen or over another window.

WindowsmethodCWindow.incdocumented

Syntax

SUB Center (BYVAL hwnd AS HWND = NULL, BYVAL hwndParent AS HWND = NULL)

Parameters

NameDescription
hwndOptional. Handle to the window. If NULL, the handle of the main window is used.
hwndParentOptional. Handle to the parent window. If NULL, the coordinates of the work area of the desktop window are used for the calculations.

Description

Centers a window on the screen or over another window. It also ensures that the placement is done within the work area.

Example

' // Creates the main window DIM pWindow AS CWindow pWindow.Create(NULL, "CWindow test", @WndProc) ' // Sizes it by setting the wanted width and height of its client area pWindow.SetClientSize(500, 320) ' // Centers the window pWindow.Center

Reference

  • Include file CWindow.inc
  • Defined in AfxNova/CWindow.inc:752
  • Documented in Windows/Windows GUI/CWindow Class.md
  • Topic: CWindow Class