Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Macro for Dialog Styles

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

  • Macro for Dialog Styles

    I've always been annoyed by long Style lines (%WS_MAXIMIZE or %WS_MAXIMIZEBOX or %WS_MINIMIZE or %WS_MINIMIZEBOX or %WS_OVERLAPPED or %WS_OVERLAPPEDWINDOW ...). A pain in the neck for me to edit, fool around with etc. I came up with something a lot easier to use. More flexible too.

    If creating more than one dialog and using different styles then you'd have to create a separate Macro for each one (or easier to C&P the appropriate styles from the existing Macros).

    '
    Code:
    'PBWIN 9.00 - WinApi 05/2008 - XP Pro SP3
    #Dim All 
    #Compile Exe  
    #Include "WIN32API.INC"
    #Include "COMDLG32.INC"
    #Include "InitCtrl.inc"
    '
      Global hdlg As Dword                
      Global Dlg_Hght&, Dlg_Wdth&
    '
    Macro Dialog_Styles
      Local Stile As Long
    '  Stile = Stile Or %DS_3DLOOK ' Give the dialog box a non-bold font, and draw three-dimensional borders around controls in the dialog box. 
    '                              '  The %DS_3DLOOK Style Is Not required by applications marked With #Option Version4 Or #Option Version5; As Windows automatically applies the 3D appearance. DDT dialogs are always Created With this Style. (Default)
    '  Stile = Stile or %DS_ABSALIGN ' Indicate that the coordinates Of the Dialog Box are screen coordinates; otherwise, Windows assumes they are Client coordinates.
    '  Stile = Stile or %DS_CENTER ' Center the dialog box in the working area (the area not obscured by the task bar and system tray). This is the default if x& and y& are not specified.
    '  Stile = Stile Or %DS_CENTERMOUSE ' Center the mouse cursor in the dialog box when the dialog is initially created.
    '  Stile = Stile Or %DS_CONTEXTHELP ' Include a question mark in the title bar of the dialog box. When the user clicks the question mark, the cursor changes to a question mark with a pointer. If the user then clicks a control in the dialog box,
    '                                   ' the Dialog CallBack receives a %WM_HELP message. This Style cannot be used With the %WS_MAXIMIZEBOX And %WS_MINIMIZEBOX styles. Also see %WS_EX_CONTEXTHELP.
    '  Stile = Stile or %DS_CONTROL ' Create a dialog that works as a child control of another dialog, smoothing the keyboard focus interface across the two dialogs when the TAB key or control accelerators are used.
    '                               '  Typically used For dialogs that form the "pages" For Tab controls And Property-sheets.
    '  Stile = Stile or %DS_MODALFRAME ' Create a dialog box with a modal dialog-box frame that can be combined with a title bar and System menu by specifying the %WS_CAPTION and %WS_SYSMENU styles. (default)
    '  Stile = Stile or %DS_NOFAILCREATE ' The dialog is created regardless of any errors that may occur during the creation phase. DDT dialogs are always created with this style. (default)
    '  Stile = Stile or %DS_SETFONT ' The font to be used by a DDT dialog and its controls can be predetermined with the DIALOG FONT statement. If the DIALOG FONT statement is not used, the default font (MS Sans Serif, 8 point) is used. 
    '                               ' The Size Of the Dialog Font proportionately affects the conversion Of Dialog Units values into Pixels, so an increase In Default Font Size will automatically Create a larger Dialog, even through the Dialog dimensions
    '                               '  have remained constant. As Child controls are added To a %DS_SETFONT Dialog, they will be sent a %WM_SETFONT message To ensure they also make use Of the specified Dialog Font.
    '                               '  DDT dialogs are always Created With this Style. (Default)
    '  Stile = Stile or %DS_SETFOREGROUND ' Bring the dialog box to the foreground. Internally, Windows calls the SetForegroundWindow API function for the dialog box.
    '  Stile = Stile or %DS_SYSMODAL ' Create a system-modal dialog box. This style causes the dialog box to have the %WS_EX_TOPMOST style, but otherwise has no effect on the dialog box or the behavior of other applications 
    '                                '  And windows when the Dialog Box Is displayed.
      Stile = Stile Or %WS_BORDER ' Create a dialog that has a thin-line border.
      Stile = Stile Or %WS_CAPTION ' Create a dialog that has a title bar. Includes the %WS_BORDER and %WS_DLGFRAME styles. When this style is used, the width& and height& parameters specify the size of the client area of the dialog;
    '                               '  otherwise, they specify the outer dimensions Of the Dialog. (Default)
    '  Stile = Stile or %WS_CHILD ' Create a child dialog. Cannot be used with the %WS_POPUP style. Typically used with %DS_CONTROL for tab control and property sheet "pages".
    '  Stile = Stile or %WS_CLIPCHILDREN ' Exclude the area occupied by child controls when drawing occurs on the dialog background. FRAME and LINE controls on a dialog with this style usually use the extended style %WS_EX_TRANSPARENT
    '                                    '  so the background Of those controls Is drawn by the Dialog before the controls are drawn. %WS_CLIPCHILDREN Is commonly used To reduce ReDraw flicker when a %WS_THICKFRAME Style Dialog Is being resized.
    '  Stile = Stile or %WS_CLIPSIBLINGS ' Child controls are clipped (not overdrawn) by one another when the dialog window is repainted. (default)
    '  Stile = Stile or %WS_DISABLED ' Create a dialog that is initially disabled. A disabled dialog cannot receive input from the user.
    '  Stile = Stile or %WS_DLGFRAME ' Create a window that has a border of the style typically used with dialog boxes. (default)
      Stile = Stile Or %WS_HSCROLL ' Dialog contains a horizontal scroll bar.
    '  Stile = Stile or %WS_ICONIC ' Create a dialog that is initially minimized, the same as the %WS_MINIMIZE style.
    '  Stile = Stile Or %WS_MAXIMIZE ' Create a dialog that is initially maximized.
      Stile = Stile Or %WS_MAXIMIZEBOX ' Create a dialog that has a Maximize button. Use with the %WS_SYSMENU style.
    '  Stile = Stile or %WS_MINIMIZE ' Create a dialog that is initially minimized, the same as the %WS_ICONIC style.
      Stile = Stile Or %WS_MINIMIZEBOX ' Create a dialog that has a Minimize button. Use with the %WS_SYSMENU style.
    '  Stile = Stile or %WS_OVERLAPPED ' Create an overlapped window. An overlapped window has a title bar (caption) and a border. Synonym of the obsolete style %WS_TILED.
    '  Stile = Stile or %WS_OVERLAPPEDWINDOW ' Combination style producing an overlapping dialog. Comprises %WS_CAPTION, %WS_SYSMENU, %WS_THICKFRAME, %WS_MINIMIZEBOX, %WS_MAXIMIZEBOX, and %WS_OVERLAPPED styles. 
    '  Stile = Stile or %WS_POPUP ' Create a popup dialog. When used by itself, a flat dialog is created with no caption or borders. Combine with %DS_MODALFRAME to create a 3D border. A popup dialog can overlap another window or dialog. (default)
    '  Stile = Stile or %WS_POPUPWINDOW ' Create a popup dialog but with a border and system menu. Comprises %WS_BORDER, %WS_POPUP and %WS_SYSMENU. Combine %WS_POPUPWINDOW with %WS_CAPTION to make the Window menu visible.
      Stile = Stile Or %WS_SYSMENU ' Create a dialog that has a System-menu box in its title bar. Must be used with the %WS_CAPTION style.
      Stile = Stile Or %WS_THICKFRAME ' Create a dialog that has a sizing border. That is, the dialog will be resizable.
      Stile = Stile Or %WS_VSCROLL ' Dialog contains a vertical scroll bar. Also see %WS_EX_LEFTSCROLLBAR
    End Macro
    '                                              
    Macro Dialog_ExStyles
      Local ExStile As Long
    'ExStile = ExStile Or %WS_EX_ACCEPTFILES ' The dialog accepts drag+drop files. The dialog Callback Function receives a %WM_DROPFILES message when files have been dropped onto the dialog.
    'ExStile = ExStile Or %WS_EX_APPWINDOW ' Force a top-level dialog onto the application taskbar when the window is minimized.
    'ExStile = ExStile Or %WS_EX_CLIENTEDGE ' Dialog has a border with a sunken edge.
    'ExStile = ExStile Or %WS_EX_CONTEXTHELP ' Include a question mark in the title bar of the dialog. When the user clicks the question mark, the cursor changes to a question mark with a pointer. If the user then clicks a child window, 
    '                    '  the child receives a %WM_HELP message. Also see %DS_CONTEXTHELP.
    'ExStile = ExStile Or %WS_EX_CONTROLPARENT ' The user may navigate among the child dialogs of the window by using the TAB key. See %DS_CONTROL.
    'ExStile = ExStile Or %WS_EX_LEFT '  Dialog has generic "left-aligned" properties. (default)
    'ExStile = ExStile Or %WS_EX_LEFTSCROLLBAR ' If present, the vertical scroll bar is positioned to the left of the client area. Also see %WS_VSCROLL.
    'ExStile = ExStile Or %WS_EX_LTRREADING ' Display the dialog text using Left to Right reading-order properties. (default)
    'ExStile = ExStile Or %WS_EX_MDICHILD ' Create a MDI child window.
    'ExStile = ExStile Or %WS_EX_NOPARENTNOTIFY ' Suppress %WM_PARENTNOTIFY messages when dialog is created or destroyed.
    'ExStile = ExStile Or %WS_EX_OVERLAPPEDWINDOW ' Comprised of the %WS_EX_CLIENTEDGE and %WS_EX_WINDOWEDGE styles.
    'ExStile = ExStile Or %WS_EX_PALETTEWINDOW ' Comprised of the %WS_EX_WINDOWEDGE, %WS_EX_TOOLWINDOW and %WS_EX_TOPMOST styles.
    'ExStile = ExStile Or %WS_EX_RIGHT ' Dialog has generic "right-aligned" properties that depend on the window class. This style has an effect only if the shell language is Hebrew, Arabic, or another language that supports reading order alignment.
    '                                  ' Otherwise, the style is ignored.
    'ExStile = ExStile Or %WS_EX_RIGHTSCROLLBAR ' If present, the vertical scroll bar is positioned to the right of the client area. See %WS_VSCROLL. (default)
    'ExStile = ExStile Or %WS_EX_RTLREADING ' If the shell language is Hebrew, Arabic, or another language that supports reading order alignment, the dialog text is displayed using Right to Left reading-order properties. For other languages, the style is ignored.
    'ExStile = ExStile Or %WS_EX_STATICEDGE ' Dialog has a 3D border. Primarily used for dialogs that do not require user-input.
    'ExStile = ExStile Or %WS_EX_TOOLWINDOW ' Create a tool window (a window intended to be used as a floating toolbar). A tool window has a shorter than normal caption area and the dialog caption is drawn using a smaller font.
    '                                       ' A tool window does not appear in the task bar,
    '                                       ' or in the window that appears when the user presses ALT+TAB. The hybrid versions of Windows (95/98/ME) may require this extended style to be added after creation, using the SetWindowLong API function.
    'ExStile = ExStile Or %WS_EX_TOPMOST ' Place dialog above all non-topmost windows and keep it above them, even while the dialog is deactivated.
    'ExStile = ExStile Or %WS_EX_TRANSPARENT ' Controls/windows beneath the dialog are drawn before the dialog is drawn. The dialog is deemed transparent because elements behind the dialog have already been painted - the dialog itself is not drawn differently.
    '                                        ' True transparency is achieved by using Regions - see MSDN for more information.
    'ExStile = ExStile Or %WS_EX_WINDOWEDGE ' Dialog has a border with a raised edge
     
    End Macro
    '''
    '''
    CallBack Function Dialog_Processor
    End Function
    '
    Function PBMain
      Dialog_Styles 'Set Dialog styles
      Dialog_ExStyles '  ""
     
      Dialog New Pixels, hdlg, "Demo", , , 400, 400, Stile, ExStile To hdlg
         Dialog Show Modal hDlg   Call Dialog_Processor
    End Function 'Applikation beendendone
    '
    Last edited by Gösta H. Lovgren-2; 16 Feb 2009, 08:46 PM.
    It's a pretty day. I hope you enjoy it.

    Gösta

    JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
    LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

  • #2
    This is an excellent opportunity to take advantage of the compound assignment operator:
    Code:
    Stile Or= %WS_CAPTION

    Comment


    • #3
      >I've always been annoyed by long Style lines ......
      Code:
      %STYLE_DIALOG_ONE =       %WS_VISIBLE _ 
                                        OR %WS_BORDER _ 
                                        OR %WS_CUTE _
                                        OR %WS_UGLY .......
      
      
          DIALOG NEW  hOwner, ......     %STYLE_DIALOG_ONE, %EXSTYLE_DIALOG_ONE
       ..
      MCM
      Michael Mattias
      Tal Systems (retired)
      Port Washington WI USA
      [email protected]
      http://www.talsystems.com

      Comment


      • #4
        Originally posted by Michael Mattias View Post
        >I've always been annoyed by long Style lines ......
        Code:
        %STYLE_DIALOG_ONE =       %WS_VISIBLE _ 
                                          OR %WS_BORDER _ 
                                          OR %WS_CUTE _
                                          OR %WS_UGLY .......
         
         
            DIALOG NEW  hOwner, ......     %STYLE_DIALOG_ONE, %EXSTYLE_DIALOG_ONE
         ..
        MCM
        Sure it's easier to read than a long line. but you can't just simply (un)comment a style to test/use it. It has to be eliminated, or moved and commented or ... using your method. Much simpler to just add/remove a ' at the beginning of the line

        Tom: This is an excellent opportunity to take advantage of the compound assignment operator:
        It would have been Tom but I'm not sure it was available when I wrote the Macro (long before I posted it). However were I to do it again ...

        =================================
        "A witty saying proves nothing."
        Voltaire (1694-1778)
        =================================
        It's a pretty day. I hope you enjoy it.

        Gösta

        JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
        LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

        Comment


        • #5
          Sure it's easier to read than a long line. but you can't just simply (un)comment a style to test/use it.
          Code:
          STYLE_DIALOG_ONE =       %WS_VISIBLE _ 
                                            OR %WS_BORDER _ 
                                            OR [COLOR="Red"]%NULL   _    ' let's see what it looks like witout   %WS_CUTE[/COLOR] _
                                            OR %WS_UGLY .......

          DIALOG NEW hOwner, ...... %STYLE_DIALOG_ONE, %EXSTYLE_DIALOG_ONE
          ..MCM
          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment

          Working...
          X