Sign in to follow this  
Followers 0
JohnOne

The bumper thread of missing winapi examples.

56 posts in this topic

#1 ·  Posted (edited)

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
4 people like this

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

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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: 04/09/2015

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

_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.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

_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
1 person likes this

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

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

Very good example BrewManNH.

Thanks.

mLipok


February 26, 2017: New SciTE4AutoIt3 available with the updated SciTE v3.7.3 release
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button:

Spoiler

Last update: 2017-02-26
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 SOAPPOP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF * WinSCP UDF *

My contribution to others projects: * _sql.au3 UDF  *

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 * Best coding practices * 

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 *

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 *

"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."

 

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

_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

February 26, 2017: New SciTE4AutoIt3 available with the updated SciTE v3.7.3 release
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button:

Spoiler

Last update: 2017-02-26
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 SOAPPOP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF * WinSCP UDF *

My contribution to others projects: * _sql.au3 UDF  *

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 * Best coding practices * 

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 *

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 *

"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."

 

Share this post


Link to post
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 

1 person likes this

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

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

_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.

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

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

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

Share this post


Link to post
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
;--------------------------------------------------------------

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

yes, but this unreliability also can be used - to know if someone stealing key presses :shifty::) or if you have some blocking function and cannot use/monitor IsPressed in meantime

beside - WasPressed in cooperation with IsPressed show full potential of  _WinAPI_GetAsyncKeyState function

Share this post


Link to post
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

Share this post


Link to post
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
Sign in to follow this  
Followers 0