Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Hiding a Fullscreen App (game)

Hiding a Fullscreen App (game)

Scheduled Pinned Locked Moved C#
game-devjsonhelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kir Birger
    wrote on last edited by
    #1

    Excuse my ignorance, i'm quite a novice to programming:) my problem is i can't get my program to find the appropriate window handle for it to hide/minimize when the game is in fullscreen.... it will do it fine in windowed mode (i use process.mainWindowHandle property), but after i fullscreen it (Even if i go back) it won't find the right handle again... i've seen pieces of code using the FindWindow(string window class, string window name) method from the Windows API (user32.dll) but it will return something well out of the bounds of a window handle (way out of the bounds of an integer :p ) so i made a class that is derived from a process.. i added a method called ToggleState() (note, hWND is also set to "this.MainWindowHandle" in the constructor of the class) public void ToggleState() { if ( IsWindowVisible(hWND) != 0 ) { this.hWND = (int) this.MainWindowHandle; ShowWindow(this.hWND, SW_HIDE ); } else if ( IsWindowVisible(hWND ) == 0 ) { ShowWindow(hWND, SW_RESTORE ); SetForegroundWindow(hWND); } } In summary: if i launch the game in windowed mode, it will work indefinately, but then if i fullscreen it (or start in fullscreen) it will cease to function (even if i go back to windowed) i've tried other alternatives, like creating a new process object and doing GetProcessByName and then getting the main handle of THAT (still no luck) Thanks for your time anybody who reads this:D

    H 1 Reply Last reply
    0
    • K Kir Birger

      Excuse my ignorance, i'm quite a novice to programming:) my problem is i can't get my program to find the appropriate window handle for it to hide/minimize when the game is in fullscreen.... it will do it fine in windowed mode (i use process.mainWindowHandle property), but after i fullscreen it (Even if i go back) it won't find the right handle again... i've seen pieces of code using the FindWindow(string window class, string window name) method from the Windows API (user32.dll) but it will return something well out of the bounds of a window handle (way out of the bounds of an integer :p ) so i made a class that is derived from a process.. i added a method called ToggleState() (note, hWND is also set to "this.MainWindowHandle" in the constructor of the class) public void ToggleState() { if ( IsWindowVisible(hWND) != 0 ) { this.hWND = (int) this.MainWindowHandle; ShowWindow(this.hWND, SW_HIDE ); } else if ( IsWindowVisible(hWND ) == 0 ) { ShowWindow(hWND, SW_RESTORE ); SetForegroundWindow(hWND); } } In summary: if i launch the game in windowed mode, it will work indefinately, but then if i fullscreen it (or start in fullscreen) it will cease to function (even if i go back to windowed) i've tried other alternatives, like creating a new process object and doing GetProcessByName and then getting the main handle of THAT (still no luck) Thanks for your time anybody who reads this:D

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      You really should read the .NET Framework SDK documentation, especially if you're just starting out. All controls in System.Windows.Forms already expose their window handles through the Handle property. And you don't need to P/Invoke ShowWindow - you just use Show and Hide (or set the Visible property accordingly). You can also control the full-screen behavior - as well as maximized, minimized, and normal states - all through the .NET Framework. Most of these classes just encapsulate the Windows APIs anyway. If you're trying to do this for a separate process, things change. But judging by your code fragments, you're trying to do this to your own window. Is that correct?

      Microsoft MVP, Visual C# My Articles

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups