如何制作VFP桌面歌词效果,API和GDI高手请进

love2008cn 2010-02-26 11:42:24
恳请各位大侠给于指点
参考VB代码
http://tieba.baidu.com/f?kz=702349514
下载地址:
http://www.quwen168.com/lrcshow.rar


现已实现在表单上画出,本来想画到图片中再通过透明窗口来实现,试了一下字体边缘很难看....
主要是这两个API不知道怎么实现
CreateDIBSection
UpdateLayeredWindow

网上找到的CreateDIBSection定义但BHDR_STRUCT_SIZE参数的值不知道是什么

nBitmapWidth=500
nBitmapHeight=300
nBitsPerPixel=24
ppvBits=0
cBITMAPINFOHEADER=num2dword(BHDR_STRUCT_SIZE) +;
num2dword(nBitmapWidth) + num2dword(nBitmapHeight) +;
num2word(1) + num2word(nBitsPerPixel) +;
num2dword(BI_RGB)
cBITMAPINFOHEADER=PADR(cBITMAPINFOHEADER,;
BHDR_STRUCT_SIZE, CHR(20))
hBitmap=CreateDIBSection(hDC, @cBITMAPINFOHEADER,;
DIB_RGB_COLORS, @ppvBits, 0, 0)



以下代码放在一个命令按键里就可看出绘制效果,注意表单的ShowWindow=0
DECLARE INTEGER GdipCreateStringFormat IN GdiPlus.dll ;
INTEGER formatAttributes, INTEGER language, INTEGER @nFormat

DECLARE INTEGER GdipDeleteBrush IN GdiPlus.dll ;
INTEGER brush
DECLARE INTEGER GdipCreateFont IN GdiPlus.dll;
INTEGER fontFamily, SINGLE emSize,;
INTEGER fntstyle, INTEGER unit, INTEGER @fnt
DECLARE INTEGER GdipDeleteFont IN GdiPlus.dll ;
INTEGER fnt
DECLARE INTEGER GdipCreateFontFamilyFromName IN GdiPlus.dll;
STRING familyname, INTEGER FontCollection, INTEGER @FontFamily
DECLARE INTEGER GdipDeleteFontFamily IN GdiPlus.dll ;
INTEGER FontFamily
DECLARE INTEGER GdipCreateFromHWND IN gdiplus.dll ;
INTEGER hWind, INTEGER @graphics
DECLARE INTEGER GdipDeleteGraphics IN GdiPlus.dll ;
INTEGER graphics



DECLARE INTEGER GdipSetSmoothingMode IN "gdiplus" INTEGER ,INTEGER
DECLARE INTEGER GdipCreateFontFamilyFromName IN gdiplus STRING familyname, INTEGER fontCollection, INTEGER @FontFamily
DECLARE INTEGER GdipCreateStringFormat IN gdiplus INTEGER formatAttributes, INTEGER language, INTEGER @fmt
DECLARE integer GdipCreateLineBrushFromRect IN gdiplus.dll string,integer,integer,integer, integer, integer @
DECLARE LONG GdipCreatePath IN GDIPLUS LONG brushmode, LONG @path
DECLARE LONG GdipAddPathStringI IN GDIPLUS LONG path, STRING str, LONG length, LONG family, LONG style, SINGLE emSize, STRING @layoutRect, LONG StringFormat
DECLARE LONG GdipFillPath IN GDIPLUS LONG graphics, LONG brush, LONG path
DECLARE LONG GdipDrawPath IN GDIPLUS LONG graphics, LONG pen, LONG path
DECLARE INTEGER GdipCreatePen1 IN gdiplus INTEGER color,SINGLE penwidth,INTEGER unit,INTEGER @ gdipen

graphics=0
GdipCreateFromHWND(thisform.hwnd,@graphics)

GdipSetSmoothingMode(graphics,2)&&SmoothingModeHighQuality

lcFontName='黑体'&&字体名称,必须是已注册的字体
lcFontName=STRCONV(lcFontName+CHR(0),5)
lnFontFamily=0


GdipCreateFontFamilyFromName(lcFontName,0,@lnFontFamily)

strFormat = 0

GdipCreateStringFormat(0,0,@strFormat)


*DECLARE LONG GdipSetStringFormatAlign IN GDIPLUS LONG @StringFormat, LONG
*GdipSetStringFormatAlign(@strFormat,1)

x=0&&绘制文字的左上角坐标
y=0
w=72
h=72

lcRectangleF=BINTOC(x,'F')+BINTOC(y,'F')+BINTOC(W,'F')+BINTOC(H,'F')
Brush = 0
GdipCreateLineBrushFromRect(lcRectangleF, 0x90000000, 0x90000000, 1, 2, @Brush)
x=1&&绘制文字的左上角坐标
y=1
rclayout=BINTOC(x,'4rs')+BINTOC(y,'4rs')
strPath = 0
GdipCreatePath(0,@strPath)
GdipAddPathStringI(strPath, STRCONV('QQ音乐,我最流行!'+CHR(0),5), -1, lnFontFamily, 1, 72, rclayout, strFormat)&&strFormat
GdipFillPath(graphics, Brush, strPath)
GdipDrawPath(graphics, 0, strPath)

