Non-Resizable, Non-Movable Window

CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

If you want to work with nonresizable, nonmovable windows, insert this code into your project (SDI or MDI applications).

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
  if (BaseClass::OnCreate(lpCreateStruct) == -1)
    return -1;

  // Do something

  // Remove positions of menu
  CMenu* pTopMenu = GetSystemMenu(FALSE);
  if(pTopMenu != NULL)
  {
  pTopMenu -> RemoveMenu(SC_SIZE, MF_BYCOMMAND);      //Size
  pTopMenu -> RemoveMenu(SC_MOVE, MF_BYCOMMAND);      //Move
  pTopMenu -> RemoveMenu(SC_MAXIMIZE, MF_BYCOMMAND);  //Maximize
  }

  return 0;
}

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
  if( !BaseClass::PreCreateWindow(cs) )
    return FALSE;

  // Create a window without max button and sizable border
  cs.style &= ~(WS_MAXIMIZEBOX|WS_THICKFRAME);

  return TRUE;
}

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read