Announcement

Collapse
No announcement yet.

Dialog with Minimize and Close ONLY

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

  • Dialog with Minimize and Close ONLY

    I would like to make a dialog with ONLY the Minimize and Close box, but have found no way to achieve that.
    Is there something I overlooked in DIALOG parms or is there a way to do this by a Win API function call?

    Sample code
    Code:
    #COMPILE EXE
    #DIM ALL
    #INCLUDE ONCE "WIN32API.INC"
    
    %ID_CBX_CAT       = 1001
    %ID_CBX_GOWEB     = 1002
    %ID_BTN_TOOLS     = 1003
    %ID_BTN_INFO      = 1004
    %ID_BTN_FONT      = 1005
    %ID_BTN_LOGIN     = 1006
    
    FUNCTION PBMAIN () AS LONG
       Show_Main_DIALOG(%HWND_DESKTOP)
    END FUNCTION
    
    FUNCTION Show_Main_DIALOG(BYVAL hParent AS DWORD) AS LONG
       LOCAL lRslt, hDlg AS LONG
    
      'I could add " OR %WS_MINIMIZEBOX" to the dialog below, but then I get the maximizebox to.
    
       DIALOG NEW hParent, "My sample", 100, 100, 155, 38, %WS_POPUP OR %WS_BORDER OR %WS_DLGFRAME OR %WS_SYSMENU OR %WS_CLIPSIBLINGS OR _
          %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_TOPMOST OR _
          %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
    
       CONTROL ADD COMBOBOX, hDlg, %ID_CBX_GOWEB,     ,  4,  4, 147, 14, %CBS_DROPDOWNLIST
       CONTROL ADD BUTTON,hDlg, %ID_BTN_TOOLS,"1"     ,  4, 21,  16, 14, %WS_CHILD
       CONTROL ADD BUTTON,hDlg, %ID_BTN_INFO, "2"     , 22, 21,  16, 14, %WS_CHILD
       CONTROL ADD BUTTON,hDlg, %ID_BTN_FONT, "3"     , 40, 21,  16, 14, %WS_CHILD
       CONTROL ADD BUTTON,hDlg, %ID_BTN_LOGIN,"Button", 79, 21,  72, 14, %WS_CHILD
    
       DIALOG SHOW MODAL hDlg, CALL Show_Main_DIALOGProc TO lRslt
       FUNCTION = lRslt
    END FUNCTION
    
    CALLBACK FUNCTION Show_Main_DIALOGProc()
       SELECT CASE AS LONG CB.MSG
          CASE %WM_INITDIALOG
          CASE %WM_NCACTIVATE
             STATIC hWndSaveFocus AS DWORD
             IF ISFALSE CB.WPARAM THEN
                hWndSaveFocus = GetFocus()
             ELSEIF hWndSaveFocus THEN
                SetFocus(hWndSaveFocus)
                hWndSaveFocus = 0
             END IF
          CASE %WM_COMMAND
             SELECT CASE AS LONG CB.CTL
                CASE %ID_CBX_GOWEB
                CASE %ID_BTN_LOGIN
                CASE %ID_BTN_TOOLS
                CASE %ID_BTN_INFO
                CASE %ID_BTN_FONT
             END SELECT
       END SELECT
    END FUNCTION
    /Mikael

  • #2
    Removed answer - misunderstood question..

    Comment


    • #3
      Add %WS_MINIMIZEBOX to the dialog style...

      Comment


      • #4
        Hi Pierre, Pls. take Another look and check my note in the CODE section.
        'I could add " OR %WS_MINIMIZEBOX" to the dialog below, but then I get the maximizebox to.

        I am looking for a dialog window with MINIMIZE and CLOSE boxes ONLY. (without the maximize box)

        Borje: If you have any advice, pls. let me know.

        Appreciate your advice and help /Mikael

        Comment


        • #5
          H Mikael,

          This might be getting close to what you are after?
          Code:
             DIALOG NEW hParent, "My sample", 100, 100, 155, 38, %WS_Caption Or %WS_SysMenu Or %WS_MinimizeBox, _
                                                                 %WS_Ex_ToolWindow Or %WS_EX_AppWindow, To hDlg
          That will let you minimize the app by right-click on the Caption bar or via the icon on the Taskbar. It doesn't have a minimize button but it doesn't show a (disabled) maximize button either
          If you really need a button too it is possible to add your own button to the Caption bar..

          Click image for larger version

