Win32 Resource Problem

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2006
Posts: 13
Reputation: webspy is an unknown quantity at this point 
Solved Threads: 0
webspy's Avatar
webspy webspy is offline Offline
Newbie Poster

Win32 Resource Problem

 
0
  #1
Nov 7th, 2006
I have the following script of a dialog box:
  1. #include "Resources.h"
  2. IDD_MAIN DIALOGEX 0,0,500,300
  3. FONT 8,"Tahoma",400,0
  4. STYLE WS_CAPTION|WS_VISIBLE|WS_SYSMENU|WS_GROUP|DS_CENTER
  5. EXSTYLE WS_EX_APPWINDOW
  6. BEGIN
  7. // controls
  8. END
  1. ...
  2. hDlgMain = CreateDialogParam(hInstance,
  3. MAKEINTRESOURCE(IDD_MAIN), hWndMain,
  4. MainDlgProc, (LPARAM)&MyData);
  5. ...
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.
Attached Thumbnails
1.jpg   2.jpg   3.jpg  
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: Win32 Resource Problem

 
0
  #2
Nov 7th, 2006
Yes you are correct. The size of the dialog box depends on the size of the font.
Originally Posted by Charles Petzold, Programming Windows-5th Edition, page 489-490
The dialog box that I designed has a template that looks like this:

  1. ABOUTBOX DIALOG DISCARDABLE 32, 32, 180, 100 STYLE DS_MODALFRAME | WS_POPUP
  2. FONT 8, "MS Sans Serif"
  3. BEGIN
  4. DEFPUSHBUTTON "OK",IDOK,66,80,50,14
  5. ICON "ABOUT1",IDC_STATIC,7,7,21,20
  6. CTEXT "About1",IDC_STATIC,40,12,100,8
  7. CTEXT "About Box Demo Program",IDC_STATIC,7,40,166,8
  8. CTEXT "(c) Charles Petzold, 1998",IDC_STATIC,7,52,166,8
  9. 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.
Last edited by WolfPack; Nov 7th, 2006 at 11:43 pm.
バルサミコ酢やっぱいらへんで
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 7
Reputation: Shiva_nan is an unknown quantity at this point 
Solved Threads: 0
Shiva_nan Shiva_nan is offline Offline
Newbie Poster

Re: Win32 Resource Problem

 
0
  #3
Nov 8th, 2006
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..
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 13
Reputation: webspy is an unknown quantity at this point 
Solved Threads: 0
webspy's Avatar
webspy webspy is offline Offline
Newbie Poster

Re: Win32 Resource Problem

 
0
  #4
Nov 8th, 2006
@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.

  1. // Resources.rc
  2. CONTROL "",IDC_TAB,"SysTabControl32",WS_CHILD|WS_VISIBLE|WS_TABSTOP|TCS_FOCUSNEVER,233,53,189,208
  3. CONTROL "",IDC_LIST,"SysListView32",LVS_REPORT|WS_CHILD|WS_VISIBLE|WS_TABSTOP|LVS_SINGLESEL,4,68,224,208,WS_EX_CLIENTEDGE
  4.  
  5. // Main.cpp (dialog box's WndProc)
  6. LPTSTR column[] = {"First Name", "Last Name", "Nickname"};
  7. HWND List = GetDlgItem(hWnd, IDC_LIST);
  8.  
  9. LVCOLUMN lvc;
  10. lvc.mask = LVCF_WIDTH | LVCF_TEXT;
  11. lvc.cx = 110;
  12.  
  13. for(unsigned int i = 0; i < sizeof(column) / sizeof(column[0]); i++)
  14. {
  15. lvc.pszText = column[i];
  16. ListView_InsertColumn(List, i, (LPARAM)&lvc);
  17. }
  18.  
  19. LPTSTR tab[] = {"Basic", "Home Address", "Work Address"};
  20. HWND wtab = GetDlgItem(hWnd, IDC_TAB);
  21.  
  22. TCITEM tci;
  23. tci.mask = TCIF_TEXT;
  24.  
  25. for(unsigned int i = 0; i < sizeof(tab)/sizeof(tab[0]); i++)
  26. {
  27. tci.pszText = tab[i];
  28. TabCtrl_InsertItem(wtab, i, &tci);
  29. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,618
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1491
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Win32 Resource Problem

 
0
  #5
Nov 8th, 2006
Originally Posted by Shiva_nan View Post
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.
Last edited by Ancient Dragon; Nov 8th, 2006 at 12:38 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC