在 普通的文本框 里加入图片背景

文本框

------------------------------------------窗口的代码-------------------

窗体:form1

图片框 picture1

文本框 text1

Private Sub Form_Load()
Set pic = LoadResPicture(102, 0)
Set Picture1.Picture = pic
Dim hdc As Long
hdc = GetDC(Text1.hwnd) '建立一个临时DC

memDc = CreateCompatibleDC(hdc)
MemBitmap = CreateCompatibleBitmap(hdc, Text1.Width, Text1.Height)
SelectObject memDc, MemBitmap
StretchBlt memDc, 0, 0, Text1.Width, Text1.Height, Picture1.hdc, 0, 0, Text1.Width, Text1.Height, SRCCOPY
ReleaseDC Text1.hwnd, hdc

If memDc = 0 Or MemBitmap = 0 Then
MsgBox "error create dc"
End
End If
Oldproc = SetWindowLong(Text1.hwnd, GWL_WNDPROC, AddressOf winproc)
OldWndProc = SetWindowLong(Me.hwnd, GWL_WNDPROC, AddressOf winproc1)
End Sub

Private Sub Form_Unload(Cancel As Integer)
DeleteObject MemBitmap
DeleteDC memDc
SetWindowLong Me.hwnd, GWL_WNDPROC, OldWndProc
SetWindowLong Text1.hwnd, GWL_WNDPROC, Oldproc
End Sub
Private Sub Text1_DblClick()
SendMessage Text1.hwnd, WM_PAINT, 0, 0
End Sub

Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
SendMessage Text1.hwnd, WM_PAINT, 0, 0
End Sub

Private Sub Text1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
'选定文本的时候如果文本选顶发生了变化,则通知更
Static Startpos0 As Long, Endpos0 As Long
Dim Startpos As Long, Endpos As Long
If Button = 1 Then
Dim v As Long
v = SendMessage(Text1.hwnd, EM_GETSEL, 0, 0)
Endpos = v \ 65536: Startpos = v Mod 65536 '-->获得选定文本位置

If Startpos <> Endpos Then '--->发现有选定时候检查选定是否和上次的相同?不同的话则重画
If Startpos0 = Startpos And Endpos = Endpos0 Then
Else '---->内容发生变化的时候发送消息请求重画
SendMessage Text1.hwnd, WM_PAINT, 0, 0
Startpos0 = Startpos: Endpos0 = Endpos
End If
End If
End If
End Sub

Private Sub Text1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
PostMessage Text1.hwnd, WM_PAINT, 0, 0
End Sub

Private Sub Text1_Change()
SendMessage Form1.Text1.hwnd, WM_PAINT, 0, 0
End Sub
--------------------------------------------模块代码-------------------------------------------------

Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Public Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Public Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Public Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Public Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Public Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long

Public Const WM_ERASEBKGND = &H14
Public Const EN_VSCROLL = &H602
Public Const WM_COMMAND = &H111
Public Const EN_HSCROLL = &H601
Public Const EN_CHANGE = &H300
Public Const EN_UPDATE = &H400
Public Const EM_GETSEL = &HB0
Public Const SRCCOPY = &HCC0020 ' (DWORD) dest = source
Public Const SRCAND = &H8800C6 ' (DWORD) dest = source AND dest
Public Const SRCPAINT = &HEE0086 ' (DWORD) dest = source OR dest
Public Const SRCERASE = &H440328 ' (DWORD) dest = source AND (NOT dest )
Public Const EM_SCROLL = &HB5
Public Const GWL_WNDPROC = (-4)
Public Const WM_PAINT = &HF

Public memDc As Long
Public MemBitmap As Long
Public OldWndProc As Long
Public Oldproc As Long
Public pic As Picture
Public Function winproc(ByVal hwnd As Long, ByVal msg As Long, ByVal wp As Long, ByVal lp As Long) As Long
With Form1.Text1
If msg = WM_PAINT Then
Debug.Print Token
Dim hdc As Long
winproc = CallWindowProc(Oldproc, Form1.Text1.hwnd, msg, wp, lp)

If wp = 1 Then .Visible = False: .Visible = True

hdc = GetDC(Form1.Text1.hwnd)
BitBlt hdc, 0, 0, Form1.Text1.Width, Form1.Text1.Height, memDc, 0, 0, SRCAND
ReleaseDC Form1.Text1.hwnd, hdc
Exit Function

End If
winproc = CallWindowProc(Oldproc, Form1.Text1.hwnd, msg, wp, lp)
End With
End Function

Public Function winproc1(ByVal hwnd As Long, ByVal msg As Long, ByVal wp As Long, ByVal lp As Long) As Long

