Author Topic: Beginners' dialog  (Read 1318 times)

0 Members and 2 Guests are viewing this topic.

Karen Zibowski

  • Guest
Beginners' dialog
« on: February 28, 2018, 08:48:19 AM »
Hi

I would like to make a simple dialog as shown below. How to code this dialog?.
Thank you
Regards
Karen



[attachment deleted by admin]

Karen Zibowski

  • Guest
Re: Beginners' dialog
« Reply #1 on: February 28, 2018, 10:04:15 AM »
The PowerBasic codes for this dialog is

Code: [Select]
#COMPILE EXE
#DIM ALL


    ' It has a nice rect frame on its dialog

 %LabelResults = 101
 %Button = 102
 %txtboxResults = 103
%IDC_Statusbar = 1060

GLOBAL  FlagExit AS LONG
GLOBAL hDlg AS DWORD
GLOBAL resix AS DOUBLE

#INCLUDE "Win32API.inc"


'---------------------------
FUNCTION PBMAIN () AS LONG

   DIALOG FONT "Arial", 9
   DIALOG NEW %HWND_DESKTOP, "Test Dialog", , , 250, 150, _
           %WS_CAPTION OR %WS_SYSMENU  OR %WS_THICKFRAME, 0 TO hDlg


     CONTROL ADD LABEL, hDlg, %LabelResults, "Results",  5, 5, 50, 11, _
         %SS_RIGHT, %WS_EX_LEFT
     CONTROL SET COLOR hDlg, %LabelResults , %RGB_DARKBLUE, -2

     CONTROL ADD TEXTBOX, hDlg, %txtboxResults, "", 65, 5, 130, 12, _
        %ES_LEFT OR %WS_BORDER OR %WS_TABSTOP, %WS_EX_LEFT OR %WS_EX_CLIENTEDGE


     CONTROL ADD BUTTON, hDlg, %Button,"Do SomeThin",  25, 45,52,22

     CONTROL ADD STATUSBAR, hdlg, %IDC_StatusBar, "", 0,0,0,0,%CCS_BOTTOM,%WS_EX_WINDOWEDGE
     STATUSBAR SET PARTS hDlg, %IDC_StatusBar, 95,99999


     DIALOG SHOW MODAL hDlg CALL DlgProc



END FUNCTION






 '--------------------------------
 CALLBACK FUNCTION DlgProc

  SELECT CASE CBMSG

      CASE %WM_INITDIALOG
          FlagExit = 0
          LOCAL sTextSb AS STRING
          ' This makes each part owndrawn - see %WM_DRAWITEM
          ' %SB_SETTEXT is 0-based, so part 0 = DDT part 1, etc.
          CONTROL SEND CB.HNDL, %IDC_StatusBar, %SB_SETTEXT, 0 OR %SBT_OWNERDRAW, 0
          sTextSb = " Enter characters only"
          CONTROL SEND CB.HNDL, %IDC_StatusBar, %SB_SETTEXT, 1 OR %SBT_OWNERDRAW, STRPTR(sTextSb)



  CASE %WM_DRAWITEM
       'draw ownerdrawn parts on the Statusbar
      LOCAL hBrushS, hPenS AS DWORD
       LOCAL zpS AS ASCIIZ PTR, lpdis AS DRAWITEMSTRUCT PTR

      IF CB.WPARAM = %IDC_StatusBar THEN
          lpdis = CB.LPARAM
          hBrushS = SelectObject(@lpdis.hDc, GetStockObject(%NULL_BRUSH))
          ' box color for the statusbar using a width of 2
          hPenS   = CreatePen(%PS_SOLID, 2,%RGB_MAGENTA )
          hPenS   = SelectObject(@lpdis.hDc, hPenS)

           'status bar text background
          SetBkColor @lpdis.hDC,%RGB_AZURE
          'statusbar text color
          SetTextColor @lpdis.hDC,%RGB_BLUE        '   %RGB_LIME
           'get text
          zpS = @lpdis.itemData
           'draw text
          DrawText @lpdis.hDC, @zpS, LEN(@zpS), @lpdis.rcItem, _
                   %DT_CENTER OR %DT_SINGLELINE OR %DT_VCENTER
          Rectangle @lpdis.hDC, @lpdis.rcItem.nLeft, @lpdis.rcItem.nTop, _
             @lpdis.rcItem.nRight, @lpdis.rcItem.nBottom

          SelectObject @lpdis.hDc, hBrushS
          'return original pen and delete the one we created
          DeleteObject SelectObject(@lpdis.hDc, hPenS)
          FUNCTION = 1
          EXIT FUNCTION
      END IF


    CASE %WM_PAINT
      paintDlgborder CB.HNDL


      CASE %WM_COMMAND
           SELECT CASE CBCTL


             CASE %Button
              ' to do somethin, display results and exit the program
              IF (CBCTLMSG = %BN_CLICKED) OR (CBCTLMSG = 1) THEN

                   ' update status bar
                   sTextSb = " Some text was entered "
                   CONTROL SEND CB.HNDL, %IDC_StatusBar, %SB_SETTEXT, 1 OR %SBT_OWNERDRAW, STRPTR(sTextSb)

                    dosomethin
                   CONTROL SET TEXT hDlg, %txtboxResults,  STR$(resix)

                  IF FlagExit = 1 THEN
