| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1713 人关注过本帖, 1 人收藏
标题:[VB6-Graphic]如何在电脑桌面写字?
只看楼主 加入收藏
NealVB
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2013-3-24
结帖率:0
收藏(1)
已结贴  问题点数:10 回复次数:5 
[VB6-Graphic]如何在电脑桌面写字?
求指教....   

使用API  获得桌面DC也不行
搜索更多相关主题的帖子: 电脑桌面 如何 
2013-03-24 22:35
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:5 
应该可以写
但是 只要刷新桌面 就又没了

DO IT YOURSELF !
2013-03-24 22:42
lowxiong
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:27
帖 子:652
专家分:3402
注 册:2008-5-7
收藏
得分:5 
新建一个工程,窗口里放一个command控件command1,一个timer控件timer1,timer1控件Interval属性值设为10,拷贝下列代码运行即可,点击按钮可以在屏幕上画一斜红线,按鼠标左键不放可以任意画点(实现画字功能)。如果你是要在桌面上打印字符的画,则需用gdi的一些api解决,一般用了透明窗体,在透明窗体上print即可。仅供参考。

'-------------------------拷贝下列代码------------------------------------------------------------
Private Type POINTAPI
  X as Long
  Y as Long
End Type
Private Const VK_LBUTTON = &H1
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function SetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long

Private Sub Command1_Click()
  Dim sDc As Long, i As Integer
  sDc = GetDC(0)
  For i = 0 To 1200
    SetPixel sDc, i, i, vbRed
  Next
  ReleaseDC Me.hwnd, sDc
End Sub

Private Sub Timer1_Timer()
  Dim i As Long, zb As POINTAPI, sDc As Long
  i = GetAsyncKeyState(VK_LBUTTON)
  If i <> 0 Then
    sDc = GetDC(0)
    i = GetCursorPos(zb)
    SetPixel sDc, zb.x, zb.y, vbRed
    ReleaseDC Me.hwnd, sDc
  End If
End Sub


[ 本帖最后由 lowxiong 于 2013-3-25 08:08 编辑 ]
2013-03-25 08:01
NealVB
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2013-3-24
收藏
得分:0 
回复 3楼 lowxiong
你这断代码有点占系统资源。

VB没有提供透明窗体选项啊
2013-03-25 15:39
lowxiong
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:27
帖 子:652
专家分:3402
注 册:2008-5-7
收藏
得分:0 
新建一工程,放三个按钮分别为command1、command2、command3,拷贝下列代码,可实现窗体透明、半透明、不透明功能,使用透明功能你可以随便用那个pset画点、line画线、print打印字符

'-------------------------拷贝下列代码------------------------------------------------------------
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
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 SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Private Const WS_EX_LAYERED = &H80000
Private Const GWL_EXSTYLE = -20
Private Const LWA_ALPHA = &H2
Private Const LWA_COLORKEY = &H1

Private Sub Command1_Click()
  '透明
  Dim rtn As Long
  rtn = GetWindowLong(hwnd, GWL_EXSTYLE)
  rtn = rtn Or WS_EX_LAYERED
  SetWindowLong hwnd, GWL_EXSTYLE, rtn
  SetLayeredWindowAttributes hwnd, Me.BackColor, 0, LWA_COLORKEY
End Sub

Private Sub Command2_Click()
  '半透明
  Dim rtn As Long
  rtn = GetWindowLong(hwnd, GWL_EXSTYLE)
  rtn = rtn Or WS_EX_LAYERED
  SetWindowLong hwnd, GWL_EXSTYLE, rtn
  SetLayeredWindowAttributes hwnd, 0, 100, LWA_ALPHA
End Sub

Private Sub Command3_Click()
  '不透明
  Dim rtn As Long
  rtn = GetWindowLong(hwnd, GWL_EXSTYLE)
  rtn = rtn Or WS_EX_LAYERED
  SetWindowLong hwnd, GWL_EXSTYLE, rtn
  SetLayeredWindowAttributes hwnd, 0, 255, LWA_ALPHA
End Sub

Sub Form_Load()
  Me.BackColor = &HE0E0E0   '颜色值必须小于&H80000000
End Sub

2013-03-25 18:08
NealVB
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2013-3-24
收藏
得分:0 
回复 5楼 lowxiong
谢谢,这个功能能够实现。直接在窗体上使用print函数就可以了
2013-03-27 13:13
快速回复:[VB6-Graphic]如何在电脑桌面写字?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.032664 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved