Author Topic: Spriggsy's API Collection  (Read 20860 times)

0 Members and 1 Guest are viewing this topic.

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Spriggsy's API Collection
« Reply #30 on: September 25, 2020, 04:54:52 pm »
Updated 09/25/2020 at 4:54 PM

Added Gravatar profile picture from email hash API to zip. Program uses MD5 library from @RhoSigma
Attached is a screenshot from the program showing my Gravatar picture:

Screenshot 2020-09-25 165512.png
« Last Edit: September 25, 2020, 04:56:48 pm by SpriggsySpriggs »
Shuwatch!

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Spriggsy's API Collection
« Reply #31 on: September 25, 2020, 11:53:04 pm »
Updated 11:50 PM on 09/26/2020

Added FindExecutableA from Shell32 WinAPI to zip folder. This allows you to find whatever program is set in the registry as being the default for opening the file that is passed to the function. For instance, if you pass it a BAS file and you have QB64 set as the default, it returns the path to the executable for QB64. Here is a screenshot of the program showing me the path to my QB64 executable after passing it a BM file:

 
Screenshot 2020-09-25 235321.png
« Last Edit: September 26, 2020, 12:07:43 am by SpriggsySpriggs »
Shuwatch!

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Spriggsy's API Collection
« Reply #32 on: September 26, 2020, 12:10:38 am »
Updated 12:08 PM on 09/26/2020

Added ShellAboutA from Shell32 WinAPI to zip. This function allows you to have a custom about page pop up in a program. This isn't an about page like you find in most programs. This gives a little information about the Windows license and allows for a custom title and description. Nothing too fancy.

Screenshot:
Screenshot 2020-09-26 000637.png
Shuwatch!

Offline badger

  • Forum Regular
  • Posts: 148
    • View Profile
Re: Spriggsy's API Collection
« Reply #33 on: September 26, 2020, 01:09:24 pm »
Hello

I will take a look at these.

I would like to ask if you ever heart if a dos database manager call btrieve. It use be owned by novel but now it has grown into a sql/btrieve type think that is awful exspensive. I was wondering if you would like to take on the challenge of maybe doing something like this. It gave quick basic 4.5 4 million record capibility. I know sql is the thing but i dont like sql so just thought i would ask.

Badger

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Spriggsy's API Collection
« Reply #34 on: September 26, 2020, 09:53:01 pm »
Updated 09/26/2020 at 09:50 PM

Added mciSendStringA function from WINMM WinAPI with source code showing the ability to record and playback audio. This code records from the default microphone. Once you press any key while it is recording it plays back the audio it heard.

Attached is a recording a made with the program:
  
And a screenshot of the program in action:
 
Screenshot 2020-09-26 215323.png


Also, I've renamed the files inside the zip folder so they have a better nomenclature.
« Last Edit: September 26, 2020, 09:54:07 pm by SpriggsySpriggs »
Shuwatch!

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Spriggsy's API Collection
« Reply #35 on: September 26, 2020, 11:46:55 pm »
Updated 09/26/2020 at 11:43 PM

Added DoEnvironmentSubstA function from Shell32 WinAPI. This performs nearly the same task as ENVIRON$ which is built into QB64 but allows for quicker return of the variables as well as the ability to call more than one at a time in the same line. For instance:
Code: QB64: [Select]
  1. PRINT Env("%homepath% %allusersprofile% %username%")

It works roughly twice as fast as the built-in ENVIRON$ function. This is included in my zip as a demo with a file containing some sample variable names for the test. It's mostly being added as a demo to show API usage rather than me telling you to start using this rather than the built-in. Personally, I will use the code that I wrote just because I like the flexibility.
Shuwatch!

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Spriggsy's API Collection
« Reply #36 on: September 27, 2020, 12:26:06 am »
Updated 12:24 AM on 09/27/2020

Added ExtractIcon from Shell32 WinAPI & DrawIcon and DestroyIcon from User32 WinAPI. This source shows extracting the handle for an icon from a program, loading it, and displaying it on the screen. Unfortunately, there appears to be a display issue so in order to keep the icon visible I have to loop the DrawIcon at about 120 FPS. Not sure what causes this but if someone wishes to dive into it then they may do so.
Shuwatch!

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Spriggsy's API Collection
« Reply #37 on: September 27, 2020, 01:07:27 am »
Updated 1:06 AM on 09/27/2020

Added SetWindowPos and GetForegroundWindow from User32 WinAPI, courtesy of Pete and visionmercer. Original post here:https://www.qb64.org/forum/index.php?topic=1365.msg105588#msg105588

This function allows the running program to be the topmost program even when clicking elsewhere on the screen.
« Last Edit: September 27, 2020, 01:16:22 am by SpriggsySpriggs »
Shuwatch!

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Spriggsy's API Collection
« Reply #38 on: September 27, 2020, 01:31:31 am »
Added source to show a waveform of the recording made with mciSendStringA. It uses ffmpeg to show a waveform from the wav file that is created. Here is a screenshot of a waveform I made from a recording:

 
Screenshot 2020-09-27 012008.png
.

Updated 09/27/2020 Had a bug in my code for mciSendStringA for the waveform creation. Bug is now fixed.

Updated (once again) 09/27/2020 Made subs and functions and allowed for STEREO recording in a much higher quality!!!!!
« Last Edit: September 27, 2020, 03:35:25 pm by SpriggsySpriggs »
Shuwatch!

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Spriggsy's API Collection
« Reply #39 on: September 30, 2020, 01:12:33 am »
Updated 01:11 AM on 09/30/2020

Added AnimateWindow function which allows you to Fade in and fade out as well as wipe left and right. Works in 64 and 32 bit. Have fun with animated windows!
Shuwatch!

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Spriggsy's API Collection
« Reply #40 on: October 02, 2020, 02:59:41 am »
Updated 02:57 AM on 10/02/2020

Added FlashWindow/FlashWindowEx functions from User32 WinAPI. This allows you to flash the taskbar icon for your program. This only works when the program does not have the foreground focus. Useful for getting the user's attention back to your program window. Here is a screenshot showing the taskbar flashing:

 
Screenshot 2020-10-02 025913.png

It might not seem like much but it's one more WinAPI thing that can be included :)
Shuwatch!

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Spriggsy's API Collection
« Reply #41 on: October 02, 2020, 11:07:22 pm »
Updated 10/02/2020 at 11:03 PM

Added capCreateCaptureWindow from Avicap32 which allows you to open your webcam driver and record a video! Recording is stopped by making the program either lose focus or pressing the ESCAPE key. Can be played back using my modified version of code by @Dav below:

Here are some YouTube videos showing videos I recorded with the code I posted in my collection:

Recorded using my ElGato capture card from my PS4!

Recorded using a VIRTUAL WEBCAM through my code!

Just footage from my webcam


