Making a window appear off screen or changing size to a couple of pixels

Posted on 2006-05-10
Last Modified: 2010-04-23
I have a bunch of code that works perfectly, only one problem, it needs to be hidden (shell command FTP) and yet the best method of sending the keystrokes necessary requires it to have focus.  

I need to make the screen either extremely small, or to start offscreen.

Can this be done?

My window is opened by using:

            Dim ProcedureID As Integer
            ProcedureID = Shell("cmd.exe", AppWinStyle.NormalFocus)

I can't use

            Dim ProcedureID As Integer
            ProcedureID = Shell("cmd.exe", AppWinStyle.Hide)
because then my commands will not be sent properly, so I have to hide it using alternative methods.

Question by:lgropper
    LVL 7

    Accepted Solution

    not sure if its the best solution but this will start the form off screen

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim intX As Integer = Screen.PrimaryScreen.Bounds.Width
            Dim intY As Integer = Screen.PrimaryScreen.Bounds.Height
            Me.Location = New Point(intX + 5, intY + 5)

        End Sub
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    How about...

        Private Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" (ByVal hwnd As IntPtr, ByVal hWndInsertAfter As Integer, ByVal x As Integer, ByVal y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer) As Integer
        Private Const SWP_NOSIZE As Integer = &H1

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim p As Process = Process.Start("cmd")
            ' give it a chance to load...  (can't use "p.WaitForInputIdle()" with cmd.exe)
            ' move the window offscreen
            SetWindowPos(p.MainWindowHandle, 0, Screen.PrimaryScreen.Bounds.Width + 25, Screen.PrimaryScreen.Bounds.Height + 25, 0, 0, SWP_NOSIZE)
        End Sub

    Author Comment

    Perfect...  simple and to the point, much appreciated...

    Idle Mind, I really liked your solution to, Thanks!
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    How exactly are you using davidrichardsons code to move an external applications (cmd) window?...

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
    Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now