Jump to content

WinAPIEx UDF


Yashied
 Share

Recommended Posts

As of v3.3.1.0 _WinAPI_GetLayeredWindowAttributes() and _WinAPI_SetLayeredWindowAttributes() exist in WinAPI.au3 for those running the beta and wondering why you're getting errors.

http://www.autoitscript.com/forum/index.php?showtopic=95367&view=findpost&p=685558

Just сomment these functions.
Link to comment
Share on other sites

The library has been updated.

Added functions

_WinAPI_DuplicateCursor

_WinAPI_EnumDisplaySettings

_WinAPI_FreeCursor

_WinAPI_GetCursor

_WinAPI_LoadCursor

_WinAPI_LoadCursorFromFile

_WinAPI_SetSystemCursor

Changes

  • Renamed _WinAPI_EnumResource#ToArray() to _WinAPI_EnumResource#()
  • Renamed _WinAPI_GetFontResourceInfoEx() to _WinAPI_GetFontResourceInfo()
  • Changed _WinAPI_GetFontResourceInfo()
  • Changed _WinAPI_AddFontResource()
  • Changed _WinAPI_RemoveFontResource()
  • Changed _WinAPI_GetKeyboardLayout(), _WinAPI_GetKeyboardLayoutList(), _WinAPI_SetKeyboardLayout(), and _WinAPI_EnumResourceLanguages() - working now with LCID (See examples)
Link to comment
Share on other sites

  • 2 weeks later...

The library has been updated.

Added functions

_WinAPI_CreateSemaphore

_WinAPI_GetDefaultPrinter

_WinAPI_GetProcessMemoryInfo

_WinAPI_GetWindowInfo

_WinAPI_OpenSemaphore

_WinAPI_ReleaseSemaphore

Changes

  • Renamed some functions to facilitate their use (eg _WinAPI_SHExtractIcons() to _WinAPI_ShellExtractIcons())
  • Fixed some minor bugs
  • Added descriptions for ALL functions
  • Added several new examples

This is final release of the library. In this form, I will support its in the future. Perhaps part of the functions of the UDF will be added in the following versions of AutoIt. But so far, who are interested, use this library. Of course, who wishes, may offer its WinAPI-functions for inclusion in the library. But do not offer the functions for working with threads. AutoIt will still not work with them, at least without a headache.

Link to comment
Share on other sites

The library has been updated.

Added functions

_WinAPI_CreateSemaphore

_WinAPI_GetDefaultPrinter

_WinAPI_GetProcessMemoryInfo

_WinAPI_GetWindowInfo

_WinAPI_OpenSemaphore

_WinAPI_ReleaseSemaphore

Changes

  • Renamed some functions to facilitate their use (eg _WinAPI_SHExtractIcons() to _WinAPI_ShellExtractIcons())
  • Fixed some minor bugs
  • Added descriptions for ALL functions
  • Added several new examples

This is final release of the library. In this form, I will support its in the future. Perhaps part of the functions of the UDF will be added in the following versions of AutoIt. But so far, who are interested, use this library. Of course, who wishes, may offer its WinAPI-functions for inclusion in the library. But do not offer the functions for working with threads. AutoIt will still not work with them, at least without a headache.

you can add and this...

