Click here to Skip to main content
15,907,392 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionHow to maximize third party app [modified] Pin
JLTBDY1-Jul-08 2:47
JLTBDY1-Jul-08 2:47 
AnswerRe: How to maximize third party app Pin
jzonthemtn1-Jul-08 4:54
jzonthemtn1-Jul-08 4:54 
GeneralRe: How to maximize third party app Pin
JLTBDY1-Jul-08 5:19
JLTBDY1-Jul-08 5:19 
GeneralRe: How to maximize third party app Pin
jzonthemtn1-Jul-08 5:34
jzonthemtn1-Jul-08 5:34 
GeneralRe: How to maximize third party app Pin
JLTBDY7-Jul-08 7:28
JLTBDY7-Jul-08 7:28 
GeneralRe: How to maximize third party app Pin
jzonthemtn7-Jul-08 8:11
jzonthemtn7-Jul-08 8:11 
GeneralRe: How to maximize third party app Pin
JLTBDY8-Jul-08 12:00
JLTBDY8-Jul-08 12:00 
GeneralRe: How to maximize third party app Pin
jzonthemtn8-Jul-08 12:19
jzonthemtn8-Jul-08 12:19 
Sure, now this isn't the prettiest code - it's darn ugly, in fact. But it does work. I threw it into a Module but it's probably best suited for a class.

Imports System.Runtime.InteropServices

Module Module1

    Public Delegate Function EnumWindowsProc(ByVal hWnd As IntPtr, ByVal lParam As Integer) As Boolean
    <DllImport("user32")> Public Function EnumWindows( _
ByVal lpFunc As EnumWindowsProc, ByVal lParam As Integer) As Integer
    End Function

    Private Declare Auto Function GetWindowText Lib "user32" _
(ByVal hWnd As System.IntPtr, ByVal lpString As System.Text.StringBuilder, _ 
ByVal nMaxCount As Integer) As Integer
    Private Declare Auto Function FindWindowEx Lib "user32" _
(ByVal hWnd1 As IntPtr, ByVal hWnd2 As IntPtr, _ 
ByVal lpsz1 As String, ByVal lpsz2 As String) As System.IntPtr

    <Runtime.InteropServices.DllImport("user32.dll")> _
    Private Function ShowWindow(ByVal hwnd As IntPtr, ByVal nCmdShow As Int32) As Boolean
    End Function

    <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
      Private Function FindWindow( _
        ByVal lpClassName As String, _
      ByVal lpWindowName As String) As IntPtr
    End Function

    Public Function EnumWindowCBK(ByVal hWnd As IntPtr, ByVal lparam As Integer) As Boolean

        Static WindowText As New System.Text.StringBuilder(100)
        Static nRet As Long

        nRet = GetWindowText(hWnd, WindowText, WindowText.Capacity)
        If nRet <> vbNull Then

            If InStr(WindowText.ToString, "Notepad") <> 0 Then

                ' maximize it
                MsgBox(hWnd.ToString)
                ShowWindow(hWnd, 3)

            End If

        End If

        EnumWindowCBK = True

    End Function

End Module


Then whenever you want to maximize the window, call:

Module1.EnumWindows(New Module1.EnumWindowsProc(AddressOf EnumWindowCBK), 0)


It's pretty self-explanatory. EnumWindows gets all the desktop windows, and in the callback function EnumWindowCBK I compare the window's title with what we are looking for - it's up to you to decide if you only want the window text to match exactly or not. In this one, as long as it contains "Notepad" somewhere in there it will be maximized.

Sorry for not cleaning up that code better.
AnswerRe: How to maximize third party app Pin
JLTBDY9-Jul-08 6:07
JLTBDY9-Jul-08 6:07 
GeneralRe: How to maximize third party app Pin
jzonthemtn10-Jul-08 3:17
jzonthemtn10-Jul-08 3:17 
Questionsql datareader Pin
Ebube1-Jul-08 2:45
Ebube1-Jul-08 2:45 
AnswerRe: sql datareader Pin
paas1-Jul-08 3:26
paas1-Jul-08 3:26 
GeneralRe: sql datareader Pin
Ebube1-Jul-08 5:05
Ebube1-Jul-08 5:05 
GeneralRe: sql datareader Pin
paas1-Jul-08 5:18
paas1-Jul-08 5:18 
GeneralRe: sql datareader Pin
Ebube1-Jul-08 5:33
Ebube1-Jul-08 5:33 
GeneralRe: sql datareader Pin
Ebube1-Jul-08 6:04
Ebube1-Jul-08 6:04 
GeneralRe: sql datareader Pin
paas1-Jul-08 7:03
paas1-Jul-08 7:03 
GeneralRe: sql datareader Pin
Ebube1-Jul-08 16:09
Ebube1-Jul-08 16:09 
QuestionInsert text at the end of the current mail in outlook Reply mail window using vb.net Pin
~Khatri Mitesh~1-Jul-08 2:42
~Khatri Mitesh~1-Jul-08 2:42 
Questionchecking image in a picturebox Pin
Ahamed Azeem1-Jul-08 2:33
Ahamed Azeem1-Jul-08 2:33 
AnswerRe: checking image in a picturebox Pin
Tom Deketelaere1-Jul-08 4:19
professionalTom Deketelaere1-Jul-08 4:19 
AnswerRe: checking image in a picturebox Pin
Kenny McKee1-Jul-08 7:31
Kenny McKee1-Jul-08 7:31 
AnswerRe: checking image in a picturebox Pin
Thomas Stockwell2-Jul-08 2:49
professionalThomas Stockwell2-Jul-08 2:49 
GeneralRe: checking image in a picturebox Pin
Ahamed Azeem2-Jul-08 3:13
Ahamed Azeem2-Jul-08 3:13 
QuestionExporting crystal report to HTML "Unhandled win32 exception in vb6.exe" Pin
atin11-Jul-08 2:00
atin11-Jul-08 2:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.