Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Will Listview work in FreeBasic
#1
Hello,

I was trying out Listview and I see some of the TYPES were missing from the INCLUDE file so I added them to my example.

The Listview will display but I'm unable to send any text to it.

I read where somebody wrote that if it's not supported in the BI files, Freebasic has not been coded to compile it.

Seeing where Listview does display on the screen, I'm wondering if my code is so messed up that text can't be sent to it.

Should I abandon this project because it's not supported or is there any hope for it. Anyway here's the code in case there's hope for it.


Code:
OPTION EXPLICIT

TYPE LV_ITEM
    mask       AS uinteger
    iItem      AS LONG
    iSubItem   AS LONG
    STATE      AS uinteger
    stateMask  AS uinteger
    pszText    AS string ptr
    cchTextMax AS LONG
    iImage     AS LONG
    lParam     AS LONG
    iIndent    AS LONG
END TYPE

TYPE LV_COLUMN
    mask AS uinteger
    fmt AS LONG
    cx AS LONG
    pszText AS string ptr
    cchTextMax AS LONG
    iSubItem AS LONG
    iImage AS LONG
    iOrder AS LONG
END TYPE



' $INCLUDE: 'win\kernel32.bi'
' $INCLUDE: 'win\user32.bi'
' $INCLUDE: 'win\GDI32.bi'
'$INCLUDE :'win\COMMCTRL32.bi'


DECLARE FUNCTION  WinMain (byval hInstance as long, _  
                       byval hPrevInstance as long, _  
                       szCmdLine as string, _          
                       byval iCmdShow as long) as long  

'entry point
  END WinMain(GetModuleHandle(null), null, Command$, SW_NORMAL)



   DATA "Rec. Nr.", 80, "Last Name", 120, "First Name", 120, "Phone", 120, "Email", 120
   DATA "101"," Boggs"," Jimmy","    (532) 223-3034","  jboggs@aol.com"
   DATA "102", "Smith", "Granny",   "(244) 545-8970",  "gsmith@msn.com"  
   DATA "103", "Washington", "Roy", "(434) 677-1432",  "rwash@pldi.net"  
   DATA "104", "James", "Frank",    "(439) 879-5468",  "james@excite.com"


FUNCTION ProcessWindow (BYVAL hDlg AS Uinteger, BYVAL wMsg AS Uinteger, BYVAL wParam _
                  AS Uinteger, BYVAL lParam AS LONG, BYVAL hInstance AS LONG) AS LONG
   DIM ff AS LONG
   DIM row AS SINGLE, xl AS LONG, yl AS LONG, xx AS LONG, lStyle AS LONG

   InitCommonControls
   STATIC hLv3 AS LONG
   DIM LvItm3 AS LV_ITEM , LVcol3 AS LV_COLUMN
   DIM Buf3 AS string *  16
  
    
   STATIC hLv4 AS LONG
   DIM LvItm4 AS LV_ITEM , LVcol4 AS LV_COLUMN
   DIM Buf4 AS string *  80
  
  

  IF wMsg = WM_CREATE THEN        'Messages that Initializes Controls and  
                                       'tasks that affects the Appearance of Dialogs


      hLv3 = CreateWindowEx  (WS_EX_CLIENTEDGE, "SysListView32", "", _
         WS_GROUP OR WS_VISIBLE OR WS_CHILD OR WS_BORDER OR _  
         LVS_SHOWSELALWAYS OR  LVS_NOSORTHEADER OR LVS_REPORT OR LVS_SINGLESEL, _
         10,  200,  240,  154, _  
         hdlg,  103, hInstance, BYVAL NULL)    

      hLv4 = CreateWindowEx   (WS_EX_CLIENTEDGE, "SysListView32", "", _
         WS_GROUP OR WS_VISIBLE OR WS_CHILD OR WS_BORDER OR _  
         LVS_SHOWSELALWAYS OR  LVS_NOSORTHEADER OR LVS_REPORT OR LVS_SINGLESEL, _
         270,  200,  330,  154, _  
         hdlg,  104, hInstance, BYVAL NULL)    


     SetWindowPos hDlg, HWND_TOP, 0, 0, 0, 0, SWP_NoSize OR SWP_NoMove


  ' hLv3 = GetDlgItem(hDlg,  103)
   lStyle = SendMessage(hLV3, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0)
   lStyle = lStyle  OR  LVS_EX_GRIDLINES  OR LVS_EX_FULLROWSELECT
   SendMessage hLv3, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, BYVAL lStyle
   LVcol3.psztext= VARPTR( Buf3 )
   LVcol3.mask=LVCF_TEXT OR LVCF_WIDTH OR LVCF_SUBITEM

   FOR xl = 0 to 8           'step 2         ' Setup to read Data for columns
      READ buf3            ' read column name
      READ LVcol3.cx          ' read column GUI width
      LVcol3.isubitem=xl/2        ' Setup for sending to LV
      SendMessage hLv3, LVM_INSERTCOLUMN, xl/2, VARPTR(LVcol3)      ' Send to LV
    '  MessageBox GetActiveWindow(), buf3+str$(lvcol3.cx), "", MB_OK
      xl=xl+1
  NEXT xl


   xl=0  
   LvItm3.mask=LVIF_TEXT
   LvItm3.psztext=VARPTR(Buf3)
   FOR row=11 TO 30 STEP 5            ' Setup to Read from DATA
      LvItm3.iitem=xl                 ' line number  
      LvItm3.isubitem=0               ' number for column 1 subitem
      READ Buf3
      SendMessage hLv3, LVM_INSERTITEM, xl, VARPTR(LvItm3)
      FOR yl = 1 TO 4  
         LvItm3.isubitem = yl         ' number for rest of items
         READ buf3                    ' Read the rest of the items and
         SendMessage hLv3, LVM_SETITEMTEXT, xl, VARPTR(LvItm3) ' Send them to LV
      NEXT yl
      xl = xl + 1
   NEXT
  
  
  ' hLv4 = GetDlgItem(hDlg,  104)
   lStyle = SendMessage(hLv4, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0)
   lStyle = lStyle  OR  LVS_EX_GRIDLINES  OR LVS_EX_FULLROWSELECT
   SendMessage hLv4, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, BYVAL lStyle
   LVcol4.psztext=VARPTR(Buf4)
   LVcol4.mask=LVCF_TEXT OR LVCF_WIDTH OR LVCF_SUBITEM

   Buf4 = "This is the header text for the listview"
   LVcol4.cx= 380              ' gui column width
   LVcol4.isubitem= 1          ' Column number
   SendMessage hLv4, LVM_INSERTCOLUMN, xl, VARPTR(LVcol4)
   xl=1
   LvItm4.mask=LVIF_TEXT      ' flag that specifies text
   LvItm4.psztext=VARPTR(Buf4) ' Point to buffer
   FOR yl = 1 TO  20           ' number of lines to display
     buf4="Record Nr" + STR$(yl)+" " + STRING$(50,"X")' Create text for LV
     LvItm4.iitem=yl           ' get Line number
     SendMessage hLv4, LVM_INSERTITEM, 0, VARPTR(LvItm4)' Send it to LV
   NEXT yl

                                       ' a control sends notification messages to its Parent
  ELSEIF wMsg = WM_CLOSE  THEN   ' Message from Clicking on system close Icon
    PostQuitMessage 0
  END IF
  ProcessWindow = DefWindowProc(hdlg, wMsg, wParam, lParam)  
  SetFocus GetNextDlgTabItem(hdlg, NULL, FALSE)
