Announcement

Collapse
No announcement yet.

Owner Drawn Combobox Error Correction

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

  • Owner Drawn Combobox Error Correction

    I have code from Chris Boss, Pierre Bellisle, and Borje Hagsten, that all three demonstrate some functionality of an owner-drawn Combobox. Although nicely done, and well documented. However all three compile and run correctly only the 1st time. From that time on, unless I rename the *.bas file, I get the error "Destination file write error".

    I have watched the process in process viewer, and they do disappear when I close the demo. But if I hit "Compile and Run" again, I get my error.

    I have looked over the code of each but can not pick out what may be lingering in the system that I can not recompile?

    Can anyone correct or show me the error? I get the same results if I compile for debug as well.


    For ease of demonstrating the problem, each contributors code is seen below

    Chris Boss
    Code:
    #COMPILE EXE '#Win 8.03#
    #DIM ALL
    #INCLUDE "WIN32API.INC" '#2005-01-27#
    %Combobox = 101
    GLOBAL hDlg          AS DWORD
    GLOBAL hCombobox     AS DWORD
    '
    ' ---------------------------------------------------------------------------
    '         OwnerDraw Code By Chris Boss - put into Public Domain (2007)
    '                            http://cwsof.com
    ' ---------------------------------------------------------------------------
    '                    Simplfied OwnerDraw routines:
    ' ---------------------------------------------------------------------------
    '
    ' ---------------------------------------------------------------------------
    ' lParam&:   lParam value for %WM_DRAWITEM
    ' ItemNum&:  returns item index number
    ' IText$:    returns item text
    ' ---------------------------------------------------------------------------
    '
    FUNCTION OD_GetInfo(BYVAL lParam&, ItemNum&, IText$) AS LONG     ' returns control ID number
         LOCAL zT AS ASCIIZ * 1025
         LOCAL ODR AS DRAWITEMSTRUCT PTR
         ODR=lParam&
         IF @ODR.CtlType=%ODT_COMBOBOX OR @ODR.CtlType=%ODT_LISTBOX THEN
              ItemNum&[email protected]
              IF @ODR.CtlType=%ODT_LISTBOX THEN
                   SendMessage @ODR.hwndItem, %LB_GETTEXT, ItemNum&, VARPTR(zT)
              ELSE
                   IF (@ODR.itemState AND %ODS_COMBOBOXEDIT) = %ODS_COMBOBOXEDIT THEN
                       GetWindowText @ODR.hwndItem, zT, 1025
                   ELSE
                       SendMessage @ODR.hwndItem, %CB_GETLBTEXT, ItemNum&, VARPTR(zT)
                   END IF
              END IF
              IText$=zT
              FUNCTION = @ODR.CtlID
         END IF
    END FUNCTION
    '
    ' ---------------------------------------------------------------------------
    ' lParam&:  lParam value from %WM_DRAWTEXT message
    ' IText$:   Text for item
    ' TXColor&: text color (use -1 for default)
    ' BGColor&: background color (use -1 for default)
    ' TProp$:   (properties) C - center text, R - right justify, L - left justify, M - multiline, F - show focus rectangle,
    ' ---------------------------------------------------------------------------
    '
    SUB OD_DrawText(BYVAL lParam&, BYVAL IText$, BYVAL TXColor&, BYVAL BGColor&, BYVAL TProp$)
         LOCAL ODR AS DRAWITEMSTRUCT PTR, XFlag&
         LOCAL hNewBrush&, TFormat&, RC AS RECT, LOffset&
         ODR=lParam&
         TProp$=UCASE$(TProp$)
         LOffset&=8    ' left margin offset
         IF @ODR.hdc<>0 THEN
              SaveDC @ODR.hDC
              IF (@ODR.itemState AND %ODS_SELECTED) = %ODS_SELECTED THEN
                   TXColor&=GetSysColor(%COLOR_HIGHLIGHTTEXT)
                   BGColor&=GetSysColor(%COLOR_HIGHLIGHT)
              ELSE
                   IF TXColor&=-1 THEN TXColor&=GetSysColor(%COLOR_WINDOWTEXT)
                   IF BGColor&=-1 THEN BGColor&=GetSysColor(%COLOR_WINDOW)
              END IF
              hNewbrush&=CreateSolidBrush(BGColor&)
              SelectObject @ODR.hDC, hNewbrush&
              FillRect @ODR.hDC, @ODR.rcItem, hNewBrush&
              SetBKColor @ODR.hDC, BGColor&
              SetTextColor @ODR.hDC, TXColor&
              RC = @ODR.rcItem
              IF INSTR(TProp$, "R") THEN
                   TFormat&=TFormat& OR %DT_RIGHT
              ELSE
                   IF INSTR(TProp$,"C") THEN TFormat&=TFormat& OR %DT_CENTER ELSE TFormat&=TFormat& OR %DT_LEFT
              END IF
              IF INSTR(TProp$, "M")=0 THEN
                   TFormat&=TFormat& OR %DT_SINGLELINE OR %DT_VCENTER
              END IF
              RC.nLeft=RC.nLeft+LOffset&
              DrawText @ODR.hDC, BYVAL STRPTR(IText$), LEN(IText$), RC, TFormat&
              IF (@ODR.itemState AND %ODS_FOCUS) = %ODS_FOCUS THEN
                   IF INSTR(TProp$,"F") THEN DrawFocusRect @ODR.hDC, @ODR.rcItem
              END IF
              RestoreDC @ODR.hDC, -1
              DeleteObject hNewBrush&
         END IF
    END SUB
    '
    CALLBACK FUNCTION DlgProc
         LOCAL ItemNum&, IText$
         SELECT CASE CBMSG
              CASE %WM_COMMAND
                   SELECT CASE CBCTL
                        CASE %IDOK
                             DIALOG END CBHNDL
                        CASE %Combobox
                             IF HIWRD(CBWPARAM) = %CBN_SELENDOK THEN
                             END IF
                   END SELECT
              CASE %WM_DRAWITEM
                   SELECT CASE OD_GetInfo(CBLPARAM, ItemNum&, IText$)     ' returns control ID #
                        CASE %Combobox
                             LOCAL C1&, C2&
                             C1&=RGB(0,0,0)
                             IF itemNum& MOD 2 = 1 THEN C2&=RGB(164,225,225) ELSE C2&=RGB(224,255,255)
                             OD_DrawText CBLPARAM, IText$, C1&, C2&, "LF"
                        CASE ELSE
                   END SELECT
              CASE ELSE
         END SELECT
    END FUNCTION
    '
    FUNCTION PBMAIN
         DIM ComboArray(0 TO 5) AS STRING
         ComboArray(0) = "Black"
         ComboArray(1) = "Green"
         ComboArray(2) = "Red"
         ComboArray(3) = "Brown"
         ComboArray(4) = "Gray"
         ComboArray(5) = "Yellow"
         DIALOG NEW %HWND_DESKTOP, "Color Combo", , , 120, 80, %WS_SYSMENU TO hDlg
         SetClassLong hDlg, %GCL_HICON, LoadIcon(BYVAL %NULL, BYVAL %IDI_INFORMATION) 'Have a nice icon
         CONTROL ADD COMBOBOX, hDlg, %Combobox, ComboArray(), 10, 10, 100, 120, _
              %CBS_OWNERDRAWFIXED OR %CBS_HASSTRINGS OR %CBS_DROPDOWNLIST OR _
              %WS_TABSTOP OR %CBS_DISABLENOSCROLL OR %WS_VSCROLL
              hCombobox = GetDlgItem(hDlg, %Combobox)
              SendMessage(hCombobox, %CB_SETCURSEL, 0, 0)
         CONTROL ADD BUTTON, hDlg, %IDOK, "&Close", 30, 35, 60, 14
         DIALOG SHOW MODAL hDlg, CALL DlgProc
    END FUNCTION
    Pierre Bellisle
    Code:
    #COMPILE EXE '#Win 8.03#
    #DIM ALL
    #INCLUDE "WIN32API.INC" '#2005-01-27#
     
    %Combobox = 101
     
    GLOBAL hDlg          AS DWORD
    GLOBAL hCombobox     AS DWORD
    '______________________________________________________________________________
     
    CALLBACK FUNCTION DlgProc
     LOCAL lpdis      AS DRAWITEMSTRUCT PTR
     LOCAL zTxt       AS ASCIIZ * 64
     LOCAL rct        AS RECT
     LOCAL hBrush     AS DWORD
     LOCAL hBrushPrev AS DWORD
     LOCAL SomeColor  AS DWORD
     
     SELECT CASE CBMSG
     
       CASE %WM_COMMAND
         SELECT CASE CBCTL
     
           CASE %IDOK
             DIALOG END CBHNDL
     
           CASE %Combobox
             IF HIWRD(CBWPARAM) = %CBN_SELENDOK THEN
             END IF
         END SELECT
     
       CASE %WM_DRAWITEM
         IF CBWPARAM = %Combobox THEN
     
           lpdis = CBlParam
           IF @lpdis.itemID <> -1 THEN 'Valid selection
     
             SELECT CASE @lpdis.itemAction
               CASE %ODA_DRAWENTIRE, %ODA_SELECT
     
                 'Background color outside text area
                 IF @lpdis.itemID MOD 2 THEN
                   SomeColor = RGB(225, 225, 225)
                 ELSE
                   SomeColor = RGB(190, 190, 190)
                 END IF
                 hBrush = CreateSolidBrush(SomeColor)
                 hBrushPrev = SelectObject(@lpdis.hDC, hBrush)   'Select brush into device context
                 CALL FillRect(@lpdis.hDC, @lpdis.rcItem, hBrush)'Paint background color rectangle
                 CALL SelectObject(@lpdis.hDC, hBrushPrev)       'Select old brush back
                 CALL DeleteObject(hBrush)                       'Delete brush
     
                 'Text fore color and text background color
                 CALL SendMessage(hCombobox, %CB_GETLBTEXT, @lpdis.itemID, VARPTR(zTxt)) 'Get text
                 CALL SetBkColor(@lpdis.hDC, SomeColor)                               'Set text Background
                 CALL SetTextColor(@lpdis.hDC, GetSysColor(%COLOR_WINDOWTEXT))        'Set text color
                 CALL TextOut(@lpdis.hDC, 2, @lpdis.rcItem.ntop + 2, zTxt, LEN(zTxt)) 'Draw text
     
                 'If item is selected
                 IF (@lpdis.itemState AND %ODS_SELECTED) THEN          'If selected
                   rct.nLeft   = 2 : rct.nRight = @lpdis.rcItem.nRight 'Set cordinates
                   rct.ntop    = @lpdis.rcItem.ntop
                   rct.nbottom = @lpdis.rcItem.nbottom
                   CALL InvertRect(@lpdis.hDC, rct)                    'Invert area around text only
                   CALL DrawFocusRect(@lpdis.hDC, @lpdis.rcItem)       'Draw a focus rectangle around all
                 END IF
     
             END SELECT
             FUNCTION = %TRUE
             EXIT FUNCTION
           END IF
     
         END IF
     
     END SELECT
     
    END FUNCTION
    '______________________________________________________________________________
     
    FUNCTION PBMAIN
     DIM ComboArray(0 TO 5) AS STRING
     
     ComboArray(0) = "Black"
     ComboArray(1) = "Green"
     ComboArray(2) = "Red"
     ComboArray(3) = "Brown"
     ComboArray(4) = "Gray"
     ComboArray(5) = "Yellow"
     
     DIALOG NEW %HWND_DESKTOP, "Color Combo", , , 120, 80, %WS_SYSMENU TO hDlg
     
     SetClassLong hDlg, %GCL_HICON, LoadIcon(BYVAL %NULL, BYVAL %IDI_INFORMATION) 'Have a nice icon
     
     CONTROL ADD COMBOBOX, hDlg, %Combobox, ComboArray(), 10, 10, 100, 120, _
       %CBS_OWNERDRAWFIXED OR %CBS_HASSTRINGS OR %CBS_DROPDOWNLIST OR _
       %WS_TABSTOP OR %CBS_DISABLENOSCROLL OR %WS_VSCROLL
     hCombobox = GetDlgItem(hDlg, %Combobox)
     SendMessage(hCombobox, %CB_SETCURSEL, 0, 0)
     
     CONTROL ADD BUTTON, hDlg, %IDOK, "&Close", 30, 35, 60, 14
     
     DIALOG SHOW MODAL hDlg, CALL DlgProc
     
    END FUNCTION
    '_____________________________________________________________________________
    Borje Hagsten
    Code:
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' ComboBox Color list, ownerdrawn - by Borje Hagsten, January 2001.
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Needed a goodlooking color pick Combo for a setup dialog, so wrote
    ' this one. Maybe could be useful for someone else, so.. :-)
    ' 
    ' Thanks to: Chris Boss, for the original GetQBColor function.
    ' Public Domain, feel free to use and customize as you like.
    ' Code is commented, should be easy to follow. GDI stuff should be
    ' safe, no leaks. Still, as always, use at own "risk".. :-)
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Declares
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    #COMPILE EXE
    #INCLUDE "WIN32API.INC"
     
    %ID_LABEL1 = 100
    %ID_COMBO1 = 120
    GLOBAL oldCBproc AS LONG 'for subclassing, to hold original window procedure address
     
    DECLARE CALLBACK FUNCTION DlgProc
    DECLARE FUNCTION GetQBColor(BYVAL c AS LONG) AS LONG
    DECLARE FUNCTION CBProc(BYVAL hWnd AS LONG, BYVAL wMsg AS LONG, _
                           BYVAL wParam AS LONG, BYVAL lParam AS LONG) AS LONG
     
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Main dialog callback
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    CALLBACK FUNCTION DlgProc
      SELECT CASE CBMSG
         CASE %WM_COMMAND
            SELECT CASE CBCTL
               CASE %IDOK : DIALOG END CBHNDL       'Exit
     
               CASE %ID_COMBO1
                  IF HIWRD(CBWPARAM) = %CBN_SELENDOK THEN
                     'You can trap changes in selection here, if needed. Uncomment
                     'the following code to see a way of picking selected color.
                     'Can also be used in other place, like checking before exit, etc.
     
                     'LOCAL col AS LONG            'returns selected color
                     'col = GetQBColor(SendMessage(CBLPARAM, %CB_GETCURSEL, 0, 0))
                     'MSGBOX "&H" + HEX$(col)
                     'FUNCTION = 0: EXIT FUNCTION
                  END IF
            END SELECT
     
         CASE %WM_DESTROY 'Un-subclass Combobox
            IF oldCBproc THEN
               SetWindowLong GetDlgItem(CBHNDL, %ID_COMBO1), %GWL_WNDPROC, oldCBproc
            END IF
     
         CASE %WM_DRAWITEM, %WM_MEASUREITEM 'Pass these on to CBproc
            IF CBWPARAM = %ID_COMBO1 THEN
               CBProc GetDlgItem(CBHNDL, %ID_COMBO1), CBMSG, CBWPARAM, CBLPARAM
               FUNCTION = 0: EXIT FUNCTION
            END IF
     
      END SELECT
     
    END FUNCTION
     
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Subclassed Combobox procedures
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    FUNCTION CBProc(BYVAL hWnd AS LONG, BYVAL wMsg AS LONG, _
                           BYVAL wParam AS LONG, BYVAL lParam AS LONG) AS LONG
      SELECT CASE wMsg
         CASE %WM_MEASUREITEM 'Don't need it here, keep it for ev. future use
         CASE %WM_DRAWITEM
            LOCAL hBrush AS LONG, hBrushOld AS LONG, rct AS RECT
            LOCAL lpdis  AS DRAWITEMSTRUCT PTR, zTxt AS ASCIIZ * 64
            lpdis = lParam
            IF @lpdis.itemID = -1 THEN EXIT FUNCTION
     
            SELECT CASE @lpdis.itemAction
               CASE %ODA_DRAWENTIRE, %ODA_SELECT
                  'CLEAR BACKGROUND
                  hBrush = CreateSolidBrush(GetSysColor(%COLOR_WINDOW)) 'Create a background brush
                  hBrushOld = SelectObject(@lpdis.hDC, hBrush)      'Select brush into device context
                  CALL FillRect(@lpdis.hDC, @lpdis.rcItem, hBrush)  'Paint background color rectangle
                  CALL SelectObject(@lpdis.hDC, hBrushOld)          'Select old brush back
                  CALL DeleteObject(hBrush)                         'Delete brush
     
                  'DRAW TEXT
                  CALL SetBkColor(@lpdis.hDC, GetSysColor(%COLOR_WINDOW))                   'Set text Background
                  CALL SetTextColor(@lpdis.hDC, GetSysColor(%COLOR_WINDOWTEXT))             'Set text color
                  CALL SendMessage(hWnd, %CB_GETLBTEXT, @lpdis.itemID, VARPTR(zTxt)) 'Get text
                  CALL TextOut(@lpdis.hDC, 28, @lpdis.rcItem.ntop + 2, zTxt, LEN(zTxt)) 'Draw text
     
                  'SELECTED ITEM
                  IF (@lpdis.itemState AND %ODS_SELECTED) THEN      'if selected
                     rct.nLeft   = 26 : rct.nRight = @lpdis.rcItem.nRight 'Set cordinates
                     rct.ntop    = @lpdis.rcItem.ntop
                     rct.nbottom = @lpdis.rcItem.nbottom
                     CALL InvertRect(@lpdis.hDC, rct)               'invert area around text only
                     CALL DrawFocusRect(@lpdis.hDC, @lpdis.rcItem)  'and draw a focus rectangle around all
                  END IF
     
                  'PAINT COLOR RECTANGLE (using RoundRect for nicer looks.. :-)
                  ' Here you can customize if you like - like BitBlt bitmaps via a memDC
                  ' instead, or use DrawFrameControl to draw a "fake" checkbox, etc..
                  rct.nLeft   = 4 : rct.nRight = 24                    'Set cordinates
                  rct.ntop    = @lpdis.rcItem.ntop + 2
                  rct.nbottom = @lpdis.rcItem.nbottom - 2
                  hBrush = CreateSolidBrush(GetQBColor(@lpdis.itemID)) 'Create brush with proper color
                  hBrushOld = SelectObject(@lpdis.hDC, hBrush)         'Select brush into device context
                  CALL RoundRect(@lpdis.hDC, rct.nLeft, rct.ntop, rct.nRight, rct.nbottom, 3, 3) 'Draw
                  CALL SelectObject(@lpdis.hDC, hBrushOld)             'Select old brush back
                  CALL DeleteObject(hBrush)                            'Delete brush
     
            END SELECT
            FUNCTION = %TRUE : EXIT FUNCTION
     
      END SELECT
      FUNCTION = CallWindowProc(oldCBproc, hWnd, wMsg, wParam, lParam) 'process other messages
     
    END FUNCTION
     
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Entrance - Create dialog and controls
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    FUNCTION PBMAIN
      LOCAL hDlg AS LONG, I AS LONG, hCombo AS LONG
      REDIM arr(15) AS STRING
     
      DIALOG NEW 0, "Color Combo sample", , , 120, 80, %WS_SYSMENU TO hDlg
     
      'Create items for list
      arr(0)  = "Black"       : arr(1)  = "Blue"
      arr(2)  = "Green"       : arr(3)  = "Cyan"
      arr(4)  = "Red"         : arr(5)  = "Magenta"
      arr(6)  = "Brown"       : arr(7)  = "Light Gray"
      arr(8)  = "Gray"        : arr(9)  = "Light Blue"
      arr(10) = "Light Green" : arr(11) = "Light Cyan"
      arr(12) = "Light Red"   : arr(13) = "Light Magenta"
      arr(14) = "Yellow"      : arr(15) = "Bright White"
     
      CONTROL ADD BUTTON, hDlg, %IDOK, "&Close", 30, 45, 60, 14
      CONTROL ADD COMBOBOX, hDlg, %ID_COMBO1, arr(), 10, 10, 100, 120, _
                  %CBS_OWNERDRAWFIXED OR %CBS_HASSTRINGS OR %CBS_DROPDOWNLIST OR _
                  %WS_TABSTOP OR %CBS_DISABLENOSCROLL OR %WS_VSCROLL
     
      CONTROL HANDLE hDlg, %ID_COMBO1 TO hCombo  'Subclass Combobox
      IF hCombo THEN oldCBproc = GetWindowLong(hCombo, %GWL_WNDPROC)
      IF oldCBproc THEN SetWindowLong hCombo, %GWL_WNDPROC, CODEPTR(CBProc)
      CONTROL SEND hDlg, %ID_COMBO1, %CB_SETCURSEL, 10, 0  'Select an item, like 10..
     
      DIALOG SHOW MODAL hDlg, CALL DlgProc
    END FUNCTION
     
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Basic QB color function. "Borrowed" from larger GetQBColor function
    ' by Chris Boss. Thank you Chris, hope you don't mind..  :-)
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    FUNCTION GetQBColor(BYVAL c AS LONG) AS LONG
      SELECT CASE c
         CASE  0 : FUNCTION = RGB(0,0,0)       ' Black
         CASE  1 : FUNCTION = RGB(0,0,128)     ' Blue
         CASE  2 : FUNCTION = RGB(0,128,0)     ' Green
         CASE  3 : FUNCTION = RGB(0,128,128)   ' Cyan
         CASE  4 : FUNCTION = RGB(196,0,0)     ' Red
         CASE  5 : FUNCTION = RGB(128,0,128)   ' Magenta
         CASE  6 : FUNCTION = RGB(128,64,0)    ' Brown
         CASE  7 : FUNCTION = RGB(196,196,196) ' Light Gray
         CASE  8 : FUNCTION = RGB(128,128,128) ' Gray
         CASE  9 : FUNCTION = RGB(0,0, 255)    ' Light Blue
         CASE 10 : FUNCTION = RGB(0,255,0)     ' Light Green
         CASE 11 : FUNCTION = RGB(0,255,255)   ' Light Cyan
         CASE 12 : FUNCTION = RGB(255,0,0)     ' Light Red
         CASE 13 : FUNCTION = RGB(255,0,255)   ' Light Magenta
         CASE 14 : FUNCTION = RGB(255,255,0)   ' Yellow
         CASE 15 : FUNCTION = RGB(255,255,255) ' Bright White
      END SELECT
    END FUNCTION
    Engineer's Motto: If it aint broke take it apart and fix it

    "If at 1st you don't succeed... call it version 1.0"

    "Half of Programming is coding"....."The other 90% is DEBUGGING"

    "Document my code????" .... "WHYYY??? do you think they call it CODE? "

  • #2
    Tried all three using PB Win 8.04 on XP, no problems.
    Just a thought - what are you calling them?

    Comment


    • #3
      Hi Chris,

      No problems here with repeated compiles and runs. Win XP, PBWIN 8.01 (using the PB IDE). I didn't name the exe in source, but saved the bas file as OD_PB.bas, OD_CBOSS.BAS ...

      Added as an afterthought:

      When MS upgraded my browser to IE 7.0, I experienced some difficulty copying source from this forum. Currently I dump the source into notepad then select all and copy from Notepad and paste into the IDE. This seemes to have corrected all of the problems.

      Scott
      Last edited by Scott Hauser; 18 Feb 2008, 05:54 PM.
      The most exasperating part of the "rat race" is how often the rats are in the lead!

      Comment


      • #4
        Your points brought an odd test when I got home. This may be one for the "DOOZIES"

        Test Machine: XP/PB 8.04/IE6
        Home Machine: Vista/PB 8.04/IE7 (I assume since I can not find "Help/About" yet)

        Funny thing is, works fine on Vista (I would have thought that would be where I would find a problem), but my reliable XP machine has problems?!?!?!?!?????

        Scott I will have to do the ole' notepad trick myself in the morning (Just to see if there are some whitespace I can not see) or something else causing the problems?

        I can fairly rule out IE7 since I have IE6 at work, and works on a machine that I believe is IE7 (but hey what do I know? I have seen weirder things happen)

        Chris, I am just leaving Default (whatever I name the *.bas, is what the name of the exe would be), but maybe you are leading to something I have to check....maybe I am somehow hitting a 8.3 format name problem?(but I would not think so, because of the core problem)

        Core Problem:
        "Why in the world? would a program close, leave the list of processes, and yet if you try to re-compile and run, not let you because the process is still in use?"
        Engineer's Motto: If it aint broke take it apart and fix it

        "If at 1st you don't succeed... call it version 1.0"

        "Half of Programming is coding"....."The other 90% is DEBUGGING"

        "Document my code????" .... "WHYYY??? do you think they call it CODE? "

        Comment


        • #5
          >and yet if you try to re-compile and run, not let you because the process is still in use?"

          Well, you don't KNOW the file is in use... you know there is a 'destination file write error' which CAN be caused by 'file in use.'

          Meaning... your problem may not be what you first thought it is....
          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            Well, you don't KNOW the file is in use... you know there is a 'destination file write error' which CAN be caused by 'file in use.'

            Meaning... your problem may not be what you first thought it is....
            And that would mean?????

            As far as I know...once a process has ended..it has ended...not "Ooops...I will end but gimme a bit, and when I get to it I will finish ending"
            Engineer's Motto: If it aint broke take it apart and fix it

            "If at 1st you don't succeed... call it version 1.0"

            "Half of Programming is coding"....."The other 90% is DEBUGGING"

            "Document my code????" .... "WHYYY??? do you think they call it CODE? "

            Comment


            • #7
              Cliff,

              Scott I will have to do the ole' notepad trick myself in the morning (Just to see if there are some whitespace I can not see) or something else causing the problems?
              This is what was happening to me before the notepad trick. Usually it would give an immediate compiler error involving improper syntax when the code usage was perfect. I finally resorted to the notepad hoping to solve potential whitespace issues and the problem never occured again. I just assumed it was an IE 7.x issue. Perhaps it was related to some other MS downloaded update.
              The most exasperating part of the "rat race" is how often the rats are in the lead!

              Comment


              • #8
                Spybot is the key

                Found my answer....Surprisingly in the PBCC forums at How do you get rid of ERROR 496?

                Copy Paste from notepad did not work, I started looking at "Depends" to see what versions of what DLL's would be different from system to system, googled a ton of thoughts, and finally out of desperation googled "PowerBasic Error 496" thinking I would only get results that I had already tried.

                Amazingly enough, the 1st result had my answer I turned off Spybot S&D TeaTimer, and sure enough no more errors.

                Maddening how 1 program can cause problems with your program.

                Now I have to determine what Spybot is doing and how I can stop it. (If anything).

                I do not think the end user will run into a problem such as this as each exe would be its own process, but unsure what would happen if the code were in a dll until I test.

                Thanx for the hints and ideas of looking "Outside the box" that led me to the answer
                Engineer's Motto: If it aint broke take it apart and fix it

                "If at 1st you don't succeed... call it version 1.0"

                "Half of Programming is coding"....."The other 90% is DEBUGGING"

                "Document my code????" .... "WHYYY??? do you think they call it CODE? "

                Comment


                • #9
                  But are you going to have this problem in a user environment?

                  It's not like a user will be attempting to replace an executable (*.exe or *.dll) file ......

                  MCM
                  Michael Mattias
                  Tal Systems (retired)
                  Port Washington WI USA
                  [email protected]
                  http://www.talsystems.com

                  Comment


                  • #10
                    But are you going to have this problem in a user environment?

                    It's not like a user will be attempting to replace an executable (*.exe or *.dll) file ......
                    Not as far as I can tell, but have not had time to test a DLL, but the other half of me is thinking that since a DLL is mapped into its parent "process" then maybe, and hence my comment of.
                    I do not think the end user will run into a problem such as this as each exe would be its own process, but unsure what would happen if the code were in a dll until I test
                    Since they will not be recompiling, no harm no foul? OR!!!!

                    Ooops wait a sec, If a DLL is loaded into the Computer's Memory when the 1st process accesses it, and each process maps its own "Copy" into its memory-space then why wouldn't the end user get the same problem if they happen to have Spybot watching, and try multiple compiles of their program using my dll? I got the same thing using PB compiling my "Process" and just because my DLL uses other system DLL's (in my best guess till I really test I will say ComCtl32.dll) then Spybot has its hooks into it, and I can not recompile

                    (OK so my only beginning tests were with EXE but guessing I am on track here)....I did find enough time today to go back and do a bit more testing after I found my answer (just so I could understand better) and found that without Spybot S&D TeaTimer running, I could "Compile and Run" as many times as I wanted. But with Spybot S&D TeaTimer running, I could compile anywhere from 2 to X times (not knowing time roughly 0 to 90 seconds from the 1st time I closed the program) so considering the timing issue.

                    Rough test was:
                    • "Compile and Run"
                    • Close Program
                    • Repeat #1


                    Can anyone confirm this? Maybe my better issue would be to post a note that if this issue occurs, to check your security software.

                    I know its a rarity if ever happen concept, but I guess I am like a cat "Curiosity will kill me", but it I keep at it "Curiosity will bring me back"
                    Engineer's Motto: If it aint broke take it apart and fix it

                    "If at 1st you don't succeed... call it version 1.0"

                    "Half of Programming is coding"....."The other 90% is DEBUGGING"

                    "Document my code????" .... "WHYYY??? do you think they call it CODE? "

                    Comment


                    • #11
                      Your compilation problem is related to your Spybot program; but all you really know about that problem is that the Spybot program prevents you from saving a new EXE file.

                      I can't see how DLL mapping by multiple processes can possibly be impacted by this problem, except that if the Spybot program is screwing up one thing, who's to say it's not screwing up something else?


                      MCM
                      Michael Mattias
                      Tal Systems (retired)
                      Port Washington WI USA
                      [email protected]
                      http://www.talsystems.com

                      Comment

                      Working...
                      X