I have a mdi app which uses an icon I put in the sys tray.

When I double click on the icon (and the app is minimized) the app is maximized and a child form is opened. This works ok.

If I double click on the icon (and the app is in any state) the app should appear and the child form should either be loaded of have focus set to it. This does not work. The mdi form does not even appear.

Can anybody explain why and how to correct this.

VB Code:
  1. Private Sub MDIForm_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  2.  
  3. Static lngMsg As Long
  4. Static blnFlag As Boolean
  5.  
  6. Dim lngResult As Long
  7.  
  8.   lngMsg = X / Screen.TwipsPerPixelX
  9.  
  10.   If blnFlag = False Then
  11.        
  12.     blnFlag = True
  13.    
  14.     Select Case lngMsg
  15.    
  16.       Case WM_LBUTTONDBLCLK
  17.        
  18.         lngResult = SetForegroundWindow(Me.hwnd)
  19.        
  20.         ' Check if RATs is minimized
  21.         If Me.WindowState = vbMinimized Then Me.WindowState = vbMaximized
  22.        
  23.         ' Check if Pinboard is open
  24.         If FormIsOpen("frmRelatedItems") Then
  25.  
  26.           ' Check if Pinboard is minimized
  27.           If frmRelatedItems.WindowState = vbMinimized Then
  28.             frmRelatedItems.WindowState = vbNormal
  29.           Else
  30.             frmRelatedItems.SetFocus
  31.           End If
  32.  
  33.         Else
  34.  
  35.           Load frmRelatedItems
  36.  
  37.         End If
  38.      
  39.     End Select
  40.    
  41.     blnFlag = False
  42.  
  43.   End If
  44.  
  45. End Sub