userd
asked on
GetWindowRect failed
HI all,
I have created MFC Dialog based application. I placed one button in invisible mode on dialog. In OnInitDialog handler, I am taking the button coordinates by using mybutton.GetWindowRect() function. I am placing the bitmap(CBItmapButton object) in the rectangle area returned by GetWindowRect(). This is fine on development machines and some machines.
But the placement of bitmap is not proper on some different machine resolutions. How to fix this?
rough code:
RECT rc;
CBitmapButton mycbitmapbutton;
m_mybutton.GetWindowRect(& rc);
//m_mybutton is member variable and attached to button control on dialog
mycbitmapbutton.Create(NUL L, WS_VISIBLE | BS_OWNERDRAW| WS_EX_CLIENTEDGE, CRect( rc.left, rc.top ,rc.left + 65 , rc.top+23), this,100);
mycbitmapbutton.LoadBitmap s(IDR_BMP_ PIC);
Regards,
UserD.
I have created MFC Dialog based application. I placed one button in invisible mode on dialog. In OnInitDialog handler, I am taking the button coordinates by using mybutton.GetWindowRect() function. I am placing the bitmap(CBItmapButton object) in the rectangle area returned by GetWindowRect(). This is fine on development machines and some machines.
But the placement of bitmap is not proper on some different machine resolutions. How to fix this?
rough code:
RECT rc;
CBitmapButton mycbitmapbutton;
m_mybutton.GetWindowRect(&
//m_mybutton is member variable and attached to button control on dialog
mycbitmapbutton.Create(NUL
mycbitmapbutton.LoadBitmap
Regards,
UserD.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I concur with bobarctor; the issue is global/scrren coordinats vs local/client coordinates (the rc.left+65 , rc.top+23 is the giveaway). Many beginners make everything fullscreen and then think that the two coordinate sets are identical.
Dan and bobarctor are right- you have to use ScreenToClient before using the CRect. It should go like this:
RECT rc;
CBitmapButton mycbitmapbutton;
m_mybutton.GetWindowRect(&rc);
ScreenToClient(rc);
mycbitmapbutton.Create(NULL, WS_VISIBLE|BS_OWNERDRAW|WS_EX_CLIENTEDGE, rc, this, 100);
mycbitmapbutton.LoadBitmaps(IDR_BMP_PIC);
Try ::ScreenToClient();
you cannot call GetWindowRect (and a lot of other CWnd-functions) for CWnd-derived objects before they are created with 'Create' or 'CreateEx' (or before they are attached to an existing window).
So, you need to specify the rect anyhow.
ZOPPO