#include-once

; Authenticity

; =======================================
; Title .........: WinAPI_for_GDIP
; AutoIt Version : 3.3.6.1
; Language ......: English
; Description ...: for GDIP
; =======================================

; #CURRENT# =============================
; _WinAPI_CloseThemeData
; _WinAPI_CreateDIBSection
; _WinAPI_DrawThemeTextEx
; _WinAPI_OpenThemeData
; _WinAPI_CreateStreamOnHGlobal
; _WinAPI_LoadIcon
; =======================================




; #FUNCTION# ====================================================================================================================
; Name...........: _WinAPI_CloseThemeData
; Description ...: Closes the theme data handle
; Syntax.........: _WinAPI_CloseThemeData($hTheme)
; Parameters ....: $hTheme - Handle to a window's specified theme data
; Return values .: Success      - True
;                  Failure      - False and either:
; Remarks .......: This function should be called when a window that has a visual style applied is destroyed
; Related .......: _WinAPI_OpenThemeData
; Link ..........; @@MsdnLink@@ CloseThemeData
; Example .......; No
; ===============================================================================================================================
Func _WinAPI_CloseThemeData($hTheme)
	Local $aResult = DllCall("uxtheme.dll", "int", "CloseThemeData", "hwnd", $hTheme)

	If @error Then Return SetError(@error, @extended, False)
	Return $aResult[0] = 0
EndFunc   ;==>_WinAPI_CloseThemeData

; #FUNCTION# ====================================================================================================================
; Name...........: _WinAPI_CreateDIBSection
; Description ...: Creates a DIB that applications can write to directly
; Syntax.........: _WinAPI_CreateDIBSection($hDC, $tBmpInfo, ByRef $pBits)
; Parameters ....: $hDC 	 - A handle to a device context
;                  $tBmpInfo - $tagBITMAPINFO structure that specifies various attributes of the DIB
;                  $pBits    - Reference to a variable that receives a pointer to the location of the DIB bit values
; Return values .: Success      - A handle to the newly created DIB
;                  Failure      - 0:
;                  |If @error is -1, there was an invalid parameter specified for the function
;                  |If @error is -2, the function failed, call _WinAPI_GetLastError to get the error code
; Remarks .......: None
; Related .......: $tagBITMAPINFO
; Link ..........; @@MsdnLink@@ CreateDIBSection
; Example .......; No
; ===============================================================================================================================
Func _WinAPI_CreateDIBSection($hDC, $tBmpInfo, ByRef $pBits)
	Local $pBmpInfo, $aResult

	$pBmpInfo = DllStructGetPtr($tBmpInfo)
	$aResult = DllCall("gdi32.dll", "hwnd", "CreateDIBSection", "hwnd", $hDC, "ptr", $pBmpInfo, "uint", 0, "int*", 0, "hwnd", 0, "uint", 0)

	If @error Then Return SetError(@error, @extended, 0)
	If $aResult[0] = 87 Then Return SetError(-1, 0, 0); 87 = ERROR_INVALID_PARAMETER
	If $aResult[0] = 0 Then Return SetError(-2, 0, 0)
	$pBits = $aResult[4]
	Return SetError(0, 0, $aResult[0])
EndFunc   ;==>_WinAPI_CreateDIBSection

; #FUNCTION# ====================================================================================================================
; Name...........: _WinAPI_DrawThemeTextEx
; Description ...: Draws text using the color and font defined by the visual style
; Syntax.........: _WinAPI_DrawThemeTextEx($hTheme, $hDC, $iPartId, $iStateId, $sText, $iFlags, $pRect, $pDTTOPTS)
; Parameters ....: $hTheme   - Handle to a window's specified theme data
;                  $hDC		 - Handle to a device context to use for drawing
;                  $iPartId  - The control part that has the desired text appearance
;                  $iStateId - The control state that has the desired text appearance
;                  $sText	 - String to be drawn
;                  $iFlags	 - String formatting flags (see remarks)
;                  $pRect	 - Pointer to a $tagRECT structure that contains the rectangle in which the text is to be drawn
;                  $pDTTOPTS - Pointer to a $tagDTTOPTS structure that defines additional formatting options that will be applied
;                  +to the text being drawn
; Return values .: Success      - True
;                  Failure      - False
; Remarks .......: The formatting flags are the same flags used by _WinAPI_DrawText
; Related .......: _WinAPI_DrawText
; Link ..........; @@MsdnLink@@ DrawThemeTextEx
; Example .......; No
; ===============================================================================================================================
Func _WinAPI_DrawThemeTextEx($hTheme, $hDC, $iPartId, $iStateId, $sText, $iFlags, $pRect, $pDTTOPTS)
	Local $aResult = DllCall("uxtheme.dll", "int", "DrawThemeTextEx", "ptr", $hTheme, "hwnd", $hDC, "int", $iPartId, "int", $iStateId, "wstr", $sText, "int", -1, "uint", $iFlags, "ptr", $pRect, "ptr", $pDTTOPTS)

	If @error Then Return SetError(@error, @extended, 0)
	Return SetError(0, 0, $aResult[0] = 0)
EndFunc   ;==>_WinAPI_DrawThemeTextEx

; #FUNCTION# ====================================================================================================================
; Name...........: _WinAPI_OpenThemeData
; Description ...: Opens the theme data for a window and its associated class
; Syntax.........: _WinAPI_OpenThemeData($hWnd, $sClassList)
; Parameters ....: $hWnd	   - Handle of the window for which theme data is required
;                  $sClassList - String that contains a semicolon-separated list of classes
; Return values .: Success      - A handle to the newly loaded icon
;                  Failure      - 0
; Remarks .......: None
; Related .......: _WinAPI_CloseThemeData
; Link ..........; @@MsdnLink@@ OpenThemeData
; Example .......; No
; ===============================================================================================================================
Func _WinAPI_OpenThemeData($hWnd, $sClassList)
	Local $aResult = DllCall("uxtheme.dll", "hwnd", "OpenThemeData", "hwnd", $hWnd, "wstr", $sClassList)

	If @error Then Return SetError(@error, @extended, 0)
	Return SetError(0, 0, $aResult[0])
EndFunc   ;==>_WinAPI_OpenThemeData

; #FUNCTION# ====================================================================================================================
; Name...........: _WinAPI_LoadIcon
; Description ...: Loads the specified icon resource from the executable (.exe) file associated with an application instance
; Syntax.........: _WinAPI_LoadIcon($hInstance, $vIconName)
; Parameters ....: $hInstance - Handle to an instance of the module whose executable file contains the icon to be loaded. This
;                  +parameter must be 0 when a standard icon is being loaded
;                  $vIconName - A string representing the icon resource name. Alternatively, this can be a number specifying the
;                  +resource identifier.
; Return values .: Success      - A handle to the newly loaded icon
;                  Failure      - 0
; Remarks .......: After you are done with the object, call _WinAPI_DestroyIcon to release the object resources
; Related .......: _WinAPI_DestroyIcon, _WinAPI_LoadImage
; Link ..........; @@MsdnLink@@ LoadIconA
; Example .......; No
; ===============================================================================================================================
Func _WinAPI_LoadIcon($hInstance, $vIconName)
	Local $sType, $aResult

	If IsString($vIconName) Then
		$sType = "str"
	Else
		$sType = "int"
	EndIf
	$aResult = DllCall("user32.dll", "hwnd", "LoadIconA", "hwnd", $hInstance, $sType, $vIconName)

	If @error Then Return SetError(@error, @extended, 0)
	Return SetError(0, 0, $aResult[0])
EndFunc   ;==>_WinAPI_LoadIcon

; #FUNCTION# ====================================================================================================================
; Name...........: _WinAPI_CreateStreamOnHGlobal
; Description ...: Creates a stream object that uses an HGLOBAL memory handle to store the stream contents
; Syntax.........: _WinAPI_CreateStreamOnHGlobal([$hGlobal = 0[, $fDeleteOnRelease = True]])
; Parameters ....: $hGlobal 	     - A memory handle. If 0, a new handle is to be allocated instead
;                  $fDeleteOnRelease - If True, the release of the IStream interface releases the memory handle as well.
;                  Otherwise, it's the responsibility of the user to release this memory handle.
; Return values .: Success      - A pointer to new stream object
;                  Failure      - 0
; Remarks .......: None
; Related .......: _MemGlobalFree
; Link ..........; @@MsdnLink@@ CreateStreamOnHGlobal
; Example .......; No
; ===============================================================================================================================
Func _WinAPI_CreateStreamOnHGlobal($hGlobal = 0, $fDeleteOnRelease = True)
	Local $aResult = DllCall("ole32.dll", "int", "CreateStreamOnHGlobal", "hwnd", $hGlobal, "int", $fDeleteOnRelease, "ptr*", 0)

	If @error Then Return SetError(@error, @extended, 0)
	Return SetError($aResult[0], 0, $aResult[3])
EndFunc   ;==>_WinAPI_CreateStreamOnHGlobal