Emil’s Blog

Programming Windows, .Net, EPiServer and whatnot…

[Powered by WordPress.]

October 13, 2006

Get IWin32Window for the main window of Visual Studio

by @ 14:05. Filed under Visual Studio tips

This is a way to wrap the main window of Visual Studio in a klass that implements the IWin32Window interface.

Public Class MainWinWrapper
    Implements System.Windows.Forms.IWin32Window
    Overridable ReadOnly Property Handle() As System.IntPtr _
            Implements System.Windows.Forms.IWin32Window.Handle
        Get
            Dim iptr As New System.IntPtr(DTE.MainWindow.HWnd)
            Return iptr
        End Get
    End Property
End Class

This is useful for example when Visual Studio should be used as the owner of a MessageBox.

Dim res As DialogResult
res = MessageBox.Show(New MainWinWrapper(), "Hello!")

The code was found here.

Start process and redirect output

by @ 13:26. Filed under .Net programming
Function GetProcessText(ByVal process As String, ByVal param As String, _
        ByVal workingDir As String) As String
    Dim p As System.Diagnostics.Process = New System.Diagnostics.Process

    ' this is the name of the process we want to execute
    p.StartInfo.FileName = process
    If Not (workingDir = "") Then
        p.StartInfo.WorkingDirectory = workingDir
    End If
    p.StartInfo.Arguments = param

    ' need to set this to false to redirect output
    p.StartInfo.UseShellExecute = False
    p.StartInfo.RedirectStandardOutput = True

    ' start the process
    p.Start()

    ' read all the output
    ' here we could just read line by line and display it
    ' in an output window
    Dim output As String = p.StandardOutput.ReadToEnd
    ' wait for the process to terminate
    p.WaitForExit()
    Return output
End Function

Code from http://www.developerfusion.co.uk/show/4662/.

[powered by WordPress.]

jour·nal n. A personal record of occurrences, experiences, and reflections kept on a regular basis; a diary.

Internal links:

Categories:

Search blog:

Archives:

October 2006
M T W T F S S
« Sep   Nov »
 1
2345678
9101112131415
16171819202122
23242526272829
3031  


View Emil Åström's profile on LinkedIn

General links:

I read:

Visitors

Recent Comments

Spam caught

Other:

Clicky Web Analytics

36 queries. 0.713 seconds