*RETURN
*---
Brush = 0
GdipCreateLineBrushFromRect(lcRectangleF, 0x30000000, 0x30000000, 1, 3, @Brush)
x=1.5&&绘制文字的左上角坐标
y=1.5
rclayout=BINTOC(x,'4rs')+BINTOC(y,'4rs')
GdipCreatePath(0,@strPath)
GdipAddPathStringI(strPath, STRCONV('QQ音乐,我最流行!'+CHR(0),5), -1, lnFontFamily, 1, 72, rclayout, strFormat)
GdipFillPath(graphics, Brush, strPath)
GdipDrawPath(graphics, 0, strPath)
*---
Brush = 0
GdipCreateLineBrushFromRect(lcRectangleF, 0x20000000, 0x20000000, 1, 3, @Brush)
x=2&&绘制文字的左上角坐标
y=2
rclayout=BINTOC(x,'4rs')+BINTOC(y,'4rs')
GdipCreatePath(0,@strPath)
GdipAddPathStringI(strPath, STRCONV('QQ音乐,我最流行!'+CHR(0),5), -1, lnFontFamily, 1, 72, rclayout, strFormat)
GdipFillPath(graphics, Brush, strPath)
GdipDrawPath(graphics, 0, strPath)
*---
Brush = 0
GdipCreateLineBrushFromRect(lcRectangleF, 0x10000000, 0x10000000, 1, 3, @Brush)
x=2.2&&绘制文字的左上角坐标
y=2.2
rclayout=BINTOC(x,'4rs')+BINTOC(y,'4rs')
GdipCreatePath(0,@strPath)
GdipAddPathStringI(strPath, STRCONV('QQ音乐,我最流行!'+CHR(0),5), -1, lnFontFamily, 1, 72, rclayout, strFormat)
GdipFillPath(graphics, Brush, strPath)
GdipDrawPath(graphics, 0, strPath)
*---
Brush = 0
GdipCreateLineBrushFromRect(lcRectangleF, 0x40000000, 0x40000000, 1, 3, @Brush)
x=-1&&绘制文字的左上角坐标
y=-1
rclayout=BINTOC(x,'4rs')+BINTOC(y,'4rs')
GdipCreatePath(0,@strPath)
GdipAddPathStringI(strPath, STRCONV('QQ音乐,我最流行!'+CHR(0),5), -1, lnFontFamily, 1, 72, rclayout, strFormat)
GdipFillPath(graphics, Brush, strPath)
GdipDrawPath(graphics, 0, strPath)

*---
Brush = 0
GdipCreateLineBrushFromRect(lcRectangleF, 0x30000000, 0x30000000, 1, 3, @Brush)
x=-1.5&&绘制文字的左上角坐标
y=-1.5
rclayout=BINTOC(x,'4rs')+BINTOC(y,'4rs')
*
GdipCreatePath(0,@strPath)
GdipAddPathStringI(strPath, STRCONV('QQ音乐,我最流行!'+CHR(0),5), -1, lnFontFamily, 1, 72, rclayout, strFormat)
GdipFillPath(graphics, Brush, strPath)
GdipDrawPath(graphics, 0, strPath)

*---
Brush = 0
GdipCreateLineBrushFromRect(lcRectangleF,0xFF013C8F,0xFF0198D4, 1, 3, @Brush)
x=0&&绘制文字的左上角坐标
y=0
rclayout=BINTOC(x,'4rs')+BINTOC(y,'4rs')
pen =0
GdipCreatePen1(0x90000000, 1, 5, @pen)
GdipCreatePath(0,@strPath)
GdipAddPathStringI(strPath, STRCONV('QQ音乐,我最流行!'+CHR(0),5), -1, lnFontFamily, 1, 72, rclayout, strFormat)
GdipFillPath(graphics, Brush, strPath)
GdipDrawPath(graphics, pen, strPath)
...全文
496 16 打赏 收藏 举报
写回复
16 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
make_sail 2010-06-24
  • 打赏
  • 举报
回复
这个真的可以实现, 只是稍有点麻烦, 没时间了, 算我路过得了! 呵呵呵, 抱歉!
chai929 2010-06-24
  • 打赏
  • 举报
回复
积分怎么获取呀,我怎么得不到积分呢,积分老不够
zxd518518 2010-04-06
  • 打赏
  • 举报
回复
细细学习,不多说了
zt736659344 2010-04-05
  • 打赏
  • 举报
回复
学习了,虽然现在还弄不懂...
wanbolantian 2010-03-16
  • 打赏
  • 举报
回复
API估计得请夜猫版主才能搞得定了。神人!
love2008cn 2010-03-01
  • 打赏
  • 举报
回复
另外有时候会窗口什么都不显示(不是每次都能成功显示),手工调用Paint后就显示了
不知道是不是VFP窗口本身的问题....
love2008cn 2010-03-01
  • 打赏
  • 举报
回复
嗯,是参数传错了应该是MDC
已经实现,将以下代码放入表单的Paint事件,表单设置为顶层表单
呵呵,这个效果和生成图片的效果一样(黑边),最后参数为1的效果就是这样(VB里也是)
现在的问题是当UpdateLayeredWindow的最后一个参数为2时倒数第二个参数到底是怎么设置的
晕哦......

DECLARE INTEGER GdipCreateStringFormat IN GdiPlus.dll INTEGER formatAttributes, INTEGER language, INTEGER @nFormat
DECLARE INTEGER GdipDeleteBrush IN GdiPlus.dll INTEGER brush
DECLARE INTEGER GdipCreateFont IN GdiPlus.dll INTEGER fontFamily, SINGLE emSize,INTEGER fntstyle, INTEGER unit, INTEGER @fnt
DECLARE INTEGER GdipDeleteFont IN GdiPlus.dll INTEGER fnt
DECLARE INTEGER GdipCreateFontFamilyFromName IN GdiPlus.dll STRING familyname, INTEGER FontCollection, INTEGER @FontFamily
DECLARE INTEGER GdipDeleteFontFamily IN GdiPlus.dll INTEGER FontFamily
DECLARE INTEGER GdipCreateFromHWND IN gdiplus.dll INTEGER hWind, INTEGER @graphics
DECLARE INTEGER GdipDeleteGraphics IN GdiPlus.dll INTEGER graphics

