CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Threaded View

  1. #1
    Join Date
    Jul 2007
    Posts
    52

    [Solved]Getting mad showing a template!

    This time I definitely need your help, I tried every way my brain found for three days and now I'm out of ideas.


    The problem: I need to show a dialog template. Dialog template measures are in Dialog Units, which depend on the dialog font's height'n'width.

    Premise: I already read a lot and a lot of times the articles:
    http://support.microsoft.com/default...b;EN-US;145994
    and
    http://support.microsoft.com/kb/125681/EN-US/#top




    My idea was this:
    I get system font width and system font height, then I get dialog custom font's width and height and I can perform the conversion with the formula
    horz pixels == 2 * horz dialog units * (average char width of dialog font
    / average char width of system font)
    vert pixels == 2 * vert dialog units * (average char height of dialog font
    / average char height of system font)


    Easy to say...

    The code I used to get system font size and dialog font's size are:


    //TO GET SYSTEM FONT AVG VALUES
    CRect rc( 0, 0, 4, 8 );

    MapDialogRect( &rc );
    int baseUnitY = rc.bottom;
    int baseUnitX = rc.right;
    TRACE("baseUnitX = %d\n", baseUnitX);
    TRACE("baseUnitY = %d\n", baseUnitY);


    //TO GET DIALOG'S FONT AVG VALUES
    CPaintDC dc(this); // contesto di periferica per il disegno

    SelectObject(dc,&m_font);
    TEXTMETRIC tm;
    CSize size;
    GetTextMetrics(dc,&tm);
    GetTextExtentPoint32(dc,"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",52,&size);
    int avgWidth = (size.cx/26+1)/2;
    int avgHeight = (WORD)tm.tmHeight;

    TRACE("baseUnitX = %d\n", avgWidth);
    TRACE("baseUnitY = %d\n", avgHeight);



    SecondPremise: m_font is a CFont variable loaded this way:
    LOGFONT lf;
    memset(&lf, 0, sizeof(LOGFONT)); // Clear out structure.
    lf.lfHeight = 8; // Request a tot-pixel-high font
    strcpy(lf.lfFaceName, "Tw Cen MT Condensed"); // with face name we read
    //lf.lfHeight = 15; // Request a tot-pixel-high font
    //strcpy(lf.lfFaceName, "MS Sans Serif"); // with face name we read
    m_font.CreateFontIndirect(&lf); // Create the font.

    Note that m_font is correctly initialized and is NOT destroyed, it is a public variable in the mfc dialog's class. And i used it to set the font to some control, so.. no errors here.

    Why coordinates I get are totally WRONG?

    Am I getting wrong in something? I also thought about creating a dialog with CreateIndirect, but couldn't find good examples. If you can, help me understanding why I am getting wrong, imho it is all right, but results are wrong
    Last edited by NasterMain; March 29th, 2008 at 07:48 AM. Reason: Problem Solved

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured