资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

关于vb.net屏保的信息

vb制作的屏保系统,由多张图片循环播放,如何在图片播放时加上一定的特效,比如百叶窗等等,就像PPT制作的

'这个拿去试一试,两个时钟,两个图片框,自己设定图片框2的大小,比如让它和窗体一样大

在阳朔等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供成都网站建设、网站制作 网站设计制作按需策划,公司网站建设,企业网站建设,成都品牌网站建设,全网整合营销推广,外贸营销网站建设,阳朔网站建设费用合理。

'查一查PaintPicture的用法,就明白了

'去掉Picture2

Dim Pic_num As Long

Dim Pic_name() As String

Dim pic_star As Long

Dim p_width As Single

Dim p_height As Single

Dim bili_w As Single

Dim bili_h As Single

Dim v_mod As Long

Private Sub Form_Load()

Dim L_name As String

Pic_num = 0

ReDim Pic_name(Pic_num)

L_name = Dir(App.Path "\pic\*.JPG")

Do While L_name ""

ReDim Preserve Pic_name(Pic_num)

Pic_name(Pic_num) = L_name

Pic_num = Pic_num + 1

L_name = Dir

Loop

L_name = Dir(App.Path "\pic\*.BMP")

Do While L_name ""

ReDim Preserve Pic_name(Pic_num)

Pic_name(Pic_num) = L_name

Pic_num = Pic_num + 1

L_name = Dir

Loop

Picture1.AutoSize = True

Picture1.AutoRedraw = True

Picture1.Visible = False

' Me.AutoSize = False

Me.AutoRedraw = True

Me.Visible = True

Timer1.Interval = 10

Timer1.Enabled = False

Timer2.Interval = 50

Timer2.Enabled = False

If Pic_num 0 Then

Picture1.Picture = LoadPicture(App.Path "\pic\" Pic_name(0))

Me.PaintPicture Picture1.Picture, 0, 0, Me.ScaleWidth, Me.ScaleHeight, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight

Timer1.Enabled = True

Timer1.Interval = 2000

Else

MsgBox ("没有图片显示!")

End If

End Sub

Private Sub Form_Resize()

Me.Width = Me.Width

Me.Height = Me.Width

Me.Top = 0

Me.Left = 0

End Sub

Private Sub Timer1_Timer()

Dim L_id As Long

Randomize

L_id = Int((Pic_num) * Rnd)

Picture1.Picture = LoadPicture(App.Path "\pic\" Pic_name(L_id))

bili_w = Picture1.ScaleWidth / Me.ScaleWidth

bili_h = Picture1.ScaleHeight / Me.ScaleHeight

p_width = Me.Width / 100

p_height = Me.Height / 100

pic_star = 0

Randomize

v_mod = Int(10 * Rnd)

'v_mod = 9'取消单引号并修改常数数可看单一效果

Timer1.Enabled = False

Timer2.Enabled = True

End Sub

Private Sub Timer2_Timer()

If pic_star 101 Then

pic_star = pic_star + 1

Select Case v_mod

Case 0

Me.PaintPicture Picture1.Picture, 0, 0, Me.Width, pic_star * p_height, 0, 0, Picture1.Width, bili_h * pic_star * p_height '从上向下

Case 1

Me.PaintPicture Picture1.Picture, 0, 0, pic_star * p_width, Me.Height, 0, 0, bili_w * pic_star * p_width, Picture1.Height '从左向右

Case 2

Me.PaintPicture Picture1.Picture, 0, 0, Me.Width, pic_star * p_height, 0, 0, Picture1.Width, Picture1.Height '压缩的从上向下

Case 3

Me.PaintPicture Picture1.Picture, 0, 0, pic_star * p_width, Me.Height, 0, 0, Picture1.Width, Picture1.Height '压缩的从左向右

Case 4

Me.PaintPicture Picture1.Picture, 0, 0, pic_star * p_width, pic_star * p_height, 0, 0, Picture1.Width, Picture1.Height '压缩的从左上向右下

Case 5

Me.PaintPicture Picture1.Picture, Me.Width - pic_star * p_width, Me.Height - pic_star * p_height, pic_star * p_width, pic_star * p_height, 0, 0, Picture1.Width, Picture1.Height '压缩的从右下向左上

Case 6

Me.PaintPicture Picture1.Picture, Me.Width / 2 - pic_star * p_width / 2, 0, pic_star * p_width / 2, Me.Height, 0, 0, Picture1.Width / 2, Picture1.Height '压缩的从中向左

Me.PaintPicture Picture1.Picture, Me.Width / 2, 0, pic_star * p_width, Me.Height, Picture1.Width / 2, 0, Picture1.Width, Picture1.Height '压缩的从中向右

Case 7

Me.PaintPicture Picture1.Picture, 0, Me.Height / 2 - pic_star * p_height / 2, Me.Width, pic_star * p_height / 2, 0, 0, Picture1.Width, Picture1.Height / 2 '压缩的从中向上

Me.PaintPicture Picture1.Picture, 0, Me.Height / 2, Me.Width, pic_star * p_height, 0, Picture1.Height / 2, Picture1.Width, Picture1.Height '压缩的从中向下

Case 8

Me.PaintPicture Picture1.Picture, Me.Width / 2 - pic_star * p_width / 2, Me.Height / 2 - pic_star * p_height / 2, pic_star * p_width / 2, pic_star * p_height / 2, 0, 0, Picture1.Width / 2, Picture1.Height / 2 '压缩的从中向左上

Me.PaintPicture Picture1.Picture, Me.Width / 2, Me.Height / 2, pic_star * p_width, pic_star * p_height, Picture1.Width / 2, Picture1.Height / 2, Picture1.Width, Picture1.Height '压缩的从中向右下

Me.PaintPicture Picture1.Picture, Me.Width / 2, Me.Height / 2 - pic_star * p_height / 2, pic_star * p_width / 2, pic_star * p_height / 2, Picture1.Width / 2, 0, Picture1.Width / 2, Picture1.Height / 2 '压缩的从中向右上

Me.PaintPicture Picture1.Picture, Me.Width / 2 - pic_star * p_width / 2, Me.Height / 2, pic_star * p_width / 2, pic_star * p_height / 2, 0, Picture1.Height / 2, Picture1.Width / 2, Picture1.Height / 2 '压缩的从中向左下

Case 9

For k = 0 To 9

Me.PaintPicture Picture1.Picture, 0, k * Me.Height / 10, Me.Width, 5 * pic_star * p_height / 10, 0, k * (Picture1.Height / 10), Picture1.Width, (Picture1.Height / 10) '水平百叶窗

Next

If pic_star = 21 Then

pic_star = 101

End If

End Select

Else

pic_star = 0

Timer1.Enabled = True

Me.PaintPicture Picture1.Picture, 0, 0, Me.ScaleWidth, Me.ScaleHeight, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight

Timer2.Enabled = False

End If

End Sub

'这回做了9个,应该明白了吧,其实你第一回的5分也应该给选我,估计是你没明白用法

用VB制做可换图片的屏幕保护程序

VC++可谓神通广大,如果学到家了,或者就掌握了那么一点MFC,你也会感到它的方便快捷,当然最重要的是功能强大。不是吗,从最基本的应用程序.EXE到动态连接库DLL,再由风靡网上的ActiveX控件到Internet Server API,当然,还有数据库应用程序……瞧,我都用它来做屏幕保护程序了。一般的屏幕保护程序都是以SCR作为扩展名,并且要放在c:\windows 目录或 c:\windows\system 目录下,由Windows 98内部程序调用(Windows NT 是在 c:\windows\system32 目录下)。怎么调用?不用说了,这谁不知道。

好了,我们来作一个简单的。选择MFC AppWizard(exe),Project Name 为MyScreensaver,[NEXT],对话框,再后面随你了。打开菜单Project、Settings,在Debug页、Executable for debug session项,以及Link页中Output file name项改为c:\windows\MyScreensaver.scr,这样,你可以调试完后,直接在VC中运行(Ctrl+F5),便可看到结果。当然,这样做的唯一缺点是你必须手动清除Windows 目录下的垃圾文件(当然是在看到满意结果后;还有,你可借助SafeClean 这个小东东来帮你清除,除非你的硬盘大的让你感到无所谓……快快快回来,看我跑到那里去了)。接下来用Class Wizard生成CMyWnd类,其基类为CWnd(在Base Class 中为generic CWnd)。这个类是我们所要重点研究的。创建满屏窗口、计时器,隐藏鼠标,展示图片,响应键盘、鼠标等等,这家伙全包了。至于MyScreensaverDlg.h与MyScreensaverDlg.cpp文件我们暂时不管。打开MyScreensaver.cpp,修改InitInstance()函数:

BOOL CMyScreensaverApp::InitInstance()

{

AfxEnableControlContainer();

#ifdef _AFXDLL

Enable3dControls(); // Call this when using MFC in a shared DLL

#else

Enable3dControlsStatic(); // Call this when linking to MFC statically

#endif

CMyWnd* pWnd = new CMyWnd;

pWnd-Create();

m_pMainWnd = pWnd;

return TRUE;

}

当然,再这之前得先 #include “MyWnd.h" 。后面要做的都在MyWnd.h 与 MyWnd.cpp 两文件中了。

下面给出CMyWnd 的说明:

class CMyWnd : public CWnd

{

public:

CMyWnd();

static LPCSTR lpszClassName; //注册类名

public:

BOOL Create();

public:

// ClassWizard generated virtual function overrides

//{{AFX_VIRTUAL(CMyWnd)

protected:

virtual void PostNcDestroy();

//}}AFX_VIRTUAL

public:

virtual ~CMyWnd();

protected:

CPoint m_prePoint; //检测鼠标移动

void DrawBitmap(CDC& dc, int nIndexBit);

//{{AFX_MSG(CMyWnd)

afx_msg void OnPaint();

afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);

afx_msg void OnLButtonDown(UINT nFlags, CPoint point);

afx_msg void OnMButtonDown(UINT nFlags, CPoint point);

afx_msg void OnMouseMove(UINT nFlags, CPoint point);

afx_msg void OnRButtonDown(UINT nFlags, CPoint point);

afx_msg void OnSysKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);

afx_msg void OnDestroy();

afx_msg void OnTimer(UINT nIDEvent);

afx_msg void OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized);

afx_msg void OnActivateApp(BOOL bActive, HTASK hTask);

//}}AFX_MSG

DECLARE_MESSAGE_MAP()

};

MyWnd.cpp 文件:

……

CMyWnd::CMyWnd()

{

m_prePoint=CPoint(-1, -1);

}

LPCSTR CMyWnd::lpszClassName=NULL;

BOOL CMyWnd::Create()

{

if(lpszClassName==NULL)

{

lpszClassName=AfxRegisterWndClass(CS_HREDRAW CS_VREDRAW,

::LoadCursor(AfxGetResourceHandle(),MAKEINTRESOURCE(IDC_NOCURSOR)));

//注册类;IDC_NOCURSOR为新建光标的ID,这个光标没有任何图案

}

CRect rect(0, 0, ::GetSystemMetrics(SM_CXSCREEN),

::GetSystemMetrics(SM_CYSCREEN));

CreateEx(WS_EX_TOPMOST, lpszClassName, _T(“”), WS_VISIBLE WS_POPUP,

rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,

GetSafeHwnd(), NULL, NULL); //创建一个全屏窗口

SetTimer(ID_TIMER, 500, NULL);//计时器,ID_TIMER别忘了定义

return TRUE;

}

为了防止同时运行两个相同的程序,下面两个函数是必需的:

void CMyWnd::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)

{

CWnd::OnActivate(nState,pWndOther,bMinimized);

if (nState==WA_INACTIVE)

PostMessage(WM_CLOSE);

}

void CMyWnd::OnActivateApp(BOOL bActive, HTASK hTask)

{

CWnd::OnActivateApp(bActive, hTask);

if (!bActive) //is being deactivated

PostMessage(WM_CLOSE);

}

OnPaint()函数将全屏窗口置为黑色:

void CMyWnd::OnPaint()

{

CPaintDC dc(this);

CBrush brush(RGB(0,0,0));

CRect rect;

GetClientRect(rect);

dc.FillRect(&rect, &brush);

}