DECLARE INTEGER GdipSetSmoothingMode IN "gdiplus" INTEGER ,INTEGER
DECLARE INTEGER GdipCreateFontFamilyFromName IN gdiplus STRING familyname, INTEGER fontCollection, INTEGER @FontFamily
DECLARE INTEGER GdipCreateStringFormat IN gdiplus INTEGER formatAttributes, INTEGER language, INTEGER @fmt
DECLARE integer GdipCreateLineBrushFromRect IN gdiplus.dll string,integer,integer,integer, integer, integer @
DECLARE LONG GdipCreatePath IN GDIPLUS LONG brushmode, LONG @path
DECLARE LONG GdipAddPathStringI IN GDIPLUS LONG path, STRING str, LONG length, LONG family, LONG style, SINGLE emSize, STRING @layoutRect, LONG StringFormat
DECLARE LONG GdipFillPath IN GDIPLUS LONG graphics, LONG brush, LONG path
DECLARE LONG GdipDrawPath IN GDIPLUS LONG graphics, LONG pen, LONG path
DECLARE INTEGER GdipCreatePen1 IN gdiplus INTEGER color,SINGLE penwidth,INTEGER unit,INTEGER @ gdipen
DECLARE integer GetDC in win32api integer
declare integer CreateCompatibleDC in gdi32 integer
graphics=0
hdc = GetDC(Thisform.hwnd)
mDC = CreateCompatibleDC(hdc)


#DEFINE DIB_RGB_COLORS 0
#DEFINE RGBQUAD_SIZE 4
#DEFINE BHDR_SIZE 40
#DEFINE GMEM_FIXED 0
#DEFINE BI_RGB 0
LOCAL lcBIHdr, lcBInfo, lcRgbQuad, lnRgbQuadSize, lpBitsArray, lnBitsSize1, lnBitsSize2
LOCAL lnBytesPerScan
nBitmapWidth=Thisform.Width
nBitmapHeight=Thisform.Height
* Obtain the XOR Bitmap
m.lnBytesPerScan = INT((m.nBitmapWidth* 32)/8)
IF MOD(m.lnBytesPerScan, 4) # 0
m.lnBytesPerScan = m.lnBytesPerScan + 4 - MOD(m.lnBytesPerScan, 4)
ENDIF

m.lnBitsSize1 = m.nBitmapHeight* m.lnBytesPerScan
m.cBITMAPINFOHEADER = BINTOC(BHDR_SIZE ,"4RS") + ; && biSize
BINTOC(m.nBitmapWidth,"4RS") + ; && biWidth
BINTOC(m.nBitmapHeight, "4RS") + ; && biHeight
BINTOC(1, "2RS") + ; && biPlanes
BINTOC(32, "2RS") + ; && biBitCount
BINTOC(BI_RGB, "4RS")


nBitsPerPixel=24
ppvBits=0
*cBITMAPINFOHEADER=num2dword(10) +;
num2dword(nBitmapWidth) + num2dword(nBitmapHeight) +;
num2word(1) + num2word(nBitsPerPixel) +;
num2dword(0)
cBITMAPINFOHEADER=PADR(cBITMAPINFOHEADER, 40, CHR(40))
DECLARE INTEGER CreateDIBSection IN gdi32 INTEGER hdc,STRING @pbmi,LONG iUsage,INTEGER @ppvBits, INTEGER hSection, LONG dwOffset
DECLARE INTEGER SelectObject IN gdi32 INTEGER hdc,INTEGER hObject
declare integer CreateCompatibleDC in gdi32 integer
Declare Long UpdateLayeredWindow IN "user32.dll" Long, Long, LONG, String, Long, String, LONG, String, Long
*Declare Long GdipCreateFromHDC IN "gdiplus" Long, Long
DECLARE INTEGER GdipCreateFromHDC IN gdiplus;
INTEGER hdc,;
INTEGER @ graphics

mainBitmap =CreateDIBSection(mDC, @cBITMAPINFOHEADER, 0, @ppvBits, 0, 0)

oldBitmap = SelectObject(mDC, mainBitmap)

GdipCreateFromHDC(mDC, @graphics)

GdipSetSmoothingMode(graphics,2)&&SmoothingModeHighQuality

lcFontName='黑体'&&字体名称,必须是已注册的字体
lcFontName=STRCONV(lcFontName+CHR(0),5)
lnFontFamily=0


GdipCreateFontFamilyFromName(lcFontName,0,@lnFontFamily)

strFormat = 0

GdipCreateStringFormat(0,0,@strFormat)


*DECLARE LONG GdipSetStringFormatAlign IN GDIPLUS LONG @StringFormat, LONG
*GdipSetStringFormatAlign(@strFormat,1)

x=0&&绘制文字的左上角坐标
y=0
w=72
h=72

lcRectangleF=BINTOC(x,'F')+BINTOC(y,'F')+BINTOC(W,'F')+BINTOC(H,'F')
Brush = 0
GdipCreateLineBrushFromRect(lcRectangleF, 0x90000000, 0x90000000, 1, 2, @Brush)
x=1&&绘制文字的左上角坐标
y=1
rclayout=BINTOC(x,'4rs')+BINTOC(y,'4rs')
strPath = 0
GdipCreatePath(0,@strPath)
GdipAddPathStringI(strPath, STRCONV('QQ音乐,我最流行!'+CHR(0),5), -1, lnFontFamily, 1, 72, rclayout, strFormat)&&strFormat
GdipFillPath(graphics, Brush, strPath)
GdipDrawPath(graphics, 0, strPath)

