Solved

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

Posted on 2002-06-27
5
1,055 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now