Jump to content

Recommended Posts

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

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

Monkey's are, like, natures humans.

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.

  Quote

###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:

  Reveal hidden contents

Updated: 22/04/2018

Posted

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!

  Reveal hidden contents

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

Posted (edited)

_WinAPI_GetFileType

  Reveal hidden contents

Edited by JohnOne

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

Monkey's are, like, natures humans.

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

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

Monkey's are, like, natures humans.

Posted

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:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

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!

  Reveal hidden contents

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

Posted

_WinAPI_GetDriveType

  Reveal hidden contents

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

Monkey's are, like, natures humans.

Posted

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

Posted

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

Posted (edited)
  On 6/22/2014 at 9:35 PM, JohnOne said:

_WinAPI_GetDriveType

  Reveal hidden contents

 

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:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

_WinAPI_OpenProcess

_WinAPI_GetGuiResources

  Reveal hidden contents

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

Monkey's are, like, natures humans.

Posted (edited)

_WinAPI_GetPriorityClass

  Reveal hidden contents

Edited by JohnOne

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

Monkey's are, like, natures humans.

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

  Reveal hidden contents

Posted

_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
;--------------------------------------------------------------
Posted

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!

  Reveal hidden contents

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

Posted

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!

  Reveal hidden contents

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

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
  • Recently Browsing   0 members

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