*RETURN
*---
Brush = 0
GdipCreateLineBrushFromRect(lcRectangleF, 0x30000000, 0x30000000, 1, 3, @Brush)
x=1.5&&绘制文字的左上角坐标
y=1.5
rclayout=BINTOC(x,'4rs')+BINTOC(y,'4rs')
GdipCreatePath(0,@strPath)
GdipAddPathStringI(strPath, STRCONV('QQ音乐,我最流行!'+CHR(0),5), -1, lnFontFamily, 1, 72, rclayout, strFormat)
GdipFillPath(graphics, Brush, strPath)
GdipDrawPath(graphics, 0, strPath)
*---
Brush = 0
GdipCreateLineBrushFromRect(lcRectangleF, 0x20000000, 0x20000000, 1, 3, @Brush)
x=2&&绘制文字的左上角坐标
y=2
rclayout=BINTOC(x,'4rs')+BINTOC(y,'4rs')
GdipCreatePath(0,@strPath)
GdipAddPathStringI(strPath, STRCONV('QQ音乐,我最流行!'+CHR(0),5), -1, lnFontFamily, 1, 72, rclayout, strFormat)
GdipFillPath(graphics, Brush, strPath)
GdipDrawPath(graphics, 0, strPath)
*---
Brush = 0
GdipCreateLineBrushFromRect(lcRectangleF, 0x10000000, 0x10000000, 1, 3, @Brush)
x=2.2&&绘制文字的左上角坐标
y=2.2
rclayout=BINTOC(x,'4rs')+BINTOC(y,'4rs')
GdipCreatePath(0,@strPath)
GdipAddPathStringI(strPath, STRCONV('QQ音乐,我最流行!'+CHR(0),5), -1, lnFontFamily, 1, 72, rclayout, strFormat)
GdipFillPath(graphics, Brush, strPath)
GdipDrawPath(graphics, 0, strPath)
*---
Brush = 0
GdipCreateLineBrushFromRect(lcRectangleF, 0x40000000, 0x40000000, 1, 3, @Brush)
x=-1&&绘制文字的左上角坐标
y=-1
rclayout=BINTOC(x,'4rs')+BINTOC(y,'4rs')
GdipCreatePath(0,@strPath)
GdipAddPathStringI(strPath, STRCONV('QQ音乐,我最流行!'+CHR(0),5), -1, lnFontFamily, 1, 72, rclayout, strFormat)
GdipFillPath(graphics, Brush, strPath)
GdipDrawPath(graphics, 0, strPath)

*---
Brush = 0
GdipCreateLineBrushFromRect(lcRectangleF, 0x30000000, 0x30000000, 1, 3, @Brush)
x=-1.5&&绘制文字的左上角坐标
y=-1.5
rclayout=BINTOC(x,'4rs')+BINTOC(y,'4rs')
*
GdipCreatePath(0,@strPath)
GdipAddPathStringI(strPath, STRCONV('QQ音乐,我最流行!'+CHR(0),5), -1, lnFontFamily, 1, 72, rclayout, strFormat)
GdipFillPath(graphics, Brush, strPath)
GdipDrawPath(graphics, 0, strPath)

*---
Brush = 0
GdipCreateLineBrushFromRect(lcRectangleF,0xFF013C8F,0xFF0198D4, 1, 3, @Brush)
x=0&&绘制文字的左上角坐标
y=0
rclayout=BINTOC(x,'4rs')+BINTOC(y,'4rs')
pen =0
GdipCreatePen1(0x90000000, 1, 5, @pen)
GdipCreatePath(0,@strPath)
GdipAddPathStringI(strPath, STRCONV('QQ音乐,我最流行!'+CHR(0),5), -1, lnFontFamily, 1, 72, rclayout, strFormat)
GdipFillPath(graphics, Brush, strPath)
GdipDrawPath(graphics, pen, strPath)

#define GWL_EXSTYLE -20
#define WS_EX_TOOLWINDOW 0x80000



DECLARE Long GetWindowLong IN WIN32API Long hWnd, Long nIndex
DECLARE Long SetWindowLong IN WIN32API Long hWnd, Long nIndex, Long dwNewLong
m.lnStyle = GetWindowLong(Thisform.hwnd, GWL_EXSTYLE)
SetWindowLong(Thisform.hwnd, GWL_EXSTYLE,BITOR(m.lnStyle, WS_EX_TOOLWINDOW))&&

DECLARE INTEGER GdipDeleteGraphics IN GdiPlus.dll INTEGER graphics
GdipDeleteGraphics(graphics)

lnBlendOp = 0 && always
lnBlendFlags = 0 && always
lnSrcConstAlpha = 255 && intensity, up to 255
lnAlphaFormat = 1 && try AC_SRC_ALPHA on non-white background
lnAlphaBlend = lnBlendOp +BitLShift(lnBlendFlags, 8) +BitLShift(lnSrcConstAlpha, 16) +BitLShift(lnAlphaFormat, 24)
*Declare LONG UpdateLayeredWindow IN "user32.dll" LONG, LONG, LONG, String, LONG, String, LONG, LONG, LONG
*UpdateLayeredWindow(Thisform.hwnd,hdc, 0, BINTOC(nBitmapWidth,'4rs')+BINTOC(nBitmapHeight,'4rs'), mDC, BINTOC(0,'F')+BINTOC(0,'F'), 0,lnAlphaBlend, 2)
Declare INTEGER UpdateLayeredWindow IN "user32.dll" LONG, LONG, LONG, String, LONG, String, LONG, String, LONG
UpdateLayeredWindow(Thisform.hwnd,hdc, 0, BINTOC(nBitmapWidth,'4rs')+BINTOC(nBitmapHeight,'4rs'), mDC, BINTOC(0,'4rs')+BINTOC(0,'4rs'), 0,BINTOC(0,'4RS')+BINTOC(255,'4RS')+BINTOC(0,'4RS')+BINTOC(1,'4RS'), 1)
*UpdateLayeredWindow(Thisform.hwnd,hdc, 0, BINTOC(nBitmapWidth,'4rs')+BINTOC(nBitmapHeight,'4rs'), mDC, BINTOC(0,'4rs')+BINTOC(0,'4rs'), 0,"", 2)
ACMAIN_CHM 2010-02-27
  • 打赏
  • 举报
回复
太复杂了 .
love2008cn 2010-02-27
  • 打赏
  • 举报
回复
2楼少了个声明,放到最前面
DECLARE INTEGER CreateDIBSection IN gdi32;
INTEGER hdc,;
STRING @pbmi,;
LONG iUsage,;
INTEGER @ppvBits,;
INTEGER hSection,;
LONG dwOffset
taohua300 2010-02-27
  • 打赏
  • 举报
回复
有请 夜猫 斑竹吧
回复内容太短了!
都市夜猫 2010-02-27
  • 打赏
  • 举报
回复
引用 8 楼 love2008cn 的回复:
嗯,问题在GdipCreateFromHDC(hDC, graphics)
应该返回0,现在返回的是2


