Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

LISTVIEW with PB9

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

  • LISTVIEW with PB9

    Code:
    'Suggestions/comments: http://www.powerbasic.com/support/pb...ad.php?t=38831
    '
    #PBFORMS CREATED V1.51
    '------------------------------------------------------------------------------
    #COMPILE EXE
    #DIM ALL
    'Created using PBWIN9
    '------------------------------------------------------------------------------
    '   ** Includes **
    '------------------------------------------------------------------------------
    #PBFORMS BEGIN INCLUDES
    %USEMACROS = 1
    #IF NOT %DEF(%WINAPI)
        #INCLUDE "WIN32API.INC"
    #ENDIF
    #IF NOT %DEF(%COMMCTRL_INC)
        #INCLUDE "COMMCTRL.INC"
    #ENDIF
    #INCLUDE "PBForms.INC"
    #PBFORMS END INCLUDES
    '------------------------------------------------------------------------------
    '------------------------------------------------------------------------------
    '   ** Constants **
    '------------------------------------------------------------------------------
    #PBFORMS BEGIN CONSTANTS
    %IDD_DIALOG1  =  101
    %IDC_BUTTON1  = 1001
    %IDC_LISTVIEW = 1002
    #PBFORMS END CONSTANTS
    '------------------------------------------------------------------------------
    '------------------------------------------------------------------------------
    '   ** Declarations **
    '------------------------------------------------------------------------------
    DECLARE CALLBACK FUNCTION ShowDIALOG1Proc()
    DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
    #PBFORMS DECLARATIONS
    '------------------------------------------------------------------------------
    '------------------------------------------------------------------------------
    '   ** Main Application Entry Point **
    '------------------------------------------------------------------------------
    FUNCTION PBMAIN()
        PBFormsInitComCtls (%ICC_WIN95_CLASSES OR %ICC_DATE_CLASSES OR %ICC_INTERNET_CLASSES)
        ShowDIALOG1 %HWND_DESKTOP
    END FUNCTION
    '------------------------------------------------------------------------------
    '------------------------------------------------------------------------------
    '   ** CallBacks **
    '------------------------------------------------------------------------------
    CALLBACK FUNCTION ShowDIALOG1Proc()
        SELECT CASE AS LONG CBMSG
            CASE %WM_INITDIALOG
                ' Initialization handler
            CASE %WM_NCACTIVATE
                STATIC hWndSaveFocus AS DWORD
                IF ISFALSE CBWPARAM THEN
                    ' Save control focus
                    hWndSaveFocus = GetFocus()
                ELSEIF hWndSaveFocus THEN
                    ' Restore control focus
                    SetFocus(hWndSaveFocus)
                    hWndSaveFocus = 0
                END IF
            CASE %WM_COMMAND
                ' Process control notifications
                SELECT CASE AS LONG CBCTL
     
                    CASE %IDC_BUTTON1
                        IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                            CONTROL DISABLE CBHNDL, %IDC_BUTTON1
                            CALL DisplayRecordSet(CBHNDL)
                            CONTROL ENABLE CBHNDL, %IDC_BUTTON1
                        END IF
                END SELECT
        END SELECT
    END FUNCTION
    '------------------------------------------------------------------------------
    '------------------------------------------------------------------------------
    '   ** Dialogs **
    '------------------------------------------------------------------------------
    FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
        LOCAL lRslt AS LONG
    #PBFORMS BEGIN DIALOG %IDD_DIALOG1->->
        LOCAL hDlg  AS DWORD
        DIALOG NEW hParent, "Dialog1", 25, 52, 527, 305, %WS_POPUP OR %WS_BORDER _
            OR %WS_DLGFRAME OR %WS_SYSMENU OR %WS_MINIMIZEBOX OR %WS_MAXIMIZEBOX _
            OR %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK _
            OR %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_CONTROLPARENT OR _
            %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
        CONTROL ADD BUTTON, hDlg, %IDC_BUTTON1, "Button1", 245, 30, 50, 15
        CONTROL ADD "SysListView32", hDlg, %IDC_LISTVIEW, "SysListView32_1", 80, _
            95, 400, 145, %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %LVS_REPORT _
            OR %LVS_SHOWSELALWAYS, %WS_EX_LEFT OR %WS_EX_CLIENTEDGE OR _
            %WS_EX_RIGHTSCROLLBAR
    #PBFORMS END DIALOG
        DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt
    #PBFORMS BEGIN CLEANUP %IDD_DIALOG1
    #PBFORMS END CLEANUP
        FUNCTION = lRslt
    END FUNCTION
    '------------------------------------------------------------------------------
     
    FUNCTION DisplayRecordSet(hDlg AS DWORD) AS DWORD
      LOCAL row AS DWORD, col AS LONG, ColumnCount AS LONG
      LOCAL x AS LONG, rows AS LONG
      'so you know it was called
     
        ColumnCount = 5
        rows = 15
      IF ColumnCount THEN
        MOUSEPTR 11
        'CONTROL SHOW STATE hDlg, %IDC_LISTVIEW, %SW_HIDE
        LISTVIEW RESET hDLG, %IDC_LISTVIEW
        LISTVIEW SET STYLE hDlg, %IDC_LISTVIEW, %LVS_EX_GRIDLINES
        FOR col = 1 TO ColumnCount   'Insert columns with column names
          LISTVIEW DELETE COLUMN hDlg, %IDC_LISTVIEW,col
          LISTVIEW INSERT COLUMN hDlg, %IDC_LISTVIEW,col,"Col" + STR$(col),100,0
        NEXT
        DOEVENT4
      ELSE
        ? "No columns"
        EXIT FUNCTION
      END IF
      row = 0
      DO WHILE row < rows
        INCR row
        LISTVIEW INSERT ITEM hDlg, %IDC_LISTVIEW,row, 0 , "ROW" + STR$(row) + " COLUMN 1"
        FOR col = 2 TO ColumnCount                               'add text into columns
          LISTVIEW SET TEXT hdlg, %IDC_LISTVIEW, row, col,"COLUMN" + STR$(col)
        NEXT
        'Display first screen faster and give others time
        IF row = 15 OR row MOD 1000 = 0  THEN       'refresh screen every so often
          DOEVENT4
        END IF
      LOOP
      CONTROL SHOW STATE hdlg, %IDC_LISTVIEW, %SW_HIDE
      FOR col = 1 TO ColumnCount   'fit columns
        LISTVIEW FIT CONTENT hDlg, %IDC_LISTVIEW, col
      NEXT
      CONTROL SHOW STATE hDlg, %IDC_LISTVIEW, %SW_SHOW
      DOEVENT4
      MOUSEPTR 1
      FUNCTION = row
    END FUNCTION
    SUB DOEVENT4
      LOCAL x AS LONG
      FOR x = 1 TO 4
        DIALOG DOEVENTS
      NEXT
    END SUB
    Last edited by Mike Doty; 13 Oct 2008, 08:55 PM.
    How long is an idea? Write it down.
Working...
X