I'm trying to get the coordinates for the client section and the whole window. This is the code, but it gives me the same top, bottom, left and right for both the client and the window.

The files are:

T1NIU.h
T1NIU.cpp
T1NIUDlg.h
T1NIUDlg.cpp

This code is in the T1NIUDlg.cpp

CClientDC dlgDC(this);
  CWindowDC frmDC(m_pMainDialog);

  CWnd* frameWindow = frmDC.GetWindow();
  CWnd* clientWindow = dlgDC.GetWindow();

  RECT MyRect;
  RECT MyWinRect;
  RECT MyStatusRect;

  clientWindow->GetWindowRect(&MyRect);
  frameWindow->GetWindowRect(&MyWinRect);

  CString sWindowRect;
  sWindowRect.Format("My Window\nTop = %d\nBottom = %d\nLeft = %d\nRight = %d",
         MyWinRect.top, MyWinRect.bottom, MyWinRect.left, MyWinRect.right);
  MessageBox(sWindowRect);

  CString MyClientRect;
  MyClientRect.Format("Top = %ld\nBottom = %ld\nLeft = %ld\nRight = %ld",
         MyRect.top, MyRect.bottom, MyRect.left, MyRect.right);
  MessageBox(MyClientRect);

The variable m_pMainDialog is a member function of the dialog box and is defined in the T1NIUDlg.h file:

CWnd* m_pMainDialog;

It is set to the address of the dialog box in the T1NIU.cpp file:

CT1NIUDlg dlg;
  m_pMainWnd = &dlg;          // CWnd* defined in AFXWIN.H
  dlg.m_pMainDialog = m_pMainWnd;

I must not be understanding something here. Is the this parameter the same as the address of the dialog box?

thanks,
HyperEngineer

Try the GetClientRect method of the CWnd class. However the coordinates are with respect to the FrameWindow. You will need some calculations to get it w.r.t the screen.
GetWindowRect gives the coordinates of the Frame window w.r.t. the screen

This article has been dead for over six months. Start a new discussion instead.