View Full Version : filling a listview AFTER it's visible on the form
Is there a %WM parameter that does the same as Visual Basic's Private Sub Form_Activate()
I tried %WM_INITDIALOG but it's fired before the form is loaded. I want to display a listview and then when it's visible i want to fill it with records (not before it's visible).
ErosOlmi
26-06-2009, 18:10
Martin,
you can use DIALOG POST ... to send a user defined command to your main dialog window just after you have finish all your duties in %WM_INITDIALOG
For example something like that:
'----------------------------------------------------------------------------
callback function cb_Main()
'----------------------------------------------------------------------------
'---Now test the message
SELECT CASE cbMsg
'---Message fired at the very beginning when dialog is initialized
case %WM_INITDIALOG
'---Do whatever is needed to init your dialog then
'---fire a post message. Posting message means put a message in the message queue of the target dialog
DIALOG post cbhndl, %WM_USER + 100, 0, 0
case %WM_USER + 100
'---Do whatever is needed to init your dialog then
'...
'...
'...
'...
END SELECT
END FUNCTION
Instead of %WM_USER + 100 it is better to define a personalized equate like:
%WM_USER_ShowData = %WM_USER + 100
and than use the new equate. In this way your code is much more readable and maintainable for future updates.
Hope it works.
Ciao
Eros
Hi Eros,
Thanks for the clear example, but no kidding it doesn't work. I tried to do this in the Dialog Callback, but no succes. And even your own example doesn't work here. Well, i'm sure I do something wrong. I will get some sleep and try again tomorrow when i'm fresh!
Goodnight!
Martin
Petr Schreiber
27-06-2009, 10:43
Hi Martin,
how about WM_ACTIVATEAPP?
It is fired when you enter or leave the window (you can recognize both states).
Here is little demo:
' Basic Template for custom dialog
' Start Date 06-27-2009
' Created by Petr Schreiber
USES "UI", "Console"
' -- ID numbers of controls
Begin Const
%btnClose = 1000
End Const
' -- Create dialog here
FUNCTION TBMAIN()
LOCAL hDlg AS DWORD
DIALOG New 0, "<Enter title here>",-1,-1, 160, 120, _
%WS_POPUP Or %WS_VISIBLE Or %WS_CAPTION OR %WS_SYSMENU Or %WS_MINIMIZEBOX To hDlg
' -- Place controls here
CONTROL ADD BUTTON, hDlg, %btnClose, "Click to close", 95, 100, 60, 14, CALL btnCloseProc
DIALOG SHOW MODAL hDlg, CALL dlgProc
END FUNCTION
' -- Callback for dialog
CALLBACK FUNCTION dlgProc()
' -- Test for messages
SELECT CASE CBMSG
CASE %WM_INITDIALOG
' -- Put code to be executed after dialog creation here
CASE %WM_COMMAND
CASE %WM_ACTIVATEAPP
if cbWparam = %TRUE then
printl "You just switched to this window..."
end if
' -- You can handle controls here
'SELECT CASE CBCTL
'
' CASE ...
' IF CBCTLMSG = ... THEN
'
' END IF
'
'END SELECT
CASE %WM_CLOSE
' -- Put code to be executed before dialog end here
END SELECT
END FUNCTION
' -- Callback for close button
CALLBACK FUNCTION btnCloseProc()
IF CBMSG = %WM_COMMAND THEN
IF CBCTLMSG = %BN_CLICKED THEN
' -- Closes the dialog
DIALOG END CBHNDL
END IF
END IF
END FUNCTION
Is it at least close to what you need? :)
ErosOlmi
27-06-2009, 10:51
Thanks for the clear example, but no kidding it doesn't work.
Of course you are right. But here it works in some cases and not in others and unfortunately I'm not able to understand why. The strange is that if I add a MSGBOX in between all is working as expected. So, for the moment do not follow my indication of using POST.
Petr suggested another road. Maybe you can use it setting a static variable that will let you know if listview has already been filled.
Here another try using a timer. Mainly you set a dummy timer just after %WM_INITDIALOG and than wait for that timer (I set it to 1000 msec but it can be much less). As soon as the timer is fired, you destroy it and fill your list.
Attached an example.
Ciao
Eros
Pfew, Windows crashed today. That's why I am a little bit late with responding because I had to reinstall everything (somehow my Ghost backup/restore software doesn't work anymore since I have another pc :unguee:)
Petr, thanks for your suggestion but WM_ACTIVATEAPP doesn't do what I want. It's seems also to be fired before loading the window. :?
Eros, your example with the timer works perfect. Thanks to your example I also learned now how I can handle two or more timers. I still consider to make a virtual listview because the time of filling the listview with ten thousands of records takes a few seconds. 2 Years ago I made a virtual listview in VB and it works great (fast!). But I couldn't find a control for a (vertical) scrollbar in thinbasic. Without this I can't make it (or I should use a progressbar). Hmm for the moment I will use your Timer-example. But if you can add someday a scrollbar control into ThinBasic you can be sure a will make the listview virtual (maybe also useful for other users here).
Greetings from the Netherlands (pfff very hot here),
Martin
ErosOlmi
28-06-2009, 10:08
Pfew, Windows crashed today. That's why I am a little bit late with responding because I had to reinstall everything (somehow my Ghost backup/restore software doesn't work anymore since I have another pc :unguee:)
I'm sorry. Nowadays considering how many info we put in our PC having a bad crash is something can bring a lot of stress. Hope you will recover.
But if you can add someday a scrollbar control into ThinBasic you can be sure a will make the listview virtual (maybe also useful for other users here).
Well, because scrollbar control is a standard Windows control, its class is already loaded by Windows so in thinBasic you could add something like:
control add "SCROLLBAR", cbhndl, 0, "", 5, 5, 150, 15, %WS_VISIBLE | %WS_CHILD
and have your scrollbar in your window.
But of course you need to add all the declares of constants and you will not have a callback.
So, if you can wait a little bit, consider a native scrollbar handling done for the next thinBasic preview update.
Eros
I'm sorry. Nowadays considering how many info we put in our PC having a bad crash is something can bring a lot of stress. Hope you will recover.
The damage was not so bad, I only had to reinstall windows and software. Ofcourse I backup all my data frequently to other (external) drives. No thinbasic scripts are lost :lol:
Well, because scrollbar control is a standard Windows control, its class is already loaded by Windows so in thinBasic you could add something like:
control add "SCROLLBAR", cbhndl, 0, "", 5, 5, 150, 15, %WS_VISIBLE | %WS_CHILD
and have your scrollbar in your window.
But of course you need to add all the declares of constants and you will not have a callback.
So, if you can wait a little bit, consider a native scrollbar handling done for the next thinBasic preview update.
Ah that sounds pretty easy! But I will wait until you have added it in the next release. I have to code enough other functions for my script. It's growing day by day but I always keep in mind what you said: think small, first finish what you want and then add something new.
Have a nice day!
Martin
ErosOlmi
28-06-2009, 16:14
Finished to develop new scrollbar control.
Next thinBasic version will have the following functions working with scrollbars:
ScrollBar_GetPageSize
ScrollBar_GetPos
ScrollBar_GetTrackPos
ScrollBar_GetRangeLow
ScrollBar_GetRangeHi
ScrollBar_SetPageSize
ScrollBar_SetPos
ScrollBar_SetRange
Scrollbar control will have the possibility to be handled by specific callback functions or will be able to be managed by %WM_HSCROLL or %WM_VSCROLL from the main dialog callback.
Eros
Wow, that's fast!! Really cool, thanks a lot!