粗粗看了一下,返回2是因为 api 声明和调用有误造成,第二个参数应该传引用:
Declare Long GdipCreateFromHDC IN gdiplus Long, Long @
相应的调用语句也要加 @
GdipCreateFromHDC(hDC, @ graphics)

此外,按照你的说明将表单 ShowWindow 设为 2,则应该取内里窗口的 hWnd,在最前面加下列语句,然后将所有的 Thisfrom.hWnd 替换为这个 hh:
DECLARE Long FindWindowEx IN WIN32API Long,Long,Long,Long
hh = FindWindowEx(Thisform.hwnd, 0, 0, 0)
如果 ShowWindow 不为 2,且 ScrollBars 为缺省值 0,则不需要修改

应该还有很多错误,自己检查吧
love2008cn 2010-02-27
  • 打赏
  • 举报
回复
嗯,问题在GdipCreateFromHDC(hDC, graphics)
应该返回0,现在返回的是2
love2008cn 2010-02-27
  • 打赏
  • 举报
回复
算了,把VB的代码贴上来好了,省的大家下载了,我是下了个绿色VB查看的
Public Function DrawText(ByVal text As String) As Boolean

SelectObject mDC, oldBitmap
DeleteObject mainBitmap
DeleteObject oldBitmap
DeleteDC mDC
GdipDeleteFontFamily fontFam
GdipDeleteStringFormat strFormat
GdipDeletePath strPath
GdipDeleteBrush Brush
GdipDeletePen pen
GdipDeleteGraphics graphics '释放graphics占用的内存
'清除上次使用的内存

If text = "" Then Exit Function
LastText = text


Dim tempBI As BITMAPINFO
Dim tempBlend As BLENDFUNCTION
Dim lngHeight As Long, lngWidth As Long
Dim curWinLong As Long
Dim img As Long
Dim winSize As Size
Dim srcPoint As POINTAPI
Dim pngPath As String

Me.Cls




With tempBI.bmiHeader
.biSize = Len(tempBI.bmiHeader)
.biBitCount = 32
.biHeight = Me.ScaleHeight
.biWidth = Me.ScaleWidth
.biPlanes = 1
.biSizeImage = .biWidth * .biHeight * (.biBitCount / 8)
End With
mDC = CreateCompatibleDC(Me.hdc)
mainBitmap = CreateDIBSection(mDC, tempBI, DIB_RGB_COLORS, ByVal 0, 0, 0)
oldBitmap = SelectObject(mDC, mainBitmap)

Call GdipCreateFromHDC(mDC, graphics)
Call GdipLoadImageFromFile(StrConv(pngPath, vbUnicode), img)
'读取图片
Call GdipGetImageHeight(img, lngHeight)
Call GdipGetImageWidth(img, lngWidth)

GdipSetSmoothingMode graphics, SmoothingModeHighQuality

GdipCreateFontFamilyFromName StrPtr(GFont.FontName), 0, fontFam
GdipCreateStringFormat 0, 0, strFormat
GdipSetStringFormatAlign strFormat, StringAlignmentCenter

Dim rectf1 As RECTF
rectf1.Height = GFont.FontSize
rectf1.Width = GFont.FontSize
rectf1.Top = 0
rectf1.Left = 0

'填充坐标 '&HFFA5DAF7, &HC8468DCC,&HFF010101


'-----------------------------------------------------
Debug.Print GdipCreateLineBrushFromRect(rectf1, &H90000000, &H90000000, LinearGradientModeVertical, WrapModeTileFlipY, Brush)
'创建一个填充笔刷
'创建一个描边的笔刷
rclayout.Left = 1
rclayout.Top = 1
rclayout.Right = Screen.Width / 15
rclayout.Bottom = 0

GdipCreatePath FillModeAlternate, strPath


Debug.Print GdipAddPathStringI(strPath, StrPtr(text), -1, fontFam, FontStyle.FontStyleBold, GFont.FontSize, rclayout, strFormat)

GdipFillPath graphics, Brush, strPath
GdipDrawPath graphics, pen, strPath
'--------------------
Debug.Print GdipCreateLineBrushFromRect(rectf1, &H30000000, &H30000000, LinearGradientModeVertical, WrapModeTileFlipXY, Brush)
'创建一个填充笔刷
'创建一个描边的笔刷
rclayout.Left = 1.5
rclayout.Top = 1.5
rclayout.Right = Screen.Width / 15
rclayout.Bottom = 0

GdipCreatePath FillModeAlternate, strPath


Debug.Print GdipAddPathStringI(strPath, StrPtr(text), -1, fontFam, FontStyle.FontStyleBold, GFont.FontSize, rclayout, strFormat)

GdipFillPath graphics, Brush, strPath
GdipDrawPath graphics, pen, strPath
'------------------------------------

'--------------------
Debug.Print GdipCreateLineBrushFromRect(rectf1, &H20000000, &H20000000, LinearGradientModeVertical, WrapModeTileFlipXY, Brush)
'创建一个填充笔刷
'创建一个描边的笔刷
rclayout.Left = 2
rclayout.Top = 2
rclayout.Right = Screen.Width / 15
rclayout.Bottom = 0

GdipCreatePath FillModeAlternate, strPath


Debug.Print GdipAddPathStringI(strPath, StrPtr(text), -1, fontFam, FontStyle.FontStyleBold, GFont.FontSize, rclayout, strFormat)

GdipFillPath graphics, Brush, strPath
GdipDrawPath graphics, pen, strPath
'------------------------------------
'--------------------
Debug.Print GdipCreateLineBrushFromRect(rectf1, &H10000000, &H10000000, LinearGradientModeVertical, WrapModeTileFlipXY, Brush)
'创建一个填充笔刷
'创建一个描边的笔刷
rclayout.Left = 2.2
rclayout.Top = 2.2
rclayout.Right = Screen.Width / 15
rclayout.Bottom = 0

GdipCreatePath FillModeAlternate, strPath


Debug.Print GdipAddPathStringI(strPath, StrPtr(text), -1, fontFam, FontStyle.FontStyleBold, GFont.FontSize, rclayout, strFormat)

GdipFillPath graphics, Brush, strPath
GdipDrawPath graphics, pen, strPath
'------------------------------------

'--------------------
Debug.Print GdipCreateLineBrushFromRect(rectf1, &H40000000, &H40000000, LinearGradientModeVertical, WrapModeTileFlipXY, Brush)
'创建一个填充笔刷
'创建一个描边的笔刷
rclayout.Left = -1
rclayout.Top = -1
rclayout.Right = Screen.Width / 15
rclayout.Bottom = 0

GdipCreatePath FillModeAlternate, strPath


Debug.Print GdipAddPathStringI(strPath, StrPtr(text), -1, fontFam, FontStyle.FontStyleBold, GFont.FontSize, rclayout, strFormat)

GdipFillPath graphics, Brush, strPath
GdipDrawPath graphics, pen, strPath
'------------------------------------

'--------------------
Debug.Print GdipCreateLineBrushFromRect(rectf1, &H30000000, &H30000000, LinearGradientModeVertical, WrapModeTileFlipXY, Brush)
'创建一个填充笔刷
'创建一个描边的笔刷
rclayout.Left = -1.5
rclayout.Top = -1.5
rclayout.Right = Screen.Width / 15
rclayout.Bottom = 0

GdipCreatePath FillModeAlternate, strPath


Debug.Print GdipAddPathStringI(strPath, StrPtr(text), -1, fontFam, FontStyle.FontStyleBold, GFont.FontSize, rclayout, strFormat)

GdipFillPath graphics, Brush, strPath
GdipDrawPath graphics, pen, strPath
'------------------------------------


'------------------------------------------------------


Debug.Print GdipCreateLineBrushFromRect(rectf1, GFont.ForeColor1, GFont.ForeColor2, LinearGradientModeVertical, WrapModeTileFlipXY, Brush)
'创建一个填充笔刷

GdipCreatePen1 &H90000000, 1, UnitDocument, pen
'创建一个描边的笔刷

rclayout.Left = 0
rclayout.Top = 0
rclayout.Right = Screen.Width / 15
rclayout.Bottom = 0

GdipCreatePath FillModeAlternate, strPath


Debug.Print GdipAddPathStringI(strPath, StrPtr(text), -1, fontFam, FontStyle.FontStyleBold, GFont.FontSize, rclayout, strFormat)

GdipFillPath graphics, Brush, strPath
GdipDrawPath graphics, pen, strPath



'--------------------------------------------------------------

curWinLong = GetWindowLong(Me.hwnd, GWL_EXSTYLE)

SetWindowLong Me.hwnd, GWL_EXSTYLE, curWinLong Or WS_EX_LAYERED


srcPoint.X = 0
srcPoint.Y = 0
winSize.cx = Me.ScaleWidth
winSize.cy = Me.ScaleHeight

With blendFunc32bpp
.AlphaFormat = AC_SRC_ALPHA
.BlendFlags = 0
.BlendOp = AC_SRC_OVER
.SourceConstantAlpha = 255
End With

Call GdipDisposeImage(img)
Call GdipDeleteGraphics(graphics)
Call UpdateLayeredWindow(Me.hwnd, Me.hdc, ByVal 0&, winSize, mDC, srcPoint, 0, blendFunc32bpp, ULW_ALPHA)


End Function
love2008cn 2010-02-27
  • 打赏
  • 举报
回复
其实也不算复杂,就是代码太乱了
关键就在这段VB代码,其它都是绘制文字的

mDC = CreateCompatibleDC(Me.hdc)
mainBitmap = CreateDIBSection(mDC, tempBI, DIB_RGB_COLORS, ByVal 0, 0, 0)
oldBitmap = SelectObject(mDC, mainBitmap)

Call GdipCreateFromHDC(mDC, graphics)

curWinLong = GetWindowLong(Me.hwnd, GWL_EXSTYLE)

SetWindowLong Me.hwnd, GWL_EXSTYLE, curWinLong Or WS_EX_LAYERED


srcPoint.X = 0
srcPoint.Y = 0
winSize.cx = Me.ScaleWidth
winSize.cy = Me.ScaleHeight

With blendFunc32bpp
.AlphaFormat = AC_SRC_ALPHA
.BlendFlags = 0
.BlendOp = AC_SRC_OVER
.SourceConstantAlpha = 255
End With

Call UpdateLayeredWindow(Me.hwnd, Me.hdc, ByVal 0&, winSize, mDC, srcPoint, 0, blendFunc32bpp, ULW_ALPHA)
lt5225262 2010-02-26
  • 打赏
  • 举报
回复
关注中......楼主努力!
love2008cn 2010-02-26
  • 打赏
  • 举报
回复
感觉就要实现了,可不知道为什么显示不出东西,我想问题应该在最后一步
想要调试却不知道如何将graphics保存到图片,这样至少知道绘制结果是否正常

代码很乱,东拼西凑的东西,先能实现效果再说

以下代码放在一个命令按键里执行,注意表单的ShowWindow=2&&作为顶层表单


DECLARE INTEGER GdipCreateStringFormat IN GdiPlus.dll ;
INTEGER formatAttributes, INTEGER language, INTEGER @nFormat

DECLARE INTEGER GdipDeleteBrush IN GdiPlus.dll ;
INTEGER brush
DECLARE INTEGER GdipCreateFont IN GdiPlus.dll;
INTEGER fontFamily, SINGLE emSize,;
INTEGER fntstyle, INTEGER unit, INTEGER @fnt
DECLARE INTEGER GdipDeleteFont IN GdiPlus.dll ;
INTEGER fnt
DECLARE INTEGER GdipCreateFontFamilyFromName IN GdiPlus.dll;
STRING familyname, INTEGER FontCollection, INTEGER @FontFamily
DECLARE INTEGER GdipDeleteFontFamily IN GdiPlus.dll ;
INTEGER FontFamily
DECLARE INTEGER GdipCreateFromHWND IN gdiplus.dll ;
INTEGER hWind, INTEGER @graphics
DECLARE INTEGER GdipDeleteGraphics IN GdiPlus.dll ;
INTEGER graphics

DECLARE INTEGER GdipSetSmoothingMode IN "gdiplus" INTEGER ,INTEGER
DECLARE INTEGER GdipCreateFontFamilyFromName IN gdiplus STRING familyname, INTEGER fontCollection, INTEGER @FontFamily
DECLARE INTEGER GdipCreateStringFormat IN gdiplus INTEGER formatAttributes, INTEGER language, INTEGER @fmt
DECLARE integer GdipCreateLineBrushFromRect IN gdiplus.dll string,integer,integer,integer, integer, integer @
DECLARE LONG GdipCreatePath IN GDIPLUS LONG brushmode, LONG @path
DECLARE LONG GdipAddPathStringI IN GDIPLUS LONG path, STRING str, LONG length, LONG family, LONG style, SINGLE emSize, STRING @layoutRect, LONG StringFormat
DECLARE LONG GdipFillPath IN GDIPLUS LONG graphics, LONG brush, LONG path
DECLARE LONG GdipDrawPath IN GDIPLUS LONG graphics, LONG pen, LONG path
DECLARE INTEGER GdipCreatePen1 IN gdiplus INTEGER color,SINGLE penwidth,INTEGER unit,INTEGER @ gdipen
declare integer GetDC in win32api integer
declare integer CreateCompatibleDC in gdi32 integer
graphics=0
hdc = GetDC(Thisform.hwnd)
mDC = CreateCompatibleDC(hdc)


#DEFINE DIB_RGB_COLORS 0
#DEFINE RGBQUAD_SIZE 4
#DEFINE BHDR_SIZE 40
#DEFINE GMEM_FIXED 0
#DEFINE BI_RGB 0
LOCAL lcBIHdr, lcBInfo, lcRgbQuad, lnRgbQuadSize, lpBitsArray, lnBitsSize1, lnBitsSize2
LOCAL lnBytesPerScan
nBitmapWidth=Thisform.Width
nBitmapHeight=Thisform.Height
* Obtain the XOR Bitmap
m.lnBytesPerScan = INT((m.nBitmapWidth* 32)/8)
IF MOD(m.lnBytesPerScan, 4) # 0
m.lnBytesPerScan = m.lnBytesPerScan + 4 - MOD(m.lnBytesPerScan, 4)
ENDIF

m.lnBitsSize1 = m.nBitmapHeight* m.lnBytesPerScan
m.cBITMAPINFOHEADER = BINTOC(BHDR_SIZE ,"4RS") + ; && biSize
BINTOC(m.nBitmapWidth,"4RS") + ; && biWidth
BINTOC(m.nBitmapHeight, "4RS") + ; && biHeight
BINTOC(1, "2RS") + ; && biPlanes
BINTOC(32, "2RS") + ; && biBitCount
BINTOC(BI_RGB, "4RS")


nBitsPerPixel=24
ppvBits=0
*cBITMAPINFOHEADER=num2dword(10) +;
num2dword(nBitmapWidth) + num2dword(nBitmapHeight) +;
num2word(1) + num2word(nBitsPerPixel) +;
num2dword(0)
cBITMAPINFOHEADER=PADR(cBITMAPINFOHEADER, 40, CHR(40))

mainBitmap =CreateDIBSection(mDC, @cBITMAPINFOHEADER,;
0, @ppvBits, 0, 0)
ACTIVATE SCREEN
DECLARE INTEGER SelectObject IN gdi32;
INTEGER hdc,;
INTEGER hObject
declare integer CreateCompatibleDC in gdi32 integer
Declare Long UpdateLayeredWindow IN "user32.dll" Long, Long, LONG, String, Long, String, LONG, String, Long
Declare INTEGER GdipCreateFromHDC IN "gdiplus" INTEGER , INTEGER

*mainBitmap = CreateDIBSection(mDC, @hBitmap, 0, 0, 0, 0)
oldBitmap = SelectObject(mDC, mainBitmap)

GdipCreateFromHDC(hDC, graphics)
GdipSetSmoothingMode(graphics,2)&&SmoothingModeHighQuality

lcFontName='黑体'&&字体名称,必须是已注册的字体
lcFontName=STRCONV(lcFontName+CHR(0),5)
lnFontFamily=0


GdipCreateFontFamilyFromName(lcFontName,0,@lnFontFamily)

strFormat = 0

GdipCreateStringFormat(0,0,@strFormat)


*DECLARE LONG GdipSetStringFormatAlign IN GDIPLUS LONG @StringFormat, LONG
*GdipSetStringFormatAlign(@strFormat,1)

x=0&&绘制文字的左上角坐标
y=0
w=72
h=72

lcRectangleF=BINTOC(x,'F')+BINTOC(y,'F')+BINTOC(W,'F')+BINTOC(H,'F')
Brush = 0
*GdipCreateLineBrushFromRect(lcRectangleF, 0x90000000, 0x90000000, 1, 2, @Brush)
*x=1&&绘制文字的左上角坐标
*y=1
*rclayout=BINTOC(x,'4rs')+BINTOC(y,'4rs')
strPath = 0
*GdipCreatePath(0,@strPath)
*GdipAddPathStringI(strPath, STRCONV('QQ音乐,我最流行!'+CHR(0),5), -1, lnFontFamily, 1, 72, rclayout, strFormat)&&strFormat
*GdipFillPath(graphics, Brush, strPath)
*GdipDrawPath(graphics, 0, strPath)

