Hi again. I'm having another splash screen problem.

I have 3 forms namely login, main, splash. Once the user has authenticated himself, the main functions will be started and the splash screen is shown as well. My problem is that if the user moves or minimizes the splash screen, the main form is shown. I also tried setting the windowstate of the main form to minimized but another problem is that it can just be clicked on the taskbar and it will be in plain view again. How do I code this such that the main form will only be visible once certain variables are set and the splash is closed?

Currently, I am using these codes:

On the login screen(after checking the username and password with the database):

main.show

On the main screen:

Private Sub Form_Load()
      Call CameraOn()
      splash.show
      End Sub

I plan to have a timer control on the splash form with the following code. loadokay is my Boolean trigger for the splash to disappear. It is triggered if all preparations in the main form are complete.

If (main.loadokay=True) Then 
splash.hide 
main.show 
End If

However, this is no use if the main form can just be activated anytime or the splash screen can be moved aside or minimized.

Recommended Answers

All 21 Replies

In the design time, you must make your form Splash Border Style property to None so it cant be moved out or minimized. You can also show your splash as modal window like this

splash.show vbModal, Me

But make sure you have a timer event make your splash form unload automatically, or unload when user click on the splash screen form.

Happy coding...

Set your form Movable property to False on Design time.

You can also add this code to your form keypress event.

KeyAscii = 0

This will disable all keys from the keyboard (even mouse - not so sure). And yes, you should use a timer control.

Thank you for your help. All I needed was the modal window addition. Thanks again.

commented: dont know why you've given me -1 for my solution. Use your brain to think and use your eyes to read the solutions! +0

On second thought, vbModal is okay but it interferes with my mouse clicks. The mouse moves and clicks I execute on the main form are not performed because of the splash screen.

Put your code on the login form.

Example:

Splash.Show vbModal, Me

Then on your splash form after the timer control time is over (?),

Me.Hide

There is a much easier way. Set your splash screen AND Main form properties as such -

MaxButton = False
MinButton = False
Moveable = False

Now add the following code that will disable the "x"/close button. This way the splash will show and can not be minimised, closed, moved or nothing. It will only happen once all events is done in your main form.:)

In a module, add the following code -

Option Explicit

'windows constants
Public Const SWP_DRAWFRAME As Long = &H20
Public Const SWP_NOMOVE As Long = &H2
Public Const SWP_NOSIZE As Long = &H1
Public Const SWP_NOZORDER As Long = &H4
Public Const SWP_FLAGS = SWP_NOZORDER Or SWP_NOSIZE Or _
                         SWP_NOMOVE Or SWP_DRAWFRAME
                    
'menu flags
Public Const MF_BYCOMMAND As Long = &H0
Public Const MF_BYPOSITION As Long = &H400
Public Const MF_REMOVE As Long = &H1000

Public Const MIIM_STATE As Long = &H1
Public Const MIIM_ID As Long = &H2
Public Const MIIM_SUBMENU As Long = &H4
Public Const MIIM_CHECKMARKS As Long = &H8
Public Const MIIM_TYPE As Long = &H10
Public Const MIIM_DATA As Long = &H20
Public Const MFT_STRING As Long = &H0
Public Const MFT_RADIOCHECK As Long = &H200
Public Const MFS_DISABLED As Long = &H3

Public Type MENUITEMINFO
    cbSize As Long
    fMask As Long
    fType As Long
    fState As Long
    wID As Long
    hSubMenu As Long
    hbmpChecked As Long
    hbmpUnchecked As Long
    dwItemData As Long
    dwTypeData As String
    cch As Long
End Type

Public Declare Function GetMenuItemInfo Lib "user32" _
    Alias "GetMenuItemInfoA" _
   (ByVal hMenu As Long, ByVal uItem As Long, _
    ByVal fByPosition As Long, lpmii As MENUITEMINFO) As Long

Public Declare Function GetMenuItemCount Lib "user32" _
   (ByVal hMenu As Long) As Long
      
Public Declare Function GetSystemMenu Lib "user32" _
   (ByVal hwnd As Long, _
    ByVal bRevert As Long) As Long
       
Public Declare Function RemoveMenu Lib "user32" _
   (ByVal hMenu As Long, _
    ByVal nPosition As Long, _
    ByVal wFlags As Long) As Long
    
Public Declare Function DrawMenuBar Lib "user32" _
   (ByVal hwnd As Long) As Long
          
Public Declare Function SetWindowPos Lib "user32" _
    (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, _
     ByVal x As Long, ByVal y As Long, _
     ByVal cx As Long, ByVal cy As Long, _
     ByVal wFlags As Long) As Long
       

