CWindow::ResizeClient() Function for CWnd (or derived classes) | CodeGuru

CWindow::ResizeClient() Function for CWnd (or derived classes)

With this Function you can resize the window to the specified client area size of your CWnd or derived classes like the CWindow::ResizeClient() function. Example You have a dialog based application and the client rect of the dialog depends on the size of a bitmap. Source Code BOOL CYourWndOrDialog::ResizeClient (int nWidth, int nHeight, BOOL bRedraw) […]

Written By
CodeGuru Staff
CodeGuru Staff
Jan 26, 2001
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

With this Function you can resize the window to the specified client area
size of your CWnd or derived classes like the CWindow::ResizeClient()
function.

Example

You have a dialog based application and the client rect of the
dialog depends on the size of a bitmap.

Source Code

BOOL CYourWndOrDialog::ResizeClient (int nWidth,
                                     int nHeight,
                                     BOOL bRedraw)
{
 RECT rcWnd;
 GetClientRect (&rcWnd);
 if(nWidth != -1)
  rcWnd.right = nWidth;
 if(nHeight != -1)
  rcWnd.bottom = nHeight;
 if(!::AdjustWindowRectEx(&rcWnd,
                          GetStyle(),
                          (!(GetStyle() & WS_CHILD)
 && GetMenu() != NULL)), GetExStyle()))
  return FALSE;
 UINT uFlags = SWP_NOZORDER | SWP_NOMOVE;
 if(!bRedraw)
  uFlags |= SWP_NOREDRAW;
 return SetWindowPos(NULL,
                     0, 0,
                     rcWnd.right - rcWnd.left,
                     rcWnd.bottom - rcWnd.top,
                     uFlags);
} // CYourWndOrDialog::ResizeClient
CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.