Thread: Problem in getting size of a window

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    205

    Problem in getting size of a window

    Hi,
    I have a program with a picture control window. The line in the .rc file is as follows:
    CONTROL "",IDC_CNTRLWIND,"Static",SS_WHITERECT | NOT WS_VISIBLE,69,0,215,149

    Now I am trying to get the picture coordinates in my program using the following code:
    Code:
    CWnd * wnd = (CWnd *)GetDlgItem(IDC_CNTRLWIND_G3);
    	CRect rect;
    	wnd->GetWindowRect(&rect);
    
    	XMIN = rect.left;
    	YMIN = rect.top;
    	XMAX = rect.right;
    	YMAX = rect.bottom;
    The problem is when I run the program the values that I get are:
    XMIN = 392
    YMIN = 123
    XMAX = 715
    YMAX = 365

    which are not even close to the original coordinates for the window. I was wondering if anybody would have any idea what can cause such a problem. It should be noted that the dialog containing the picture control is used in a tab. Thanks
    Amish

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    204
    Try GetClientRect().

  3. #3
    Registered User
    Join Date
    Dec 2004
    Posts
    205
    That does not help because I need the absolute coordinate since I want to do something special when the mouse button is clicked inside the rectangle.
    Amish

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    The coordinates you specify in the resource script are not pixel values but dialog units and so will no correspond directly to the pixel coordinate values returned by GetClientRect. For more information regarding dialog units and their conversion, consult msdn for the following functions:

    GetDialogBaseUnits.
    MapDialogRect

    I don't know if there are mfc analogues of these api functions.

    If the problem is actually mapping screen to client coordinates and vice versa then ScreenToClient and ClientToScreen may be of some interest.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Just starting Windows Programming, School me!
    By Shamino in forum Windows Programming
    Replies: 17
    Last Post: 02-22-2008, 08:14 AM
  2. Fixed window size
    By The Brain in forum Windows Programming
    Replies: 5
    Last Post: 02-23-2006, 03:07 PM
  3. problem with open gl engine.
    By gell10 in forum Game Programming
    Replies: 1
    Last Post: 08-21-2003, 04:10 AM
  4. OpenGL and Windows
    By sean345 in forum Game Programming
    Replies: 5
    Last Post: 06-24-2002, 10:14 PM
  5. Problem with non-functional window
    By Magos in forum Windows Programming
    Replies: 5
    Last Post: 04-14-2002, 11:32 PM