您的位置:程序门 -> vb ->



大哥~有没有函数可以将字符直接输出到桌面


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


大哥~有没有函数可以将字符直接输出到桌面
发表于:2007-04-21 12:53:08 楼主
有没有函数可以将字符直接输出到桌面
发表于:2007-04-21 14:44:211楼 得分:0
根据zzyong00(阿勇)提供的代码改动:
option   explicit
      '   在form的声明部分加上以下代码:
        private   declare   function   setwindowlong   lib   "user32 "   alias   _
        "setwindowlonga "   (byval   hwnd   as   long,   byval   nindex   as   long,   _
        byval   dwnewlong   as   long)   as   long
        private   declare   function   setparent   lib   "user32 "   (byval   hwndchild   _
        as   long,   byval   hwndnewparent   as   long)   as   long
        const   ws_ex_transparent   =   &h20&
        const   gwl_exstyle   =   (-20)
        private   declare   function   getdesktopwindow   lib   "user32.dll "   ()   as   long
        private   declare   function   getwindowdc   lib   "user32.dll "   (byval   hwnd   as   long)   as   long
        'private   declare   function   drawtext   lib   "user32.dll "   alias   "drawtexta "   (byval   hdc   as   long,   byval   lpstr   as   string,   byval   ncount   as   long,   byref   lprect   as   rect,   byval   wformat   as   long)   as   long
        private   declare   function   textout   lib   "gdi32.dll "   alias   "textouta "   (byval   hdc   as   long,   byval   x   as   long,   byval   y   as   long,   byval   lpstring   as   string,   byval   ncount   as   long)   as   long
        'private   type   rect
        '         left   as   long
        '         top   as   long
        '         right   as   long
        '         bottom   as   long
        'end   type

private   sub   form_click()
        end
end   sub

private   sub   form_load()
        setwindowlong   hwnd,   gwl_exstyle,   ws_ex_transparent
        timer1.interval   =   1000
end   sub

private   sub   timer1_timer()
        dim   h   as   long,   hd   as   long,   ret   as   long
        h   =   getdesktopwindow
        hd   =   getwindowdc(h)
        dim   c   as   string
        c   =   "有没有函数可以将字符直接输出到桌面 "
        ret   =   textout(hd,   280,   280,   c,   34)
        timer1.enabled   =   false
end   sub
发表于:2007-04-21 14:48:332楼 得分:0
运行后直接输入的例子:
添加一个模块,移除窗体,粘贴一下代码
private   declare   function   textout   lib   "gdi32 "   alias   "textouta "   (byval   hdc   as   long,   byval   x   as   long,   byval   y   as   long,   byval   lpstring   as   string,   byval   ncount   as   long)   as   long
private   declare   function   getdc   lib   "user32 "   (byval   hwnd   as   long)   as   long

sub   main()
textout   getdc(0),   100,   100,   "hell   world ",   10
end   sub

手动输出的例子:
新建窗体,放个按钮:

private   declare   function   textout   lib   "gdi32 "   alias   "textouta "   (byval   hdc   as   long,   byval   x   as   long,   byval   y   as   long,   byval   lpstring   as   string,   byval   ncount   as   long)   as   long
private   declare   function   getdc   lib   "user32 "   (byval   hwnd   as   long)   as   long

sub   command1_click()
textout   getdc(0),   100,   100,   "hell   world ",   10
end   sub

发表于:2007-04-21 14:48:333楼 得分:0
运行后直接输入的例子:
添加一个模块,移除窗体,粘贴一下代码
private   declare   function   textout   lib   "gdi32 "   alias   "textouta "   (byval   hdc   as   long,   byval   x   as   long,   byval   y   as   long,   byval   lpstring   as   string,   byval   ncount   as   long)   as   long
private   declare   function   getdc   lib   "user32 "   (byval   hwnd   as   long)   as   long

sub   main()
textout   getdc(0),   100,   100,   "hell   world ",   10
end   sub

手动输出的例子:
新建窗体,放个按钮:

private   declare   function   textout   lib   "gdi32 "   alias   "textouta "   (byval   hdc   as   long,   byval   x   as   long,   byval   y   as   long,   byval   lpstring   as   string,   byval   ncount   as   long)   as   long
private   declare   function   getdc   lib   "user32 "   (byval   hwnd   as   long)   as   long

sub   command1_click()
textout   getdc(0),   100,   100,   "hell   world ",   10
end   sub

发表于:2007-04-21 14:50:214楼 得分:0
程序运行后自动   输出的例子:
添加一个模块,移除原来的窗体,粘贴一下代码
private   declare   function   textout   lib   "gdi32 "   alias   "textouta "   (byval   hdc   as   long,   byval   x   as   long,   byval   y   as   long,   byval   lpstring   as   string,   byval   ncount   as   long)   as   long
private   declare   function   getdc   lib   "user32 "   (byval   hwnd   as   long)   as   long

sub   main()
textout   getdc(0),   100,   100,   "hell   world ",   10
end   sub

手动输出例子:
新建窗体,放个按钮,粘贴一下代码:

private   declare   function   textout   lib   "gdi32 "   alias   "textouta "   (byval   hdc   as   long,   byval   x   as   long,   byval   y   as   long,   byval   lpstring   as   string,   byval   ncount   as   long)   as   long
private   declare   function   getdc   lib   "user32 "   (byval   hwnd   as   long)   as   long

sub   command1_click()
textout   getdc(0),   100,   100,   "hell   world ",   10
end   sub


就这样了
发表于:2007-04-21 18:59:185楼 得分:0
楼主的 "桌面 "指的是什么
发表于:2007-04-21 21:22:186楼 得分:0
呵呵.....是啊..如果是桌面窗体,也就是一般窗体他爹,那获取句柄后直接用draw一类的api画上去就好了吧....
发表于:2007-04-22 11:47:127楼 得分:0
能不能以透明的方式显示呢???
发表于:2007-04-22 13:07:208楼 得分:0
鱼和熊掌不可兼得.
发表于:2007-04-22 16:44:199楼 得分:0
private   declare   function   getdc   lib   "user32 "   (byval   hwnd   as   long)   as   long
private   declare   function   setbkmode   lib   "gdi32 "   (byval   hdc   as   long,   byval   nbkmode   as   long)   as   long
private   declare   function   textout   lib   "gdi32.dll "   alias   "textouta "   (byval   hdc   as   long,   byval   x   as   long,   byval   y   as   long,   byval   lpstring   as   string,   byval   ncount   as   long)   as   long

private   const   transparent   =   1
private   sub   timer1_timer()
dim   hwnd   as   long
hwnd   =   getdc(0)
setbkmode   hwnd,   transparent         '设置透明
textout   hwnd,   550,   150,   "桌面写字测试~~ ",   14       '写字
doevents
end   sub
可以透明输送到桌面,但要注意timer   interval


快速检索

最新资讯
热门点击