Danmilkman Posted March 18, 2004 Posted March 18, 2004 Hello, I'm trying to access a hidden window which a process started but then minimized to tray. The mainwindowhandle of the process in vb.net becomes 0 so I can't access it anymore by using the API functions. Or am I doing something wrong? Can anybody help me? I'll give an example of what I mean by these questions. When u start MSN Messenger by example it shows the main window. This window can be altered by using the windows API functions like SHOWWINDOW, SETWINDOWPOS and so on. However when you click the close button (X) the window disappears and MSN Messenger stays active in the system tray. How can I access the MSN Messenger window again by using API calls. The mainwindowhandle from de msnmsgr.exe process is 0? Anyone? Thnx. Quote Intellectuals solve problems, geniuses prevent them!
VBUser Posted March 20, 2004 Posted March 20, 2004 Microsoft have stopped the MSN messenger SDK now For the process, you can use GetProcessByName. One you have the process you can then continue Hello, I'm trying to access a hidden window which a process started but then minimized to tray. The mainwindowhandle of the process in vb.net becomes 0 so I can't access it anymore by using the API functions. Or am I doing something wrong? Can anybody help me? I'll give an example of what I mean by these questions. When u start MSN Messenger by example it shows the main window. This window can be altered by using the windows API functions like SHOWWINDOW, SETWINDOWPOS and so on. However when you click the close button (X) the window disappears and MSN Messenger stays active in the system tray. How can I access the MSN Messenger window again by using API calls. The mainwindowhandle from de msnmsgr.exe process is 0? Anyone? Thnx. Quote
decrypt Posted March 20, 2004 Posted March 20, 2004 If your saying that when they click the x button your program goes to the system tray this is easy. Do the following code: Setup: First put a NotifyIcon (found in the windows forms menu on the side) and a context menu onto your form. 'now do the following code: Private Sub frmMain_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing ' Hide the main form, as a program running as a tray icon doesn't typically ' have a visible form. Me.Hide() ntfSystemInfo.Visible = True ntfSystemInfo.Text = "Chat" End Sub 'then Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ntfSystemInfo.Visible = True End Sub 'then when they exit the application using exit on the context menu do this: ntfSystemInfo.Visible = False 'this is so that the thing doesn't stay visible until they have restarted... 'then Private Sub ntfSystemInfo_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ntfSystemInfo.DoubleClick ' When the user double-clicks the tray icon, display the main form again. Me.Show() End Sub 'set the context menu as the menu on the system tray 'ntfsysteminfo is what the microsoft example used as the notify icon... I'm not so sure if the form1_closing will work though :/ maybe you can try this: Dim whentoexit as string Private Sub ContextMenu_ExitButton(blahblah) whentoexit = "0" Me.Close End Sub Private Sub Form1_Closing(blah blah,blah) If whentoexit = "0" Then Me.Close Else Me.Hide() ntfSystemInfo.Visible = True ntfSystemInfo.Text = "Chat" End If End Sub Quote
VBUser Posted March 21, 2004 Posted March 21, 2004 My form icon is my NotifyIcon too. This is what I done & it works perfectly!! Create a module & make it the startup Module modStart Public Sub main() Dim frm As New Form1 frm.ShowInTaskbar = False frm.Opacity = 0 Application.Run(frm) frm.Dispose() End Sub End Module -------------- Sub New (form): ' Give the form a title Me.Text = "Your Title" ' Set the icon of the tray control Tray.Icon = Me.Icon ' Set the text of the tray control to the form's text Tray.Text = Me.Text Form Closing Event(): ' Cancel closing the program e.Cancel = True ' Show the NotifyIcon icon Tray.Visible = True ' Hide your form Me.Hide() ------------------------------- Use this code to show the form: Private Sub ShowForm() ' Check to see if the form is visible If Not Me.Opacity = 100 Then ' If not, show it in the taskbar Me.ShowInTaskbar = True ' Make the form visible Me.Opacity = 100 End If ' Show the form Me.Visible = True ' Activate it so, its on top of other forms Me.Activate() ' Remove the NotifyIcon icon Tray.Visible = False End Sub --------------------------------------------- On double click (Icon (System Tray)): Just call the above sub ---------------------------------------------- I hope this helps Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.