由计数器调用DrawBitmap()函数,切换图片;注意,下面两个函数中的IDB_BITMAP1, dc.BitBlt(0,0,800,600……以及if(nIndexBit=5)中的有关数据依据你的bmp图片个数、尺寸、位置不同而不同,我是选择了5张800x600的bmp图片。注意,ID值是连续的,IDB_BITMAP1最小。

void CMyWnd::DrawBitmap(CDC &dc, int nIndexBit)

{

CDC dcmem;

dcmem.CreateCompatibleDC(&dc);

CBitmap m_Bitmap;

m_Bitmap.LoadBitmap(IDB_BITMAP1+nIndexBit);

dcmem.SelectObject(m_Bitmap);

dc.BitBlt(0,0,800,600,&dcmem,0,0,SRCCOPY);

}

void CMyWnd::OnTimer(UINT nIDEvent)

{

CClientDC dc(this);

static nIndexBit=0;

if(nIndexBit=5)

nIndexBit=0;

DrawBitmap(dc, nIndexBit++);

CWnd::OnTimer(nIDEvent);

}

响应键盘、鼠标是屏幕保护程序不可缺少的,在OnKeyDown()、 OnLButtonDown()、 OnMButtonDown()、OnRButtonDown()、OnSysKeyDown()函数中都加入:

PostMessage(WM_CLOSE);

OnMouseMove()函数比较特殊,它应加的代码为:

if(m_prePoint == CPoint(-1,-1))

m_prePoint = point;

else if(m_prePoint!=point)

PostMessage(WM_CLOSE);

快要完工了。在OnDestroy()函数中删掉计时器:KillTimer(ID_TIMER);

还有啦,在CMyWnd::PostNcDestroy() 中加入: delete this;

哎呀,腰酸背疼,眼球发涩,手背奇麻(不会吧)!不过,相信你一定会迫不及待地按下Ctrl+F5, 看着一幅幅图片在你面前轮番展示,啊,自己的屏幕保护程序!赶快赶快,换上自制的屏保,感觉就是不一样:图片任你挑,时间间隔任你改,鼠标?键盘?我想响应谁就响应谁……哎呀,谁扔的纸团:(。

其实,上面的程序还有很多可以改进的地方,比如图片总是单一地显示;bmp 文件太大,导致生成的屏幕保护程序也很大,远没有jpg合算;没有密码,没有可直接控制的界面。由于InitInstance()函数的简单处理(直接调用CMyWnd类),你会发现当你在桌面上右击,选择“属性”、“屏幕保护程序”页、“屏幕保护程序”下拉菜单、选中MyScreensaver时,MyScreensaver就直接预览了(或是直接运行了);假设你确定MyScreensaver作为你的屏幕保护程序,等你第二次进入“屏幕保护程序”页时,就直接预览。Why? 回头看看InitInstance()函数就明白了。为了让它更听话地工作,可修改InitInstance()函数:

LPTSTR lpszArgv = __argv[1];

if (lpszArgv[0] ==‘/’)

lpszArgv++;

if (lstrcmpi(lpszArgv, _T(“s”))==0)

{

CMyWnd* pWnd=new CMyWnd;

pWnd-Create();

m_pMainWnd=pWnd;

return TRUE;

}

return FALSE;

不过现在你要是再在VC中运行这个程序,“该程序执行了非法操作,即将关闭。将会伴随着一超重低音供你欣赏。(啊?)原因是我们加了一句return FALSE; 还有,别忘了还有一个CMyScreensaverDlg类没有用上,用它来与你的屏保直接对话再好不过了。例如,为了方便地确定时间间隔,选取图片,加上一个编辑框和几个按钮就可以了。重申一点,由于生成文件较大,占用的内存也多,如果不能运行,很可能是开的窗口太多了。这时你可以换较小的图片。

关于VB屏幕保护问题--求助

熟悉Windows操作系统的朋友一定对Windows的屏幕保护程序不陌生吧。如何自己编写Windows屏幕保护程序呢?当你看完下面的讲解后便可以轻易地编写一标准的Windows屏幕保护程序了!

一个标准的屏保有以下几个特点:

一:它是以.SCR作为文件的扩展名!

二:它有三种运行方式。

(1)运行在预览框中(用于预览屏保的效果。在“显示属性”→“屏幕保护程序”→“小屏幕”)。(见图)

(2)运行设置程序(用于设置一些相关的样式。在“显示属性”→“屏幕保护程序”→“点击设置按钮”)。

(3)真正的运行屏保(屏保运行时的效果。在“显示属性”→“屏幕保护程序”→“点击预览”或鼠标、键盘在指定的时间内无动作时)。

如何让屏保识别当前需要运行哪一种方式呢?答案很简单——分析Windows调用屏保的参数。下面以Windows 98为例向大家分析一下调用屏保的参数。

当Windows需要屏保显示在“小屏幕”中时会在调用屏保的后面加上两个参数。

如:myscr.scr /p 7981(参数一:/p 表示让程序显示在“小屏幕”里,参数二:7981表示“小屏幕”的句柄hWnd。这样屏保就会得知Windows要它显示在“小屏幕”中。)

当Windows需要屏保显示设置对话框时会在调用屏保的后面不加或加上两个参数。

如:myscr.scr或myscr.scr /C 7987(参数一:/C表示让程序显示设置对话框,参数二:7987表示该属性页的句柄。)

当Windows需要运行屏保时会在调用屏保的后面加上一个参数。

如:myscr.scr /S(参数:/S表示让屏保运行。)

好了,知道了Windows如何让屏保运行的三种方式后,接下来就要讨论如何实现它们了。

实现原理:Windows通过某种方式调用屏保,屏保知道了它此时要干什么便会在当前环境中搜索是否有相同的实例存在。如果该实例的运行方式与此次要启动的运行方式不同则关闭前个实例,如果该实例的运行方式与此次要启动的运行方式相同则关闭此次运行的实例。

显然要实现这种方法靠VB的App.PrevInstance是不可行的。因为我们要达到的目的是:侦测到前一个实例后要关闭它然后启动程序。而App.PrevInstance属性只能返回当前是否已启动一个应用程序的实例而不能对前个实例做些什么。(实例 简单地说就是相同的对象集合——同一程序。)在实现此方法之前首先向大家介绍三条API函数:GetClassName、FindWindow和SendMessage。其原型如下:

Declare Function GetClassName Lib “user32” Alias “GetClassNameA” (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long

Declare Function FindWindow Lib “user32” Alias “FindWindowA” (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Declare Function SendMessage Lib “user32” Alias “SendMessageA” (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

GetClassName用于取得窗体的类名。调用成功后返回类名长度,失败返回零。函数需要三个参数:参数一.窗体的句柄,参数二.存放类名的缓冲,参数三.缓冲的大小。

FindWindow用于寻找窗体。调用成功后返回窗体的句柄,失败返回零。函数需要两个参数:参数一.窗体的类名,参数二.窗体的标题。

SendMessage用于向窗体发送一消息。函数需要四个参数:参数一.窗体的句柄,参数二:发送的消息名称,参数三、四.分别表示消息所附带的参数。

使用了这三个函数便可轻易地实现关闭前有一个已启动的实例从而达到我们的目的。

其次我们要实现如何让屏幕保护程序显示在预览框中(“小屏幕”)。

要让屏幕保护程序在预览框中显示必须动态地改变窗口的样式使之成为“小屏幕”的子窗体,这样才能使预览框关闭时得到关闭消息。动态地改变窗口的样式可以使用GetWindowLong、SetWindowLong和SetParent。

它们的原型如下:

Public Declare Function GetWindowLong Lib “user32” Alias “GetWindowLongA” (ByVal hwnd As Long, ByVal nIndex As Long) As Long Public Declare Function SetWindowLong Lib “user32” Alias “SetWindowLongA” (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Declare Function SetParent Lib “user32” (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long

GetWindowLong的作用用于得到窗体的样式。调用成功后返回窗体的样式。函数需要两个参数:参数一.窗体的句柄,参数二.要取得窗体的样式只需使用常数GWL_STYLE。

SetWindowLong的作用用于设置窗体的样式。函数需要三个参数:参数一.窗体的句柄,参数二.要设置窗体的样式只需用常数GWL_STYLE,参数三.要设置窗体的样式。

SetParent的作用用于设置子窗体属于哪个父窗体。函数需要两个参数:参数一.子窗体的句柄,参数二.父窗体的句柄。

知道了以上两点就可编写出标准的屏保。(关于效果就看你自己的了!)纸上谈兵了一阵就要落实到真正的编程上了。为了着重讲解屏保的实现方法故将屏保的效果简单化。

首先新建一工程再添加一窗口,各属性设置如下:

窗口 名称 Caption BorderStyle

Form1 Frm_Setup 无 1 - None

Form2 Frm_Run 任意 1 - Fixed Single

其余属性均缺省。再在Frm_Run中添加一Timer控件,将该控件的名称改为Timer_Mov,Interval属性制改为500。

添加两个模块,将Module1的名称改为Mod_Const,Module2的名称改为Mod_Main,添加以下代码:

Mod_Const:

Option Explicit

Public Const WM_LOOK=“屏保预览(demo)”

Public Const WM_SET=“屏保设置(demo)”

Public Const WM_RUN=“屏保运行(demo)”

Public Const HWND_TOP=0&

Public Const WS_CHILD=&H40000000

Public Const GWL_STYLE=(-16)

Type RECT

Left As Long

Top As Long

Right As Long

Bottom As Long

End Type

Public Const SWP_NOZORDER=&H4

Public Const SWP_NOACTIVATE=&H10

Public Const SWP_SHOWWINDOW=&H40

Public Const WM_CLOSE=&H10

Declare Function GetClientRect Lib “user32” (ByVal hwnd As Long, lpRect As RECT) As Long

Declare Function GetClassName Lib “user32” Alias “GetClassNameA” (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long

Declare Function FindWindow Lib “user32” Alias “FindWindowA” (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Declare Function SendMessage Lib “user32” Alias “SendMessageA” (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Declare Function SetParent Lib “user32” (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long

Public Declare Function GetWindowLong Lib “user32” Alias “GetWindowLongA” (ByVal hwnd As Long, ByVal nIndex As Long) As Long

Public Declare Function SetWindowLong Lib “user32” Alias “SetWindowLongA” (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Declare Function SetWindowPos Lib “user32” (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Declare Function ShowCursor Lib “user32” (ByVal bShow As Long) As Long

Mod_Main:

Option Explicit

Sub Main() '程序运行入口

Dim ClassName As String * 64 ’存放窗口的类名

Dim ExeCmd As String '存放命令行参数

GetClassName Frm_Setup.hwnd, ClassName, 64 ’取得窗口的类名

ExeCmd=UCase(Command$) ’将调用的屏保的参数转换成大写后存放在变量ExeCmd里

If Not (InStr(ExeCmd,“/P”)=0)Then ’检查屏保的调用参数中是否有“/P”参数

If Not (FindWindow(ClassName, WM_LOOK)=0)Then End ’如果找到已有同一个运行方式的实例存在则程序结束

ClosePreWindow ClassName, WM_SET ’关闭前面已启动的其他运行方式的实例

ClosePreWindow ClassName, WM_RUN ’同上

SCR_Look

ElseIf Not (InStr(ExeCmd,“/S”)=0)Then

If Not (FindWindow(ClassName,WM_RUN)=0) Then End

ClosePreWindow ClassName, WM_LOOK ’同上

ClosePreWindow ClassName, WM_SET ’同上

Scr_Run

Else

If Not (FindWindow(ClassName, WM_SET)=0) Then End

ClosePreWindow ClassName, WM_LOOK ’同上

ClosePreWindow ClassName, WM_RUN ’同上

Scr_Setup

End If

End Sub

Public Sub ClosePreWindow(ClassName As String, WinCaption As String)

Dim PreWnd As Long

PreWnd=FindWindow(ClassName, WinCaption) ’寻找类名为ClassName,标题为WinCaption的窗口

If Not (PreWnd = 0) Then Call SendMessage(PreWnd, WM_CLOSE, 0, 0) ’如果窗口已找到则关闭它

End Sub

Public Sub SCR_Look()

Dim LookScrWnd As Long

Dim Style As Long

Dim LookRect As RECT

Frm_Run.Caption=WM_LOOK ’赋上具有相应运行方式的标题

LookScrWnd=Val(Right(Command$, Len(Command$) - 2)) ’取得小屏幕的窗口句柄

Style=GetWindowLong(Frm_Run.hwnd, GWL_STYLE) ’取得窗口的样式

Style=Style Or WS_CHILD ’在窗口的样式中加入子窗体常数

SetWindowLong Frm_Run.hwnd, GWL_STYLE, Style ’改变窗体的样式

SetParent Frm_Run.hwnd, LookScrWnd ’设置窗体的父窗体

GetClientRect LookScrWnd, LookRect ’取得小屏幕的大小

SetWindowPos Frm_Run.hwnd, HWND_TOP, 0, 0, LookRect.Right, LookRect.Bottom, SWP_

NOZORDER Or SWP_NOACTIVATE Or SWP_SHOWWINDOW

'显示窗体并将窗体的大小设置为小屏幕的大小以便覆盖小屏幕

End Sub

Public Sub Scr_Setup()

Frm_Run.Caption=WM_SET ’赋上具有相应运行方式的标题

Frm_Setup.Show

End Sub

Public Sub Scr_Run()

Frm_Run.Caption = WM_RUN ’赋上具有相应运行方式的标题

ShowCursor False ’隐藏鼠标

Frm_Run.Move 0, 0, Screen.Width, Screen.Height

Frm_Run.Show

End Sub

Public Sub CloseSCR()

ShowCursor True ’显示鼠标

Unload Frm_Setup ’卸载窗体关闭屏保

Unload Frm_Run ’同上

End Sub

Public Function Scan_RUN() As Boolean’侦测当前屏保的运行方式

If (Frm_Run.Caption = WM_RUN) Then ’如果屏保是以运行方式在运行则返回“真”,否则返回“假”

Scan_RUN=True

Else

Scan_RUN=False

End If

End Function

Frm_Run:

Option Explicit

Dim i As Integer ’定义循环变量

Dim OldX As Integer ’定义存放旧的鼠标水平坐标

Dim OldY As Integer ’定义存放旧的鼠标垂直坐标

Dim Pic(1) As New StdPicture ’定义一个图片类的数组

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

If Mod_Main.Scan_RUN Then ’如果此时是在运行屏保则关闭屏保

Mod_Main.CloseSCR

End If

End Sub

Private Sub Form_Load()

i=1 ’为循环变量赋初值

OldX=-1 ’为旧鼠标水平坐标赋初值

OldY=-1 ’为旧鼠标垂直坐标赋初值

Set Pic(0)=LoadPicture(请写入图片一的路径和名称) ’读取图片一

Set Pic(1)=LoadPicture(请写入图片二的路径和名称) ’读取图片二

End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y A

s Single)

If Mod_Main.Scan_RUN Then ’如果此时是在运行屏保则关闭屏保

Mod_Main.CloseSCR

End If

End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

If Mod_Main.Scan_RUN Then

If (OldX=-1) And (OldY=-1) Then

OldX=X

OldY=Y

Else

If (ScaleX(Abs(X-OldX),vbTwips,vbPixels)= 3) Then

Mod_Main.CloseSCR ’将鼠标当前的水平坐标和垂直坐标与旧鼠标的水平坐标和垂直坐标相减其绝对值如果大于3个像素则退出屏保

End If

End If

End If

End Sub

Private Sub Form_Unload(Cancel As Integer)

Mod_Main.CloseSCR ’关闭屏保

End Sub

Private Sub Timer_Mov_Timer()

If (i=2) Then

i=1 ’如果循环变量大于图片的数量则变量赋为1

Else

i=i+1 ’否则循环变量加一

End If

Frm_Run.PaintPicture Pic(i-1),0,0,Width,Height,0,0,ScaleX(Pic(i-1).Width,vbHimetric,vbTwips),ScaleY(Pic(i-1).Height,vbHimetric,vbTwips)’在Frm_Run上画图

End Sub

Frm_Setup:

Option Explicit

Private Sub Com_OK_Click()

Mod_Main.CloseSCR

End Sub

Private Sub Form_Unload(Cancel As Integer)

Mod_Main.CloseSCR

End Sub

好了,一个标准的屏幕保护程序就编写好了。按下F5运行试试看。不要忘了生成EXE文件时一定要将屏保的扩展名改为SCR并将其拷贝到Windows的System目录里才可在屏保设置中见到喔!(程序在VB 5.0中编写并运行通过。)

求VB.net程序源代码 绘图板、二十一点游戏、计算器、井字棋游戏、屏幕保护程序等

说明:1.共有4个文本框其,其中三个是填入或输出数据的(名称分别是:txta txtb txtc),剩下的那个是符号(txtd)2.共7个按钮,4个是符号按钮,一个计算,一个清零.这是我弄的程序”袖珍计算器”代码也是自己编写的,代码如下:通用声明Dim j As Integer '定义j为整型

Private Sub Text1_Change()End SubPrivate Sub Command1_Click()

txtfuhao.Text = "+" '将”+”显示到文本框txtfuhao.Text中

End SubPrivate Sub Command2_Click()

txtfuhao.Text = "-" ''将”-”显示到文本框txtfuhao.Text中

End SubPrivate Sub Command3_Click()

txtfuhao.Text = "×" '将”×”显示到文本框txtfuhao.Text中

End SubPrivate Sub Command4_Click()

txtfuhao.Text = "÷" 将”÷”'显示到文本框txtfuhao.Text中

End Sub

Private Sub Command5_Click()

Dim a, b, c As Integer

a = Val(txta.Text) '将txta.Text里的内容转化为数值型,然后再赋给a

b = Val(txtb.Text) '将txtb.Text里的内容转化为数值型,然后再赋给b

If txtfuhao.Text = "+" Then '运算过程

c = a + b '运算过程

ElseIf txtfuhao.Text = "-" Then '运算过程

c = a - b '运算过程

ElseIf txtfuhao.Text = "÷" Then '运算过程

c = a / b '运算过程

ElseIf txtfuhao.Text = "×" Then '运算过程

c = a * b '运算过程

Else

j = MsgBox("您输入的符号不正确", vbOKOnly, "错误信息")

End If

txtc.Text = c '将运算结果c输出到文本框txtc中

End SubPrivate Sub Command6_Click()

txta.Text = "" '将空字符输入到文本框内(刷新)

txtb.Text = "" '将空字符输入到文本框内(刷新)

txtc.Text = "" '将空字符输入到文本框内(刷新)

txtfuhao.Text = "" '将空字符输入到文本框内(刷新)

End SubPrivate Sub Command7_Click()

End '结束程序

End SubPrivate Sub Form_Load()End Sub

vb.net 屏幕保护程序

系统就有这个屏保啊!~!

Option EXPlicit

Dim quitflag As Boolean '声明终止程序标志变量

Dim lleft

'声明隐藏或显示鼠标的API函数

Private Declare Function ShowCursor Lib "user32"

(ByVal bShow As Long) As Long

'检测鼠标单击或移动

Private Sub Form_Click()

quitflag = True

End Sub

Private Sub Form_MouseMove(Button As Integer,Shift As Integer, X As Single, Y As Single)

Static xlast, ylast

Dim xnow As Single

Dim ynow As Single

xnow = X

ynow = Y

If xlast = 0 And ylast = 0 Then

xlast = xnow

ylast = ynow

Exit Sub

End If

If xnow xlast Or ynow ylast Then

quitflag = True

End If

End Sub

'检测按键

Private Sub Form_KeyDown(KeyCode As Integer,Shift As Integer)

quitflag = True

End Sub

Private Sub Form_Load()

Dim X As Long

lleft = 0

'横向滚动文字的起始X坐标

If App.PrevInstance = True Then

'用APP对象的PrevInstance属性

Unload Me

'防止同时运行屏幕保护程序的两个实例

Exit Sub

End If

Select Case Ucase$(Left$(Command$, 2))

'装载命令行参数

Case "/S" '在显示器属性对话框中单击了

预览按钮或屏幕保护程序被系统正常调用。

Show

'全屏显示Form1窗体

Randomize

'初始化随机数生成器

X = ShowCursor(False)

'隐藏鼠标

BackColor = VBBlack

Do

Timer2.Enabled = True

'启动Timer2 ,显示屏幕保护滚动文字

DoEvents

'转让控制权,以便检测鼠标和按键行为

Loop Until quitflag = True

'运行屏幕保护滚动文字直至有鼠标和按键行为

Timer2.Enabled = False

'终止滚动文字

Timer1.Enabled = True

'启动Timer1,退出屏幕保护程序

Case Else

Unload Me

Exit Sub

End Select

End Sub

Private Sub Form_Unload(Cancel As Integer)

Dim X

X = ShowCursor(True)

'显示鼠标

End Sub

Private Sub Timer1_Timer()

Unload Me

'退出屏幕保护程序

End Sub

Private Sub Timer2_Timer()

显示横向滚动文字

lleft = lleft + 100

If lleft = 11810 Then

lleft = 0

Lab1.Top = Int(Rnd * 7000)

End If

Lab1.Left = lleft

Timer2.Enabled = False

End Sub

如何用VB.NET写一个简单的屏幕保护程序?

在窗体上建立2个文本框text1和text2,一个按钮command1,text1里面输入你要转换的字符串,text2里面显示结果,代码如下:

Dim MyString As String

Dim EveryStr(50) As String

Dim TargetStr As String

Private Sub Command1_Click()

MyString = Text1

For i = 1 To Len(MyString)

EveryStr(i) = Right(Left(MyString, i), 1)

If Asc(EveryStr(i)) 123 And Asc(EveryStr(i)) 96 Then EveryStr(i) = \"_\"

If Asc(EveryStr(i)) 91 And Asc(EveryStr(i)) 64 Then EveryStr(i) = \"_\"

TargetStr = TargetStr EveryStr(i)

Next i

Text2 = TargetStr

TargetStr = \"\"

End Sub

引号前面怎么自动给加了个“\”?用的时候请手动把那几个“\”去掉


分享名称:关于vb.net屏保的信息
分享地址:http://cdkjz.cn/article/dodjhdi.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220