'                      DIALOG DISABLE CB.HNDL
                    ' pause for 1 secs
                      SLEEP(1000)

                      DIALOG END hDlg
                '     exit the system
                      EXIT FUNCTION
                  END IF
              END IF


       END SELECT

     END SELECT

 END FUNCTION


'-------------------------------------------
 ' Routine to paint the Internal dialog border
 ' to make it look stunning
 ' This takes care of the Statusbar
SUB paintDlgborder( dlgH AS DWORD)

         LOCAL hdgBrush, hdgPen  AS DWORD
         LOCAL rcdg, rcsb , rcb AS RECT
         LOCAL psdg  AS PAINTSTRUCT

         ' get dialog clientarea and statusbar height to "frame"
          GetClientRect dlgH, rcdg

          ' get rectangle of statusbar
          GetWindowRect GetDlgItem(dlgH, %IDC_Statusbar), rcsb
          MapWindowPoints 0, dlgH, BYVAL VARPTR(rcsb), 2

          'get button's pos and size on screen
          GetWindowRect GetDlgItem(dlgH, %Button), rcb
          'map rect to dialog
          MapWindowPoints 0, dlgH, BYVAL VARPTR(rcb), 2




          BeginPaint dlgH, psdg

             ' frame dialog button
              Rectangle psdg.hDC, rcb.nLeft-1, rcb.nTop-1, rcb.nRight+1, rcb.nBottom+1


              '   create pen with desired color       ' cyan , magenta and yellow are ok
              ' using a width of 1
              hdgPen   = CreatePen(%PS_SOLID, 1, %RGB_MAGENTA)
            ' select pen into control's dc
              hdgPen   = SelectObject(psdg.hDc, hdgPen)
             'prepare for hollow rect
              hdgBrush = SelectObject(psdg.hDc, GetStockObject(%NULL_BRUSH))

              ' frame dialog client area minus statusbar height and draw its rectangle
              Rectangle psdg.hDC, rcdg.nLeft, rcdg.nTop, _
                                  rcdg.nRight, rcdg.nBottom - (rcsb.nBottom - rcsb.nTop) '-4


             'return original brush
              SelectObject psdg.hDc, hdgBrush
              DeleteObject SelectObject(psdg.hDc, hdgPen)
          EndPaint dlgH, psdg
 END SUB



 '---------------------
 ' do something and return  FlagExit = 1
 ' upon completion
 SUB dosomethin
      LOCAL I AS LONG
      LOCAL ix AS DOUBLE

      FOR I = 1 TO 100
            ix = I + (ix + 21) *2
      NEXT I

      MSGBOX " did some thing and then exit " + $CRLF + $CRLF + _
                STR$(ix)


      FlagExit = 1
      resix = ix

 END SUB
         


JRS

  • Guest
Re: Beginners' dialog
« Reply #2 on: February 28, 2018, 10:09:18 AM »
Welcome Karen!

Glad to have a female perspective to the project.

John


Charles Pegge

  • Guest
Re: Beginners' dialog
« Reply #3 on: February 28, 2018, 10:45:56 AM »
We have a good selection of dialogs, thanks to Roland. They are included in OxygenBasicProgress.zip (as of 2 Feb 2018) in examples\WinDynDialogs

https://github.com/Charles-Pegge/OxygenBasic/blob/master/oxygenBasicProgress.zip


Karen Zibowski

  • Guest
Re: Beginners' dialog
« Reply #4 on: February 28, 2018, 09:08:48 PM »
Thanks I'll will check it out