GuiIPAddress.au3 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. #include-once
  2. #include "IPAddressConstants.au3"
  3. #include "Memory.au3"
  4. #include "SendMessage.au3"
  5. #include "StructureConstants.au3"
  6. #include "UDFGlobalID.au3"
  7. #include "WinAPIConv.au3"
  8. #include "WinAPIGdi.au3"
  9. #include "WinAPIHObj.au3"
  10. #include "WinAPISysInternals.au3"
  11. ; #INDEX# =======================================================================================================================
  12. ; Title .........: IPAddress
  13. ; AutoIt Version : 3.3.14.5
  14. ; Language ......: English
  15. ; Description ...: Functions that assist with IPAddress control management.
  16. ; Author(s) .....: Gary Frost (gafrost)
  17. ; ===============================================================================================================================
  18. ; #VARIABLES# ===================================================================================================================
  19. Global $__g_hIPLastWnd
  20. ; ===============================================================================================================================
  21. ; #CONSTANTS# ===================================================================================================================
  22. Global Const $__IPADDRESSCONSTANT_ClassName = "SysIPAddress32"
  23. Global Const $__IPADDRESSCONSTANT_DEFAULT_GUI_FONT = 17
  24. Global Const $__IPADDRESSCONSTANT_LOGPIXELSX = 88
  25. Global Const $__IPADDRESSCONSTANT_PROOF_QUALITY = 2
  26. ; ===============================================================================================================================
  27. ; #CURRENT# =====================================================================================================================
  28. ; _GUICtrlIpAddress_Create
  29. ; _GUICtrlIpAddress_ClearAddress
  30. ; _GUICtrlIpAddress_Destroy
  31. ; _GUICtrlIpAddress_Get
  32. ; _GUICtrlIpAddress_GetArray
  33. ; _GUICtrlIpAddress_GetEx
  34. ; _GUICtrlIpAddress_IsBlank
  35. ; _GUICtrlIpAddress_Set
  36. ; _GUICtrlIpAddress_SetArray
  37. ; _GUICtrlIpAddress_SetEx
  38. ; _GUICtrlIpAddress_SetFocus
  39. ; _GUICtrlIpAddress_SetFont
  40. ; _GUICtrlIpAddress_SetRange
  41. ; _GUICtrlIpAddress_ShowHide
  42. ; ===============================================================================================================================
  43. ; #FUNCTION# ====================================================================================================================
  44. ; Author ........: Gary Frost (gafrost)
  45. ; Modified.......:
  46. ; ===============================================================================================================================
  47. Func _GUICtrlIpAddress_Create($hWnd, $iX, $iY, $iWidth = 125, $iHeight = 25, $iStyles = 0x00000000, $iExstyles = 0x00000000)
  48. If Not IsHWnd($hWnd) Then Return SetError(1, 0, 0) ; Invalid Window handle for _GUICtrlIpAddress_Create 1st parameter
  49. If $iStyles = -1 Then $iStyles = 0x00000000
  50. If $iExstyles = -1 Then $iExstyles = 0x00000000
  51. Local $iStyle = BitOR($__UDFGUICONSTANT_WS_CHILD, $__UDFGUICONSTANT_WS_VISIBLE, $__UDFGUICONSTANT_WS_TABSTOP, $iStyles)
  52. Local Const $ICC_INTERNET_CLASSES = 0x0800
  53. Local $tICCE = DllStructCreate('dword dwSize;dword dwICC')
  54. DllStructSetData($tICCE, "dwSize", DllStructGetSize($tICCE))
  55. DllStructSetData($tICCE, "dwICC", $ICC_INTERNET_CLASSES)
  56. DllCall('comctl32.dll', 'bool', 'InitCommonControlsEx', 'struct*', $tICCE)
  57. If @error Then Return SetError(@error, @extended, 0)
  58. Local $nCtrlID = __UDF_GetNextGlobalID($hWnd)
  59. If @error Then Return SetError(@error, @extended, 0)
  60. Local $hIPAddress = _WinAPI_CreateWindowEx($iExstyles, $__IPADDRESSCONSTANT_ClassName, "", $iStyle, $iX, $iY, $iWidth, $iHeight, $hWnd, $nCtrlID)
  61. _WinAPI_SetFont($hIPAddress, _WinAPI_GetStockObject($__IPADDRESSCONSTANT_DEFAULT_GUI_FONT))
  62. Return $hIPAddress
  63. EndFunc ;==>_GUICtrlIpAddress_Create
  64. ; #FUNCTION# ====================================================================================================================
  65. ; Author ........: Gary Frost (gafrost)
  66. ; Modified.......:
  67. ; ===============================================================================================================================
  68. Func _GUICtrlIpAddress_ClearAddress($hWnd)
  69. _SendMessage($hWnd, $IPM_CLEARADDRESS)
  70. EndFunc ;==>_GUICtrlIpAddress_ClearAddress
  71. ; #FUNCTION# ====================================================================================================================
  72. ; Author ........: Gary Frost (gafrost)
  73. ; Modified.......:
  74. ; ===============================================================================================================================
  75. Func _GUICtrlIpAddress_Destroy($hWnd)
  76. If Not _WinAPI_IsClassName($hWnd, $__IPADDRESSCONSTANT_ClassName) Then Return SetError(2, 2, False)
  77. Local $iDestroyed = 0
  78. If _WinAPI_InProcess($hWnd, $__g_hIPLastWnd) Then
  79. Local $nCtrlID = _WinAPI_GetDlgCtrlID($hWnd)
  80. Local $hParent = _WinAPI_GetParent($hWnd)
  81. $iDestroyed = _WinAPI_DestroyWindow($hWnd)
  82. Local $iRet = __UDF_FreeGlobalID($hParent, $nCtrlID)
  83. If Not $iRet Then
  84. ; can check for errors here if needed, for debug
  85. EndIf
  86. Else
  87. ; Not Allowed to Delete Other Applications IPAddress Control(s)
  88. Return SetError(1, 1, False)
  89. EndIf
  90. If $iDestroyed Then $hWnd = 0
  91. Return $iDestroyed <> 0
  92. EndFunc ;==>_GUICtrlIpAddress_Destroy
  93. ; #FUNCTION# ====================================================================================================================
  94. ; Author ........: Gary Frost (gafrost)
  95. ; Modified.......:
  96. ; ===============================================================================================================================
  97. Func _GUICtrlIpAddress_Get($hWnd)
  98. Local $tIP = _GUICtrlIpAddress_GetEx($hWnd)
  99. If @error Then Return SetError(2, 2, "")
  100. Return StringFormat("%d.%d.%d.%d", DllStructGetData($tIP, "Field1"), _
  101. DllStructGetData($tIP, "Field2"), _
  102. DllStructGetData($tIP, "Field3"), _
  103. DllStructGetData($tIP, "Field4"))
  104. EndFunc ;==>_GUICtrlIpAddress_Get
  105. ; #FUNCTION# ====================================================================================================================
  106. ; Author ........: Gary Frost
  107. ; Modified.......:
  108. ; ===============================================================================================================================
  109. Func _GUICtrlIpAddress_GetArray($hWnd)
  110. Local $tIP = _GUICtrlIpAddress_GetEx($hWnd)
  111. Local $aIP[4]
  112. $aIP[0] = DllStructGetData($tIP, "Field1")
  113. $aIP[1] = DllStructGetData($tIP, "Field2")
  114. $aIP[2] = DllStructGetData($tIP, "Field3")
  115. $aIP[3] = DllStructGetData($tIP, "Field4")
  116. Return $aIP
  117. EndFunc ;==>_GUICtrlIpAddress_GetArray
  118. ; #FUNCTION# ====================================================================================================================
  119. ; Author ........: Gary Frost (gafrost)
  120. ; Modified.......:
  121. ; ===============================================================================================================================
  122. Func _GUICtrlIpAddress_GetEx($hWnd)
  123. Local $tIP = DllStructCreate($tagGETIPAddress)
  124. If @error Then Return SetError(1, 1, "")
  125. If _WinAPI_InProcess($hWnd, $__g_hIPLastWnd) Then
  126. _SendMessage($hWnd, $IPM_GETADDRESS, 0, $tIP, 0, "wparam", "struct*")
  127. Else
  128. Local $iIP = DllStructGetSize($tIP)
  129. Local $tMemMap
  130. Local $pMemory = _MemInit($hWnd, $iIP, $tMemMap)
  131. _SendMessage($hWnd, $IPM_GETADDRESS, 0, $pMemory, 0, "wparam", "ptr")
  132. _MemRead($tMemMap, $pMemory, $tIP, $iIP)
  133. _MemFree($tMemMap)
  134. EndIf
  135. Return $tIP
  136. EndFunc ;==>_GUICtrlIpAddress_GetEx
  137. ; #FUNCTION# ====================================================================================================================
  138. ; Author ........: Gary Frost (gafrost)
  139. ; Modified.......:
  140. ; ===============================================================================================================================
  141. Func _GUICtrlIpAddress_IsBlank($hWnd)
  142. Return _SendMessage($hWnd, $IPM_ISBLANK) <> 0
  143. EndFunc ;==>_GUICtrlIpAddress_IsBlank
  144. ; #FUNCTION# ====================================================================================================================
  145. ; Author ........: Gary Frost (gafrost)
  146. ; Modified.......:
  147. ; ===============================================================================================================================
  148. Func _GUICtrlIpAddress_Set($hWnd, $sAddress)
  149. Local $aAddress = StringSplit($sAddress, ".")
  150. If $aAddress[0] = 4 Then
  151. Local $tIP = DllStructCreate($tagGETIPAddress)
  152. For $x = 1 To 4
  153. DllStructSetData($tIP, "Field" & $x, $aAddress[$x])
  154. Next
  155. _GUICtrlIpAddress_SetEx($hWnd, $tIP)
  156. EndIf
  157. EndFunc ;==>_GUICtrlIpAddress_Set
  158. ; #FUNCTION# ====================================================================================================================
  159. ; Author ........: Gary Frost (gafrost)
  160. ; Modified.......:
  161. ; ===============================================================================================================================
  162. Func _GUICtrlIpAddress_SetArray($hWnd, $aAddress)
  163. If UBound($aAddress) = 4 Then
  164. Local $tIP = DllStructCreate($tagGETIPAddress)
  165. For $x = 0 To 3
  166. DllStructSetData($tIP, "Field" & $x + 1, $aAddress[$x])
  167. Next
  168. _GUICtrlIpAddress_SetEx($hWnd, $tIP)
  169. EndIf
  170. EndFunc ;==>_GUICtrlIpAddress_SetArray
  171. ; #FUNCTION# ====================================================================================================================
  172. ; Author ........: Gary Frost (gafrost)
  173. ; Modified.......:
  174. ; ===============================================================================================================================
  175. Func _GUICtrlIpAddress_SetEx($hWnd, $tIP)
  176. _SendMessage($hWnd, $IPM_SETADDRESS, 0, _
  177. _WinAPI_MakeLong(BitOR(DllStructGetData($tIP, "Field4"), 0x100 * DllStructGetData($tIP, "Field3")), _
  178. BitOR(DllStructGetData($tIP, "Field2"), 0x100 * DllStructGetData($tIP, "Field1"))))
  179. EndFunc ;==>_GUICtrlIpAddress_SetEx
  180. ; #FUNCTION# ====================================================================================================================
  181. ; Author ........: Gary Frost (gafrost)
  182. ; Modified.......:
  183. ; ===============================================================================================================================
  184. Func _GUICtrlIpAddress_SetFocus($hWnd, $iIndex)
  185. _SendMessage($hWnd, $IPM_SETFOCUS, $iIndex)
  186. EndFunc ;==>_GUICtrlIpAddress_SetFocus
  187. ; #FUNCTION# ====================================================================================================================
  188. ; Author ........: Gary Frost (gafrost)
  189. ; Modified.......:
  190. ; ===============================================================================================================================
  191. Func _GUICtrlIpAddress_SetFont($hWnd, $sFaceName = "Arial", $iFontSize = 12, $iFontWeight = 400, $bFontItalic = False)
  192. Local $hDC = _WinAPI_GetDC(0)
  193. Local $iHeight = Round(($iFontSize * _WinAPI_GetDeviceCaps($hDC, $__IPADDRESSCONSTANT_LOGPIXELSX)) / 72, 0)
  194. _WinAPI_ReleaseDC(0, $hDC)
  195. Local $tFont = DllStructCreate($tagLOGFONT)
  196. DllStructSetData($tFont, "Height", $iHeight)
  197. DllStructSetData($tFont, "Weight", $iFontWeight)
  198. DllStructSetData($tFont, "Italic", $bFontItalic)
  199. DllStructSetData($tFont, "Underline", False) ; font underline
  200. DllStructSetData($tFont, "Strikeout", False) ; font strikethru
  201. DllStructSetData($tFont, "Quality", $__IPADDRESSCONSTANT_PROOF_QUALITY)
  202. DllStructSetData($tFont, "FaceName", $sFaceName)
  203. Local $hFont = _WinAPI_CreateFontIndirect($tFont)
  204. _WinAPI_SetFont($hWnd, $hFont)
  205. EndFunc ;==>_GUICtrlIpAddress_SetFont
  206. ; #FUNCTION# ====================================================================================================================
  207. ; Author ........: Gary Frost (gafrost)
  208. ; Modified.......:
  209. ; ===============================================================================================================================
  210. Func _GUICtrlIpAddress_SetRange($hWnd, $iIndex, $iLowRange = 0, $iHighRange = 255)
  211. If ($iLowRange < 0 Or $iLowRange > $iHighRange) Or $iHighRange > 255 Or ($iIndex < 0 Or $iIndex > 3) Then Return SetError(-1, -1, False)
  212. Return _SendMessage($hWnd, $IPM_SETRANGE, $iIndex, BitOR($iLowRange, 0x100 * $iHighRange)) <> 0
  213. EndFunc ;==>_GUICtrlIpAddress_SetRange
  214. ; #FUNCTION# ====================================================================================================================
  215. ; Author ........: Gary Frost (gafrost)
  216. ; Modified.......:
  217. ; ===============================================================================================================================
  218. Func _GUICtrlIpAddress_ShowHide($hWnd, $iState)
  219. If $iState <> @SW_HIDE And $iState <> @SW_SHOW Then Return SetError(1, 1, 0)
  220. Return _WinAPI_ShowWindow($hWnd, $iState) <> 0
  221. EndFunc ;==>_GUICtrlIpAddress_ShowHide