I have the following script of a dialog box:

#include "Resources.h"
IDD_MAIN DIALOGEX 0,0,500,300
FONT 8,"Tahoma",400,0
STYLE WS_CAPTION|WS_VISIBLE|WS_SYSMENU|WS_GROUP|DS_CENTER
EXSTYLE WS_EX_APPWINDOW
BEGIN
    // controls
END
...
hDlgMain = CreateDialogParam(hInstance, 
  MAKEINTRESOURCE(IDD_MAIN), hWndMain, 
  MainDlgProc, (LPARAM)&MyData);
...

The dialog box itself works great, the problem is that it's not propely sized. As in the script, I want it 500 by 300 pixels, but for a reason I can't figure out, it's much bigger than that (it has around 800 by 600 pixels). I think it's something related with the font, cause when I lower the font's point size to 6, the whole dialog box becomes smaller (still not 500 by 300), but all the controls shrink as well.

I've attached some images. The third image appears normal, but I had to change the width and size to 426 and 281 so it appears at 645 by 489.

Can someone please tell me what I did wrong ? Thanks in advance.

Yes you are correct. The size of the dialog box depends on the size of the font.

The dialog box that I designed has a template that looks like this:

ABOUTBOX DIALOG DISCARDABLE 32, 32, 180, 100 STYLE DS_MODALFRAME | WS_POPUP 
FONT 8, "MS Sans Serif" 
BEGIN 
         DEFPUSHBUTTON "OK",IDOK,66,80,50,14 
         ICON "ABOUT1",IDC_STATIC,7,7,21,20 
         CTEXT "About1",IDC_STATIC,40,12,100,8 
         CTEXT "About Box Demo Program",IDC_STATIC,7,40,166,8 
         CTEXT "(c) Charles Petzold, 1998",IDC_STATIC,7,52,166,8 
END

The first line gives the dialog box a name (in this case, ABOUTBOX). As is the case for other resources, you can use a number instead. The name is followed by the keywords DIALOG and DISCARDABLE, and four numbers. The first two numbers are the x and y coordinates of the upper left corner of the dialog box, relative to the client area of its parent when the dialog box is invoked by the program. The second two numbers are the width and height of the dialog box.

These coordinates and sizes are not in units of pixels. They are instead based on a special coordinate system used only for dialog box templates. The numbers are based on the size of the font used for the dialog box (in this case, an 8-point MS Sans Serif font): x-coordinates and width are expressed in units of 1/4 of an average character width; y-coordinates and height are expressed in units of 1/8 of the character height. Thus, for this particular dialog box, the upper left corner of the dialog box is 5 characters from the left edge of the main window's client area and 2-1/2 characters from the top edge. The dialog itself is 40 characters wide and 10 characters high. This coordinate system allows you to use coordinates and sizes that will retain the general dimensions and look of the dialog box regardless of the resolution of the video display and the font you've selected. Because font characters are often approximately twice as high as they are wide, the dimensions on both the x-axis and the y-axis are nearly the same.

Also read the section on "Dialog Box Measurements" from this MSDN page. It explains on how to convert between dialog box measurements and pixels.

Hi this is Shiva..

I saw the snap shots of your application..

Can i have the piece of code to create the tabcontrol(and adding button,labrls to it) and datagrid..

Now i am developing Sample Library management Project using Win32 using Dev c++ compiler..

I really need of Datagrid to display book details and also need Tab control ..

Please send me the way to do this ..please send some simple tutorials..


Thanks in advance..

@Wolfpack: Thanks. I coincidentally happen to read Charles Petzold's book, but I'm only at page 273 :cheesy:.

@Shiva_nan: I'm a beginner in Windows programming, so I don't think I can help you very much. I'll post the code I used to create the listview and tab controls you see in the screenshots, but I don't know how to work with them yet.

// Resources.rc
  CONTROL "",IDC_TAB,"SysTabControl32",WS_CHILD|WS_VISIBLE|WS_TABSTOP|TCS_FOCUSNEVER,233,53,189,208
  CONTROL "",IDC_LIST,"SysListView32",LVS_REPORT|WS_CHILD|WS_VISIBLE|WS_TABSTOP|LVS_SINGLESEL,4,68,224,208,WS_EX_CLIENTEDGE

// Main.cpp (dialog box's WndProc)
    LPTSTR column[] = {"First Name", "Last Name", "Nickname"};
    HWND List = GetDlgItem(hWnd, IDC_LIST);

    LVCOLUMN lvc;
    lvc.mask = LVCF_WIDTH | LVCF_TEXT;
    lvc.cx = 110;

    for(unsigned int i = 0; i < sizeof(column) / sizeof(column[0]); i++)
    {
        lvc.pszText = column[i];
        ListView_InsertColumn(List, i, (LPARAM)&lvc);
    }

    LPTSTR tab[] = {"Basic", "Home Address", "Work Address"};
    HWND wtab = GetDlgItem(hWnd, IDC_TAB);

    TCITEM tci;
    tci.mask = TCIF_TEXT;

    for(unsigned int i = 0; i < sizeof(tab)/sizeof(tab[0]); i++)
    {
        tci.pszText = tab[i];
        TabCtrl_InsertItem(wtab, i, &tci);
    }

Hi this is Shiva..

I saw the snap shots of your application..

Can i have the piece of code to create the tabcontrol(and adding button,labrls to it) and datagrid..

Now i am developing Sample Library management Project using Win32 using Dev c++ compiler..

I really need of Datagrid to display book details and also need Tab control ..

Please send me the way to do this ..please send some simple tutorials..


Thanks in advance..

Please see the link I posted in your other thread.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.