Announcement

Collapse
No announcement yet.

A Newbie needs help

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

  • A Newbie needs help

    Can someone help me with the following code. I thought when buttons are disabled they receive no messages, but when I click on the buttons twice I get the spinning busy signal from windows. I even did a Control Hide on the buttons but if I click anywhere on the dialog it messes up,now I may have to click twice to cause it. I would like for the progress bars to finish without being interrupted. I know it is something I am doing wrong or something I am not doing but can someone help me.



    Code:
    #COMPILE EXE
    #DIM ALL
    '#RESOURCE BITMAP, 101, "Q_D_Start.bmp"
    '#RESOURCE BITMAP, 102, "Q_D_Exit.bmp"
    
    #INCLUDE "WIN32API.INC"
    
    DECLARE CALLBACK FUNCTION DlgMainProc
    '------------------------------------------------------------------------------
    %ID_BUTNSTART   = 301
    %ID_LABEL1      = 150
    %ID_LABEL2      = 155
    %ID_BAR1        = 202
    %ID_BAR2        = 203
    %ID_BAR3        = 204
    %ID_BUTNEXIT    = 305
    
    GLOBAL pBar&
    
    FUNCTION PBMAIN () AS LONG
      FONT NEW "Comic Sans MS",10,1,0,1 TO pBar&
    
      GLOBAL hDlg AS DWORD
    
      DIALOG NEW UNITS,0, "TRIPPEL-BAR demo", ,, 250, 120, %WS_CAPTION OR %WS_SYSMENU TO hDlg
      DIALOG SET COLOR hDlg, %RGB_GRAY, %RGB_NAVY
    
    '  CONTROL ADD IMGBUTTONX, hDlg, %ID_BUTNSTART, "#101", 85, 70, 80, 18
    '  CONTROL ADD IMGBUTTONX, hDlg, %ID_BUTNEXIT,  "#102", 97,95,58,16
      CONTROL ADD BUTTON, hDlg, %ID_BUTNSTART, "START BARS", 85,70,80,18
      CONTROL ADD BUTTON, hDlg, %ID_BUTNEXIT, "EXIT", 97,95,58,16
      CONTROL ADD LABEL, hDlg, %ID_LABEL1,"",48,5,154,14,%SS_CENTER OR %SS_CENTERIMAGE, %WS_EX_CLIENTEDGE
      CONTROL SET COLOR hDlg, %ID_LABEL1, %RGB_BLACK, %RGB_WHITE
      CONTROL SET FONT hDlg,%ID_LABEL1,pBar&
      CONTROL ADD LABEL, hDlg, %ID_LABEL2,"",65,44,120,14,%SS_CENTER OR %SS_CENTERIMAGE, %WS_EX_CLIENTEDGE
      CONTROL SET COLOR hDlg, %ID_LABEL2, %RGB_BLACK, %RGB_WHITE
      CONTROL SET FONT hDlg,%ID_LABEL2,pBar&
    
      CONTROL ADD PROGRESSBAR, hDlg, %ID_BAR1,"", 5, 24, 82, 15, %PBS_SMOOTH
      CONTROL SET COLOR hDlg,%ID_BAR1,%RGB_RED,%RGB_GRAY
      CONTROL ADD PROGRESSBAR, hDlg, %ID_BAR2,"", 81, 24, 83, 15, %PBS_SMOOTH
      CONTROL SET COLOR hDlg,%ID_BAR2,%RGB_YELLOW,%RGB_GRAY
      CONTROL ADD PROGRESSBAR, hDlg, %ID_BAR3,"", 161, 24, 84, 15, %PBS_SMOOTH
      CONTROL SET COLOR hDlg,%ID_BAR3,%RGB_BLUE,%RGB_GRAY
    
      CONTROL ADD LABEL, hDlg, -1, "", 5, 24, 240, 15, 0, %WS_EX_TRANSPARENT OR %WS_EX_CLIENTEDGE
      CONTROL SET COLOR hDlg, -1,%RGB_GRAY,%RGB_GRAY
    
      DIALOG SHOW MODAL hDlg, CALL DlgMainProc
    END FUNCTION
    
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Main dialog callback procedure
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    CALLBACK FUNCTION DlgMainProc
      LOCAL P&,P2&
       SELECT CASE CBMSG
         CASE %WM_COMMAND
            IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
               SELECT CASE CBCTL
                  CASE %ID_BUTNSTART
                      CONTROL DISABLE hDlg,%ID_BUTNEXIT
                      CONTROL DISABLE hDlg,%ID_BUTNSTART
                      PROGRESSBAR SET RANGE hDlg, %ID_BAR1, 0,80
                      PROGRESSBAR SET RANGE hDlg, %ID_BAR2, 81,162
                      PROGRESSBAR SET RANGE hDlg, %ID_BAR3, 162,242
                      PROGRESSBAR SET POS hDlg,%ID_BAR1,0
                      PROGRESSBAR SET POS hDlg,%ID_BAR2,81
                      PROGRESSBAR SET POS hDlg,%ID_BAR3,162
                      CONTROL SET TEXT hDlg,%ID_LABEL1,""
                      P2& = 1 : P3& = 1
                      FOR P& = 0 TO 240
                         SELECT CASE P&
                            CASE < 82
                               IF P& = 0 THEN
                                  CONTROL SET TEXT hDlg,%ID_LABEL1,"Printing Manifest at this time"
                                  CONTROL SET COLOR hDlg,%ID_LABEL2,%RGB_BLACK,%RGB_RED
                                  CONTROL SET COLOR hDlg,%ID_LABEL1,%RGB_BLACK,%RGB_RED
                                  CONTROL REDRAW hDlg,%ID_LABEL1
                                  CONTROL REDRAW hDlg,%ID_LABEL2
                               END IF
                               PROGRESSBAR STEP hDlg, %ID_BAR1,P2&
                            CASE 82 TO 161
                               IF P& = 82 THEN
                                  CONTROL SET TEXT hDlg,%ID_LABEL1,"Printing Invoice at this time"
                                  CONTROL SET COLOR hDlg,%ID_LABEL1,%RGB_BLACK, %RGB_YELLOW
                                  CONTROL SET COLOR hDlg,%ID_LABEL2,%RGB_BLACK,%RGB_YELLOW
                                  CONTROL REDRAW hDlg,%ID_LABEL1
                                  CONTROL REDRAW hDlg,%ID_LABEL2
                               END IF
                               PROGRESSBAR STEP hDlg,%ID_BAR2,P2&
                            CASE > 162
                               IF P& = 162 THEN
                                  CONTROL SET TEXT hDlg,%ID_LABEL1,"Printing Bill of Lading at this time"
                                  CONTROL SET COLOR hDlg,%ID_LABEL1,%RGB_WHITE,%RGB_BLUE
                                  CONTROL SET COLOR hDlg,%ID_LABEL2,%RGB_WHITE,%RGB_BLUE
                                  CONTROL REDRAW hDlg,%ID_LABEL1
                                  CONTROL REDRAW hDlg,%ID_LABEL2
                               END IF
                               PROGRESSBAR STEP hDlg,%ID_BAR3,P2&
                         END SELECT
                         SLEEP 50
                         CONTROL SET TEXT hDlg,%ID_LABEL2,"Processing "+ FORMAT$(P&/240,"#%"" Complete""")
                      NEXT P&
                      CONTROL ENABLE hDlg,%ID_BUTNEXIT
                      CONTROL ENABLE hDlg,%ID_BUTNSTART
                 CASE %ID_BUTNEXIT
                     DIALOG END hDlg
               END SELECT
            END IF
       END SELECT
    END FUNCTION

  • #2
    Looks like SLEEP 50 casues some sort of built-up message halt. If you add DIALOG DOEVENTS to the loop, for example at the top, right under FOR P& = 0 TO 240, it seems to work like expected.

    Comment


    • #3
      Mr. Borje Hagsten

      Thank you very much sir, that fixes the problem I would have never thought of the Sleep thing. You need to write a book for powerbasic programming, I would be the first to purchase it. You have done some amazing things most of which are far above my knowledge. Thanks again for the help.

      Comment

      Working...
      X