Form show event

trapping a form show event

Page 1 of 1

0 Replies - 818 Views - Last Post: 21 October 2009 - 01:17 AM Rate Topic: -----

#1 BidSki   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 30-June 05

Form show event

Posted 21 October 2009 - 01:17 AM

Hello all.

What I am trying to do seems fairly simple and straightforward (at least, it does to me :P). Basically what I am wanting to do is trap an event that occurs when a dialog box is shown to the screen, but I only want it to happen once (being the first time that the form is displayed to screen after its initial loading).

I have tried a handful of things and none of them work.

I have tried a couple of hooks that I thought might have triggered at the right point (WH_FOREGROUNDIDLE, CBT_PROC - WH_ACTIVATE and CBT_PROC - WH_CREATEWND), but all of these trigger BEFORE the dialog is visible on the screen.

I used SetWindowsHookEx to set the hook and the appropriate CALLBACK functions for the above mentioned hooks.

I also tried handling the WM_SHOWWINDOW message, but once again this triggers before the dialog is visible.


A little about my code and why I am trying to do this .........

At present, this is the general flow of the prgram:

User clicks button on main form.

Open a database and a recordset, extracting some information from the recordset which is being stored in 3 different arrays (2 CStringArrays and 1 CUIntArray). 

Open a text file, extract some information and then use that information to populate a CTreeView control with various nodes.

Populate a CListbox control with the information from 1 of the CStringArrays and setting the ItemData with the information from the CUIntArray

Select the top-most item in the CListbox control and populate about 35 on-screen controls and about 5 hidden controls (textboxes, labels and combo/listboxes) with information from the database using a couple of different recordsets.

Form is diplayed (not the main form, but a new one).


At the moment it is all happening pretty quickly with the longest part being the populating of the CListbox control which is taking about 1-2 seconds to populate it with about 1800 items. This part used to take close to 10 secs to complete, but with a slight change to the code I managed to reduce it to its current 1-2 secs. My concern is that if the amount of data to be populated into the CListbox control grows (which is very possible, I could see possible situations requiring 10,000+ items) that the loading of the form will once again increase to a pathetically long time.

With a long delay, the user will click the button on the main form and the program will appear to do nothing. I have a progress bar on the form I am displaying, but its not much good if the form isnt visible, but if I can get the form to show and then do my loading the user will at least have some sort of visual recognition that the program is doing something.

And therein lies my problem, is there any event that gets fired AFTER the form is displayed to the screen that will allow me to do all the loading that I need to do?

I hope that makes some sense to everyone. If you need further clarification just ask.

And for anyone that is wondering, this is not homework.

Thanks in advance
Bidski

Is This A Good Question/Topic? 0
  • +

Page 1 of 1