Background
I was almost finished with an app I was writing. Twice in this app I did some time consuming formatting and I thought it would be nice to have a status bar in these loops. My program had Modal windows so the problem begun. I could not show a non modal window on to of a modal window and if I loaded a Modal window I could not execute the code in the current module. I did not want to put the code in the status window because there were 2 big loops that had to be in the modules they were. So this is what I found. You can show a window non-modal with the SetWindowPos call from windows. By showing the window with this call I had two windows that could get the focus so I had to disable the first form and I just did that with Me.Enabled = False. When the loop was finished I just Enabled my for again and unloaded the status form.
Code
Global Declare:
Declare Function SetWindowPos Lib "User" (ByVal hWnd As Integer, ByVal hWndInsertAfter As Integer,
ByVal X As Integer, ByVal Y As Integer, ByVal cX As Integer, ByVal cY As Integer,
ByVal wFlags As Integer) As Integer
Global Const SWP_NOMOVE = &H2
Global Const SWP_NOSIZE = &H1
Global Const SWP_SHOWWINDOW = &H40
Global Const HWND_TOP = 0
The loop:
Sub DoAnyThing ()
' Show the status window
i = SetWindowPos(frm_Status.hWnd, HWND_TOP, 0, 0, 0, 0,
SWP_NOSIZE Or SWP_NOMOVE Or SWP_SHOWWINDOW)
' Disable Me
Me.Enabled = False
DoEvents
' Do the loop
For I = 1 To 200
' do stuff
' set the status
frm_Status.pic_Status.Line (0, 0)-(I, 100), QBColor(1), BF
frm_Status.pic_Status.Refresh
DoEvents
Next I
'Unload the status window
Unload frm_Status
' Enable Me ...
Me.Enabled = True
' and give me the focus
Me.SetFocus
End Sub
Tip Submitted By: Olafur Orn Jonsson
Discover more from dotNetTips.com
Subscribe to get the latest posts sent to your email.
