Jump to content

The bumper thread of missing winapi examples.


JohnOne
 Share

Recommended Posts

As I look through _WinAPI_* entries in the help file there are many without examples.

It's quite a task for any one person to undertake, so I propose anyone who can be bothered every now and then, figure one out and post an example here.

I'd suggest not using the help forum as that defeats the object.

I'll go first with an easy one from near the top.

EDIT: (regarding guinness' below post)

If you wish your example to be considered for help file entry, please follow his instructions.

If you don't care then don't worry, just the example will do however you like.

EDIT2:

The links below are to the examples, not the online help.

EDIT3:

If anyone wants to modify any examples to be help file worthy you are most welcome to.

_WinAPI_ArrayToStruct

 

 

Spoiler
#include <WinAPIMisc.au3>

Example_WinAPI_ArrayToStruct()

Func Example_WinAPI_ArrayToStruct()
    Local $iArrayLen = 3
    Local $aData[$iArrayLen] = ["wstr", "wstr", "wstr"]

    Local $dsStruct = _WinAPI_ArrayToStruct($aData)
    If @error Then
        Exit MsgBox(0, "Failed", "_WinAPI_ArrayToStruct")
    EndIf

    DllStructSetData($dsStruct, 1, "one")
    DllStructSetData($dsStruct, 2, "two")
    DllStructSetData($dsStruct, 3, "three")

    Local $vType = VarGetType($dsStruct)
    ConsoleWrite("This variable type is " & $vType & @LF)

    ConsoleWrite("The contents of this " & $vType & " are ..." & @LF)
    For $i = 1 To $iArrayLen
        ConsoleWrite(DllStructGetData($dsStruct, $i) & @LF)
    Next
EndFunc   ;==>Example_WinAPI_ArrayToStruct 

 

_WinAPI_AbortPath

>_WinAPI_AdjustWindowRectEx

>_WinAPI_GetDefaultUserProfileDirectory

>_WinAPI_DeleteFile

>_WinAPI_GetAsyncKeyState

>_WinAPI_GetCurrentDirectory

>_WinAPI_GetDefaultPrinter

>_WinAPI_GetDeviceCaps

>_WinAPI_GetDriveType

>_WinAPI_GetErrorMessage

>_WinAPI_GetFileType

>_WinAPI_GetGraphicsMode

 
 
Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Just to add (if these are designed for the help file) then they should pass Au3Check with the following parameters (see below) and use the correct variable naming convention as stated in the Readme.txt (located in the docs zip file).
 

; All examples should pass #AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 without errors or warning.

Readme.txt.

###Parameters###
Parameters naming:
The first letter signifies the expected type of the variable. This should be as follows:
$a<letter> - Array (the following letter describes the data type taken from the rest of the data types below,
if it varies then v can be used.
$d - Binary data.
$h - Handle, usually to a file or window. NB: AutoIt handled controls return IDs, and so use $id instead.
$id - An AutoIt control Id.
$i - Integer.
$b - Boolean.
$f - Floating point number.
$n - general number with no preference for floating point or integer.
$s - String.
$v - Variant (unknown/variable type of data).
$o - COM object.
$p - Pointer. It is assumed that it points to a struct so no further letters are needed.
The type of struct being pointed to should be inferrable from the variable name e.g. $pWindowRect can be assumed to be a pointer to a $tagRECT structure.

Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

I've added an example recently for _WinAPI_GetAsyncKeyState, and updated the help file text for it because it wasn't right. It will probably show up in the next beta release. In the meantime, this is the example I added.

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WinAPI.au3>
#include <WinAPIvkeysConstants.au3>

Example()

Func Example()
    GUICreate("_WinAPI_GetAsyncKeyState Demo", 500, 300)
    GUICtrlCreateLabel("Press the number to select the task you wish to use from list below", 10, 30)
    GUICtrlCreateLabel("Press 1 key for task 1", 10, 60)
    GUICtrlCreateLabel("Press 2 key for task 2", 10, 90) ;  line and next cell
    GUICtrlCreateLabel("Press 3 key for task 3", 10, 120) ;
    GUICtrlCreateLabel("Press the ESCAPE key, or click the close button, to exit", 10, 150)
    GUISetState(@SW_SHOW)

    While GUIGetMsg() <> $GUI_EVENT_CLOSE
        If BitAND(_WinAPI_GetAsyncKeyState($VK_1), 0x8000) <> 0 Then
            MsgBox($MB_SYSTEMMODAL, "_WinAPI_GetAsyncKeyState", "Task 1")
        ElseIf BitAND(_WinAPI_GetAsyncKeyState($VK_2), 0x8000) <> 0 Then
            MsgBox($MB_SYSTEMMODAL, "_WinAPI_GetAsyncKeyState", "Task 2")
        ElseIf BitAND(_WinAPI_GetAsyncKeyState($VK_3), 0x8000) <> 0 Then
            MsgBox($MB_SYSTEMMODAL, "_WinAPI_GetAsyncKeyState", "Task 3")
        ElseIf BitAND(_WinAPI_GetAsyncKeyState($VK_ESCAPE), 0x8000) <> 0 Then
            MsgBox($MB_SYSTEMMODAL, "_WinAPI_GetAsyncKeyState", "The Esc Key was pressed, exiting.")
            ExitLoop
        EndIf
    WEnd
EndFunc   ;==>Example

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

_WinAPI_GetFileType

#include <WinAPI.au3>
#include <WinAPIFiles.au3>

Example_WinAPI_GetFileType()

Func Example_WinAPI_GetFileType()

    If Not FileExists("_WinAPI_GetFileType.txt") Then
        FileWrite("_WinAPI_GetFileType.txt", "")
    EndIf

    $hFile = _WinAPI_CreateFile("_WinAPI_GetFileType.txt", 2)
    If @error Then
        FileDelete("_WinAPI_GetFileType.txt")
        Exit MsgBox(0, "Failure", "_WinAPI_CreateFile")
    EndIf

    $fType = _WinAPI_GetFileType($hFile)
    If @error Then
        _WinAPI_CloseHandle($hFile)
        FileDelete("_WinAPI_GetFileType.txt")
        Exit MsgBox(0, "Failure", "_WinAPI_GetFileType: " & @extended)
    EndIf

    Switch $fType
        Case 1
            ConsoleWrite("The specified file is a disk file." & @LF)
        Case 2
            ConsoleWrite("The specified file is a character file, typically an LPT device or a console." & @LF)
        Case 3
            ConsoleWrite("The specified file is a socket, a named pipe, or an anonymous pipe." & @LF)
        Case Else
            ConsoleWrite("Either the type of the specified file is unknown, or the function failed." & @LF)
    EndSwitch

    _WinAPI_CloseHandle($hFile)
    FileDelete("_WinAPI_GetFileType.txt")
EndFunc   ;==>Example_WinAPI_GetFileType
 

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

_WinAPI_GetCurrentDirectory

#include <WinAPIFiles.au3>

ConsoleWrite(_WinAPI_GetCurrentDirectory() & @LF)

_WinAPI_GetDefaultPrinter

#include <WinAPISys.au3>
ConsoleWrite(_WinAPI_GetDefaultPrinter ( ) & @LF) 

Yes, I'm picking all the easy ones :)

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Very good example BrewManNH.

Thanks.

mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

It's actually the code from _IsPressed() without the error checking or the ability to pre-open the DLL. ;)

It also uses the correct virtual key code constants instead of the numbers listed in the _IsPressed function in the help file.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

_WinAPI_GetDriveType

#include <WinAPIFiles.au3>

Example_WinAPI_GetDriveType()

Func Example_WinAPI_GetDriveType()

    $tDrive = _WinAPI_GetDriveType("C:")
    If Not $tDrive Or $tDrive = 1 Then
        Exit MsgBox(0, "Failure", "The path is invalid or the type cannot be determined")
    EndIf

    Switch $tDrive
        Case 2
            ConsoleWrite("The drive has removable media; for example, a floppy drive, thumb drive, or flash card reader." & @LF)
        Case 3
            ConsoleWrite("The drive has fixed media; for example, a hard disk drive or flash drive." & @LF)
        Case 4
            ConsoleWrite("The drive is a remote (network) drive." & @LF)
        Case 5
            ConsoleWrite("The drive is a CD-ROM drive." & @LF)
        Case 6
            ConsoleWrite("The drive is a RAM disk." & @LF)
    EndSwitch

    Return $tDrive
EndFunc   ;==>Example_WinAPI_GetDriveType 

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

_WinAPI_GetErrorMessage

#include <WinAPIFiles.au3>
#include <WinAPIDiag.au3>

Example_WinAPI_GetErrorMessage()

Func Example_WinAPI_GetErrorMessage()

    $tDrive = _WinAPI_GetFileAttributes(12345.678)
    ConsoleWrite(_WinAPI_GetErrorMessage(_WinAPI_GetLastError()) & @LF)

EndFunc   ;==>Example_WinAPI_GetDriveType

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

_WinAPI_GetGraphicsMode

#include <WinAPI.au3>
#include <WinAPIGdi.au3>

$gMode = _WinAPI_GetGraphicsMode(_WinAPI_GetDC(0)) ; Desktop DC

Switch $gMode
    Case 1
        ConsoleWrite("Compatible mode" &@LF)
    Case 2
        ConsoleWrite("Advanced mode" &@LF)
EndSwitch

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

_WinAPI_GetDriveType

#include <WinAPIFiles.au3>

Example_WinAPI_GetDriveType()

Func Example_WinAPI_GetDriveType()

    $tDrive = _WinAPI_GetDriveType("C:")
    If Not $tDrive Or $tDrive = 1 Then
        Exit MsgBox(0, "Failure", "The path is invalid or the type cannot be determined")
    EndIf

    Switch $tDrive
        Case 2
            ConsoleWrite("The drive has removable media; for example, a floppy drive, thumb drive, or flash card reader." & @LF)
        Case 3
            ConsoleWrite("The drive has fixed media; for example, a hard disk drive or flash drive." & @LF)
        Case 4
            ConsoleWrite("The drive is a remote (network) drive." & @LF)
        Case 5
            ConsoleWrite("The drive is a CD-ROM drive." & @LF)
        Case 6
            ConsoleWrite("The drive is a RAM disk." & @LF)
    EndSwitch

    Return $tDrive
EndFunc   ;==>Example_WinAPI_GetDriveType 

 

small modyfication

#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#include <APIFilesConstants.au3>

Example_WinAPI_GetDriveType()

Func Example_WinAPI_GetDriveType()

    Local $iTypeOfDrive = _WinAPI_GetDriveType("C:")
    If $iTypeOfDrive = $DRIVE_UNKNOWN Or $iTypeOfDrive = $DRIVE_NO_ROOT_DIR Then
        MsgBox($MB_SYSTEMMODAL, "Failure", "The path is invalid or the type cannot be determined")
    EndIf

    Switch $iTypeOfDrive
        ; Case $DRIVE_UNKNOWN
        ;    ConsoleWrite("The drive type cannot be determined." & @LF)
        ; Case $DRIVE_NO_ROOT_DIR
        ;    ConsoleWrite("The root path is invalid; for example, there is no volume mounted at the specified path." & @LF)
        Case $DRIVE_REMOVABLE
            ConsoleWrite("The drive has removable media; for example, a floppy drive, thumb drive, or flash card reader." & @LF)
        Case $DRIVE_FIXED
            ConsoleWrite("The drive has fixed media; for example, a hard disk drive or flash drive." & @LF)
        Case $DRIVE_REMOTE
            ConsoleWrite("The drive is a remote (network) drive." & @LF)
        Case $DRIVE_CDROM
            ConsoleWrite("The drive is a CD-ROM drive." & @LF)
        Case $DRIVE_RAMDISK
            ConsoleWrite("The drive is a RAM disk." & @LF)
    EndSwitch

    Return $iTypeOfDrive
EndFunc   ;==>Example_WinAPI_GetDriveType

EDIT: typo 1>>0

 

EDIT:

If $iTypeOfDrive = $DRIVE_UNKNOWN Or $iTypeOfDrive = $DRIVE_NO_ROOT_DIR Then
        MsgBox($MB_SYSTEMMODAL, "Failure", "The path is invalid or the type cannot be determined")
    EndIf

0 = $DRIVE_UNKNOWN

1 = $DRIVE_NO_ROOT_DIR

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

_WinAPI_OpenProcess

_WinAPI_GetGuiResources

#include <WinAPI.au3>

Local $PID = Run("notepad.exe")
ProcessWait("notepad.exe")
$hProc = Example__WinAPI_OpenProcess($PID)

Local $aFlagsEx[2][2] = [[0, "GDI objects "],[1, "USER objects "]]

For $i = 0 To 1
    $COUNT = _WinAPI_GetGuiResources($aFlagsEx[$i][0], $hProc)
    If @error Then
        _WinAPI_CloseHandle($hProc)
        ProcessClose($PID)
        Exit MsgBox(0, "Failure", "_WinAPI_GetGuiResources")
    EndIf
    ConsoleWrite($aFlagsEx[$i][1] & $COUNT & @LF)
Next

_WinAPI_CloseHandle($hProc)
ProcessClose($PID)

Func Example__WinAPI_OpenProcess($_PID)
    $_hProc = _WinAPI_OpenProcess(0x0400, 0, $_PID) ;0x0400 = PROCESS_QUERY_INFORMATION
    If @error Then
        ProcessClose($_PID)
        Exit MsgBox(0, "Failure", "_WinAPI_OpenProcess")
    EndIf
    Return $_hProc
EndFunc   ;==>Example__WinAPI_OpenProcess 

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

_WinAPI_GetPriorityClass

#include <WinAPIProc.au3>

Example_WinAPI_GetPriorityClass()

Func Example_WinAPI_GetPriorityClass()
    Local $PID = Run("notepad.exe")
    ProcessWait("notepad.exe")

    $Class = _WinAPI_GetPriorityClass($PID)
    If Not $Class Then
        Exit MsgBox(0, "Failure", "_WinAPI_GetPriorityClass")
    EndIf

    Switch $Class
        Case 0x00008000
            ConsoleWrite("ABOVE_NORMAL_PRIORITY_CLASS" & @LF)
        Case 0x00004000
            ConsoleWrite("BELOW_NORMAL_PRIORITY_CLASS" & @LF)
        Case 0x00000080
            ConsoleWrite("HIGH_PRIORITY_CLASS" & @LF)
        Case 0x00000040
            ConsoleWrite("IDLE_PRIORITY_CLASS" & @LF)
        Case 0x00000020
            ConsoleWrite("NORMAL_PRIORITY_CLASS" & @LF)
        Case 0x00000100
            ConsoleWrite("REALTIME_PRIORITY_CLASS" & @LF)
    EndSwitch
    ProcessClose($PID)
EndFunc   ;==>Example_WinAPI_GetPriorityClass 

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

_WinAPI_DeleteFile

#include <WinAPIFiles.au3>

Local $sFile

FileWrite($sFile, "")

If Not _WinAPI_DeleteFile($sFile) Then
    FileDelete($sFile)
    Exit MsgBox(0, "Failure", "_WinAPI_DeleteFile")
EndIf

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Didnt realize you took the effort to link to the updated examples within this thread,  you should totally point that out as its hella useful.  Dont know what i initially thought they linked to since the whole point is that they were not in the helpfile.

Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

_WinAPI_GetAsyncKeyState

#include <WinAPI.au3>
#include <Misc.au3>

_WasPressed("")

While 1
    _MySubFunction(888)
    If _WasPressed("20") Then ConsoleWrite("_WasPressed - Space Key was pressed" & @CRLF)
    If _IsPressed("20") Then ConsoleWrite("_IsPressed - Space Key was pressed" & @CRLF)
    If _WasPressed("10") Then ConsoleWrite("_WasPressed - Shift Key was pressed" & @CRLF)
    If _IsPressed("10") Then ConsoleWrite("_IsPressed - Shift Key was pressed" & @CRLF)


    If _IsPressed("1B") Then
        ConsoleWrite("_IsPressed - The Esc Key was pressed, therefore we will close the application" & @CRLF)
        ExitLoop
    EndIf

    If _WasPressed("1B") Then
        ConsoleWrite("_WasPressed - The Esc Key was pressed, therefore we will close the application" & @CRLF)
        ExitLoop
    EndIf
WEnd
Exit
;--------------------------------------------------------------
Func _MySubFunction($t)
    Sleep($t)
EndFunc
;--------------------------------------------------------------
Func _WasPressed($vKey)
    Local $a_R = _WinAPI_GetAsyncKeyState("0x"&$vKey)
    If @error Then Return SetError(@error, @extended, False)
    Return BitAND($a_R, 0x0001) <> 0
EndFunc   ;==>_WasPressed
;--------------------------------------------------------------
Link to comment
Share on other sites

The WasPressed function probably won't work very reliably. It's only useful when using the script on pre-XP machines using 16 bit software.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

You can't use it for that, that's not what it does and you haven't read the MSDN site as to how it works. That script doesn't show the full potential of the function, it isn't really showing anything more than I posted and misleading people.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...