*RETURN
*---
Brush = 0
GdipCreateLineBrushFromRect(lcRectangleF, 0x30000000, 0x30000000, 1, 3, @Brush)
x=1.5&&绘制文字的左上角坐标
y=1.5
rclayout=BINTOC(x,'4rs')+BINTOC(y,'4rs')
GdipCreatePath(0,@strPath)
GdipAddPathStringI(strPath, STRCONV('QQ音乐,我最流行!'+CHR(0),5), -1, lnFontFamily, 1, 72, rclayout, strFormat)
GdipFillPath(graphics, Brush, strPath)
GdipDrawPath(graphics, 0, strPath)
*---
Brush = 0
GdipCreateLineBrushFromRect(lcRectangleF, 0x20000000, 0x20000000, 1, 3, @Brush)
x=2&&绘制文字的左上角坐标
y=2
rclayout=BINTOC(x,'4rs')+BINTOC(y,'4rs')
GdipCreatePath(0,@strPath)
GdipAddPathStringI(strPath, STRCONV('QQ音乐,我最流行!'+CHR(0),5), -1, lnFontFamily, 1, 72, rclayout, strFormat)
GdipFillPath(graphics, Brush, strPath)
GdipDrawPath(graphics, 0, strPath)
*---
Brush = 0
GdipCreateLineBrushFromRect(lcRectangleF, 0x10000000, 0x10000000, 1, 3, @Brush)
x=2.2&&绘制文字的左上角坐标
y=2.2
rclayout=BINTOC(x,'4rs')+BINTOC(y,'4rs')
GdipCreatePath(0,@strPath)
GdipAddPathStringI(strPath, STRCONV('QQ音乐,我最流行!'+CHR(0),5), -1, lnFontFamily, 1, 72, rclayout, strFormat)
GdipFillPath(graphics, Brush, strPath)
GdipDrawPath(graphics, 0, strPath)
*---
Brush = 0
GdipCreateLineBrushFromRect(lcRectangleF, 0x40000000, 0x40000000, 1, 3, @Brush)
x=-1&&绘制文字的左上角坐标
y=-1
rclayout=BINTOC(x,'4rs')+BINTOC(y,'4rs')
GdipCreatePath(0,@strPath)
GdipAddPathStringI(strPath, STRCONV('QQ音乐,我最流行!'+CHR(0),5), -1, lnFontFamily, 1, 72, rclayout, strFormat)
GdipFillPath(graphics, Brush, strPath)
GdipDrawPath(graphics, 0, strPath)

*---
Brush = 0
GdipCreateLineBrushFromRect(lcRectangleF, 0x30000000, 0x30000000, 1, 3, @Brush)
x=-1.5&&绘制文字的左上角坐标
y=-1.5
rclayout=BINTOC(x,'4rs')+BINTOC(y,'4rs')
*
GdipCreatePath(0,@strPath)
GdipAddPathStringI(strPath, STRCONV('QQ音乐,我最流行!'+CHR(0),5), -1, lnFontFamily, 1, 72, rclayout, strFormat)
GdipFillPath(graphics, Brush, strPath)
GdipDrawPath(graphics, 0, strPath)

*---
Brush = 0
GdipCreateLineBrushFromRect(lcRectangleF,0xFF013C8F,0xFF0198D4, 1, 3, @Brush)
x=0&&绘制文字的左上角坐标
y=0
rclayout=BINTOC(x,'4rs')+BINTOC(y,'4rs')
pen =0
GdipCreatePen1(0x90000000, 1, 5, @pen)
GdipCreatePath(0,@strPath)
GdipAddPathStringI(strPath, STRCONV('QQ音乐,我最流行!'+CHR(0),5), -1, lnFontFamily, 1, 72, rclayout, strFormat)
GdipFillPath(graphics, Brush, strPath)
GdipDrawPath(graphics, pen, strPath)

#define GWL_EXSTYLE -20
#define WS_EX_TOOLWINDOW 0x80000

DECLARE Long GetWindowLong IN WIN32API Long hWnd, Long nIndex
DECLARE Long SetWindowLong IN WIN32API Long hWnd, Long nIndex, Long dwNewLong
m.lnStyle = GetWindowLong(Thisform.hwnd, GWL_EXSTYLE)
SetWindowLong(Thisform.hwnd, GWL_EXSTYLE, BITOR(m.lnStyle, BITOR(m.lnStyle, WS_EX_TOOLWINDOW)))&&
*此段代码放入 表单INIT 事件中:
*SetWindowLong(Thisform.HWnd, -20, 0x80000)
DECLARE INTEGER GdipDeleteGraphics IN GdiPlus.dll INTEGER graphics
*GdipDeleteGraphics(graphics)
Declare Long UpdateLayeredWindow IN "user32.dll" Long, Long, LONG, String, Long, String, LONG, String, Long
LOCAL lnAlphaBlend, lnResult,;
lnBlendOp, lnBlendFlags, lnSrcConstAlpha, lnAlphaFormat
lnBlendOp = 0 && always
lnBlendFlags = 0 && always
lnSrcConstAlpha = 255 && intensity, up to 255
lnAlphaFormat = 1 && try AC_SRC_ALPHA on non-white background
* assembling the BLENDFUNCTION structure
lnAlphaBlend = lnBlendOp +;
BitLShift(lnBlendFlags, 8) +;
BitLShift(lnSrcConstAlpha, 16) +;
BitLShift(lnAlphaFormat, 24)
UpdateLayeredWindow(Thisform.hwnd,hdc, 0, BINTOC(nBitmapWidth,'F')+BINTOC(nBitmapHeight,'F'), mDC, BINTOC(0,'F')+BINTOC(0,'F'), 0, BINTOC(0,'4rs')+BINTOC(0,'4rs')+BINTOC(1,'4rs')+BINTOC(255,'4rs'), 2)
*UpdateLayeredWindow(Thisform.hwnd,hdc, 0, BINTOC(nBitmapWidth,'4rs')+BINTOC(nBitmapHeight,'4rs'), mDC, BINTOC(0,'F')+BINTOC(0,'F'), 0, BINTOC(0,'4rs')+BINTOC(0,'4rs')+BINTOC(1,'4rs')+BINTOC(255,'4rs'), 2)
发帖
VFP

2574

社区成员

VFP,是Microsoft公司推出的数据库开发软件,用它来开发数据库,既简单又方便。
社区管理员
  • VFP社区
加入社区
帖子事件
创建了帖子
2010-02-26 11:42
社区公告
暂无公告