Results 1 to 10 of 10

Thread: Force a Form to Hide

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2002
    Posts
    50

    Question Force a Form to Hide

    How would I force a form to hide? After logging off and logging back on, the forms on my VB Service app no longer respond to the .Hide command nor the visible property ... any ideas?

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    How about using this...
    Code:
    'SHOWWINDOW COMMANDS
    Public Const SW_HIDE = 0
    Public Const SW_SHOWNORMAL = 1
    Public Const SW_NORMAL = 1
    Public Const SW_SHOWMINIMIZED = 2
    Public Const SW_SHOWMAXIMIZED = 3
    Public Const SW_MAXIMIZE = 3
    Public Const SW_SHOWNOACTIVATE = 4
    Public Const SW_SHOW = 5
    Public Const SW_MINIMIZE = 6
    Public Const SW_SHOWMINNOACTIVE = 7
    Public Const SW_SHOWNA = 8
    Public Const SW_RESTORE = 9
    Public Const SW_SHOWDEFAULT = 10
    Public Const SW_MAX = 10
    
    Public Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
    
    Call ShowWindow(App.hwnd, SW_HIDE)
    Last edited by RobDog888; Apr 8th, 2003 at 09:23 PM.

  3. #3

    Thread Starter
    Member
    Join Date
    Jul 2002
    Posts
    50
    Ok, the problem was that for some reason the Form_QueryUnload doesn't get called when the Form's close button is clicked ...

    Can anyone suggest a solution to this? Maybe subclassing the form to recieve the clicked event of the form's close button?

  4. #4
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    My guess would be that you're using the "END" statement in the unload button. BUt it's kinda hard to tell since you've shown no code.
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  5. #5

    Thread Starter
    Member
    Join Date
    Jul 2002
    Posts
    50
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    ShowWindow Me.hwnd, SW_HIDE
    End Sub
    Real complex stuff...

    But the unload method is not the problem, I even tested it by making a message box popup if queryunload is called, but it never does, thus it is never called. And the X button on the form goes acts wierd too, after the log off/log on it doesn't "act" normally ... its hard to explain ... it doesn't depress properly sometimes ...

    Maybe there is some way I can use API to re-initialize the form controls? I know you can manipulate them with API ... anything is worth a try.
    Last edited by VB_GOD; Apr 10th, 2003 at 01:33 PM.

  6. #6
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    Originally posted by VB_GOD
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    ShowWindow Me.hwnd, SW_HIDE
    End Sub

    lol well that is why...

    first of all... your in the queryunload routine..which means hiding the form is pointless.. because it is being unloaded from memory... plus the fact that you are sending a message via api to the window (which is why .show/.hide and .visible doesn't work after you do this).. you don't need to do this... try something like this

    VB Code:
    1. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    2.     if UnloadMode = vbFormControlMenu Then'X button
    3.         Cancel = True
    4.         Me.Hide
    5.     end if
    6. End Sub
    this will make it so when the form is closed... if the user closed it with the X button.. it doesn't unload the form from memory.. but just hides it.. and you can get it back using the .show method of the form

  7. #7

    Thread Starter
    Member
    Join Date
    Jul 2002
    Posts
    50
    Still doesn't work .....
    I think windows messes it up when it logs off ... even if I intercept WM_ENDSESSION = &H16 or WM_QUERYENDSESSION = &H11 messages to the form or not.

  8. #8
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    Originally posted by VB_GOD
    Still doesn't work .....
    I think windows messes it up when it logs off ... even if I intercept WM_ENDSESSION = &H16 or WM_QUERYENDSESSION = &H11 messages to the form or not.
    well then try
    VB Code:
    1. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    2.     if UnloadMode = vbFormControlMenu or UnloadMode = vbAppWindows Then'X button
    3.         Cancel = True
    4.         Me.Hide
    5.     end if
    6. End Sub

    although windows might unload the form anyway... u would have to try it

  9. #9

    Thread Starter
    Member
    Join Date
    Jul 2002
    Posts
    50
    I would say that fixes it ... but only because it prevents windows from shutting down in the first place . So this is not of much help .. lol.

  10. #10
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    Originally posted by VB_GOD
    I would say that fixes it ... but only because it prevents windows from shutting down in the first place . So this is not of much help .. lol.
    maybe I don't understand what you are looking to do then.. i thought you didn't want it to shutdown.. only hide

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width