Link to home
Start Free TrialLog in
Avatar of engllf
engllf

asked on

Convert Pixel to Dlg unit

I need to size a dialog box to that exactly of a bitmap.
How do I convert the bitmap's width & height (in pixel)
to that of dialog's unit?  

Below  is the code which i think might work.
Is there any better method?

// load bitmap
HBITMAP hBmp = (HBITMAP)::LoadImage(AfxGetInstanceHandle(),
                         MAKEINTRESOURCE(IDB_BITMAP1),
                         IMAGE_BITMAP,
                         0,0,
                         LR_LOADMAP3DCOLORS);

if (hBmp!= NULL)
{
  BITMAP   bmInfo;
  int result = ::GetObject(hBmp, sizeof(BITMAP), &bmInfo);

  if (result != 0)
  {
   // calculate dlg box size based in bitmap size
   int nNewDlgHeight = ConvertToDlgUnit(bmInfo.bmHeight); //???? How to convert
   int nNewDlgWidtht = ConvertToDlgUnit(bmInfo.bmWidth); //????
   
   // Set dlg box new size
   WINDOWPLACEMENT lpwndpl ;
    GetWindowPlacement(&lpwndpl );
    lpwndpl.rcNormalPosition.bottom = lpwndpl.rcNormalPosition.top + nNewDlgHeight ;
    lpwndpl.rcNormalPosition.right = lpwndpl.rcNormalPosition.left + nNewDlgWidth ;
    SetWindowPlacement(&lpwndpl );
  }
}
ASKER CERTIFIED SOLUTION
Avatar of mikeblas
mikeblas

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial