Announcement

Collapse
No announcement yet.

Ok, why doesn't this work?

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

  • Ok, why doesn't this work?

    I have been painfully converting a VB app to PB and one of the last major
    hurdles is to convert a bunch of tabbed dialog boxes into PB code. These dialog
    boxes are essentially property sheets and contain dozens of controls. I finally found some
    sample code on this forum which did a nice job explaining how to implement a tab using DDT. Here is
    the problem I'm having. One of the tabs is used for an owner drawn control I developed.
    When I draw to the tab hdc, the control never really appears. You can see a flicker of it when you change
    tabs, but thats it. I have placed the redraw code in the tab's WM_PAINT event, but nothing seems to
    make the disply persist. What am I doing wrong? Here is the code.

    (BTW, thanks to the member who uploaded this sample code. Its nice code!)
    Code:
    #COMPILE EXE
    #REGISTER NONE
    #DIM ALL
    
    $INCLUDE "win32api.inc"
    $INCLUDE "comdlg32.inc"
    $INCLUDE "Commctrl.inc"
    
    %ID_TAB = 1001
    %IDC_STATIC = 1
    %IDC_RADIO1 = 1000
    %IDC_RADIO2 = 1001
    %IDC_RADIO3 = 1002
    %IDC_RADIO4 = 1003
    %IDC_RADIO5 = 1004
    %IDC_SPIN1 = 1007
    %MAX_SPIN   = 20
    %MIN_SPIN   = 1
    %ID_LABEL1 = 1008
    %ID_UPDOWN  = 1010
    %IDC_BUTTON1=  1011
    DECLARE FUNCTION DrawColorWindow LIB "tgutil.dll" ALIAS "DrawColorWindow"(BYVAL hdc&, rc AS RECT, BYVAL Index&, BYVAL flag&) AS LONG
    
    CALLBACK FUNCTION TabProc1
      SELECT CASE CBMSG
        CASE %WM_INITDIALOG
          CONTROL ADD FRAME,CBHNDL,%IDC_STATIC,"Line Style",17,5,88,107,,
          CONTROL ADD OPTION,CBHNDL,%IDC_RADIO1,"",23,23,12,9,%WS_CHILD OR %BS_AUTORADIOBUTTON,, 'CALL IDC_RADIO1_CB
          CONTROL ADD OPTION,CBHNDL,%IDC_RADIO2,"",23,40,12,9,%WS_CHILD OR %BS_AUTORADIOBUTTON,, 'CALL IDC_RADIO2_CB
          CONTROL ADD OPTION,CBHNDL,%IDC_RADIO3,"",23,57,12,9,%WS_CHILD OR %BS_AUTORADIOBUTTON,, 'CALL IDC_RADIO3_CB
          CONTROL ADD OPTION,CBHNDL,%IDC_RADIO4,"",23,73,12,9,%WS_CHILD OR %BS_AUTORADIOBUTTON,, 'CALL IDC_RADIO4_CB
          CONTROL ADD OPTION,CBHNDL,%IDC_RADIO5,"",23,90,12,9,%WS_CHILD OR %BS_AUTORADIOBUTTON,, 'CALL IDC_RADIO5_CB
          CONTROL ADD FRAME,CBHNDL,%IDC_STATIC,"Line Width",150,5,64,33,%WS_CHILD,
          CONTROL ADD LABEL,CBHNDL,%ID_LABEL1,"",163,19,38,12,%WS_CHILD,%WS_EX_CLIENTEDGE, 'CALL IDC_STATIC_CB
          'CONTROL ADD "MSCTLS_UPDOWN32",hTabDlg1,%IDC_SPIN1,"",283,19,9,13,%UDS_AUTOBUDDY OR %UDS_ARROWKEYS,, 'CALL IDC_SPIN1_CB
          CONTROL ADD "msctls_updown32", CBHNDL, %ID_UPDOWN, "", 0, 0, 8, 8,%WS_CHILD OR %WS_BORDER OR %WS_VISIBLE OR %UDS_WRAP OR %UDS_ARROWKEYS OR %UDS_ALIGNRIGHT OR %UDS_SETBUDDYINT
          CONTROL SEND CBHNDL, %ID_UPDOWN, %UDM_SETBUDDY, GetDlgItem(CBHNDL, %ID_LABEL1), 0&
          CONTROL SEND CBHNDL, %ID_UPDOWN, %UDM_SETRANGE, 0&, MAKLNG(%MAX_SPIN, %MIN_SPIN)
      END SELECT
    END FUNCTION
    
    CALLBACK FUNCTION TabProc2
      LOCAL a&,x&,y&,xx&,yy&,hdc&,k AS LONG,txt$,nm$,rc AS rect, d&
      LOCAL index&
      SELECT CASE CBMSG
        CASE %WM_INITDIALOG
        CASE %WM_PAINT
          hdc&= GetDC(CBHNDL)
          DIALOG GET SIZE CBHNDL TO x&,y&
          DIALOG UNITS CBHNDL,x&,y& TO PIXELS xx&, yy&
          rc.ntop= CLNG(.1*yy&)
          rc.nleft= CLNG(.2*xx&)
          rc.nright = CLNG(.9*xx&)
          rc.nbottom = CLNG(.9*yy&)
          d& = DrawColorWindow(hdc&, rc, Index&, 3)
          ReleaseDC CBHNDL, hdc&
        CASE %WM_COMMAND
          SELECT CASE CBMSG
            CASE %WM_MOUSEMOVE
          END SELECT
      END SELECT
    END FUNCTION
    
    CALLBACK FUNCTION TabProc3
      SELECT CASE CBMSG
        CASE %WM_INITDIALOG
      END SELECT
    END FUNCTION
    
    CALLBACK FUNCTION MainDlgProc
      STATIC LastIdx AS LONG, hWndTab() AS LONG
      LOCAL tie AS TC_ITEM, i AS LONG, Caption AS STRING
      %nTabCh = 4
      SELECT CASE CBMSG
        CASE %WM_INITDIALOG
          REDIM hWndTab(1 TO %nTabCh)
          FOR i = 1 TO %nTabCh
            DIALOG NEW CBHNDL, "",15,30, 225, 130, %DS_CONTROL OR %WS_CHILD TO hWndTab(i)
            SELECT CASE i
              CASE 1
                DIALOG SHOW MODELESS hWndTab(i) CALL TabProc1
                Caption = "Line Style"
              CASE 2
                DIALOG SHOW MODELESS hWndTab(i) CALL TabProc2
                Caption = " Two "
              CASE 3
                DIALOG SHOW MODELESS hWndTab(i) CALL TabProc3
                Caption = " Three "
            END SELECT
            IF i = 1 THEN
              ShowWindow hWndTab(i), %SW_SHOW
              ELSE
                ShowWindow hWndTab(i), %SW_HIDE
            END IF
            Tie.mask = %TCIF_TEXT OR %TCIF_IMAGE
            tie.iImage = -1
            tie.pszText = STRPTR(Caption)
            TabCtrl_InsertItem GetDlgItem(CBHNDL, %ID_TAB), i, tie
          NEXT
          SetFocus GetDlgItem(CBHNDL, %ID_TAB)
      CASE %WM_COMMAND
        SELECT CASE CBCTL
           CASE= %IDC_BUTTON1
             DIALOG END CBHNDL
        END SELECT
      CASE %WM_NOTIFY
        LOCAL lpNmh AS NMHDR PTR
        lpNmh = CBLPARAM
        SELECT CASE @lpNmh.Code
          CASE %TCN_LAST TO %TCN_FIRST
            SELECT CASE @lpNmh.idFrom
              CASE %ID_TAB
                SELECT CASE @lpNmh.Code
                  CASE %TCN_SELCHANGE
                    i = TabCtrl_GetCurSel(GetDlgItem(CBHNDL,%ID_TAB))
                    ShowWindow hWndTab(LastIdx + 1), %SW_HIDE
                    LastIdx = i
                    ShowWindow hWndTab(LastIdx + 1), %SW_SHOW
                END SELECT
              END SELECT
            END SELECT
          END SELECT
    END FUNCTION
    
    FUNCTION PBMAIN
    LOCAL hDlg AS LONG
    InitCommonControls
    DIALOG NEW 0, "Object Properties",,, 265, 200,%WS_CAPTION, %WS_EX_CONTROLPARENT, TO hDlg
    CONTROL ADD "SysTabControl32", hDlg, %ID_TAB, "", 10, 10, 245, 160, %WS_CHILD OR %WS_VISIBLE
    CONTROL ADD BUTTON, hdlg, %IDC_BUTTON1, "Close",200,175,55,16,%WS_CHILD
    DIALOG SHOW MODAL hDlg CALL MainDlgProc
    END FUNCTION
    ------------------
    * UUB tags added by Administrator for clarity... Please use the CODE tags for source code posts. Thank you.

  • #2
    What is the TGUTIL.DLL...? Is that an ActiveX DLL?
    Anyway, the bulk of the problem is your use of GetDC() instead of BeginPaint().

    Change these (and swap ReleaseDC() with EndPaint()) and you should be away laughing as long as the DLL is drawing properly... replace the call to the DLL with a

    CALL LineTo(hDc&, rc.nright,rc.nbottom)

    and you should see a line across tab page 2, to verify that the paint code itself is working.



    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Lance
    mailto:[email protected]

    Comment


    • #3
      Lance, correct as always. I made the minor changes you indicated and the routine
      works perfectly. BTW, tgutil.dll is not an activeX dll, its a utility
      library I created with PBDLL to service the application I originally
      mentioned. The DrawColorWindow function is an owner-draw color selection
      control which is more flexible than the standard Windows Choosecolor dialog.

      Thanks again, hope I can return the favor sometime!

      Jeff

      ------------------

      Comment


      • #4
        One more thing... don't forget to return FUNCTION = 1 for WM_PAINT so that the default handler does not get executed (wasting time, etc).

        This applies to all other DDT messages that your code handles... return non-zero unless you actually want the default dialog handler to process the message.

        I often see (experienced) programmers forget to do this, and I'm guilty of it myself on occasion!


        ------------------
        Lance
        PowerBASIC Support
        mailto:[email protected][email protected]</A>
        Lance
        mailto:[email protected]

        Comment

        Working...
        X