Public Sub MenuRemoveClose(frm As Form)

   Dim c As Long
   Dim hMenu As Long
   Dim mInfo As MENUITEMINFO
   Dim pos As Long
  
  'get the system menu handle
   hMenu = GetSystemMenu(frm.hwnd, 0)

  'loop backwards through the menu
   For c = GetMenuItemCount(hMenu) To 0 Step -1

      With mInfo
         .cbSize = Len(mInfo)
         .fMask = MIIM_TYPE Or MIIM_ID
         .fType = MFT_STRING
         .dwTypeData = Space$(256)
         .cch = Len(mInfo.dwTypeData)
      End With
         
      
     'Retrieve the current MENUITEMINFO.
     'Specifying fByPosition=True indicates
     'uItem points to an item by position.
     'Returns 1 if successful
      If GetMenuItemInfo(hMenu, c, True, mInfo) = 1 Then

        'The close command has an ID of 61536. Once
        'that has been deleted, in a MDI Child window
        'two separators would remain (in a SDI one
        'separator would remain).
        '
        'To assure that this code will cover both
        'MDI and SDI system menus, 1 is subtracted
        'from the item number (c) to remove either
        'the top separator (of the two that will
        'remain in a MDIChild), or the single SDI
        'one (that would remain if this code was
        'applied against a SDI form.)
         If (mInfo.wID = 61536) Then
         
            Call RemoveMenu(hMenu, c, _
                            MF_REMOVE Or MF_BYPOSITION)
                         
            Call RemoveMenu(hMenu, c - 1, _
                            MF_REMOVE Or MF_BYPOSITION)
            
         End If
         
      End If
      
   Next
   
  'force a redraw of the non-client
  'area of the form to cause the
  'disabled X to paint correctly
   Call SetWindowPos(frm.hwnd, 0, 0, 0, 0, 0, SWP_FLAGS)
   Call DrawMenuBar(frm.hwnd)
   
End Sub

In your form, call it as in -

Call MenuRemoveClose(Me)

Put your code on the login form.
Example:

Splash.Show vbModal, Me

Then on your splash form after the timer control time is over (?),

Me.Hide

Thanks but I get an error if I use this code.
Run time error -2147024726 (800700aa)
Method 'Navigate' of object 'IWebBrowser2' failed

There is a much easier way. Set your splash screen AND Main form properties as such -

MaxButton = False
MinButton = False
Moveable = False

Now add the following code that will disable the "x"/close button. This way the splash will show and can not be minimised, closed, moved or nothing. It will only happen once all events is done in your main form.:)

In a module, add the following code -

Option Explicit

'windows constants
Public Const SWP_DRAWFRAME As Long = &H20
Public Const SWP_NOMOVE As Long = &H2
Public Const SWP_NOSIZE As Long = &H1
...   
End Sub

In your form, call it as in -

Call MenuRemoveClose(Me)

Thanks for the module. Now the splash can't be closed. However, the mouse move codes of the main form are executed on the splash form. It seems that the mouse move and mouse click functions are executed on the objects on screen and not on the form. Is there any other way to solve this? Thanks.

You need to do the call in the form load event, first of any other code.

Yes, set both form properties - "KeyPreview to true until all the code ran.

Yes, set both form properties - "KeyPreview to true until all the code ran.

Hi Andre,

Code still does not work after setting keypreview. I see the mouse being moved and clicked on the splash form. When it is unloaded, the main form shows that it was not clicked and modified at all.

I helped another member here about 2 weeks ago. See if you can find the post about keydown events on a form. I gave him all the sample code he needed to get the form mouse move events.:)

Another question, why don't you just load all the start up code on the splash screen and then show the main form?

I'll start looking for it. :)

About loading the code on the splash screen, I was planning on doing it but I don't think it will work with the mouse clicks(its really a pain). Given the code I found, I'm about certain that it will just click whatever is on screen. If I hide the main form with a splash screen, it just clicks the splash.

http://www.vb6.us/tutorials/move-mouse-api - the code I mentioned last time.

If you find the code (about a week or 2 back) you will see that all mouse events is caught and send to a form, whether it is on a form or just the screen, no matter.;)

Is it this one?
DataList & Mouse scroll

That sounds like a better code. :)


Edit: Can't seem to find anything else that is related to keydown events. Checked your last posts about up to 18 days back.

Nah, I'll find it tomorrow Martin and help out with the solution. I'm "sat"/tired, going home now.:)

Okay, Andre. Thanks.

I couldn't find the link, but the code below should solve your problem. Adjust it to suit your needs -

Option Explicit

Private Type POINTAPI
    X As Long
    Y As Long
End Type

Private Declare Function GetCursorPos Lib "user32" _
(lpPoint As POINTAPI) As Long

'***********************
'THESE TWO FUNCTIONS RETURN THE POSITION ON THE SCREEN
'IN PIXELS, OF THE CURSOR

'EXAMPLE USAGE:

'Private Sub Form_MouseMove(Button As Integer, _
     'Shift As Integer, X As Single, Y As Single)

'    Label1.Caption = "X Screen Position = " & GetXCursorPos
'    Label2.Caption = "Y Screen Position =  " & GetYCursorPos
'End Sub
'***********************************

Public Function GetXCursorPos() As Long
   Dim pt As POINTAPI
   GetCursorPos pt
   GetXCursorPos = pt.X
End Function

Public Function GetYCursorPos() As Long
   Dim pt As POINTAPI
   GetCursorPos pt
   GetYCursorPos = pt.Y
End Function

Hi Andre,

I think it is better to show you what I mean. I have uploaded a sample program which depicts the problem.

I don't know why the splash screen is not on top anymore in this sample program though. In my original program, it is always on top. Hope you understand what I mean.

Thanks,
Martin

I have lost total track of this thread, will have to go all again, TOMORROW.;)

Thanks Andre.

@all,
Just bumping the thread. Has anyone tried out the project I attached? Thanks.

I forgot about this.... sorry.

Will post soon.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.