Name:	NoMaxBtn.png
Views:	146
Size:	11.2 KB
ID:	774622
          Rgds, Dave

          Comment


          • #6
            Hi Dave and thank you for your suggestion.
            It is really pretty close, but I need to add add a program Icon and a button to minimize in the caption bar.
            /Mikael

            Comment


            • #7
              Without %ws_maximizebox the maximize button is created (along with minimize and exit buttons) but it is grayed and disabled. The maximize item on the system menu is also grayed and disabled. Same on task bar button menu. The user can not maximize the dialog.

              DIALOG SET ICON is used to set the icon. It is not done in DIALOG NEW.

              Cheers,
              Dale

              Comment


              • #8
                Mikael,

                If you take the path of the API design, you use a dialog editor to draw the dialog which you save as a resource script (name .rc) then include the resource in the exe file.
                hutch at movsd dot com
                The MASM Forum

                www.masm32.com

                Comment


                • #9
                  More explicitly:
                  Code:
                    dialog new hParent, "My sample", 100, 100, 155, 38, %ws_popup or _
                       %ws_border or %ws_dlgframe or %ws_sysmenu or %ws_clipsiblings or _
                       %ws_visible or %ds_modalframe or %ds_3dlook or %ds_nofailcreate or _
                       %ds_setfont or %ws_caption or %ws_minimizebox, %ws_ex_controlparent or _
                       %ws_ex_topmost or %ws_ex_left or %ws_ex_ltrreading or _
                                                                    %ws_ex_rightscrollbar, to hDlg
                  Is from your post 1 code. I added the two styles shown in bold. %ws_sysmenu you already had, but it requires %ws_caption. You said you wanted minimize button and %ws_minimizebox adds it. As I said before, the maximize is drawn gray and disabled. To not have maximize at all do as Steve suggested.

                  Cheers,
                  Dale

                  Comment


                  • #10
                    Well, I misunderstood question first and answered with try to use DestroyMenu, etc.
                    I think there is no way to separate the two Min/Max buttons, but one can create own caption using a subclassed label with 2 buttons next to it and handle all self. Small example gfollows - probably need more work with colors and fonts, etc, but as a start:
                    Code:
                    '====================================================================
                    ' Dialog with own caption bar and buttons
                    '--------------------------------------------------------------------
                    #COMPILE EXE
                    #DIM ALL
                    #INCLUDE "WIN32API.INC"
                    %ID_CAPTIONBAR = 110
                    %ID_MINBUTN    = 120
                    GLOBAL oldBarProc AS LONG
                    
                    '====================================================================
                    ' Main entrance
                    '--------------------------------------------------------------------
                    FUNCTION PBMAIN
                      LOCAL hDlg, hFont AS LONG
                    
                      DIALOG NEW 0, "My sample",,, 155, 38, %WS_POPUP OR %WS_DLGFRAME TO hDlg
                    
                      ' Caption bar label - must not cover buttons next to it.
                      CONTROL ADD LABEL, hDlg, %ID_CAPTIONBAR, " My sample Dialog", 0, 0, 135, 10, %SS_NOTIFY
                      CONTROL SET COLOR hDlg, %ID_CAPTIONBAR, GetSysColor(%COLOR_CAPTIONTEXT), _
                                                              GetSysColor(%COLOR_ACTIVECAPTION)
                      '------------------------------------------------------------------
                       'adding a meaningless button style to aviod tabbing to these buttons
                      CONTROL ADD BUTTON, hDlg, %ID_MINBUTN, "---", 135, 0, 10, 10, %BS_VCENTER
                      CONTROL ADD BUTTON, hDlg, %IDCANCEL, "X", 145, 0, 10, 10, %BS_VCENTER
                      '------------------------------------------------------------------
                      FONT NEW "Arial", 10, 1 TO hFont
                      CONTROL SET FONT hDlg, %ID_CAPTIONBAR, hFont
                      CONTROL SET FONT hDlg, %ID_MINBUTN, hFont
                      CONTROL SET FONT hDlg, %IDCANCEL, hFont
                    
                      '------------------------------------------------------------------
                      DIALOG SHOW MODAL hDlg CALL DlgProcedure
                    
                      FONT END hFont
                    
                    END FUNCTION
                    
                    '====================================================================
                    ' Main dialog procedure
                    '--------------------------------------------------------------------
                    CALLBACK FUNCTION DlgProcedure()
                      STATIC hCaptionBar AS LONG
                    
                      SELECT CASE CB.MSG
                      CASE %WM_INITDIALOG
                          CONTROL HANDLE CB.HNDL, %ID_CAPTIONBAR TO hCaptionBar
                          'sub-class captionbar label and let BarProc handle it
                          oldBarProc = SetWindowLong(hCaptionBar, %GWL_WNDPROC, CODEPTR(BarProc))
                    
                      CASE %WM_COMMAND
                          SELECT CASE CBCTL
                          CASE %ID_MINBUTN : ShowWindow(CB.HNDL, %SW_MINIMIZE) ' click taskbar icon to restore
                          CASE %IDCANCEL   : DIALOG END CBHNDL
                          END SELECT
                    
                      CASE %WM_DESTROY
                          IF oldBarProc THEN 'un-subclass captionbar label at exit
                              SetWindowLong hCaptionBar, %GWL_WNDPROC, oldBarProc
                          END IF
                      END SELECT
                    
                    END FUNCTION
                    
                    '====================================================================
                    ' Sub-classed captionbar label procedure
                    '   Handle moving dialog with the mouse
                    '--------------------------------------------------------------------
                    CALLBACK FUNCTION BarProc()
                      SELECT CASE CBMSG
                      CASE %WM_LBUTTONDOWN 'do dragging if mouse down on caption bar label
                          SendMessage GetParent(CBHNDL), %WM_NCLBUTTONDOWN, %HTCAPTION, BYVAL %NULL
                          FUNCTION = 0 : EXIT FUNCTION
                    
                      END SELECT
                    
                      FUNCTION = CallWindowProc(oldBarProc, CBHNDL, CBMSG, CBWPARAM, CBLPARAM)
                    END FUNCTION

                    Comment


                    • #11
                      To add a little on what Börje wrote...
                      So, even if %WS_MINIMIZEBOX the [Maximize] button is visible but disabled,
                      you also want a cosmetic solution that remove it from the view.
                      Sadly, no can do with only setting the style of the dialog.
                      It is going to be more difficult.

                      What version of Windows are you targetting?
                      Does it have to work on non themed, Areo, and Metro?

                      On Areo maybe search those following keywords and try to move the [Minimize] button over the disabled [Maximize] button.
                      OpenThemeData, WP_MAXBUTTON, WP_MINBUTTON, HTMAXBUTTON, HTMINBUTTON, WM_NCHITTEST, WM_GETTITLEBARINFOEX / TITLEBARINFOEX,
                      and something like DrawThemeBackground(hTheme, GetDc(CtrlHandle), WP_MINBUTTON, %CBS_HOT, rc, BYVAL %NULL).
                      Or you could create a dialog with only the [Close] button and add the [Minimize] button.

                      How-to-bold-text-in-the-title
                      Add-a-button-to-the-title-bar
                      Aero Style Classes, Parts, and States
                      DrawThemeBackground
                      Dave Biggs's non-client-area-drawing

                      Click image for larger version  Name:	maxbutton.png Views:	1 Size:	17.0 KB ID:	774632

                      Comment


                      • #12
                        Mikael,
                        See my modified version of Peter Redei's work here. Create your own 24x15 monochrome bitmaps for - and X. It does have a redraw problem that needs to be corrected. Also I don't think the XP Theme changes the look any.
                        Enjoy.

                        Comment


                        • #13
                          You can write to the nonclient area yourself, if you want to.
                          Code:
                          #DIM ALL
                          #INCLUDE ONCE "WIN32API.INC"
                          #RESOURCE BITMAP ghead, "ncahead.bmp"
                          #RESOURCE BITMAP gback, "ncaback.bmp"
                          
                          ENUM controls SINGULAR
                              id_timer = 200
                              id_init
                              grfc
                          END ENUM
                          
                          FUNCTION PBMAIN()
                              LOCAL hDlg  AS DWORD
                              LOCAL lRslt, xsize, ysize, xpos, ypos AS LONG
                              xsize = 640: ysize = 300
                              xpos = (METRICS(MAXIMIZED.X) - xsize) \ 2
                              ypos = (METRICS(MAXIMIZED.Y) - ysize) \ 2
                              DIALOG NEW PIXELS, 0, "Custom NCA", xpos, ypos, xsize, ysize, _
                                  %WS_DLGFRAME OR %WS_VISIBLE OR %DS_NOFAILCREATE TO hDlg
                              DIALOG SET COLOR hDlg, %BLACK, %RGB_BURLYWOOD
                              CONTROL ADD GRAPHIC, hDlg, %grfc, "", 0, 0, xsize, ysize
                              GRAPHIC ATTACH hDlg, %grfc
                              GRAPHIC COLOR %WHITE, %BLACK
                              GRAPHIC CLEAR
                              DIALOG SHOW MODAL hDlg, CALL DLGProc TO lRslt
                              FUNCTION = lRslt
                          END FUNCTION
                          
                          CALLBACK FUNCTION DLGProc() AS LONG
                              LOCAL x, y, sx, sy AS LONG, pt AS POINT
                          
                              SELECT CASE AS LONG CB.MSG
                                  CASE %WM_NCACTIVATE
                                      LOCAL fwnd AS DWORD
                                      fwnd = GetForegroundWindow() 'See if this Dialog is the foreground window
                                      IF fwnd = CB.HNDL THEN settimer(CB.HNDL, %id_timer, 10, 0) 'update ncarea if foreground
                                  CASE %WM_TIMER
                                      SELECT CASE CB.CTL
                                          CASE %id_timer
                                              killtimer(CB.HNDL, %id_timer) 'timer is used to allow Windows time to get out of the way
                                              draw_ncarea CB.HNDL
                                              DIALOG REDRAW CB.HNDL
                                          CASE %id_init
                                              DIALOG REDRAW CB.HNDL
                                              SLEEP 100
                                              killtimer(CB.HNDL, %id_init)
                                              DIALOG POST CB.HNDL, %WM_COMMAND, %grfc, %stn_clicked 'this does nothing, but sets focus to speed startup
                                      END SELECT
                                  CASE %WM_NCPAINT
                                      draw_ncarea CB.HNDL 'intercept and handle message
                                      FUNCTION = 1        'do not allow Aero mode handling
                                  CASE %WM_NCLBUTTONDOWN  'intercept click on nonclient area
                                      getcursorpos(pt)
                                      DIALOG GET LOC CB.HNDL TO x, y
                                      DIALOG GET SIZE CB.HNDL TO sx, sy
                                      sx -= METRICS(FRAME.FIXED.X) * 2
                                      pt.x -= x: pt.y -= y
                                      IF inbox(pt, sx - 55, 8, 20, 14) THEN   'handle minimize control click
                                          DIALOG SHOW STATE CB.HNDL, %SW_MINIMIZE
                                      END IF
                                      IF inbox(pt, sx - 25, 8, 20, 14) THEN   'handle X control click
                                          DIALOG END CB.HNDL
                                      END IF
                                  CASE %WM_INITDIALOG
                                      settimer(CB.HNDL, %id_init, 100, 0)
                                  CASE %WM_COMMAND
                              END SELECT
                          END FUNCTION
                          
                          FUNCTION inbox(pt AS POINT, x AS LONG, y AS LONG, xp AS LONG, yp AS LONG) AS LONG
                              IF (pt.x >= x) AND (pt.x < x + xp) AND (pt.y >= y) AND (pt.y < y + yp) THEN FUNCTION = 1
                          END FUNCTION
                          
                          'This SUB will handle drawing the nonclient area
                          SUB draw_ncarea(hDlg AS DWORD)
                              LOCAL ncDC, bmpDC, hBmp, tbmp AS DWORD, title, fore, back AS STRING, hfont AS LONG
                              LOCAL dx, dy, cx, cy, mx, my AS LONG, transa, transb AS LONG PTR
                              DIALOG GET SIZE hDlg TO dx, dy
                              CONTROL GET SIZE hDlg, %grfc TO cx, cy
                              mx = METRICS(FRAME.FIXED.X)
                              my = METRICS(FRAME.FIXED.Y)
                              GRAPHIC BITMAP LOAD "gback", dx, dy TO hBmp
                              GRAPHIC ATTACH hBmp, 0
                              GRAPHIC GET DC TO bmpDC
                              ncDC = getwindowdc(hDlg) 'get window DC
                              selectobject(bmpDC, 0)   'select bitmap
                              bitblt(ncDC, 0, 0, dx, dy, bmpDC, 0, 0, %srccopy) 'copy bitmap to window
                              GRAPHIC BITMAP END     'end bitmap - releases DC
                              GRAPHIC BITMAP LOAD "ghead", cx, 24 TO hBmp
                              GRAPHIC ATTACH hBmp, 0
                              GRAPHIC GET DC TO bmpDC
                              selectobject(bmpDC, 0)   'select bitmap
                              bitblt(ncDC, mx, my, cx, 24, bmpDC, 0, 0, %srccopy) 'copy bitmap to window
                              releasedc(hDlg, ncDC)  'release dialog DC
                              GRAPHIC BITMAP END     'end bitmap - releases DC
                          END SUB
                          Click image for larger version

