• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 158
  • Last Modified:

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

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.

Thanks
0
lgropper
Asked:
lgropper
  • 2
1 Solution
 
davidrichardsonCommented:
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
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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)
        System.Threading.Thread.Sleep(500)
        ' move the window offscreen
        SetWindowPos(p.MainWindowHandle, 0, Screen.PrimaryScreen.Bounds.Width + 25, Screen.PrimaryScreen.Bounds.Height + 25, 0, 0, SWP_NOSIZE)
    End Sub
0
 
lgropperAuthor Commented:
Perfect...  simple and to the point, much appreciated...

Idle Mind, I really liked your solution to, Thanks!
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
How exactly are you using davidrichardsons code to move an external applications (cmd) window?...
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now