📄 9937.txt
字号:
// Set value
if( RegSetValueEx(hKey,
SERVICE_NAME,
0,
REG_SZ,
(CONST BYTE *)lpszName,
dwStrCb ) != ERROR_SUCCESS )
{
//DebugOut("RegSetValueEx() error!");
RegCloseKey( hKey );
return FALSE;
}
RegCloseKey( hKey );
return TRUE;
}
// Unknow type
RegCloseKey( hKey );
return FALSE;
}
---- 主 程 序:
// WinMain function is the entry of the this program
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
if( W95ServiceRegister( RSP_SIMPLE_SERVICE ) )
{
W95StartService( RSP_SIMPLE_SERVICE );
}
MessageBox(NULL, "Sample service", "SERVICE", MB_OK );
UNREFERENCED_PARAMETER( hInstance );
UNREFERENCED_PARAMETER( lpCmdLine );
UNREFERENCED_PARAMETER( nCmdShow );
UNREFERENCED_PARAMETER( hPrevInstance );
return 0;
}
---- 运 行 这 个 程 序, 等 到MessageBox 弹 出 后, 从WINDOWS 中 退
出 到LOG ON 状 态, 你 会 看 见MessageBox 一 直 保 持 打 开 状 态
直 至 受 到 响 应 或 系 统 关 机. 所 以 要 做WINDOWS95 下 系 统 级
的 后 台 进 程, 并 不 一 定 非 要 去 编 写 容 易 引 起 系 统 混 乱
的VXD 程 序, 在 硬 件 部 分 允 许 的 情 况 下, 我 认 为 本 文 介
绍 的 方 法 更 加 方 便 有 效.
****************************************************************
在VB中建立可旋转的文本特效
长沙 陈锐
在VB中利用Windows的API函数可以实现很多的VB无法实现的扩展功能,
下面的程序介绍的是如何通过调用Windows中的API函数实现文本旋转显示
的特级效果。
首先建立一个工程文件,然后选菜单中的Project | Add Class Module
加入一个新的类文件,并将这个类的Name属性改变为APIFont,然后在类
的代码窗口中加入以下的代码:
Option Explicit
Private Declare Function SelectClipRgn Lib “gdi32”(ByVal hdc
As Long, ByVal hRgn As Long) As Long
Private Declare Function CreateRectRgn Lib “gdi32”(ByVal X1
As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function SetTextColor Lib “gdi32”(ByVal hdc
As Long, ByVal crColor As Long) As Long
Private Declare Function DeleteObject Lib “gdi32”(ByVal hObject
As Long) As Long
Private Declare Function CreateFontIndirect Lib “gdi32” Alias
“CreateFontIndirectA” (lpLogFont As LOGFONT) As Long
Private Declare Function SelectObject Lib “gdi32”(ByVal hdc
As Long, ByVal hObject As Long) As Long
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 SetTextAlign Lib “gdi32”(ByVal hdc As
Long, ByVal wFlags As Long) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Const TA_LEFT = 0
Private Const TA_RIGHT = 2
Private Const TA_CENTER = 6
Private Const TA_TOP = 0
Private Const TA_BOTTOM = 8
Private Const TA_BASELINE = 24
Private Type LOGFONT
lfHeight As Long
lfWidth As Long
lfEscapement As Long
lfOrientation As Long
lfWeight As Long
lfItalic As Byte
lfUnderline As Byte
lfStrikeOut As Byte
lfCharSet As Byte
lfOutPrecision As Byte
lfClipPrecision As Byte
lfQuality As Byte
lfPitchAndFamily As Byte
lfFaceName As String * 50
End Type
Private m_LF As LOGFONT
Private NewFont As Long
Private OrgFont As Long
Public Sub CharPlace(o As Object, txt$, X, Y)
Dim Throw As Long
Dim hregion As Long
Dim R As RECT
R.Left = X
R.Right = X + o.TextWidth(txt$) * 2
R.Top = Y
R.Bottom = Y + o.TextHeight(txt$) * 2
hregion = CreateRectRgn(R.Left, R.Top, R.Right, R.Bottom)
Throw = SelectClipRgn(o.hdc, hregion)
Throw = TextOut(o.hdc, X, Y, txt$, Len(txt$))
DeleteObject (hregion)
End Sub
Public Sub SetAlign(o As Object, Top, BaseLine, Bottom, Left, Center, Right)
Dim Vert As Long
Dim Horz As Long
If Top = True Then Vert = TA_TOP
If BaseLine = True Then Vert = TA_BASELINE
If Bottom = True Then Vert = TA_BOTTOM
If Left = True Then Horz = TA_LEFT
If Center = True Then Horz = TA_CENTER
If Right = True Then Horz = TA_RIGHT
SetTextAlign o.hdc, Vert Or Horz
End Sub
Public Sub setcolor(o As Object, CValue As Long)
Dim Throw As Long
Throw = SetTextColor(o.hdc, CValue)
End Sub
Public Sub SelectOrg(o As Object)
Dim Throw As Long
NewFont = SelectObject(o.hdc, OrgFont)
Throw = DeleteObject(NewFont)
End Sub
Public Sub SelectFont(o As Object)
NewFont = CreateFontIndirect(m_LF)
OrgFont = SelectObject(o.hdc, NewFont)
End Sub
Public Sub FontOut(text$, o As Control, XX, YY)
Dim Throw As Long
Throw = TextOut(o.hdc, XX, YY, text$, Len(text$))
End Sub
Public Property Get Width() As Long
Width = m_LF.lfWidth
End Property
Public Property Let Width(ByVal W As Long)
m_LF.lfWidth = W
End Property
Public Property Get Height() As Long
Height = m_LF.lfHeight
End Property
Public Property Let Height(ByVal vNewValue As Long)
m_LF.lfHeight = vNewValue
End Property
Public Property Get Escapement() As Long
Escapement = m_LF.lfEscapement
End Property
Public Property Let Escapement(ByVal vNewValue As Long)
m_LF.lfEscapement = vNewValue
End Property
Public Property Get Weight() As Long
Weight = m_LF.lfWeight
End Property
Public Property Let Weight(ByVal vNewValue As Long)
m_LF.lfWeight = vNewValue
End Property
Public Property Get Italic() As Byte
Italic = m_LF.lfItalic
End Property
Public Property Let Italic(ByVal vNewValue As Byte)
m_LF.lfItalic = vNewValue
End Property
Public Property Get UnderLine() As Byte
UnderLine = m_LF.lfUnderline
End Property
Public Property Let UnderLine(ByVal vNewValue As Byte)
m_LF.lfUnderline = vNewValue
End Property
Public Property Get StrikeOut() As Byte
StrikeOut = m_LF.lfStrikeOut
End Property
Public Property Let StrikeOut(ByVal vNewValue As Byte)
m_LF.lfStrikeOut = vNewValue
End Property
Public Property Get FaceName() As String
FaceName = m_LF.lfFaceName
End Property
Public Property Let FaceName(ByVal vNewValue As String)
m_LF.lfFaceName = vNewValue
End Property
Private Sub Class_Initialize()
m_LF.lfHeight = 30
m_LF.lfWidth = 10
m_LF.lfEscapement = 0
m_LF.lfWeight = 400
m_LF.lfItalic = 0
m_LF.lfUnderline = 0
m_LF.lfStrikeOut = 0
m_LF.lfOutPrecision = 0
m_LF.lfClipPrecision = 0
m_LF.lfQuality = 0
m_LF.lfPitchAndFamily = 0
m_LF.lfCharSet = 0
m_LF.lfFaceName = "Arial" + Chr(0)
End Sub
在工程文件的Form1中加入一个PictureBox和一个CommandButton控
件,然后在Form1的代码窗口中加入以下的代码:
Option Explicit
Dim AF As APIFont
Dim X, Y As Integer
Private Sub Command1_Click()
Dim i As Integer
Set AF = Nothing
Set AF = New APIFont
Picture2.Cls
For i = 0 To 3600 Step 360
AF.Escapement = i
AF.SelectFont Picture2
X = Picture2.ScaleWidth / 2
Y = Picture2.ScaleHeight / 2
'在字符串后面要加入7个空格
AF.FontOut “电脑商情报第42期 ”, Picture2, X, Y
AF.SelectOrg Picture2
Next i
End Sub
Private Sub Form_Load()
Picture2.ScaleMode = 3
End Sub
运行程序,点击Form上的Command1按钮,在窗口的图片框就会出现旋
转的文本显示,程序的效果如图所示:
值得注意的问题是,由于Windows的动态连接库的中英文版本的关系,
在一些系统中显示中文可能会有一些问题,大家可能看到,上面程序中的
语句:AF.FontOut “脑商情报第42期”,Picture2, X, Y中的字符串后面
有7个空格,这是对于“电脑商情报第42期”中的7个中文字符,中文系统
计算的是7个字符,但是实际它们占据的是14个字节的空间,所以在输出时
要在后面添加7个空格做“替身”。上面的程序在中文Win98,VB6下运行通过。
****************************************************************
在VB中动态建立控件
重庆 林林
在Delphi等编程语言中可以仅用一个很简单的语句在程序的运行过
程中动态地建立控件,其实这在VB中也可以做到,只是稍微复杂,下面
就介绍一下如何在Vb中动态地建立控件,首先请看以下程序
Option Explicit
Private WithEvents NewButton As CommandButton
Private Sub Form_Load()
Command1.Caption = “建立按钮”
End Sub
Private Sub Command1_Click()
If NewButton Is Nothing Then
‘建立Command控件,并设置它的各种属性
Set NewButton = Controls.Add(“VB.CommandButton”,“cmdNew”, Me)
NewButton.Move Command1.Left + Command1.Width + 240, Command1.Top
NewButton.Caption =“新按钮”
NewButton.Visible = True
End If
End Sub
在这个示例程序里,在窗体中有一个按钮Command1,当你点击此按
钮时,程序会自动建立另一名为“新按钮”的按钮,程序首先将NewButton
定义为CommandButton类型,然后再建立按钮控件,其中有一句
Set NewButton = Controls.Add(“VB.CommandButton”,“cmdNew”, Me)。
其具体用法如下:
object.Add(index, key, caption, style, image)
Add 方法的语法包含下面部分:
object 必需的。对象表达式,其值是 Buttons 集合。
index 可选的。整数,它指定要插入Button对象的位置。如果没有指
定任何index,则将Button对象添加到Buttons集合的末尾。
key 可选的。唯一标识 Button 对象的字符串。用这个值检索特定的
Button 对象。
caption 可选的。将出现在 Button 对象之下的字符串。
style 可选的。Button 对象的样式。在 Style 属性(Button 对象)
中详细描述了可用的样式。
image 可选的。整数或唯一关键字,在某个相关联的 ImageList 控件
内,它指定一个ListImage 对象。
****************************************************************
VFP下汉字输入法的编程
东方烟草集团有限公司 王俊峰
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -