Solved

Convert Pixel to Dlg unit

Posted on 1998-06-19
1
419 Views
Last Modified: 2013-11-20
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 );
  }
}
0
Comment
Question by:engllf
1 Comment
 
LVL 11

Accepted Solution

by:
mikeblas earned 50 total points
ID: 1318253
To convert, use MapDialogRect().

B ekiM
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question