Shoutbox

Showing Form without vbModal in VB? For the programmers out there... :D - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Forum: Plug-Ins (/forumdisplay.php?fid=28)
+------ Thread: Showing Form without vbModal in VB? For the programmers out there... :D (/showthread.php?tid=45041)

Showing Form without vbModal in VB? For the programmers out there... :D by (CyBeRDuDe) on 05-20-2005 at 08:00 PM

Is it possible in a MsgPlus! Plugin to show a form without using the vbModal arguement, since it puts Messenger "on hold"... I need to show a form without holding back on Messenger....
And NOT open a instance of a seperate exe file...
I think I read somewhere that you could create a seperate activex .dll file and just load that?`.. How would I do that?...
Or should I use the CreateWindow API and some various other API's?.... Would you adivse to use the CreateWindow API to create a form in runtime?... Or not?.. I've read it should be very though to make it good, and that is was sometimes unstable... Is that true?...
How would you do it?

Please Help me!?....


RE: Showing Form without vbModal in VB? For the programmers out there... :D by matty on 05-21-2005 at 04:05 AM

code:
Public Declare Function ShowWindow Lib "user32" Alias "ShowWindow" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long

Public Declare Function DestroyWindow Lib "user32" Alias "DestroyWindow" (ByVal hwnd As Long) As Long

Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Public Const SW_SHOW = 5
Public Const SW_HIDE = 0
Public Const WM_CLOSE = &H10

'Usage: Show Window
     ShowWindow Form1.hWnd, SW_SHOW

'Usage: Hide Window
     ShowWindow Form1.hWnd, SW_HIDE

'Usage: Close Window #1
     SendMessage Form1.hWnd, 0&, 0&, WM_CLOSE

'Usage: Close Window #2
     DestroyWindow Form1.hWnd


Hope that helps.
They all go into a module. Change them from Public to Private if you want to just put them in the Class.
RE: Showing Form without vbModal in VB? For the programmers out there... :D by Mike on 05-21-2005 at 11:46 AM

quote:
Originally posted by Matty
Form1.hWnd
If you want to get the hwnd of a form, doesn't it need to be shown? :S

What I would do, is to enum all the windows, and use the EnableWindow API on msn's windows hWnds...

Did you try the above...?
RE: Showing Form without vbModal in VB? For the programmers out there... :D by CookieRevised on 05-21-2005 at 01:11 PM

quote:
Originally posted by Mike2
quote:
Originally posted by Matty
Form1.hWnd
If you want to get the hwnd of a form, doesn't it need to be shown? :S
No, it must simply exist (aka loaded in memory), and in VB a created form in your project always exist...

quote:
Originally posted by Mike2
What I would do, is to enum all the windows, and use the EnableWindow API on msn's windows hWnds...
Cyberdude isn't talking about MSN Messenger windows.
RE: Showing Form without vbModal in VB? For the programmers out there... :D by RaceProUK on 05-21-2005 at 01:56 PM

quote:
Originally posted by CookieRevised
in VB a created form in your project always exist...
You sure? I would have thought the form was loaded on the first .Show line.
I suppose if that's the case, you can use 'Load Form1'. Probably wouldn't make any difference whether the form was loaded or not when that line is executed: it just makes certain.
RE: RE: Showing Form without vbModal in VB? For the programmers out there... :D by CookieRevised on 05-21-2005 at 02:47 PM

quote:
Originally posted by raceprouk
quote:
Originally posted by CookieRevised
in VB a created form in your project always exist...
You sure?
yes... although I maybe didn't explained it well...

quote:
Originally posted by raceprouk
I would have thought the form was loaded on the first .Show line.
The normal command for loading a form is "Load", but this will not show the form yet.

The "Show" method itself, also automatically loads the form if it wasn't loaded already and then shows the form. This is the same as its counterpart method "Hide", it also automatically loads the form if it wasn't loaded already and then hides the form.

But a form is not only automatically loaded when used with methods or commands, it is also loads automatically whenever you use a property of the form itself, hence when using .hWnd the forms gets loaded.

quote:
Originally posted by raceprouk
I suppose if that's the case, you can use 'Load Form1'. Probably wouldn't make any difference whether the form was loaded or not when that line is executed: it just makes certain.
in this case, yep.


you can check this yourself:
code:
'To make sure the form is "unloaded":
Unload Form1

'show the handle
MsgBox Form1.hWnd
You'll see it is a valid handle again because the form was loaded again


But note that DestroyWindow will effectivly destroy the form in memory!! After DestroyWindow you wont be able to show the form again; it's like it never existed, everything will be cleared. Hence I said in my first reply to this thread that a form always exists in memory in VB.
RE: Showing Form without vbModal in VB? For the programmers out there... :D by (CyBeRDuDe) on 05-21-2005 at 02:50 PM

quote:
Originally posted by Matty
code:
Public Declare Function ShowWindow Lib "user32" Alias "ShowWindow" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long

Public Declare Function DestroyWindow Lib "user32" Alias "DestroyWindow" (ByVal hwnd As Long) As Long

Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Public Const SW_SHOW = 5
Public Const SW_HIDE = 0
Public Const WM_CLOSE = &H10

'Usage: Show Window
     ShowWindow Form1.hWnd, SW_SHOW

'Usage: Hide Window
     ShowWindow Form1.hWnd, SW_HIDE

'Usage: Close Window #1
     SendMessage Form1.hWnd, 0&, 0&, WM_CLOSE

'Usage: Close Window #2
     DestroyWindow Form1.hWnd


Hope that helps.
They all go into a module. Change them from Public to Private if you want to just put them in the Class.
This is SO NICE!!! :D..
Works perfectly.. Well.. At least until now.. :D..
Well.. I have some problems with my odl code.. just need to rewrite eveyrthing I think... But thanks.... I just didn't think you could use the ShowWindow api like that.. but It works brilliant, showing forms without putting Messenger on hold... Nice matty... :D..
Well.. I gues thread is kinda closed now.. :D..
RE: Showing Form without vbModal in VB? For the programmers out there... :D by CookieRevised on 05-21-2005 at 03:10 PM

quote:
Originally posted by (CyBeRDuDe)
I just didn't think you could use the ShowWindow api like that
You can do even a lot more with it ;)


'Hides the window and activates another window.
Public Const SW_HIDE = 0

'Activates and displays a window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when displaying the window for the first time.
Public Const SW_SHOWNORMAL = 1

'Activates the window and displays it as a minimized window.
Public Const SW_SHOWMINIMIZED = 2

'Activates the window and displays it as a maximized window.
Public Const SW_SHOWMAXIMIZED = 3

'Displays a window in its most recent size and position. The active window remains active.
Public Const SW_SHOWNOACTIVATE = 4

'Activates the window and displays it in its current size and position.
Public Const SW_SHOW = 5

'Minimizes the specified window and activates the next top-level window in the Z order.
Public Const SW_MINIMIZE = 6

'Displays the window as a minimized window. The active window remains active.
Public Const SW_SHOWMINNOACTIVE = 7

'Displays the window in its current state. The active window remains active.
Public Const SW_SHOWNA = 8

'Activates and displays the window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when restoring a minimized window.
Public Const SW_RESTORE = 9

'Sets the show state based on the SW_ flag specified in the STARTUPINFO structure passed to the CreateProcess function by the program that started the application.
Public Const SW_SHOWDEFAULT = 10
RE: Showing Form without vbModal in VB? For the programmers out there... :D by DeVill on 07-03-2005 at 12:20 PM

That's grate! But I have problem with this one... I have a tag with:

code:
        sResult = "Okay1"
        ShowWindow Form1.hwnd, SW_SHOW
        do
                DoEvents
        loop until Allow
        ParseCommand = True
        Exit Function


Allow is a global boolean! Now the command desapeares, and Okay1 is displayed, but message is not sent... first I thought it hade something to do with DoEvents, but that's not the case, if I remove the line with ShowWindow, than it works!