Solved

Resize Property Page to fit bitmap (using SDK - not MFC)

Posted on 2002-06-27
5
1,058 Views
Last Modified: 2013-12-03
Hello,

I am building a property page using Visual C++ Windows SDK (Non-MFC) and I want my property page to be bitmap based.  The only thing I want displayed int the Property Page display region is a bitmap and the program will respond to mouse movements and button control.  

The problem is that the Property Page is defined in a .rc file as a dialog as follows and as you see the size of the dialog is based on DIALOG UNITS although I would prefer to define the size in pixels so that it will exactly fit my bitmap:

IDD_MYPROPPAGE DIALOG DISCARDABLE  0, 0, 140, 180
STYLE WS_CHILD
FONT 8, "MS Sans Serif"
BEGIN
END

Since I cannot define the dialog in pixels, I guess I will need to resize it after it is created so that it is the proper size.  How can I do that?

Thanks,
Mark
0
Comment
Question by:kaplan1
  • 2
5 Comments
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 7115638
Displays the settings for the grid spacing in dialog box units (DLUs).

Width: DLUs
Sets the width of the layout grid in DLUs. A horizontal DLU is the average width of the dialog box font divided by four.
Height: DLUs
Sets the height of the layout grid in DLUs. A vertical DLU is the average height of the dialog box font divided by eight


MSDN SAYS:

BOOL CMyDlg::OnInitDialog()
{
    CDialog::OnInitDialog();

    // Set tabstops at 100 and 200 dialog units
    int tab_stop[2] = {100, 200};
    VERIFY(m_listbox.SetTabStops(2, tab_stop));

    m_listbox.AddString("String1\tString2\tString3");

    CDC *pDC = m_listbox.GetDC();

    // Get a handle to the font used in the list box
    CFont *pFont;
    pFont = m_listbox.GetFont();

    // Select the list box font into the temporary DC
    CFont *pFontOld = pDC->SelectObject(pFont);

    // Call GetTextExtentPoint to compute the string dimensions
    // NOTE: use GetTextExtentPoint32 in Win32 for better results
    CSize size;
    GetTextExtentPoint(pDC->GetSafeHdc(),
      "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
      52, &size);

    int avg_char_width = (size.cx/26 +1)/2;

    // Restore Original Font
    pDC->SelectObject(pFontOld);

    m_listbox.ReleaseDC(pDC);

    // Convert DLU to pixel positions
    int xPos1 = (tab_stop[0] * avg_char_width + 2)/4;
    int xPos2 = (tab_stop[1] * avg_char_width + 2)/4;
...........
}

GOOD LUCK
0
 

Author Comment

by:kaplan1
ID: 7116845
What I am trying to accomplish is to set the dialog box associated with my Property page to be an exact height and width of pixels.  Since the dialog definition in the .rc file is in DLU's which seem to be user dependent (depends on users screen resolution) I don't think I can set it there.  Therefore I assume I must resize the dialog box at runtime to the exact pixel dimensions that I want.  Is this possible, and if so how?

Thanks,
Mark
0
 
LVL 8

Accepted Solution

by:
fl0yd earned 200 total points
ID: 7123620
This is possible. Use the SetWindowPos()-function and specifiy ( SWP_NOMOVE | SWP_NOREPOSITION | SWP_NOZORDER ) as your flags. All window/display-functions take actual pixel dimensions, with one exception: printing.
0
 

Author Comment

by:kaplan1
ID: 7125549
I tried using SetWindowPos() but nothing happened.  That is probably because the dialog box of the Property Page is a child of the outer TabCtrl.  
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

860 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