MsgBox(4096, LockDevice("F:", 1), "Try yo CD")
;MsgBox(4096, LockDevice("F:", 0), "All Better")
Func LockDevice($szdrivewithcolon, $block)
    Local Const $invalid_handle_value = -1
    Local Const $open_existing = 3
    Local Const $file_attribute_normal = 128
    Local Const $file_share_write = 2
    Local Const $file_share_read = 1
    Local Const $generic_read = 2147483648
    Local Const $ioctl_storage_media_removal = 2967556
    $block = Not (Not $block)
    $szdrivewithcolon = StringReplace($szdrivewithcolon, "\", "")
    If StringLen($szdrivewithcolon) <> 2 Then Return -1
    $szdrivewithcolon = "\\.\" & $szdrivewithcolon
    $hdrive = DllCall("kernel32.dll", "int", "CreateFile", "str", $szdrivewithcolon, _
            "int", $generic_read, "int", BitOR($file_share_read, $file_share_write), "ptr", 0, "int", $open_existing, _
            "int", $file_attribute_normal, "ptr", 0)
    If $hdrive[0] = $invalid_handle_value Then Return -2
    $bool = DllStructCreate("byte")
    DllStructSetData($bool, 1, $block)
    $lockmediarslt = DllCall("kernel32.dll", "int", "DeviceIoControl", "int", $hdrive[0], _
            "int", $ioctl_storage_media_removal, "ptr", DllStructGetPtr($bool), "int", 1, _
            "int", 0, "int", 0, "int_ptr", 0, "ptr", 0)
    DllCall("kernel32.dll", "int", "CloseHandle", "int", $hdrive[0])
    $bool = 0
    Return $lockmediarslt[0]
EndFunc   ;==>LockDevice
Edited by psandu.ro
Link to comment
Share on other sites

The library has been updated to version 1.75.

Added functions

_WinAPI_CopyRect

_WinAPI_EqualRect

_WinAPI_GetCurrentDirectory

_WinAPI_GetROP2

_WinAPI_GetSystemPowerStatus

_WinAPI_InflateRect

_WinAPI_InvertRect

_WinAPI_LockDevice (Thanks psandu.ro)

_WinAPI_Rectangle

_WinAPI_RoundRect

_WinAPI_SetCurrentDirectory

_WinAPI_SetROP2

_WinAPI_UnionRect

_WinAPI_WindowFromDC

Link to comment
Share on other sites

I added WinAPIEx.au3 library for AutoIt 3.3.1.0 and above. This is the same, but with disabled _WinAPI_GetLayeredWindowAttributes() and _WinAPI_SetLayeredWindowAttributes() functions and related constants. As these functions already exist in the native AutoIt library.

Link to comment
Share on other sites

I added WinAPIEx.au3 library for AutoIt 3.3.1.0 and above. This is the same, but with disabled _WinAPI_GetLayeredWindowAttributes() and _WinAPI_SetLayeredWindowAttributes() functions and related constants. As these functions already exist in the native AutoIt library.

Hi and thank you for your effort, nice work,

It's saved me from a few trips to MSDN already >_<

Another function that's already in AutoIt v3.3.0.0 is _WinAPI_GetForegroundWindow()

Some more resource functions to add

#AutoIt3Wrapper_Au3Check_Parameters= -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6

#include <WinAPI.au3>

Opt('MustDeclareVars', 1)
 
; #FUNCTION# ====================================================================================================================
; Name...........: _WinAPI_CreateIconFromResource
; Description ...: Creates an icon or cursor from resource bits describing the icon.
; Syntax.........: _WinAPI_CreateIconFromResource($hLockRes, $iSizeRes)
; Parameters ....: $hLockRes    - Handle to the data associated with the resource as returned from _WinAPI_LockResource.
;                  $iSizeRes    - The number of bytes in the resource as returned from _WinAPI_SizeOfResource.
; Return values .: Success      - Handle to the Icon (hIcon)
;                  Failure      - Return 0 and set @error
;                                 @error 1 ~ 3 then it's a failed AutoIt DLLCall
;                                 @error 4 then it's the WinAPI error, @extended for _WinAPI_GetLastError().
; Author ........: Smashly
; Modified.......:
; Remarks .......: The user should call _WinAPI_DestroyIcon when they are finished with the hIcon.
; Related .......: _WinAPI_CreateIconFromResourceEx, _WinAPI_DestroyIcon
; Link ..........; @@MsdnLink@@ CreateIconFromResource
; Example .......;
; ===============================================================================================================================
Func _WinAPI_CreateIconFromResource($hLockRes, $iSizeRes)
    Local $aResult
    
    $aResult = DllCall("User32.dll", "int", "CreateIconFromResource", "hwnd", $hLockRes, "int", $iSizeRes, "int", 1, "int", 0x00030000)
    If @error Then Return SetError(@error, 0, 0)
    If Not IsArray($aResult) Or $aResult[0] = 0 Then Return SetError(4, _WinAPI_GetLastError(), 0)
    Return SetError(0, 0, $aResult[0])
EndFunc

; #FUNCTION# ====================================================================================================================
; Name...........: _WinAPI_CreateIconFromResourceEx
; Description ...: Creates an icon or cursor from resource bits describing the icon.
; Syntax.........: _WinAPI_CreateIconFromResourceEx($hLockRes, $iSizeRes)
; Parameters ....: $hLockRes    - Handle to the data associated with the resource as returned from _WinAPI_LockResource.
;                  $iSizeRes    - The number of bytes in the resource as returned from _WinAPI_SizeOfResource.
;                  $iCX         - Specifies the desired width, in pixels, of the icon or cursor. 
;                                  If this parameter is zero, the function uses the SM_CXICON or SM_CXCURSOR 
;                                  system metric value to set the width.
;                  $iCY         - Specifies the desired height, in pixels, of the icon or cursor. 
;                                  If this parameter is zero, the function uses the SM_CYICON or SM_CYCURSOR 
;                                  system metric value to set the height.
;                  $iFlags      - Specifies a combination of the following values:
;                                  $LR_DEFAULTCOLOR - Uses the default color format.
;                                  $LR_DEFAULTSIZE  - Uses the width or height specified by the system metric values 
;                                                     for cursors or icons, if the cxDesired or cyDesired values are set to zero.
;                                                     If this flag is not specified and cxDesired and cyDesired are set to zero, 
;                                                     the function uses the actual resource size. 
;                                                     If the resource contains multiple images, 
;                                                     the function uses the size of the first image.
;                                  $LR_MONOCHROME   - Creates a monochrome icon or cursor. 
;                                  $LR_SHARED       - Shares the icon or cursor handle if the icon or cursor is created multiple
;                                                     times. If LR_SHARED is not set, a second call to CreateIconFromResourceEx 
;                                                     for the same resource will create the icon or cursor again and return a 
;                                                     different handle.
;                                                     When you use this flag, the system will destroy the resource when it is 
;                                                     no longer needed.
;                                                     Do not use LR_SHARED for icons or cursors that have non-standard sizes, 
;                                                     that may change after loading, or that are loaded from a file.
;                                                     When loading a system icon or cursor, you must use LR_SHARED or the 
;                                                     function will fail to load the resource.
; Return values .: Success      - Handle to the Icon (hIcon)
;                  Failure      - Return 0 and set @error
;                                 @error 1 ~ 3 then it's a failed AutoIt DLLCall
;                                 @error 4 then it's the WinAPI error, @extended for _WinAPI_GetLastError().
; Author ........: Smashly
; Modified.......:
; Remarks .......: The user should call _WinAPI_DestroyIcon when they are finished with the hIcon.
; Related .......: _WinAPI_DestroyIcon
; Link ..........; @@MsdnLink@@ CreateIconFromResourceEx
; Example .......;
; ===============================================================================================================================
Func _WinAPI_CreateIconFromResourceEx($hLockRes, $iSizeRes, $iCX, $iCY, $iFlags)
    Local $aResult
    
    $aResult = DllCall("User32.dll", "int", "CreateIconFromResourceEx", "hwnd", $hLockRes, "int", $iSizeRes, _
                                    "int", 1, "int", 0x00030000, "int", $iCX, "int", $iCY, "int", $iFlags)
    If @error Then Return SetError(@error, 0, 0)
    If Not IsArray($aResult) Or $aResult[0] = 0 Then Return SetError(4, _WinAPI_GetLastError(), 0)
    Return SetError(0, 0, $aResult[0])
EndFunc

Cheers

Link to comment
Share on other sites

The library has been updated to version 1.76.

Added functions

_WinAPI_ArrayToStruct

_WinAPI_CreateRect

_WinAPI_DefineDosDevice

_WinAPI_DeleteVolumeMountPoint

_WinAPI_GetDiskFreeSpaceEx

_WinAPI_GetTempFileName

_WinAPI_GetVolumeNameForVolumeMountPoint

_WinAPI_OffsetRect

_WinAPI_PathCompactPath

_WinAPI_PathFindOnPath

_WinAPI_PathIsDirectory

_WinAPI_PathIsDirectoryEmpty

_WinAPI_PathSearchAndQualify

_WinAPI_PathYetAnotherMakeUniqueName

_WinAPI_PtInRectEx

_WinAPI_QueryDosDevice

_WinAPI_SetVolumeMountPoint

_WinAPI_ShowLastError

_WinAPI_StructToArray

_WinAPI_WinHelp

+ Examples

Edited by Yashied
Link to comment
Share on other sites

Thanks for improving Autoit's UDFs!! Good work!

I think _WinAPI_ArrayToStruct and _WinAPI_StructToArray should be in Array.au3 and not in WinAPI.au3

WinAPI.au3 should contain only functions related to Windows API from user32.dll, kernel32.dll,shell32.dll,comdlg32.dll,ole32.dll,gdi32.dll.

Hi, Zedna.

Heh, _WinAPI_ArrayToStruct() and _WinAPI_StructToArray() are used by some WinAPI functions, including are functions of this library. This is needed to better use WinAPI functions in AutoIt scripts. When writing this library, I tried to ease call WinAPI functions for the user. If I had just replaced the DllCall() to _WinFunc(), then the usefulness of such work would vanish. Anyway, are present in native AutoIt WinAPI.au3 functions such as _WinAPI_MakeDWord() or _WinAPI_PointFromRect(), which are absent in the *. dll, but it are needed to assist in other functions.

Link to comment
Share on other sites

Heh, _WinAPI_ArrayToStruct() and _WinAPI_StructToArray() are used by some WinAPI functions, including are functions of this library. This is needed to better use WinAPI functions in AutoIt scripts.

OK. In this case it's OK to have helper functions for main WinAPI ones (it's related to them).

I didn't looked deeply at your whole UDF I looked just at some functions.

Edited by Zedna
Link to comment
Share on other sites

@Yashied

Have you ever gotten around to fixing all the duplicate function errors when your file is #included in a script?

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

@Yashied

Have you ever gotten around to fixing all the duplicate function errors when your file is #included in a script?

They are commented in the UDF. I did not remove them from the file.

EDIT:

What functions you have duplicates?

Edited by Yashied
Link to comment
Share on other sites

They are commented in the UDF. I did not remove them from the file.

EDIT:

What functions you have duplicates?

I don't remember them all now. A quick test is to create a new test.au3 file on your desktop with just one line of code.

#include<WinAPIEx.au3>

and then run it.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

I don't remember them all now. A quick test is to create a new test.au3 file on your desktop with just one line of code.

#include<WinAPIEx.au3>

and then run it.

If you use AutoIt 3.3.x.x beta, in the first post I put WinAPIEx specifically for this release. There are disabled_WinAPI_GetLayeredWindowAttributes(), _WinAPI_SetLayeredWindowAttributes() and related constants.

Edited by Yashied
Link to comment
Share on other sites

That would account for it. I think the last time I downloaded, it was from the link on another of your posts in this thread.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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