If msg = WM_COMMAND Then
Select Case wp \ 65536
Case EN_VSCROLL '---->获得文本框纵向滚动消息
SendMessage Form1.Text1.hwnd, WM_PAINT, 1, 0
Case EN_HSCROLL '----->获得横向滚动消息
SendMessage Form1.Text1.hwnd, WM_PAINT, 1, 0
Case EN_UPDATE
SendMessage Form1.Text1.hwnd, WM_PAINT, 0, 0
End Select
End If
winproc1 = CallWindowProc(OldWndProc, hwnd, msg, wp, lp)
End Function
-------------------------------------------------------------------------------------------------------

这样就可以 在图片里加如图片的背景了。

本程序在 2000/XP 下调试通过。有一个缺点是闪动比较厉害,希望各位大虾指正。

时间: 2024-10-21 22:29:16

在 普通的文本框 里加入图片背景的相关文章

JavaScript实现文本框中默认显示背景图片在获得焦点后消失的方法

  本文实例讲述了JavaScript实现文本框中默认显示背景图片在获得焦点后消失的方法.分享给大家供大家参考.具体如下: html代码: ? 1 2 3 4 5 6 7 8 9 <form name="searchform" id="search-form"> <div> <b>Search</b> <input type="text" name="txtInput" t

求助:C#里对word文档进行文本替换无法替换文本框里的所有文本

问题描述 以下是我写的一个程序,目的是通过替换一个word模版内的文本框里的文本然后另存为一个新的文档,可是循环替换的时候,只有少部分替换成功,请高手指点一下这是什么回事.因为不能上传附件,我就直接把代码贴出来,界面很简单,一个form和一个按钮,另外,word模版文件要自己在电脑上建一个就行,我使用的2003的格式.也可以留下邮箱我直接发一个压缩包给你们.就剩这几分了.需要引用Microsoft.Office.Interop.WordusingSystem;usingSystem.Collec

VB文本框里正在输入数据怎么转换到程序标题列里?

问题描述 VB文本框里正在输入数据怎么转换到程序标题列里? VB文本框里正在输入数据怎么转换到程序标题列里?表里列提示正在输入的窗口名,怎么获得窗口名? 解决方案 文本框的change事件中,调用me.caption = ""正在输入...""

显示-Android怎么设置文本框里的文字区间?

问题描述 Android怎么设置文本框里的文字区间? 如图,想让文字只显示在红色框以内,应该怎么设置. 解决方案 设置android:paddingleft和android:paddingRight 解决方案二: padding或margin 解决方案三: 在编辑框的布局文件上设置margin:left属性20dp左右 解决方案四: android:paddingLeft=""15dp""; ? 解决方案五: 在布局里可以设置padding或margin用法和div

请问如何在文本框里获取一个http地址

问题描述 请问如何在文本框里获取一个http地址 问题:有一个添加页面,每次点击添加页面时,页面中有一个文本框时要自动获取一个网站地址显示到文本框中(不是当前页面url).该怎么做呀是不是要用js解析那个URL呀,具体怎么做呀"http://dd.myapp.com/16891/148FD03E4F11362D6A5688E6022045D8.apk"就是这样的.放在input中每次打开时input中都是最新的那个url不是固定的一个 解决方案 你要获取什么地址?是短地址还是什么?你可

mscomm-MFC 程序,传感器里的数据无法读取到文本框里

问题描述 MFC 程序,传感器里的数据无法读取到文本框里 写了一个MFC程序,想把传感器的数据通过MSComm 读取出来.现在的问题是程序不出错,但是数据显示不出来.代码如下: void CEmapDlg::OnCommMscomm1() { // TODO: 在此处添加消息处理程序代码 //printf("system is running here"); static unsigned int cnt = 0; VARIANT variant_inp; COleSafeArray

怎么发送文本框里的文字到手机上的微信软件账号?

问题描述 怎么发送文本框里的文字到手机上的微信软件账号? 请问怎么利用文本框和按钮,向朋友圈的手机微信软件发消息?怎么发送文本框里的文字到手机上的微信软件账号?

vb 串口发送16进制-Vb将文本框里输入的十进制数据按chr(13)分割,然后转换成&amp;amp;amp;h+16进制字符串形式

问题描述 Vb将文本框里输入的十进制数据按chr(13)分割,然后转换成&h+16进制字符串形式 例如文本框里输入253chr(13)255chr(13),要求输出结果书"&HFD" "&HFF",看了好多算法,但是还是没有研究出来. 我自己做的结果如下 Private Sub Text2_KeyPress(KeyAscii As Integer) Dim tmp() As String Dim aa As String * 1 Dim rd

文本框 代码创建布局-发送文本框里输入的内容

问题描述 发送文本框里输入的内容 我想点击按钮时发送文本框里的内容,将文本框里的内容显示到自己用代码写的布局里,以下是我写的代码: Time t=new Time(); t.setToNow(); int year=t.year; int month=t.month+1; int day=t.monthDay; int hour=t.hour; int minute=t.minute; tt=year+"-"+month+"-"+day+" "+