My version of Dav's code for playing AVI videos:
Code: QB64: [Select]
  1.     FUNCTION mciSendStringA% (lpstrCommand AS STRING, lpstrReturnString AS STRING, BYVAL uReturnLength AS INTEGER, BYVAL hwndCallback AS INTEGER)
  2.     ' mciSendStringA function plays media files and returns the following:
  3.     ' 0 = command sucessful
  4.     ' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5.     ' lpstrCommand is the MCI command string (and optional flags) to send.
  6.     ' lpstrReturnString is a string that holds any return information.
  7.     ' uReturnLength is the length of the lpstrReturnString string passed.
  8.     ' NOTE: If lpstrCommand given doesn't retun a value then lpstrReturnString
  9.     '       can be empty and uReturnLength can be set to 0.
  10.     ' hwndCallback contains a callback window handle (only if the Notify flag used in lpstrCommand)
  11.     '====================================================================
  12.     FUNCTION mciGetErrorStringA% (BYVAL dwError AS INTEGER, lpstrBuffer AS STRING, BYVAL uLength AS INTEGER)
  13.     ' mciGetErrorStringA returns error info if the mciSendStringA failed.
  14.     ' dwError is the return value from the mciSendString function.
  15.     ' lpstrBuffer string holds the error information returned by the function.
  16.     ' uLength is the length of the lpstrBuffer string buffer.
  17.     '====================================================================
  18.  
  19. 'DECLARE CUSTOMTYPE LIBRARY
  20. '    FUNCTION FindWindow& (BYVAL ClassName AS _OFFSET, WindowName$)
  21. 'END DECLARE
  22.  
  23.  
  24. handle& = _NEWIMAGE(640, 480, 32)
  25. SCREEN handle&
  26.  
  27.  
  28. _TITLE "QB64 Video"
  29. hwnd& = _WINDOWHANDLE 'FindWindow(0, "QB64 Video" + CHR$(0))
  30.  
  31. ReturnString$ = SPACE$(255)
  32. ErrorString$ = SPACE$(255)
  33. filename$ = "Video.avi" '<========== video file to play
  34.  
  35. a% = mciSendStringA%("open " + filename$ + " parent " + _TRIM$(STR$(_WINDOWHANDLE)) + " style child", ReturnString$, LEN(ReturnString$), 0)
  36.  
  37. IF a% THEN
  38.     x% = mciGetErrorStringA%(a%, ErrorString$, LEN(ErrorString$))
  39.     PRINT ErrorString$
  40.     END
  41.     a2% = mciSendStringA%("window " + filename$ + " handle " + STR$(hwnd&), ReturnString$, LEN(ReturnString$), 0)
  42.     b% = mciSendStringA%("play " + filename$, "", 0, 0)
  43.     '=== Play video...
  44.     DO: _LIMIT 30: LOOP UNTIL INKEY$ <> ""
  45.  
  46.     x% = mciSendStringA%("stop " + filename$, "", 0, 0)
  47.     x% = mciSendStringA%("close " + filename$, "", 0, 0)
« Last Edit: October 02, 2020, 11:10:10 pm by SpriggsySpriggs »
Shuwatch!

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Spriggsy's API Collection
« Reply #42 on: October 05, 2020, 02:17:00 am »
Updated 02:11 AM on 10/05/2020

Added OpenProcess, TerminateProcess, Process32First, Process32Next, and CreateToolhelp32Snapshot functions from Kernel32 WinAPI. This set of functions allow for you to kill running processes by name or PID (process ID). These functions kill the program outright, similar to using Task Manager so the programs DO NOT close gracefully. It's useful for killing a rogue SHELL _DONTWAIT. However, if you want something to be closed gracefully then you should use the SendSignal executable which I have included in my folder with a SUB that I use to call it. It sends a quit signal to a running process and allows for it to close correctly without worry of corrupting files. I've included 3 functions in my source code that you can use for your own code. KillProcessByName, which accepts a STRING of the processname, KillProcessByPID, which accepts an _UNSIGNED INTEGER of the PID, and SoftKill, which accepts a STRING of the processname.
« Last Edit: October 05, 2020, 02:19:12 am by SpriggsySpriggs »
Shuwatch!

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Spriggsy's API Collection
« Reply #43 on: October 05, 2020, 02:41:32 am »
Updated 02:40 AM on 10/05/2020

Added MessageBeep function from User32 which plays WAV audio for each of the standard Windows message sounds.
Shuwatch!

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Spriggsy's API Collection
« Reply #44 on: October 07, 2020, 01:48:06 am »
Updated 01:45 AM on 10/07/2020

Added OpenClipboard and GetClipboard functions from User32. Program is basically a rewrite of what is going on behind the scenes with var$ = _CLIPBOARD$. Uses PeekPoke library from the Wiki found here: https://www.qb64.org/wiki/PEEK_and_POKE_Library
Also, added more functions to DoEnvironmentSubstA API for speed comparison between each of the different functions that achieve the same end result (if used the same way).

Added InternetOpenA, InternetConnect, FtpGetFile from Wininet. Will add code for HttpOpenRequest and HttpSendRequest in the future. Code will revamp all my online APIs to be more advanced.
« Last Edit: October 07, 2020, 02:06:27 am by SpriggsySpriggs »
Shuwatch!