【已解决】请教一个有关自定义函数的问题,我不懂怎么描述,请高手进来看一看
本帖最后由 fengjie 于 2012-10-28 23:52 编辑$Tital = "Test Func"
_Big()
Func _Big()
MsgBox(64, $Tital, "_Big() 1", 50)
_Mini()
Func _Mini()
MsgBox(64, $Tital, "_Mini()", 50)
EndFunc
MsgBox(64, $Tital, "_Big() 2", 50)
EndFunc
最近在学习Autoit上面这段代码运行会出错,但是我不懂怎么修改,
_Mini()这个函数不好放在外面,请高手帮下忙指点一下,谢谢!
"D:\AutoSet\Func.au3"(42,2) : error: 表达式错误
Func
^
"D:\AutoSet\Func.au3"(40,8) : error: _Mini(): 未定义的函数.
_Mini()
~~~~~~^
D:\AutoSet\Func.au3 - 2 错误, 0 警告
楼主 注册时间2008-10-23
如果是有心学习, 为什么都没耐心看下帮助文档呀? 函数不能嵌套,Func _Mini()放到外面就可以了
$Tital = "Test Func"
_Big()
Func _Big()
MsgBox(64, $Tital, "_Big() 1", 50)
_Mini()
MsgBox(64, $Tital, "_Big() 2", 50)
EndFunc ;==>_Big
Func _Mini()
MsgBox(64, $Tital, "_Mini()", 50)
EndFunc ;==>_Mini
不知楼主的“_Mini()这个函数不好放在外面”是什么意思,受什么限制的吗? 楼主 注册时间2008-10-23
如果是有心学习, 为什么都没耐心看下帮助文档呀?
user3000 发表于 2012-4-11 00:26 http://www.autoitx.com/images/common/back.gif
说到这个真是惭愧啊,以前没有时间学习,只是关注了一下,所以很早注册了,这段时间由于工作的关系,才有心思时间学习一下 不知楼主的“_Mini()这个函数不好放在外面”是什么意思,受什么限制的吗?
zldfsz 发表于 2012-4-11 00:31 http://www.autoitx.com/images/common/back.gif
原来不能这样嵌套啊,我把源文件上传吧,其中BackGround.bmp是一张1440*900的图片
我的目的是想要吧这段代码写成一个用户自定义函数直接调用 本帖最后由 fengjie 于 2012-10-28 23:53 编辑
#include <GDIPlus.au3>;内嵌GDI+的UDF,以供程序调用GDI+
$BgImg = @ScriptDir & "\BackGround.bmp"
$PngImg = @ScriptDir & "\Form.png"
$BMPCLSID = '{557CF400-1A04-11D3-9A73-0000F81EF32E}';指定BMP的图像编码器,测试N次为个值是固定的,所以直接用,大家也可以用_GDIPlus_EncodersGetCLSID('BMP')
_GDIPlus_Startup();启动GDI+
$hBgImage = _GDIPlus_BitmapCreateFromFile($BgImg);从文件中创建一个位图对象
$hPngImage = _GDIPlus_ImageLoadFromFile($PngImg);创建基于文件的图像对象
$PngWidth = _GDIPlus_ImageGetWidth($hPngImage);返回图像对象的宽度
$PngHeight = _GDIPlus_ImageGetHeight($hPngImage);返回图像对象的高度
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hBgImage);获取刚刚创建的位图对象的图形句柄
_GDIPlus_GraphicsSetSmoothingMode($hGraphic,2);设置图形的平滑度,使图形的图像有抗锯齿功能
DllCall($ghGDIPDll, "int", "GdipSetTextRenderingHint", "hwnd", $hGraphic , "int", 4);设置字体的平滑度,使图形的文字有抗锯齿功能
;~ _GDIPlus_GraphicsDrawImageRect($hGraphic, $hPngImage, 1025, 10, $width, $height);在$hGraphic图形坐标30,0的位置绘制和$hPngImage高度和宽度一致的$hPngImage对象
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hPngImage, 1010, 10, 425, 350);在$hGraphic图形坐标1010,10的位置绘制和一个宽度为425,高度为300的$hPngImage对象
$SeatNum = "001"
$SerialNum = "SA12587300"
$Mac = "50-E5-49-D7-4A-15"
$Notices1 = "座位:" & $SeatNum
$Notices2 = "请勿带饮水零食到机位"
$Notices3 = "课后请将键盘鼠标归位"
$Notices4 = "出厂编号:" & $SerialNum
$Notices5 = "MAC地址:" & $Mac
_PenImg($Notices1, "0xffffffff", "微软雅黑", "50", "1", "2", "1090", "50", "0", "0")
_PenImg($Notices2, "0xffffffff", "微软雅黑", "25", "1", "2", "1085", "160", "0", "0")
_PenImg($Notices3, "0xffffffff", "微软雅黑", "25", "1", "2", "1085", "200", "0", "0")
_PenImg($Notices4, "0xffffffff", "微软雅黑", "20", "1", "2", "1100", "260", "0", "0")
_PenImg($Notices5, "0xffffffff", "微软雅黑", "18", "1", "2", "1070", "290", "0", "0")
#CS $String = "座位:001" & @CRLF & "";定义字符串
$Color = "0xffffffff";定义_GDIPlus_BrushCreateSolid实心画笔的颜色
$FontType = "微软雅黑";定义_GDIPlus_FontFamilyCreate字体
$FontSize = "50";定义_GDIPlus_FontCreate字体大小
$FontStyle = "1";定义_GDIPlus_FontCreate字体为粗体
$FontUnit = "2";定义_GDIPlus_FontCreate坐标参照为像素
$X = "1090";定义_GDIPlus_RectFCreate矩形左上角 X 坐标
$Y = "50";定义_GDIPlus_RectFCreate矩形左上角 Y 坐标
$Width = "0";定义_GDIPlus_RectFCreate矩形宽度
$Height = "0";定义_GDIPlus_RectFCreate矩形高度
#CE
Func _PenImg($String, $Color, $FontType, $FontSize, $FontStyle, $FontUnit, $X, $Y, $Width, $Height) ;_PenImg使用画笔在图片上写字
$hBrush = _GDIPlus_BrushCreateSolid($Color);创建实心画笔对象,其中Alpha通道值为$Color
$hFormat = _GDIPlus_StringFormatCreate();创建字符串格式对象
$hFamily = _GDIPlus_FontFamilyCreate($FontType);创建字体为"微软雅黑"的字体族对象
$hFont = _GDIPlus_FontCreate($hFamily, $FontSize, $FontStyle,$FontUnit);用上面创建的字体族创建一个字体大小为50,粗体,坐标参照为像素的字体对象,坐标参照很重要,会影响到字体在图形上的位置
$tLayout = _GDIPlus_RectFCreate($X, $Y, $Width, $Height);创建 $tagGDIPRECTF 数据结构
$aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $String, $hFont, $tLayout, $hFormat);根据上面创建的字体、字符串等信息测量字符串在图形中的尺寸,以便在图形中绘制
_GDIPlus_GraphicsDrawStringEx($hGraphic, $String, $hFont, $aInfo, $hFormat, $hBrush);在图形中绘制上面创建的字符串对象
EndFunc
_GDIPlus_ImageSaveToFileEx($hBgImage, @ScriptDir & "\Wallpaper.bmp",$BMPCLSID,0);把位图对象保存为BMP文件
_GDIPlus_GraphicsDispose($hGraphic);释放资源
_WinAPI_DeleteObject($hBgImage);释放资源
_GDIPlus_Shutdown();关闭GDI+ 简单转了一下,更多参数自己照作添加
DrawImg.au3
#include <GDIPlus.au3>;内嵌GDI+的UDF,以供程序调用GDI+
Func DrawImg($BgImg,$PngImg)
Global $hGraphic,$hBgImage,$BMPCLSID
If Not FileExists($BgImg) Then $BgImg = @ScriptDir & "\BackGround.bmp"
If Not FileExists($PngImg) Then $PngImg = @ScriptDir & "\Form.png"
$BMPCLSID = '{557CF400-1A04-11D3-9A73-0000F81EF32E}';指定BMP的图像编码器,测试N次为个值是固定的,所以直接用,大家也可以用_GDIPlus_EncodersGetCLSID('BMP')
_GDIPlus_Startup();启动GDI+
$hBgImage = _GDIPlus_BitmapCreateFromFile($BgImg);从文件中创建一个位图对象
$hPngImage = _GDIPlus_ImageLoadFromFile($PngImg);创建基于文件的图像对象
$PngWidth = _GDIPlus_ImageGetWidth($hPngImage);返回图像对象的宽度
$PngHeight = _GDIPlus_ImageGetHeight($hPngImage);返回图像对象的高度
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hBgImage);获取刚刚创建的位图对象的图形句柄
_GDIPlus_GraphicsSetSmoothingMode($hGraphic,2);设置图形的平滑度,使图形的图像有抗锯齿功能
DllCall($ghGDIPDll, "int", "GdipSetTextRenderingHint", "hwnd", $hGraphic , "int", 4);设置字体的平滑度,使图形的文字有抗锯齿功能
;~ _GDIPlus_GraphicsDrawImageRect($hGraphic, $hPngImage, 1025, 10, $width, $height);在$hGraphic图形坐标30,0的位置绘制和$hPngImage高度和宽度一致的$hPngImage对象
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hPngImage, 1010, 10, 425, 350);在$hGraphic图形坐标1010,10的位置绘制和一个宽度为425,高度为300的$hPngImage对象
$SeatNum = "001"
$SerialNum = "SA12587300"
$Mac = "50-E5-49-D7-4A-15"
$Notices1 = "座位:" & $SeatNum
$Notices2 = "请勿带饮水零食到机位"
$Notices3 = "课后请将键盘鼠标归位"
$Notices4 = "出厂编号:" & $SerialNum
$Notices5 = "MAC地址:" & $Mac
_PenImg($Notices1, "0xffffffff", "微软雅黑", "50", "1", "2", "1090", "50", "0", "0")
_PenImg($Notices2, "0xffffffff", "微软雅黑", "25", "1", "2", "1085", "160", "0", "0")
_PenImg($Notices3, "0xffffffff", "微软雅黑", "25", "1", "2", "1085", "200", "0", "0")
_PenImg($Notices4, "0xffffffff", "微软雅黑", "20", "1", "2", "1100", "260", "0", "0")
_PenImg($Notices5, "0xffffffff", "微软雅黑", "18", "1", "2", "1070", "290", "0", "0")
#CS $String = "座位:001" & @CRLF & "";定义字符串
$Color = "0xffffffff";定义_GDIPlus_BrushCreateSolid实心画笔的颜色
$FontType = "微软雅黑";定义_GDIPlus_FontFamilyCreate字体
$FontSize = "50";定义_GDIPlus_FontCreate字体大小
$FontStyle = "1";定义_GDIPlus_FontCreate字体为粗体
$FontUnit = "2";定义_GDIPlus_FontCreate坐标参照为像素
$X = "1090";定义_GDIPlus_RectFCreate矩形左上角 X 坐标
$Y = "50";定义_GDIPlus_RectFCreate矩形左上角 Y 坐标
$Width = "0";定义_GDIPlus_RectFCreate矩形宽度
$Height = "0";定义_GDIPlus_RectFCreate矩形高度
#CE
_GDIPlus_ImageSaveToFileEx($hBgImage, @ScriptDir & "\Wallpaper.bmp",$BMPCLSID,0);把位图对象保存为BMP文件
_GDIPlus_GraphicsDispose($hGraphic);释放资源
_WinAPI_DeleteObject($hBgImage);释放资源
_GDIPlus_Shutdown();关闭GDI+
EndFunc
Func _PenImg($String, $Color, $FontType, $FontSize, $FontStyle, $FontUnit, $X, $Y, $Width, $Height) ;_PenImg使用画笔在图片上写字
$hBrush = _GDIPlus_BrushCreateSolid($Color);创建实心画笔对象,其中Alpha通道值为$Color
$hFormat = _GDIPlus_StringFormatCreate();创建字符串格式对象
$hFamily = _GDIPlus_FontFamilyCreate($FontType);创建字体为"微软雅黑"的字体族对象
$hFont = _GDIPlus_FontCreate($hFamily, $FontSize, $FontStyle,$FontUnit);用上面创建的字体族创建一个字体大小为50,粗体,坐标参照为像素的字体对象,坐标参照很重要,会影响到字体在图形上的位置
$tLayout = _GDIPlus_RectFCreate($X, $Y, $Width, $Height);创建 $tagGDIPRECTF 数据结构
$aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $String, $hFont, $tLayout, $hFormat);根据上面创建的字体、字符串等信息测量字符串在图形中的尺寸,以便在图形中绘制
_GDIPlus_GraphicsDrawStringEx($hGraphic, $String, $hFont, $aInfo, $hFormat, $hBrush);在图形中绘制上面创建的字符串对象
EndFunc
调用方法
#include <DrawImg.au3>
$BgImg = @ScriptDir & "\BackGround.bmp"
$PngImg = @ScriptDir & "\Form.png"
DrawImg($BgImg,$PngImg) 本帖最后由 zldfsz 于 2012-4-10 18:12 编辑
顺便说下高亮方法,将【code】【/code】里的code改为au3就行了,或者回帖时用高级模式会看到“代码"按钮右边企鹅上面有个A2按钮,点击后直接粘贴代码就可以了 大师跑滴快,小弟来凑凑热闹{:face (411):} 非常感谢zldfsz大师的指点,我的问题终于解决了 回复 12# fengjie
问题解决了就请编辑帖子在标题上加【已解决】
页:
[1]