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:


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;


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

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

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?


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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.