Grid Gadget - Is there going to be one?

Just starting out? Need help? Post your questions and find answers here.
neomlsra
User
User
Posts: 14
Joined: Sun Feb 27, 2005 6:32 pm

Grid Gadget - Is there going to be one?

Post by neomlsra »

I was searching the post and found many examples of how to program a grid gadget or use other objects with some coding to create ones but they alway fell short of the posting person's expectations because of course they are not a grid gadget.

I am exploring the use of Pure Basic for a project before purchasing and grids are something I use often in my applications. Are there considerations to create a grid gadget? If so, when will it be available? If not, why wouldn't this be important considering the amount of post asking for it?

Regards,

neomlsra
User avatar
blueb
Addict
Addict
Posts: 1111
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Post by blueb »

Check out http://www.softwareinnovators.com/produ ... &PD=SIGRID

They have a grid that works with PureBasic (and others).

--blueb
El_Choni
TailBite Expert
TailBite Expert
Posts: 1007
Joined: Fri Apr 25, 2003 6:09 pm
Location: Spain

Post by El_Choni »

Here's another one, includes ASM source (check the projects page):

http://radasm.visualassembler.com
El_Choni
neomlsra
User
User
Posts: 14
Joined: Sun Feb 27, 2005 6:32 pm

Post by neomlsra »

The one package cost 97.00 dollars. That's alot of money just for a grid control. The second one looks more promising from a cost standpoint and it appears to pack some good features. It is a DLL so the next question is how do you integrate a control developed by a 3rd party into PureBasic?

Regards,

neomlsra
El_Choni
TailBite Expert
TailBite Expert
Posts: 1007
Joined: Fri Apr 25, 2003 6:09 pm
Location: Spain

Post by El_Choni »

Put RAGrid.dll in the same folder as this code, and run it:

Code: Select all

