Author Topic: Maximize a minimized program anytime using WinAPI  (Read 4011 times)

0 Members and 1 Guest are viewing this topic.

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Maximize a minimized program anytime using WinAPI
« on: December 11, 2020, 07:09:36 pm »
I needed to make a minimized program to wake up and maximize when completing a task.  Couldn't remember if QB64 had a command to do it (I know it has a minimize command,_SCREENICON), so I used a WindowAPI -  OpenIcon.  This will maximize and active the program window when called.  With this you can prevent a program from ever being minimized, and forever stay in your face and nag you like a bad wife.

- Dav

Code: QB64: [Select]
  1. '============
  2. 'OPENICON.BAS
  3. '============
  4. 'Maximizes a minimized program using WinAPI.
  5. 'By Dav, DEC/2020
  6.  
  7.     FUNCTION OpenIcon& (BYVAL hwnd AS LONG)
  8.  
  9. PRINT "Minimize this program at it will pop back up in 2 secs."
  10.  
  11.         SLEEP 2: x& = OpenIcon&(_WINDOWHANDLE)
  12.     END IF
  13.  

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Maximize a minimized program anytime using WinAPI
« Reply #1 on: December 11, 2020, 08:10:30 pm »
Won’t _SCREENSHOW unminimize a program?  I think it will.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Maximize a minimized program anytime using WinAPI
« Reply #2 on: December 12, 2020, 04:36:56 am »
Perfect. I will finally be able to complete my screen recorder! Thanks Dav, I missed this feature.

_SCREENSHOW does nothing at all because it is linked to _SCREENHIDE and not with _SCREENICON.

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Maximize a minimized program anytime using WinAPI
« Reply #3 on: December 12, 2020, 09:23:32 am »
I'm glad it can be useful to you, @Petr

I couldn't get _SCREENSHOW to maximize for me here - perhaps I'm not calling it right though.  I tried adding the metacommand and did a _SCREENHIDE first, but _SCREENSHOW didn't max.   I'm on Win7 32 bit, if OS matters.

- Dav

FellippeHeitor

  • Guest
Re: Maximize a minimized program anytime using WinAPI
« Reply #4 on: December 12, 2020, 09:43:36 am »
Screen show will only make the window visible again after screen hide. Nothing to do with screen icon.

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Maximize a minimized program anytime using WinAPI
« Reply #5 on: December 12, 2020, 10:29:29 am »
Thanks for the clarification, @FellippeHeitor.

@Petr, the screen recorder sounds interesting.  Looking forward to seeing that.

- Dav

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Maximize a minimized program anytime using WinAPI
« Reply #6 on: December 12, 2020, 10:42:50 am »
Dav, my ScreenRecorder is already somwhere on the forum, in order for _SCREENIMAGE to provide the current image (for example, when saving a video from Youtube), the program must be minimized. I think (it's been a long time since I wrote it and then left it aside) that there was probably a problem with the control, when minimized, I think it stopped responding to the keyboard and mouse. But it's been a long time. I will deal with it next year, first I will complete the program with a Christmas theme. Of course, what I would also like, and maybe SpriggsySpriggs could do, would be to record the sound of the current audio stream. But that is again a question of the future... :)

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Maximize a minimized program anytime using WinAPI
« Reply #7 on: December 12, 2020, 11:24:54 am »
@Petr: I have't done any audio recording using API yet, but I can look into it.  Maybe SpriggsySpriggs has already worked that up though - he's been pumping out a lot of great API code lately!

- Dav

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Maximize a minimized program anytime using WinAPI
« Reply #8 on: December 14, 2020, 09:10:23 am »
@Dav @Petr

I do have code that does webcam capturing and I have code for recording audio with WinAPI. Both were fairly difficult and both are in my API collection. The webcam one works but I'm sure it could be done even better. As a matter of fact, one could use a virtual webcam software to pipe the desktop into the webcam capturing code I wrote and still record the desktop. Not sure about how the compression will be, though.
« Last Edit: December 14, 2020, 09:13:08 am by SpriggsySpriggs »
Shuwatch!

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Maximize a minimized program anytime using WinAPI
« Reply #9 on: December 14, 2020, 09:19:33 am »
Cool. I'm gonna re-download and take a closer look at your API collection. 

- Dav

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Maximize a minimized program anytime using WinAPI
« Reply #10 on: December 14, 2020, 09:20:27 am »
@Dav

Actually, I have to reupload my audio recording code because I realized I had incorrect variable types in a few spots. Give me a few minutes while I rectify this.
Shuwatch!

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Maximize a minimized program anytime using WinAPI
« Reply #11 on: December 14, 2020, 09:30:19 am »
OK, all good. Variable types for that are fixed. Didn't check the webcam code but I think that came after I started really understanding the WinAPI and so (I hope) it should have the correct variable types/sizes. It didn't. Fixed that, too (I think). It still worked when I tested it after changing the variable types and TYPE sizes. It still requires going over it with a fine-tooth comb. Maybe Petr wants to take a whack at it.
« Last Edit: December 14, 2020, 09:37:23 am by SpriggsySpriggs »
Shuwatch!

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Maximize a minimized program anytime using WinAPI
« Reply #12 on: December 14, 2020, 09:36:49 am »
Got it!  There's a lot more in there than I remembered.   Thanks, @SpriggsySpriggs.

- Dav

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Maximize a minimized program anytime using WinAPI
« Reply #13 on: December 14, 2020, 10:59:17 am »
Thanks @SpriggsySpriggs. I will look at it. It will take some time. :)