Announcement

Collapse
No announcement yet.

Dialog control placement help...

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Dialog control placement help...

    Hi Everybody!

    Is there a better way to design dialogs. Dialog units really are
    giving me a head ache. Every time I want to position a control
    they just dont go where i want them, they always seem to be out
    by just a pixel or so.

    Please sombody tell me that there is a solution?

    ------------------
    Cheers

  • #2
    Mark;

    Thats the nature of Dialog Units.

    A Dialog Unit horizontal unit is 1/4 of the average character size
    of the Font used when the window is created. The vertical unit is
    1/8 of the font average character size.

    Now when a window is created using CreateWindow the default font
    is the System font which is 8 x 16 pixels average.

    8/4 = 2 pixels horizontal dialog unit
    16/8 = 2 pixels vertical dialog unit

    Now that sounds fine, but the problem is that when you use any other
    font as the default font, then the values changes and they may not
    divide into whole number pixels per Dialog unit.

    Now if a Dialog uses any other font as its default font, then its
    average character size doesn't divide well into Dialog Units.
    MS Sans Serif, 8 point has become the standard font in many Windows
    Visual Designers today, but if the dialog depends upon that font size
    for calculating dialog units, then you won't get accurate pixel
    coordinates for controls. It just can't be helped.

    One technique would be to create your controls like normal
    and then resize your controls via the API, before you display the
    Dialog. In most cases a pixel off here or there doesn't make a
    difference, but the few controls where it does look bad, then
    simply resize them via the API. If you have a row of buttons, then
    use the first button as the starting point and resize all the
    buttons to the same size and make then equally spaced apart.

    I suggest your read up in MSDN (use the Microsoft online library)
    to read up on Dialog Units. They give a lot of important info
    on using Dialog Units.



    [This message has been edited by Chris Boss (edited November 25, 2000).]
    Chris Boss
    Computer Workshop
    Developer of "EZGUI"
    http://cwsof.com
    http://twitter.com/EZGUIProGuy

    Comment


    • #3
      Thanks Chris!


      I kinda knew most of that already but it was nice to see it explained
      in depth like that. There doesn't seem to be enough of that now a days

      It's funny that you mentioned creating a control on a dialog with
      CreateWindowEx because I tried that just after I posted this question.
      It worked just fine but now I have another question.


      How can you get the handles of all the child windows that belong to
      a window?



      ------------------
      Cheers

      Comment


      • #4
        Look at all the API functions that start with Enum !

        These functions are for enumerating things, like all the child
        windows, all the fonts in the system, all the printers in the system.



        ------------------
        Chris Boss
        Computer Workshop
        Developer of "EZGUI"
        http://cwsof.com
        http://twitter.com/EZGUIProGuy

        Comment


        • #5
          Mark,

          The advantage of using dialogs is the scaling that works off the font
          size, a modal dialog is simple code to get going, espacially if you
          use a dialog editor but the dialog engine is simply not as powerful as
          writing the complete window code yourself.

          Windows created with CreateWindowEx() can literally do anything if you
          want to code it yourself. There are more variations and a higher level
          of control and adding controls created with CreateWindowEx() is relatively
          straight forward, the return value is the handle and it is usually a
          good idea to make the handle a global value so you can access it from
          anywhere in the program if necessary.

          It really depends if you want the auto scaling or are willing to do your
          own sizing code, depends on the app of course as there is certainly room
          for both.

          Regards,

          [email protected]

          ------------------
          hutch at movsd dot com
          The MASM Forum

          www.masm32.com

          Comment

          Working...
          X