C# Force window to continue painting while minimized



  • Goal:
    Add a windows capture scene to OBS and have it display updates to the scene while the target window is minimized.

    Background:

    • I have an application that displays a web browser (custom made for an application to essentially translate an irc chat room into a fancy web chat room that supports images and such)
    • The core of this application runs invisibly in the background retrieving data from a server
    • The front end of this application is a resizeable windows form that loads a local HTML file. This HTML file has javascript that the core application invokes to push the remote server data to the local web display.
    • It works beautifully, and when OBS captures the windows, it looks perfect
    • The target user (a twitch.tv broadcaster) wants to minimize the window (or, more accurately minimize it to tray so it's invisible/out of the way due to the other windows they have to have open)

    The problem:
    When the broadcaster minimizes the window, OBS no longer sees it as a valid input source, which I suspect is due to the draw events no longer being issued.

    So the question is:
    How can I force windows to treat my form as if it's not minimized, while it is? (Or more specifically, continue to issue paint events so OBS can do it's thing?


  • FoxDev

    try

    Form.Invalidate();
    

    or

    Form.Refresh();
    

    on an appropraite timer when window is minimized?



  • Mmmmm no.


  • FoxDev

    that didn't work?

    hmm....

    can you capture the minimize unminimize request so that when minimizing you safe the window layout then shove it offscreen left by bout a million pixels, then when unminimizing restore to previous location? (if it works in javascript maybe? :-P )



  • Shoving it way off screen might actually be a good solution. Let me try that.



  • Are you sure that the window is actually backed by a frame buffer when it's minimized?

    This used to be (and perhaps still is) with off-screen rendering: parts of windows that are off-screen, obscured or otherwise hidden wouldn't actually own those portions of the frame buffer. That is, even if draw commands are issued that touch those regions, there is no buffer to store the pixels there.

    (Disclaimer: It was a while since I looked at this - in particular, I've not looked at it after WinXP on windows, or under C#).



  • @Matches said:

    Shoving it way off screen might actually be a good solution. Let me try that.

    You wouldn’t be the first to do this, at least…



  • Never thought I was, but by the same token I'm trying to do something windows doesn't actively want you to do. Why waste resources when the application can't be seen! It's a reasonable design decision. The problem I face is because of how obs streams video, my existing application setup, and my target audience (broadcasters who want stuff on screen to viewers, but don't need to see it themselves)

    I haven't tried off screen yet, but I'm betting with double buffer and offscreen, it should work. I hope.



  • @Matches said:

    So the question is:How can I force windows to treat my form as if it's not minimized, while it is? (Or more specifically, continue to issue paint events so OBS can do it's thing?

    Can't be done, AFAIK. This is a feature, not a bug...

    The offscreen thing should work, but you're talking about the edgiest of edge-cases here. Better would just be to expose your visual to something OBS likes, for example, a virtual webcam. (Yes, I realize that's a lot more work.)



  • I wouldn't even begin to know where to start with something like that, and it seems like it would be a (potentially) even bigger WTF than what I'm currently doing.



  • @Matches said:

    I wouldn't even begin to know where to start with something like that, and it seems like it would be a (potentially) even bigger WTF than what I'm currently doing.

    It would, but it's not as WTF-y as trying to turn a chat room into HTML into video into a stream, while it's not even on the fucking screen. All for one single person who's probably (and let's be frank here) a total jerk. Who would rather make you do tons of work than just drag a window to the right.



  • I'm not trying to turn a chat room into a video into a stream,

    If you go to twitch.tv and look at broadcasters with say, 100 viewers to 10k viewers, you will see many have chat overlays on their screen. (Not games like league of legends or dota, but more indie games, dark souls, etc)

    The streamers use the chat overlay to increase their chat interaction, namely, they talk to their chat. The overlay is for people who go back and watch the VODs, or people who lurk (watch in full screen mode and don't chat) - that way if something interesting happens they can drop out of full screen and talk.

    It's a broadcasting style, there's things like better twitch tv that Night has created, but they don't fill the niche I'm in quite the way the broadcasters like, so I provide a service to them.

    Blakey, the broadcasters I'm working with are both large and small. The small broadcasters help me pilot my features so the big broadcasters are more inclined to use it. It's a business model that I will move into selling within the next year.



  • @Matches said:

    I'm not trying to turn a chat room into a video into a stream,

    Yes you are.

    @Matches said:

    If you go to twitch.tv and look at broadcasters with say, 100 viewers to 10k viewers, you will see many have chat overlays on their screen. (Not games like league of legends or dota, but more indie games, dark souls, etc)

    Of course. I watch a shitload of Twitch. I'm watching a Twitch stream right now.

    @Matches said:

    The streamers use the chat overlay to increase their chat interaction, namely, they talk to their chat.

    No, they use it so when they archive the video to YouTube, the chat is preserved in context. If they were more technically sophisticated, they'd record the chat separately and only attach it to the YouTube version instead of cluttering-up their stream.

    @Matches said:

    Blakey, the broadcasters I'm working with are both large and small. The small broadcasters help me pilot my features so the big broadcasters are more inclined to use it. It's a business model that I will move into selling within the next year.

    Right, but if you're building this specifically for Twitch, you'd think there'd be a better way to do it than have OBS or XSplit record your window like a video.

    Maybe there isn't.

    But this still strikes me as WTF.



  • @Matches said:

    I wouldn't even begin to know where to start with something like that, and it seems like it would be a (potentially) even bigger WTF than what I'm currently doing.

    You could take a look at Awesomium or CEF. Both allow you to render HTML into a off-screen buffer of your choosing. You'd have to figure out how to forward that to OBS.

    If you also want to display the stuff on-screen at times, you'd have to transfer the off-screen buffer to a real window, and forward the appropriate messages from the window to whatever.

    A bit of a pain, but should be more robust than relying on off-screen windows having their contents accessible, IMO.



  • A decent portion of the twitch broadcasters I have been working with did that long before they ever had a youtube (they got youtube when twitch changed the video retention policy) - so no, that's not the only reason. But I will concede that is a reason.

    Attaching it to the youtube later is a better course, and one I do hope to go down eventually. Basically I want to do an RTMP proxy so they stream to me, I do management processes (including chat/video time sync) and forward on to twitch. Why do that? Several reasons, including non muted stream source files, true source quality file archive, ability to forward to multiple services (IE: Twitch + Hitbox + Youtube live stream) and so forth. I've got big plans, some might pan out, others might not.

    You're not wrong that there should be a better way.

    But as of right now there isn't. Baby steps.



  • @Matches said:

    A decent portion of the twitch broadcasters I have been working with did that long before they ever had a youtube (they got youtube when twitch changed the video retention policy)

    Tell them not to, it's annoying. The chat window's RIGHT THERE.

    BLAKEYRAT IS LAW.



  • Nope, I only see chat when they do it, I only watch streams in full screen mode.

    TOURNYMASTERBOT IS THE LAW


  • FoxDev

    @blakeyrat said:

    BLAKEYRAT IS LAW.

    no.



  • BlakeyRat is Rant though.


  • FoxDev

    @Matches said:

    BlakeyRat is Rant though.

    i'll agree to that.



  • @blakeyrat said:

    Tell them not to, it's annoying. The chat window's RIGHT THERE.

    BLAKEYRAT IS LAW.

    So you have a helmet on, never remove it for anything or anyone and bellow - I AM THE LAW - in a manner even Stallone would be envious of?

    I demand YouTube.







  • @blakeyrat said:

    https://www.youtube.com/watch?v=itmNiTwHOsM

    No, I didn't demand you finding that clip, I demanded you being Judge Blakeyrat and bellowing that line yourself.

    I seem to recall my calling you Judge Blakeyrat in the past, too.



  • Confirmed, this works.

    Since I'm already removing the taskbar icon to remove clutter (there's only a tray icon - i'll make it configurable later) I'll make clicking on the tray icon restore the application to the center of the screen. Then it's just adding some stuff to remember screen size.

    This is coming along quite nicely, excellent suggestion @accalia.

    For the record, this is the code required to do the minimize event.

    #region Minimize Event
    		private const int WM_SYSCOMMAND = 0x0112;
    		private const int SC_MINIMIZE = 0xf020;
    
    		protected override void WndProc(ref Message m)
    		{
    			if (m.Msg == WM_SYSCOMMAND)
    			{
    				if (m.WParam.ToInt32() == SC_MINIMIZE)
    				{
    					m.Result = IntPtr.Zero;
    					MinimizeEvent();
    					return;
    				}
    			}
    			base.WndProc(ref m);
    		}
    
    		private void MinimizeEvent()
    		{
    			this.Location = new Point(-30000, -30000);
    		}
    		#endregion
    

    I have no idea what discoformatting is doing. But I CBA to fix it.



  • You could disable minimizing since Windows keeps drawing windows even if they're fully obscured behind other things.



  • http://www.charlatanshanty.com/BotMenu Demo.mp4

    (Might need to right click -> save video as)



  • Streaming some BF4 for the next hour or so if you care



  • You can dual cast and see both Hitbox & Twitch chat if you care :P



  • I have no idea what you are talking about.



    1. Set up a Twitch.Tv account
    2. Set up a HitBox.tv account
    3. Set up a local NGINX RTMP server
    4. Broadcast to both websites
    5. My tool merges both sites into a single chat stream
    6. Profit!


  • Right I don't care. Hitbox has no latency so I use it



  • I'm not sure delay is your issue.



  • Any reason you posted a video of an offline twitch channel?



  • It's my channel, It's just showing the tool off with a mini demo to show what it's doing.



  • Nah we've had this chat before, everybody I know is on the lame coast or in Europenis so when I steam nobody's awake.

    EDIT: done



  • which is why VODs are great. (And chat overlays on said VODs) <motherfucker>





  • Almost 5% increase in total viewership in just a few minutes!

    That's pretty impressive really.


Log in to reply