Thread: Resource size problem...

  1. #1
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768

    Question Resource size problem...

    I know there are two ways to create a control:

    1. using resource:
    Code:
    EDITTEXT        IDD_CONTROL, 10, 50, 80, 14, ES_AUTOHSCROLL
    2. creating the window yourself:
    Code:
    CreateWindowEx(NULL, "Edit", "", WS_CHILD | WS_VISIBLE, 
    10, 50, 80, 14, hDlg, (HMENU)IDD_CONTROL, 
    GetModuleHandle(NULL), NULL);
    As you may noticed, the location and size is the same: 10, 50, 80, 14.
    The problem is the way the CreateWindowEx() fucntion sees the value, which is different than the way the resource sees it.

    Is there any way I could match them?



    Thank you.
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Resources dimensions are calculated in dialogbox units, non-resource windows use pixels. Dialogbox units are relative to the font size (usually the system font - see GetDialogBaseUnits). MapDialogRect can convert from dialogbox units to pixels.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    But this is a control, not text that uses a font.
    Can you please give me an example?
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    >>But this is a control, not text that uses a font.<<

    It doesn't matter: dialogbox units are based on font dimensions.

    >>Can you please give me an example?<<

    There's one here with a little discussion.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  5. #5
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    this single line crashes the program:
    Code:
    RECT ref;
    
    MapDialogRect(hDlg, &ref);
    So I checked the msdn again... take a look at the hDlg part:
    BOOL MapDialogRect(
    HWND hDlg, // handle of dialog box
    LPRECT lpRect // address of structure with rectangle
    );

    Parameters
    hDlg
    Identifies a dialog box. This function accepts only handles for dialog boxes created by one of the dialog box creation functions; handles for other windows are not valid.
    lpRect
    Pointer to a RECT structure that contains the dialog box coordinates to be converted.
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  6. #6
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    >>this single line crashes the program<<

    I cannot induce a crash with mingw or msvc.net2003 with winxp although MapDialogRect does return zero with non-dialog windows.

    If you are not changing the font of your controls' then GetDialogBaseUnits will return dialogbox units based on the system font which you can use to convert to pixels. An example of its use ('using combo boxes') can be found on the msdn page for the function, a link to which I have provided in a previous post.
    Last edited by Ken Fitlike; 04-28-2004 at 02:53 PM.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  7. #7
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    well, maybe because i'm on win98... but still, could it be because I'm not creating the dialog with a function, instead I create it with a resource.
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  8. #8
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    When the MapDialogRect function mentions dialog boxes created by one of the dialog box creation functions it is referring to:

    CreateDialog
    CreateDialogIndirect
    CreateDialogIndirectParam
    CreateDialogParam
    DialogBox
    DialogBoxIndirect
    DialogBoxIndirectParam
    DialogBoxParam

    All of these functions rely on a dialog template generated either in memory or from a resource script.
    Last edited by Ken Fitlike; 04-28-2004 at 03:18 PM.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  9. #9
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    thank you
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  10. #10
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    just one last thing.

    I've noticed that the convertion is not 100% accurate... actually it more like 85%.

    Is there a way I could make it a 100%?
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Having a problem with templates and classes
    By bowluswj in forum C++ Programming
    Replies: 4
    Last Post: 06-26-2007, 12:55 PM
  2. Resource Script Problem
    By ltanusaputra in forum Windows Programming
    Replies: 2
    Last Post: 06-02-2007, 09:08 AM
  3. Problem with struture size
    By xErath in forum C Programming
    Replies: 9
    Last Post: 06-22-2004, 06:53 AM
  4. problem with resource files
    By nickeax in forum Windows Programming
    Replies: 1
    Last Post: 03-14-2003, 02:32 AM
  5. Custom resource problem
    By Traveller in forum Windows Programming
    Replies: 2
    Last Post: 06-23-2002, 12:55 PM