#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <GuiEdit.au3>


Dim $w_picctrl = 172, $h_picctrl = 100, $pic1



;reg 读取注册表的系统注册项
$regowner = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion","RegisteredOwner")
$regzation = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion","RegisteredOrganization")
$reguctid = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion","ProductId")
;INI 读取计算机与厂商信息
$inimanuf = IniRead(@SystemDir&"\OemInfo.ini","General","Manufacturer","")
$inimodel = IniRead(@SystemDir&"\OemInfo.ini","General","Model","")
;读取技术支持信息

Func _oem()
$Afrom_1 = GUICreate("OEM 设置", 376, 382, -1, -1, -1, -1, $window)
GUISetBkColor(0xEFF0F2)
$Group1 = GUICtrlCreateGroup("LOGO", 4, 16, 185, 121)
$Pic1 = GUICtrlCreatePic("", 8, 32, $w_picctrl, $h_picctrl)
$Deter = GUICtrlCreateButton("确定", 208, 344, 75, 25)
$Cancel = GUICtrlCreateButton("取消", 296, 344, 75, 25)
$Reg = GUICtrlCreateGroup("注册到", 194, 12, 177, 97)
$Owner = GUICtrlCreateInput($regowner, 202, 32, 161, 21)
$Zation = GUICtrlCreateInput($regzation, 202, 56, 161, 21)
$UctId = GUICtrlCreateInput($reguctid, 202, 80, 161, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Cust = GUICtrlCreateButton("自定义图片", 8, 144, 75, 25)
$delete = GUICtrlCreateButton("删除OEM", 104, 144, 75, 25)
$compute = GUICtrlCreateGroup("计算与厂商", 192, 112, 177, 73)
$Manuf = GUICtrlCreateInput($inimanuf, 200, 128, 161, 21)
$Model = GUICtrlCreateInput($inimodel, 200, 152, 161, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$mation = GUICtrlCreateEdit("", 4, 192, 366, 137)
$Info = IniReadSection(@SystemDir & "\OemInfo.ini","Support Information")
If Not @error Then
	For $i = 1 To $Info[0][0]
		If $i <> $Info[0][0] Then
			GUICtrlSetData($mation, GUICtrlRead($mation) & $Info[$i][1] & @CRLF)
		Else
			GUICtrlSetData($mation, GUICtrlRead($mation) & $Info[$i][1])
		EndIf
	Next
EndIf
GUISetState(@SW_SHOW)

_show()

While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			GUIDelete($Afrom_1)
			ExitLoop
		Case $Cust
			$bmpoem = FileOpenDialog("请选择一个BMP图片",@ScriptDir & "\","图像文件 (*.bmp)",1+2)
			$acn = MsgBox(32+1,"提示","确定要修改OemLogo.bmp ?")
			If  $acn = 1 Then
				Local $hImage, $h_img
				_GDIPlus_Startup()
				$hImage = _GDIPlus_ImageLoadFromFile($bmpoem)
				$w_img = _GDIPlus_ImageGetWidth($hImage)
				$h_img = _GDIPlus_ImageGetHeight($hImage)
				If $w_img > 180 And $h_img > 114 Then
					MsgBox(16,"错误","图片必须是180X114或者更小！")
				ElseIf $w_img * $h_img = 0 Then
					MsgBox(16,"错误","非法图片或者不是图片！")
				Else
					Local $kgb = $h_picctrl / $w_picctrl
					Local $kgb1 = $h_img / $w_img
					Local $x_py = 0, $y_py = 0, $hBMP, $hObject
					If $w_img > $w_picctrl Or $h_img > $h_picctrl Then
						If $kgb1 > $kgb Then
							$h_img = $h_picctrl
							$w_img = Round(1 / $kgb1 * $h_img)
							$x_py = ($w_picctrl - $w_img) / 2
						Else
							$w_img = $w_picctrl
							$h_img = Round($kgb1 * $w_img)
							$y_py = ($h_picctrl - $h_img) / 2
						EndIf
					Else
						$x_py = ($w_picctrl - $w_img) / 2
						$y_py = ($h_picctrl - $h_img) / 2
					EndIf
					$hBMP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
					$hObject = GUICtrlSendMsg($pic1, 0x0172, 0, $hBMP)
					_WinAPI_DeleteObject($hObject)
					_GDIPlus_ImageDispose($hImage)
					_WinAPI_DeleteObject($hBMP)
					_GDIPlus_Shutdown()
					GUICtrlSetPos($Pic1, 8 + $x_py - 1, 32 + $y_py - 1, $w_img, $h_img)
					GUICtrlSetPos($Pic1, 8 + $x_py, 32 + $y_py)
				EndIf
				FileCopy($bmpoem,@SystemDir & "\",1)
			EndIf
		Case $delete
			$anc = MsgBox(32+1,"提示","确定要删除所有Oem信息吗 ？")
			If $anc = 1 Then
				GUICtrlSetImage($Pic1,"")
				GUICtrlSetData($Manuf,"")
				GUICtrlSetData($Model,"")
				GUICtrlSetData($mation,"")
				FileDelete(@SystemDir & "\OemInfo.ini")
				FileDelete(@SystemDir & "\Oemlogo.bmp")
			EndIf
		Case $Deter
			$z1 = GUICtrlRead($Owner)
			$z2 = GUICtrlRead($Zation)
			$z3 = GUICtrlRead($UctId)
			$j1 = GUICtrlRead($Manuf)
			$j2 = GUICtrlRead($Model)
			RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion","RegisteredOwner","REG_SZ",$z1)
			RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion","RegisteredOrganization","REG_SZ",$z2)
			RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion","ProductId","REG_SZ",$z3)
			IniWrite(@SystemDir & "\OemInfo.ini","General","Manufacturer",$j1)
			IniWrite(@SystemDir & "\OemInfo.ini","General","Model",$j2)
			$Nson =  _GUICtrlEdit_GetLineCount($mation) -1
			IniDelete (@SystemDir & "\OemInfo.ini", "Support Information")
			For $i = 0 To $Nson
				IniWrite(@SystemDir & "\OemInfo.ini","Support Information","Line"&$I + 1,_GUICtrlEdit_GetLine($mation,$I))
			Next
			MsgBox(64,"提示","OemInfo信息修改成功！")
		Case $Cancel
			GUIDelete($Afrom_1)
			ExitLoop
	EndSwitch
WEnd
EndFunc


Func _show()
	 Local $imgfile = @SystemDir & "\Oemlogo.bmp", $hImage, $h_img
	 _GDIPlus_Startup()
	 $hImage = _GDIPlus_ImageLoadFromFile($imgfile)
	 $w_img = _GDIPlus_ImageGetWidth($hImage)
	 $h_img = _GDIPlus_ImageGetHeight($hImage)
	 Local $kgb = $h_picctrl / $w_picctrl
	 Local $kgb1 = $h_img / $w_img
	 Local $x_py = 0, $y_py = 0, $hBMP, $hObject
	 If $w_img > $w_picctrl Or $h_img > $h_picctrl Then
		 If $kgb1 > $kgb Then
			 $h_img = $h_picctrl
			 $w_img = Round(1 / $kgb1 * $h_img)
			 $x_py = ($w_picctrl - $w_img) / 2
		 Else
			 $w_img = $w_picctrl
			 $h_img = Round($kgb1 * $w_img)
			 $y_py = ($h_picctrl - $h_img) / 2
		 EndIf
	 Else
		 $x_py = ($w_picctrl - $w_img) / 2
		 $y_py = ($h_picctrl - $h_img) / 2
	 EndIf
	 $hBMP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
	 $hObject = GUICtrlSendMsg($pic1, 0x0172, 0, $hBMP)
	 _WinAPI_DeleteObject($hObject)
	 _GDIPlus_ImageDispose($hImage)
	 _WinAPI_DeleteObject($hBMP)
	 _GDIPlus_Shutdown()
	 GUICtrlSetPos($Pic1, 8 + $x_py - 1, 32 + $y_py - 1, $w_img, $h_img)
	 GUICtrlSetPos($Pic1, 8 + $x_py, 32 + $y_py)
EndFunc
