GRD for Freebasic (Windows only)

User projects written in or related to FreeBASIC.
Post Reply
James Klutho
Posts: 14
Joined: Nov 11, 2009 23:44

GRD for Freebasic (Windows only)

Post by James Klutho »

I uploaded a grid control at the plantsquires website.

http://www.planetsquires.com/protect/fo ... 5#msg30215

It is a Wide String control. It is programmed as an include file but could be turned into a DLL without too much work. It can be used as a multi-sheet workbook and I have included options things like Buttons, Drop-down Lists, Vertical text, Borders, Bitmaps, Storing record numbers in the row header etc. It is still pretty basic but someone might find it useful. Multi-Cell selection is Shift-Click only with no drag selection. There are no written docs but hopefully the example code can get you going. You might want to tweak the code if you have the desire to dig into it. I have quite a few hooks roughed in case I get motivated down the road. The formatting for the cells are stored as part of the grid strings. Formatting can be stored in the Column header, Row header or the cell itself with the priority being in that order also. There are enough notifications to act as a database editor.

This is my first real attempt at FreeBasic programming. I was pleasantly surprised with Freebasic. I hope to be writing more controls in the future.

Jim
srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

Re: GRD for Freebasic (Windows only)

Post by srvaldez »

this is great, thank you :-)
here's a pic of the demo for people to see.
Image
Cherry
Posts: 358
Joined: Oct 23, 2007 12:06
Location: Austria
Contact:

Re: GRD for Freebasic (Windows only)

Post by Cherry »

Very nice, however scrolling is behaving erratically when a device is used which has fine-grained scroll control, e.g. a touchpad or a trackpoint. It would keep scrolling down most of the time, even when trying to scroll up.

This is because your WM_MOUSEWHEEL handler considers only a delta of exactly WHEEL_DELTA a "scroll down" and everything else a "scroll up", which is of course not true. You need to keep a scroll delta variable and add the latest delta to it all the time and then calculate if scrolling is needed (and by how many lines).

I fixed it as follows:

1) In the GridData type, I added a field "AccumulatedScrollDeltaY As Integer"
2) I replaced the WM_MOUSEWHEEL as follows:

Code: Select all

   CASE WM_MOUSEWHEEL
           v->AccumulatedScrollDeltaY += GET_WHEEL_DELTA_WPARAM(wParam)
           
           Var fullCellDelta = v->AccumulatedScrollDeltaY \ WHEEL_DELTA
           
           If fullCellDelta Then
           	SendMessage(hWnd, GRD_SETTOPROW, min(max(GS_.TopRow - fullCellDelta, 1), GS_.TotRows), 1) 'Do a refresh with 1
           	v->AccumulatedScrollDeltaY -= fullCellDelta * WHEEL_DELTA
           EndIf
I also noticed that horizontal scrolling with the mouse doesn't work, because WM_MOUSEHWHEEL is not handled. I didn't add it yet though because it appeared to be more work because I couldn't find any GRD_SETLEFTROW message. Would be great if somebody could add it, though...

Plus, I think it's weird that you can scroll until the last row is at the top (as opposed to at the bottom), especially because then the scrollbar thumb will become smaller. I didn't find an easy way to fix it though.
James Klutho
Posts: 14
Joined: Nov 11, 2009 23:44

Re: GRD for Freebasic (Windows only)

Post by James Klutho »

Thanks Cherry for the feedback. I never seem to get scrolling right. I'm on another project now but I think I will return to the GRD and implement your suggestions in a month or two. I will also make an attempt at some documentation which I do even poorer than scrolling :). Jim
Cherry
Posts: 358
Joined: Oct 23, 2007 12:06
Location: Austria
Contact:

Re: GRD for Freebasic (Windows only)

Post by Cherry »

Hi, I found another issue:

You are using "GetModuleHandle(NULL)" in your "GRD_Int" code to get the current hInstance. However, this wrong because your code may be used in a DLL (that's what I'm doing for example). In this case it will go haywire as soon as more than one DLL (or the DLL plus the host application itself) use GRD.

See this article for a good explanation of this issue: https://blogs.msdn.microsoft.com/oldnew ... 0/?p=10133

You need to allow an hInstance to be passed into your function instead. You can use the default hInstance as fallback, e.g. by using a signature like "Sub GRD_Int(hInstance As HINSTANCE = GetModuleHandle(NULL))".
Post Reply