END FUNCTION



  FUNCTION WINMAIN (BYVAL hInstance     AS LONG, _
                    BYVAL hPrevInstance AS LONG, _          
                    szCmdLine           AS STRING, _    
                    BYVAL iCmdShow      AS LONG) AS LONG    

     DIM wMsg       AS Msg      

     DIM wcls AS wndclass  
     DIM hWnd      AS unsigned LONG        
     DIM szpgmname AS STRING, style as long
                
     szpgmname = "FreeBasic GUI Samples"
     WITH wcls
         .lpfnWndProc   = @ProcessWindow  'point to callback code  
         .hInstance     = hInstance  
         .hIcon         = LoadIcon( hInstance, "MAINICON" )
         .hCursor       = LoadCursor( NULL, BYVAL IDC_ARROW )
         .hbrBackground = COLOR_MENU +1
         .lpszMenuName  = NULL
         .lpszClassName = STRPTR(szpgmname)
     END WITH
     RegisterClass wcls
          style =   WS_VISIBLE OR WS_OVERLAPPEDWINDOW OR  DS_MODALFRAME

          hWnd = CreateWindowEx(0, szpgmname, "Regular SDK Example", _
                                Style,  90,  92,  610,  391, _
                                HWND_DESKTOP, NULL, hInstance, BYVAL NULL)

     WHILE (GetMessage(wMsg, NULL, 0, 0) <> false )    
         TranslateMessage wMsg
         DispatchMessage  wMsg
     WEND
     WinMain = wMsg.wParam
END FUNCTION
Reply
#2
Hi:

I had a quick look at your code, and I can see you messed up the last parameter of sendmessage. Join the club. It is declared VB style and catching out everybody.

SendMessage hLv3, LVM_INSERTCOLUMN, xl/2, LVcol3

If you change all the places you send pointers to structures it works fine.

Have fun

Garvan
Reply
#3
Thanks Garvin,

I would have sworn that I had already tried that, but it must have been when I was having other problems also which I probably had fixed. Of course I don't know anything about VB or C, but I had just learned about using ByVAL instead of STRPTR in SendMessage. That VARPTR I was using comes from using PowerBasic.



I'll give it a go, thank again......
Reply
#4
That did it, Garvin

Now I have to try out the Treeview and Richedit and maybe font picker and color picker and file picker and nose picker. I tried out all the other controls and they all work fine including the rectangles and circles.

This is about my second week playing with freebasic, and I'm pretty happy with it so far.

Thanks again.........Jerry
Reply
#5
Quote:maybe font picker and color picker and file picker and nose picker.

*giggles*
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)