;
; Sample from the RAGrid package: GridTest.
; Translated to PureBasic (more or less: this one doesn't use a resource dialog)
;
Global *OldGridProc

Structure COLUMN
 colwt.l
 lpszhdrtext.l
 halign.l
 calign.l
 ctype.l
 ctextmax.l
 lpszformat.l
 himl.l
 hdrflag.l
 colxp.l
 edthwnd.l
EndStructure

Structure ROWDATA
 lpszName.l
 nID.l
EndStructure

Procedure GridProc(hWnd, uMsg, wParam, lParam)
  Select uMsg
    Case #WM_MOUSEMOVE
      SetWindowText_(WindowID(), "X: "+Str(lParam&$ffff)+", Y: "+Str(lParam>>16))
    Case #WM_LBUTTONDOWN
      SetWindowText_(WindowID(), "WM_LBUTTONDOWN")
    Case #WM_LBUTTONUP
      SetWindowText_(WindowID(), "WM_LBUTTONUP")
  EndSelect
  ProcedureReturn CallWindowProc_(*OldGridProc, hWnd, uMsg, wParam, lParam)
EndProcedure

#GM_ADDCOL = #WM_USER+1 ;wParam=0, lParam=lpCOLUMN
#GM_ADDROW = #WM_USER+2 ;wParam=0, lParam=lpROWDATA (can be NULL)
#GM_SETBACKCOLOR = #WM_USER+21 ;wParam=nColor, lParam=0
#GM_SETGRIDCOLOR = #WM_USER+23 ;wParam=nColor, lParam=0
#GM_SETTEXTCOLOR = #WM_USER+25 ;wParam=nColor, lParam=0
#GA_ALIGN_LEFT = 0
#GA_ALIGN_RIGHT = 2
#TYPE_EDITTEXT = 0   ;String
#TYPE_EDITLONG = 1   ;Long

If OpenWindow(0, 100, 200, 195, 260, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget, "PureBasic Window")
  If OpenLibrary(0, "RAGrid.DLL")
    InitCommonControls_()
    hGrid = CreateWindowEx_($00000200, "RAGrid", "Grid test", $5001000D, 0, 0, 195, 260, WindowID(), 0, LibraryID(0), 0)
    If hGrid
      *OldGridProc = SetWindowLong_(hGrid, #GWL_WNDPROC, @GridProc())
      hFont = SendMessage_(WindowID(), #WM_GETFONT, 0, 0)
      SendMessage_(hGrid, #WM_SETFONT, hFont, #FALSE)
      SendMessage_(hGrid, #GM_SETBACKCOLOR, $0C0FFFF, 0)
      SendMessage_(hGrid, #GM_SETGRIDCOLOR, $808080, 0)
      SendMessage_(hGrid, #GM_SETTEXTCOLOR, $800000, 0)
      col.COLUMN
      col\colwt = 130
      col\lpszhdrtext = @"Name"
      col\halign = #GA_ALIGN_LEFT
      col\calign = #GA_ALIGN_LEFT
      col\ctype = #TYPE_EDITTEXT
      col\ctextmax = 31
      col\lpszformat = 0
      col\himl = 0
      col\hdrflag = 0
      SendMessage_(hGrid, #GM_ADDCOL, 0, @col)
  ;Number column
      col\colwt = 42
      col\lpszhdrtext = @"ID"
      col\halign = #GA_ALIGN_RIGHT
      col\calign = #GA_ALIGN_RIGHT
      col\ctype = #TYPE_EDITLONG
      col\ctextmax = 11
      col\lpszformat = 0
      col\himl = 0
      col\hdrflag = 0
      SendMessage_(hGrid, #GM_ADDCOL, 0, @col)
  ;Add some rows
      Dim rdta.ROWDATA(3)
      For i=0 To 3
        SendMessage_(hGrid, #GM_ADDROW, 0, @rdta(i))
      Next i
      ShowWindow_(hGrid, #SW_SHOW)
      Repeat
        EventID.l = WaitWindowEvent()
        If EventID = #PB_Event_CloseWindow
          Quit = 1
        EndIf
      Until Quit = 1
    EndIf
    DestroyWindow_(hGrid)
  EndIf
  CloseLibrary(0)
EndIf
End
El_Choni
neomlsra
User
User
Posts: 14
Joined: Sun Feb 27, 2005 6:32 pm

Post by neomlsra »

Thanks for the code sample!


Question:

1. Is window also equal to form?
2. Can the grid be created on a form/tab control/tab 1?

Reason:

I have a primary form with a tab control which will have all the views and entry being controled through this interface. I will need to establish the grid on different tabs as the user selects the ones they need to interface to.

Regards,

neomlsra
El_Choni
TailBite Expert
TailBite Expert
Posts: 1007
Joined: Fri Apr 25, 2003 6:09 pm
Location: Spain

Post by El_Choni »

1. I don't know what a form is.
2. Yes:

Code: Select all

;
; Sample from the RAGrid package: GridTest.
; Translated to PureBasic (more or less: this one doesn't use a resource dialog)
;

Global menuID

Structure COLUMN
 colwt.l
 lpszhdrtext.l
 halign.l
 calign.l
 ctype.l
 ctextmax.l
 lpszformat.l
 himl.l
 hdrflag.l
 colxp.l
 edthwnd.l
EndStructure

Structure ROWDATA
 lpszName.l
 nID.l
EndStructure

#GM_ADDCOL = #WM_USER+1 ;wParam=0, lParam=lpCOLUMN
#GM_ADDROW = #WM_USER+2 ;wParam=0, lParam=lpROWDATA (can be NULL)
#GM_SETBACKCOLOR = #WM_USER+21 ;wParam=nColor, lParam=0
#GM_SETGRIDCOLOR = #WM_USER+23 ;wParam=nColor, lParam=0
#GM_SETTEXTCOLOR = #WM_USER+25 ;wParam=nColor, lParam=0
#GA_ALIGN_LEFT = 0
#GA_ALIGN_RIGHT = 2
#TYPE_EDITTEXT = 0   ;String
#TYPE_EDITLONG = 1   ;Long

Global *ClassBuffer
*ClassBuffer = AllocateMemory(64)

Procedure CreateGrids(hWnd, lParam)
  If *ClassBuffer
    GetClassName_(hWnd, *ClassBuffer, 64)
    If PeekS(*ClassBuffer, 6)="Static"
      hGrid = CreateWindowEx_($00000200, "RAGrid", "Grid test", $5001000D, 0, 0, 195, 260, hWnd, menuID, LibraryID(0), 0)
      If hGrid
        SendMessage_(hGrid, #WM_SETFONT, hFont, #FALSE)
        SendMessage_(hGrid, #GM_SETBACKCOLOR, $0C0FFFF, 0)
        SendMessage_(hGrid, #GM_SETGRIDCOLOR, $808080, 0)
        SendMessage_(hGrid, #GM_SETTEXTCOLOR, $800000, 0)
        col.COLUMN
        col\colwt = 130
        col\lpszhdrtext = @"Name"
        col\halign = #GA_ALIGN_LEFT
        col\calign = #GA_ALIGN_LEFT
        col\ctype = #TYPE_EDITTEXT
        col\ctextmax = 31
        col\lpszformat = 0
        col\himl = 0
        col\hdrflag = 0
        SendMessage_(hGrid, #GM_ADDCOL, 0, @col)
    ;Number column
        col\colwt = 42
        col\lpszhdrtext = @"ID"
        col\halign = #GA_ALIGN_RIGHT
        col\calign = #GA_ALIGN_RIGHT
        col\ctype = #TYPE_EDITLONG
        col\ctextmax = 11
        col\lpszformat = 0
        col\himl = 0
        col\hdrflag = 0
        SendMessage_(hGrid, #GM_ADDCOL, 0, @col)
    ;Add some rows
        Dim rdta.ROWDATA(3)
        For i=0 To 3
          SendMessage_(hGrid, #GM_ADDROW, 0, @rdta(i))
        Next i
        ShowWindow_(hGrid, #SW_SHOW)
        menuID+1
      EndIf
    EndIf
    ProcedureReturn #TRUE
  Else
    ProcedureReturn #FALSE
  EndIf
EndProcedure

Procedure DestroyGrids(hWnd, lParam)
  If *ClassBuffer
    GetClassName_(hWnd, *ClassBuffer, 64)
    If PeekS(*ClassBuffer, 6)="Static"
      hGrid = GetWindow_(hWnd, #GW_CHILD)
      GetClassName_(hGrid, *ClassBuffer, 64)
      If PeekS(*ClassBuffer, 6)="RAGrid"
        DestroyWindow_(hGrid)
      EndIf
    EndIf
    ProcedureReturn #TRUE
  Else
    ProcedureReturn #FALSE
  EndIf
EndProcedure

If OpenWindow(0, 100, 200, 195, 260, #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget, "PureBasic Window")
  If OpenLibrary(0, "RAGrid.DLL")
    InitCommonControls_()
    hFont = SendMessage_(WindowID(), #WM_GETFONT, 0, 0)
    If CreateGadgetList(WindowID())
      Panel = PanelGadget(0, 0, 0, 195, 260)
      For j=1 To 6
        AddGadgetItem(0, -1, "Tab "+Str(j))
      Next j
      EnumChildWindows_(Panel, @CreateGrids(), 0)
      CloseGadgetList()
      Repeat
        EventID = WaitWindowEvent()
        If EventID=#PB_Event_CloseWindow
          Quit = 1
        EndIf
      Until Quit=1
    EndIf
    EnumChildWindows_(Panel, @DestroyGrids(), 0)
  EndIf
  CloseLibrary(0)
EndIf
End
El_Choni
User avatar
GedB
Addict
Addict
Posts: 1313
Joined: Fri May 16, 2003 3:47 pm
Location: England
Contact:

Post by GedB »

Just for cross reference, Fred has promised a Grid in the next version:

(At least, I'm told thats what it said. The text appears to be strangely garbled.)

http://purebasic.hmt-forum.com/viewtopi ... highlight=
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post by traumatic »

GedB wrote:(At least, I'm told thats what it said. The text appears to be strangely garbled.)
*lol* :lol:
Good programmers don't comment their code. It was hard to write, should be hard to read.
User avatar
GedB
Addict
Addict
Posts: 1313
Joined: Fri May 16, 2003 3:47 pm
Location: England
Contact:

Post by GedB »

1. Is a PB Window the same as a VB Form?

In VB A form is a unit of code that includes the definition of the window and it's controls and the code to handle the events raised by the form.

In PB the Window is defined within the code. A single code file can defined multiple windows and a single main loop can handle all their events.

It is easy to emulate VBs approach using a WindowCallback and a Select statement.
User avatar
fiver
User
User
Posts: 36
Joined: Wed May 05, 2004 8:21 pm
Location: An outer spiral arm of the Milky Way

Post by fiver »

I have been tinkering with El Choni's code for RaGrid and it seems like it's possible to do some pretty useful things with it.
Where I am struggling though, is with the notifications from RaGrid as my knowledge of windows messaging is next to non -existent :wink:.
I notice in RaGrid's Inc file (see below) there is a GRIDNOTIFY structure, can anyone explain how to implement this?

-fiver

Code: Select all

; RaGrid.Inc:
; From RaGrid zip, http://radasm.visualassembler.com/projects/Grid.zip

;GridInstall			PROTO	:DWORD
;
;;Column structure
;COLUMN struct
;	colwt			dd ?	;Column width.
;	lpszhdrtext		dd ?	;Pointer to header text.
;	halign			dd ?	;Header text alignment.
;	calign			dd ?	;Column text alignment.
;	ctype			dd ?	;Column data type.
;	ctextmax		dd ?	;Max text lenght for TYPE_EDITTEXT and TYPE_EDITLONG.
;	lpszformat		dd ?	;Format string for TYPE_EDITLONG.
;	himl			dd ?	;Handle of image list. For the image columns and combobox only.
;	hdrflag			dd ?	;Header flags. Set to ZERO or if initially sorted set to initial sort direction
;	colxp			dd ?	;Column position. Internally used.
;	edthwnd			dd ?	;Column control handle. Internally used.
;COLUMN ends
;
;ROWCOLOR struct
;	backcolor		dd ?
;	textcolor		dd ?
;ROWCOLOR ends
;
;;Notifications GN_*
;
;GRIDNOTIFY struct
;	nmhdr			NMHDR <?>
;	col			dd ?	;Column
;	row			dd ?	;Row
;	hwnd			dd ?	;Handle of column edit control
;	lpdata			dd ?	;Pointer to data
;	fcancel			dd ?	;Set to TRUE to cancel operation
;GRIDNOTIFY ends
;
;GN_HEADERCLICK		equ 1	;User clicked header
;GN_BUTTONCLICK		equ 2	;Sendt when user clicks the button in a button cell
;GN_CHECKCLICK		equ 3	;Sendt when user double clicks the checkbox in a checkbox cell
;GN_IMAGECLICK		equ 4	;Sendt when user double clicks the image in an image cell
;GN_BEFORESELCHANGE	equ 5	;Sendt when user request a selection change
;GN_AFTERSELCHANGE	equ 6	;Sendt after a selection change
;GN_BEFOREEDIT		equ 7	;Sendt before the cell edit control shows
;GN_AFTEREDIT		equ 8	;Sendt when the cell edit control is about to close
;GN_BEFOREUPDATE		equ 9	;Sendt before a cell updates grid data
;GN_AFTERUPDATE		equ 10	;Sendt after grid data has been updated
;GN_USERCONVERT		equ 11	;Sendt when user cell needs to be converted.
;
;;Messages GM_*
;
;GM_ADDCOL		equ WM_USER+1	;wParam=0, lParam=lpCOLUMN
;GM_ADDROW		equ WM_USER+2	;wParam=0, lParam=lpROWDATA (can be NULL)
;GM_INSROW		equ WM_USER+3	;wParam=nRow, lParam=lpROWDATA (can be NULL)
;GM_DELROW		equ WM_USER+4	;wParam=nRow, lParam=0
;GM_MOVEROW		equ WM_USER+5	;wParam=nFromRow, lParam=nToRow
;GM_COMBOADDSTRING	equ WM_USER+6	;wParam=nCol, lParam=lpszString
;GM_COMBOCLEAR		equ WM_USER+7	;wParam=nCol, lParam=0
;GM_GETCURSEL		equ WM_USER+8	;wParam=0, lParam=0
;GM_SETCURSEL		equ WM_USER+9	;wParam=nCol, lParam=nRow
;GM_GETCURCOL		equ WM_USER+10	;wParam=0, lParam=0
;GM_SETCURCOL		equ WM_USER+11	;wParam=nCol, lParam=0
;GM_GETCURROW		equ WM_USER+12	;wParam=0, lParam=0
;GM_SETCURROW		equ WM_USER+13	;wParam=nRow, lParam=0
;GM_GETCOLCOUNT		equ WM_USER+14	;wParam=0, lParam=0
;GM_GETROWCOUNT		equ WM_USER+15	;wParam=0, lParam=0
;GM_GETCELLDATA		equ WM_USER+16	;wParam=nRowCol, lParam=lpData
;GM_SETCELLDATA		equ WM_USER+17	;wParam=nRowCol, lParam=lpData (can be NULL)
;GM_GETCELLRECT		equ WM_USER+18	;wParam=nRowCol, lParam=lpRECT
;GM_SCROLLCELL		equ WM_USER+19	;wParam=0, lParam=0
;GM_GETBACKCOLOR		equ WM_USER+20	;wParam=0, lParam=0
;GM_SETBACKCOLOR		equ WM_USER+21	;wParam=nColor, lParam=0
;GM_GETGRIDCOLOR		equ WM_USER+22	;wParam=0, lParam=0
;GM_SETGRIDCOLOR		equ WM_USER+23	;wParam=nColor, lParam=0
;GM_GETTEXTCOLOR		equ WM_USER+24	;wParam=0, lParam=0
;GM_SETTEXTCOLOR		equ WM_USER+25	;wParam=nColor, lParam=0
;GM_ENTEREDIT		equ WM_USER+26	;wParam=nCol, lParam=nRow
;GM_ENDEDIT		equ WM_USER+27	;wParam=nRowCol, lParam=fCancel
;GM_GETCOLWIDTH		equ WM_USER+28	;wParam=nCol, lParam=0
;GM_SETCOLWIDTH		equ WM_USER+29	;wParam=nCol, lParam=nWidth
;GM_GETHDRHEIGHT		equ WM_USER+30	;wParam=0, lParam=0
;GM_SETHDRHEIGHT		equ WM_USER+31	;wParam=0, lParam=nHeight
;GM_GETROWHEIGHT		equ WM_USER+32	;wParam=0, lParam=0
;GM_SETROWHEIGHT		equ WM_USER+33	;wParam=0, lParam=nHeight
;GM_RESETCONTENT		equ WM_USER+34	;wParam=0, lParam=0
;GM_COLUMNSORT		equ WM_USER+35	;wParam=nCol, lParam=0=Ascending, 1=Descending, 2=Invert
;GM_GETHDRTEXT		equ WM_USER+36	;wParam=nCol, lParam=lpBuffer
;GM_SETHDRTEXT		equ WM_USER+37	;wParam=nCol, lParam=lpszText
;GM_GETCOLFORMAT		equ WM_USER+38	;wParam=nCol, lParam=lpBuffer
;GM_SETCOLFORMAT		equ WM_USER+39	;wParam=nCol, lParam=lpszText
;GM_CELLCONVERT		equ WM_USER+40	;wParam=nRowCol, lParam=lpBuffer
;GM_RESETCOLUMNS		equ WM_USER+41	;wParam=0, lParam=0
;GM_GETROWCOLOR		equ WM_USER+42	;wParam=nRow, lParam=lpROWCOLOR
;GM_SETROWCOLOR		equ WM_USER+43	;wParam=nRow, lParam=lpROWCOLOR
;
;;Column alignment GA_*
;
;GA_ALIGN_LEFT		equ 0
;GA_ALIGN_CENTER		equ 1
;GA_ALIGN_RIGHT		equ 2
;
;;Column types TYPE_*
;
;TYPE_EDITTEXT		equ 0	;String
;TYPE_EDITLONG		equ 1	;Long
;TYPE_CHECKBOX		equ 2	;Long
;TYPE_COMBOBOX		equ 3	;Long
;TYPE_HOTKEY		equ 4	;Long
;TYPE_BUTTON		equ 5	;String
;TYPE_IMAGE		equ 6	;Long
;TYPE_DATE		equ 7	;Long
;TYPE_TIME		equ 8	;Long
;TYPE_USER		equ 9	;0=String, 1 to 512 bytes binary data
;TYPE_EDITBUTTON		equ 10	;String
;
;;Column sorting SORT_*
;
;SORT_ASCENDING		equ 0
;SORT_DESCENDING		equ 1
;SORT_INVERT		equ 2
;
;;Window styles STYLE_*
;
;STYLE_NOSEL		equ 01h
;STYLE_NOFOCUS		equ 02h
;STYLE_HGRIDLINES	equ 04h
;STYLE_VGRIDLINES	equ 08h
;STYLE_GRIDFRAME		equ 10h
;
;ODT_GRID		equ 6
;
;.const
;
;IFDEF DLL
;	szRAGridClass	db 'RAGrid',0
;ELSE
;	szRAGridClass	db 'MyRAGrid',0
;ENDIF


Global *OldGridProc

Structure COLUMN
 colwt.l
 lpszhdrtext.l
 halign.l
 calign.l
 ctype.l
 ctextmax.l
 lpszformat.l
 himl.l
 hdrflag.l
 colxp.l
 edthwnd.l
EndStructure

Structure ROWDATA
 lpszName.s
 nID.l
EndStructure


#GM_ADDCOL = #WM_USER+1 ;wParam=0, lParam=lpCOLUMN
#GM_ADDROW = #WM_USER+2 ;wParam=0, lParam=lpROWDATA (can be NULL)
#GM_GETCURROW	 = #WM_USER+12	;wParam=0, lParam=0
#GM_SETBACKCOLOR = #WM_USER+21 ;wParam=nColor, lParam=0
#GM_SETGRIDCOLOR = #WM_USER+23 ;wParam=nColor, lParam=0
#GM_SETTEXTCOLOR = #WM_USER+25 ;wParam=nColor, lParam=0
#GM_SETHDRHEIGHT = #WM_USER+31	;wParam=0, lParam=nHeight
#GM_SETROWHEIGHT	= #WM_USER+33	;wParam=0, lParam=nHeight
#GM_COLUMNSORT	 = #WM_USER+35	;wParam=nCol, lParam=0=Ascending, 1=Descending, 2=Invert

#GN_HEADERCLICK	= 1	;User clicked header

#GA_ALIGN_LEFT = 0
#GA_ALIGN_RIGHT = 2
#TYPE_EDITTEXT = 0   ;String
#TYPE_EDITLONG = 1   ;Long
#SORT_INVERT = 2

Procedure GridProc(hWnd, uMsg, wParam, lParam)
  Select uMsg
    Case #WM_MOUSEMOVE
      SetWindowText_(WindowID(), "X: "+Str(lParam&$ffff)+", Y: "+Str(lParam>>16))
    Case #WM_LBUTTONDOWN
      SetWindowText_(WindowID(), "WM_LBUTTONDOWN")
    Case #WM_LBUTTONUP
      SetWindowText_(WindowID(), "WM_LBUTTONUP")
    Case #WM_NOTIFY
; Catch RaGrid notifications here?
   EndSelect
   Debug wParam
  ProcedureReturn CallWindowProc_(*OldGridProc, hWnd, uMsg, wParam, lParam)
EndProcedure


If OpenWindow(0, 100, 200, 195, 260, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget, "PureBasic Window")
  If OpenLibrary(0, "RAGrid.DLL")
    InitCommonControls_()
    hGrid = CreateWindowEx_($00000200, "RAGrid", "Grid test", $5001000D, 0, 0, 195, 260, WindowID(), 0, LibraryID(0), 0)
    If hGrid
      *OldGridProc = SetWindowLong_(hGrid, #GWL_WNDPROC, @GridProc())
      hFont = SendMessage_(WindowID(), #WM_GETFONT, 0, 0)
      SendMessage_(hGrid, #WM_SETFONT, hFont, #FALSE)
      ; Beware Delphi style Hex colour codes (not html style)
      SendMessage_(hGrid, #GM_SETBACKCOLOR, $FFFFC0, 0)
      SendMessage_(hGrid, #GM_SETGRIDCOLOR, $808080, 0)
      SendMessage_(hGrid, #GM_SETTEXTCOLOR, $800000, 0)
      SendMessage_(hGrid, #GM_SETHDRHEIGHT, 0, 24)

      col.COLUMN
      col\colwt = 130
      col\lpszhdrtext = @"Name"
      col\halign = #GA_ALIGN_LEFT
      col\calign = #GA_ALIGN_LEFT
      col\ctype = #TYPE_EDITTEXT
      col\ctextmax = 31
      col\lpszformat = 0
      col\himl = 0
      col\hdrflag = 0
      SendMessage_(hGrid, #GM_ADDCOL, 0, @col)

  ;Number column
      col\colwt = 42
      col\lpszhdrtext = @"ID"
      col\halign = #GA_ALIGN_RIGHT
      col\calign = #GA_ALIGN_RIGHT
      col\ctype = #TYPE_EDITLONG
      col\ctextmax = 11
      col\lpszformat = 0
      col\himl = 0
      col\hdrflag = 0
      SendMessage_(hGrid, #GM_ADDCOL, 0, @col)

  ;Add some rows
      Dim rdta.ROWDATA(6)
      ;Test values
      rdta(0)\lpszName="Anders"
      rdta(0)\nID=1
      rdta(1)\lpszName="Carson"
      rdta(1)\nID=3
      rdta(2)\lpszName="Balantine"
      rdta(2)\nID=2
      rdta(3)\lpszName="Novus"
      rdta(3)\nID=4
      rdta(4)\lpszName="Ordo"
      rdta(4)\nID=5
      rdta(5)\lpszName="Seclorum"
      rdta(5)\nID=6
      rdta(6)\lpszName="Zachariah"
      rdta(6)\nID=7
      For i=0 To 6
        SendMessage_(hGrid, #GM_ADDROW, 0, @rdta(i))
        SendMessage_(hGrid, #GM_SETROWHEIGHT, 0, 24)
      Next i
      ShowWindow_(hGrid, #SW_SHOW)
      ; Will column sort work here.. yup
      ; SendMessage_(hGrid, #GM_COLUMNSORT, 1, 0)
      Repeat
        EventID.l = WaitWindowEvent()
        If EventID = #PB_Event_CloseWindow
          Quit = 1
        EndIf
      Until Quit = 1
    EndIf
    DestroyWindow_(hGrid)
  EndIf
  CloseLibrary(0)
EndIf
End 
El_Choni
TailBite Expert
TailBite Expert
Posts: 1007
Joined: Fri Apr 25, 2003 6:09 pm
Location: Spain

Post by El_Choni »

Code: Select all

Structure GRIDNOTIFY
   nmhdr.NMHDR
   col.l
   row.l
   hwnd.l
   lpdata.l
   fcancel.l
EndStructure

;

Procedure GridProc(hWnd, uMsg, wParam, lParam)
  Select uMsg
    Case #WM_MOUSEMOVE
      SetWindowText_(WindowID(), "X: "+Str(lParam&$ffff)+", Y: "+Str(lParam>>16))
    Case #WM_LBUTTONDOWN
      SetWindowText_(WindowID(), "WM_LBUTTONDOWN")
    Case #WM_LBUTTONUP
      SetWindowText_(WindowID(), "WM_LBUTTONUP")
    Case #WM_NOTIFY ; Catch RaGrid notifications here? Yes ;)
      *gn.GRIDNOTIFY = lParam ; now the structure members hold the necessary data
      Debug *gn\col
   EndSelect
  ProcedureReturn CallWindowProc_(*OldGridProc, hWnd, uMsg, wParam, lParam)
EndProcedure 

El_Choni
User avatar
fiver
User
User
Posts: 36
Joined: Wed May 05, 2004 8:21 pm
Location: An outer spiral arm of the Milky Way

Post by fiver »

You are a star El_Choni! - Thankyou
Max.
Enthusiast
Enthusiast
Posts: 225
Joined: Fri Apr 25, 2003 8:39 pm

Post by Max. »

Looks very promising, El Choni! Thanks.

Where did you find the documentation, btw? Did look on the homepage and in the archive, but wasn't successful. But ok, maybe I am just blind!
Athlon64 3800+ · 1 GB RAM · Radeon X800 XL · Win XP Prof/SP1+IE6.0/Firefox · PB 3.94/4.0
Intel Centrino 1.4 MHz · 1.5 GB RAM · Radeon 9000 Mobility · Win XP Prof/SP2+IE6.0/Firefox · PB 3.94/4.0
User avatar
fiver
User
User
Posts: 36
Joined: Wed May 05, 2004 8:21 pm
Location: An outer spiral arm of the Milky Way

Post by fiver »

Max: I don't think there are any docs, although the code for the examples is well commented, of course that will only help if you understand the asm!

I still can't get the column sort working but I suspect I still have the messaging set up wrong:

Code: Select all


Structure GRIDNOTIFY
   nmhdr.NMHDR
   col.l
   row.l
   hwnd.l
   lpdata.l
   fcancel.l
EndStructure


#GM_ADDCOL = #WM_USER+1 ;wParam=0, lParam=lpCOLUMN
#GM_ADDROW = #WM_USER+2 ;wParam=0, lParam=lpROWDATA (can be NULL)
#GM_GETCURROW	 = #WM_USER+12	;wParam=0, lParam=0
#GM_SETBACKCOLOR = #WM_USER+21 ;wParam=nColor, lParam=0
#GM_SETGRIDCOLOR = #WM_USER+23 ;wParam=nColor, lParam=0
#GM_SETTEXTCOLOR = #WM_USER+25 ;wParam=nColor, lParam=0
#GM_SETHDRHEIGHT = #WM_USER+31	;wParam=0, lParam=nHeight
#GM_SETROWHEIGHT	= #WM_USER+33	;wParam=0, lParam=nHeight
#GM_COLUMNSORT	 = #WM_USER+35	;wParam=nCol, lParam=0=Ascending, 1=Descending, 2=Invert

#GN_HEADERCLICK	= 1	;User clicked header

#GA_ALIGN_LEFT = 0
#GA_ALIGN_RIGHT = 2
#TYPE_EDITTEXT = 0   ;String
#TYPE_EDITLONG = 1   ;Long
#SORT_INVERT = 2


Procedure GridProc(hWnd, uMsg, wParam, lParam)
  Select uMsg
    Case #WM_MOUSEMOVE
      SetWindowText_(WindowID(), "X: "+Str(lParam&$ffff)+", Y: "+Str(lParam>>16))
    Case #WM_LBUTTONDOWN
      SetWindowText_(WindowID(), "WM_LBUTTONDOWN")
    Case #WM_LBUTTONUP
      SetWindowText_(WindowID(), "WM_LBUTTONUP")
    Case #WM_NOTIFY ; Catch RaGrid notifications here? Yes ;)
      notify.s="Are we there yet?"
      *gn.GRIDNOTIFY = lParam ; now the structure members hold the necessary data
      Debug *gn\col
      Debug notify ; doesn't show
      If *gn\lpdata = #GN_HEADERCLICK
        SendMessage_(hGrid, #GM_COLUMNSORT, 1, 0)
      EndIf
   EndSelect
  ProcedureReturn CallWindowProc_(*OldGridProc, hWnd, uMsg, wParam, lParam)
EndProcedure
Post Reply