Name:	ncahead.bmp
Views:	168
Size:	42.3 KB
ID:	774637Click image for larger version

Name:	ncaback.bmp
Views:	135
Size:	586.7 KB
ID:	774638
                          The world is strange and wonderful.*
                          I reserve the right to be horrifically wrong.
                          Please maintain a safe following distance.
                          *wonderful sold separately.

                          Comment


                          • #14
                            "If you take the path of the API design, you use a dialog editor to draw the dialog which you save as a resource script (name .rc) then include the resource in the exe file."
                            Steve, I have used ResEdit (RC editor), but I can not see how I should be able to create a dialog with only the PROGRAMICON, CAPTION, MINIMIZE and CLOSE (without MAXIMIZE) that way.

                            Pierre, I will do some more research and try the suggestions you wrote.


                            Thank you ALL for the suggested solutions, it gives me a lot of options to try.

                            Click image for larger version

Name:	Samle layout.png
Views:	139
Size:	7.2 KB
ID:	774690


                            /Mikael

                            Comment


                            • #15
                              > ... I can not see how I should be able to create a dialog with only the PROGRAMICON, CAPTION, MINIMIZE and CLOSE (without MAXIMIZE) that way.

                              Hi Mikael, you simply can't. ;-)

                              Comment


                              • #16
                                Custom Window Frame Using DWM looks like a alternative to try.
                                https://docs.microsoft.com/en-us/win...e-client-frame

                                I will try to see if I can figure out how it works and then (if possible) add my own "system" buttons.

                                Links, info, sample code would be much appreciated and welcome if anyone have any experience of using the function DwmExtendFrameIntoClientArea with PB.

                                /Mikael

                                Comment


                                • #17
                                  Hi Mikael,

                                  Couple of links here and more recently here

                                  Best of luck with DWM. Consensus seems to be - "not very enticing"

                                  Did you look into Pierre's suggestion to try to move the [Minimize] button over the disabled [Maximize] button?
                                  Rgds, Dave

                                  Comment


                                  • #18
                                    Hi Dave, no I have not been able to find out how to move the button and I am not so shure that it is a good idea to do so. They have different position in different versions.
                                    I have added my own minimize button beside the X button and that worked fine, but it demands a lot of coding and many things to consider.

                                    I will go on a short holiday now, but I will continue after that with the suggestions and links I have received.

                                    Borje, the sample code you supplied was really a very good starting Point. The coding is clear, fairly easy and the program becomes consistent in almost any version of Windows. No messing with DWM and Themes. I shall add some more functionality to it and see where it will end up.

                                    /Mikael

                                    Comment


                                    • #19
                                      Mikael, yes you can with this.

                                      Comment


                                      • #20
                                        That removing the maximized button rather than just disabling it would confuse my people from what they might consider to be a windows standard and i have a hard enough time getting them to learn standards
                                        Here is a good example. I used the windows msgbox to display a message where something was running in a batch process and i use taskkill to destroy the message box when the process is over but the process could hangup or crash before it got to the taskkill command
                                        the message in the msgbox said something like this
                                        WARNING WARNING WARNING
                                        PDF files are being built.
                                        This box will close by itself shortly.
                                        After the pdf fikes are built
                                        do not close this box

                                        i just used the OK button in the msgbox
                                        guess what they did
                                        some where pressing the OK button to confirm they read the message
                                        i left the ok button in so only if the newly processes we are implementing did not finish while we implement the new batch code. I hide the window of important batch proceses to keep the, from being stooped by a user.
                                        The msgbox was only to let them know something was running and for them to wait and not do something like roboot, shutdown or start another instance of the program
                                        p purvis

                                        Comment

                                        Working...
                                        X