Office中国论坛/Access中国论坛
标题:
Access能使用GDI+API编程吗?
[打印本页]
作者:
站到终点站
时间:
2014-9-6 11:13
标题:
Access能使用GDI+API编程吗?
我在VB6里面可以正常看到GDI+编程的效果,如下图
以下是转换到ACCESS里后的代码,运行时没任何反应,也没有任何出错提示,不知道是何原因,有谁知道的吗?是否ACCESS的窗体不支持GDI+?
Private TOKEN As Long
Private Graphics As Long
Dim pen As Long, brush As Long
Private Sub Command0_Click()
Dim p1 As POINTF, p2 As POINTF
InitGDIPlus
GdipCreateFromHWND Me.Hwnd, Graphics
GdipSetSmoothingMode Graphics, SmoothingModeAntiAlias
GdipCreatePen1 &HFFFF0000, 500, UnitPixel, pen
GdipDrawLineI Graphics, pen, 10, 10, 4000, 2000
GdipCreatePen1 &HFFFF0000, 1, UnitPixel, pen
GdipDrawRectangleI Graphics, pen, 30, 30, 2000, 2000
GdipCreateSolidFill &HAA0000FF, brush
GdipFillRectangleI Graphics, brush, 30, 30, 2000, 2000
GdipDrawRectangleI Graphics, pen, 30, 30, 200, 2000
p1.X = 10
p1.Y = 10
p2.X = 2000
p2.Y = 1000
GdipCreateLineBrush p1, p2, &H8AFF00FF, &HFFFF0000, WrapModeTileFlipXY, brush
GdipFillEllipseI Graphics, brush, p1.X, p1.Y, p2.X - p1.X, p2.Y - p1.X
Me.Repaint
End Sub
Private Sub Form_Unload(Cancel As Integer)
GdipDeletePen pen
GdipDeleteBrush brush
TerminateGDIPlus
End Sub
Private Sub TerminateGDIPlus()
GdipDeleteGraphics Graphics
GdiplusShutdown TOKEN
End Sub
Private Sub InitGDIPlus()
Dim uInput As GdiplusStartupInput
uInput.GdiplusVersion = 1
If GdiplusStartup(TOKEN, uInput) <> Ok Then
MsgBox "GDI+ 初始化错误。程序即将关闭。", vbCritical, "InitError"
End
End If
End Sub
复制代码
作者:
tmtony
时间:
2014-9-6 17:24
这个你要请教 t小宝,他是图片专家
作者:
zpy2
时间:
2014-9-7 05:12
这个用了什么库,不是win Api直接写的吧
作者:
t小宝
时间:
2014-9-9 22:54
tmtony 发表于 2014-9-6 17:24
这个你要请教 t小宝,他是图片专家
王站过奖了,不敢当啊。。。
要在access窗体上画图,不能使用Me.Hwnd,因为access有个神密的东西叫节,节覆盖在窗体上,所有的控件都在节上面显示,所以要在节上作画,可通过FindWindowEx取得节句柄,节的类名是OFormSub
作者:
tmtony
时间:
2014-9-13 08:41
赞一下!
作者:
zpy2
时间:
2014-9-14 06:42
赞一个!
作者:
站到终点站
时间:
2014-9-14 11:32
我把按钮单击代码更换了下,但是还是没有效果,困惑!
Private Sub Command0_Click()
Dim p1 As POINTF, p2 As POINTF
InitGDIPlus
GdipCreateFromHWND FindWindowEx(Me.hwnd, 0&, "OFormSub", vbNullString), graphics
GdipSetSmoothingMode graphics, SmoothingModeAntiAlias
GdipCreatePen1 &HFFFF0000, 500, UnitPixel, pen
GdipDrawLineI graphics, pen, 10, 10, 4000, 2000
GdipCreatePen1 &HFFFF0000, 1, UnitPixel, pen
GdipDrawRectangleI graphics, pen, 30, 30, 2000, 2000
GdipCreateSolidFill &HAA0000FF, brush
GdipFillRectangleI graphics, brush, 30, 30, 2000, 2000
GdipDrawRectangleI graphics, pen, 30, 30, 200, 2000
p1.X = 10
p1.Y = 10
p2.X = 2000
p2.Y = 1000
GdipCreateLineBrush p1, p2, &H8AFF00FF, &HFFFF0000, WrapModeTileFlipXY, brush
GdipFillEllipseI graphics, brush, p1.X, p1.Y, p2.X - p1.X, p2.Y - p1.X
Me.Repaint
End Sub
复制代码
作者:
站到终点站
时间:
2014-9-14 11:33
zpy2 发表于 2014-9-7 05:12
这个用了什么库,不是win Api直接写的吧
这个要引用gdiplus.dll
作者:
t小宝
时间:
2014-9-14 19:14
首先,access窗体始终有3个节,页眉、主体、页脚,即使在设计视图中没有,用FindWindowEx也能找到3个。
所以如果是使用主体节作画,则要FindWindowEx两次得到主体节句柄,具体请百度FindWindowEx的用法。
另外不要使用 Me.Repaint ,刷新窗体后在上面画的东西就没有了。
作者:
站到终点站
时间:
2014-9-15 13:55
感谢小宝版主,修改后,测试成功~[attach]54636[/attach]
修改后的按钮单击代码如下:
Private Sub Command0_Click()
Dim p1 As POINTF, p2 As POINTF
Dim tempHwnd As Long
InitGDIPlus
tempHwnd = FindWindowEx(Me.hwnd, 0&, "OFormSub", vbNullString)
tempHwnd = FindWindowEx(Me.hwnd, tempHwnd, "OFormSub", vbNullString)
GdipCreateFromHWND tempHwnd, graphics
GdipSetSmoothingMode graphics, SmoothingModeAntiAlias
GdipCreatePen1 &HFFFF0000, 1, UnitPixel, pen
GdipDrawLineI graphics, pen, 1, 1, 400, 200
GdipCreatePen1 &HFFFF0000, 1, UnitPixel, pen
GdipDrawRectangleI graphics, pen, 30, 30, 200, 200
GdipCreateSolidFill &HAA0000FF, brush
GdipFillRectangleI graphics, brush, 30, 30, 200, 200
GdipDrawRectangleI graphics, pen, 30, 30, 200, 200
p1.X = 10
p1.Y = 10
p2.X = 200
p2.Y = 100
GdipCreateLineBrush p1, p2, &H8AFF00FF, &HFFFF0000, WrapModeTileFlipXY, brush
GdipFillEllipseI graphics, brush, p1.X, p1.Y, p2.X - p1.X, p2.Y - p1.X
End Sub
复制代码
作者:
站到终点站
时间:
2014-9-15 14:06
我找到了GdiPlus的API声明,没有的可以下载去用。
[attach]54637[/attach]
作者:
zpy2
时间:
2014-9-16 05:40
谢谢分享
欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/)
Powered by Discuz! X3.3