网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

vb.net屏幕保护 vbs锁定窗口

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

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

岫岩ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为成都创新互联的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:18980820575(备注:SSL证书合作)期待与您的合作!

好了,我们来作一个简单的。选择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.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怎么做屏幕保护程序啊

用Visual C#编写屏幕保护程序

Visual C#是微软公司推出的新一代程序开发语言,是微软.Net框架中的一个重要组成部分。屏幕保护程序是以scr为扩展名的标准Windows可执行程序。屏幕保护程序不仅可以延长显示器的使用寿命,还可以保护私人信息。本文向大家介绍一个.Net平台上用C#编写的一个动态文本及图形的屏幕保护程序。

一、具体实现步骤:

(1)在Visual Studio.Net下新建一个C#的Windows应用程序工程,不妨命名为screen_saver。

(2)现在我们来设计程序的主界面:

先将窗体的Name属性设置为screen、Text属性设置为空,BackColor属性设置为Black、Size属性设置为(800, 600)、 ControlBox、MaximizeBox、MinimizeBox、ShowInTaskbar属性设置均为false、FormBorderStyle属性设置为None。再往窗体上添加Label控件、PictureBox控件、Timer控件各一个。将Label控件的Name设置为word、Text属性设置为空;将PictureBox控件的Name设置为picture1、Image设置为一个预知图片;将Timer控件的Name设置为timerSaver、Enabled 属性设为true、Interval属性设为5。

(3)现在我们开始编写完整程序代码部分:

//导入使用到的名称空间

using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;

file://

namespace screen_saver

{

///

/// Form1 的摘要说明。

///

public class screen : System.Windows.Forms.Form

{

file://加入私有成员变量

private System.ComponentModel.IContainer components;

private int iSpeed = 2;

private string str="福建南纺股份公司计算机中心";

file://定义文本字体及大小

private System.Drawing.Font TextStringFont = new System.Drawing.Font ("宋体”, 10,System.Drawing.FontStyle.Bold);

private Color TextStringcolor =System.Drawing.Color.Yellow; file://文本字体颜色

private int iDistance;

private int ixStart= 0;

private int iyStart= 0;

private int speed;

private int x1,y1;

int width1,height1;

private System.Windows.Forms.Timer timerSaver; file://计时器控件

private System.Windows.Forms.PictureBox picture1; file://图形控件

private System.Windows.Forms.Label word; file://文本显示控件

///

/// 必需的设计器变量。

///

public screen()

{

file://

// Windows 窗体设计器支持所必需的

file://

InitializeComponent();

word.Font=TextStringFont;

word.ForeColor=TextStringcolor;

System.Windows.Forms.Cursor.Hide(); file://隐藏光标

file://

// TODO: 在 InitializeComponent 调用后添加任何构造函数代码

file://

}

///

/// 清理所有正在使用的资源。

///

protected override void Dispose( bool disposing )

{

if( disposing )

{

if (components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}

#region Windows Form Designer generated code

///

/// 设计器支持所需的方法 - 不要使用代码编辑器修改

/// 此方法的内容。

///

private void InitializeComponent() file://初始化程序中使用到的组件

{

this.components = new System.ComponentModel.Container();

System.Resources.ResourceManager resources = new system.Resources.ResourceManger(typeof(screen));

this.word = new System.Windows.Forms.Label();

this.timerSaver = new System.Windows.Forms.Timer(this.components);

this.picture1 = new System.Windows.Forms.PictureBox();

this.SuspendLayout();

//

// 设置文本显示控件(word)属性

this.word.ForeColor = System.Drawing.Color.Yellow;

this.word.Location = new System.Drawing.Point(624, 8);

this.word.Name = "word";

this.word.Size = new System.Drawing.Size(168, 16);

this.word.TabIndex = 0;

this.word.Visible = false;

//

// 设置计时器控件(timerSaver)属性

this.timerSaver.Enabled = true;

this.timerSaver.Interval = 5;

this.timerSaver.Tick += new System.EventHandler(this.timerSaver_Tick);

//

// 设置图片控件(picture1)属性

this.picture1.Image = ((System.Drawing.Bitmap)(resources.GetObject("picture1.Image")));

this.picture1.Location = new System.Drawing.Point(800, 600);

this.picture1.Name = "picture1";

this.picture1.Size = new System.Drawing.Size(304, 224);

this.picture1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;

this.picture1.TabIndex = 1;

this.picture1.TabStop = false;

//

// 设置窗体(screen)属性

this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);

this.BackColor = System.Drawing.Color.Black;

this.ClientSize = new System.Drawing.Size(800, 600);

this.ControlBox = false;

this.Controls.AddRange(new System.Windows.Forms.Control[] {this.picture1,this.word});

this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;

this.KeyPreview = true;

this.MaximizeBox = false;

this.MinimizeBox = false;

this.Name = "screen";

this.ShowInTaskbar = false;

this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;

this.WindowState = System.Windows.Forms.FormWindowState.Maximized;

file://键盘按下响应事件

this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.screen_KeyDown);

file://鼠标按下响应事件

this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.screen_MouseDown);

file://窗体启动调用事件

this.Load += new System.EventHandler(this.Form1_Load);

file://鼠标移动响应事件

this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.screen_MouseMove);

this.ResumeLayout(false);

}

#endregion

///

/// 应用程序的主入口点。

///

[STAThread]

static void Main(string[] args)

{

if(args.Length==1)

if(args[0].Substring(0,2).Equals("/c"))

{

MessageBox.Show("没有设置项功能","C# Screen Saver");

Application.Exit();

}

else if(args[0]=="/s")

Application.Run(new screen());

else if(args[0]=="/a")

{

MessageBox.Show("没有口令功能","C# Screen saver");

Application.Exit();

}

else

Application.Run(new screen());

}

private void Form1_Load(object sender, System.EventArgs e)

{

speed=0;

System.Drawing.Rectangle ssWorkArea=System.Windows.Forms.Screen.GetWorkingArea(this);

file://屏幕显示区域

width1=ssWorkArea.Width; file://屏幕宽度

height1=ssWorkArea.Height; file://屏幕高度

}

private void timerSaver_Tick(object sender, System.EventArgs e) file://计时器响应事件

{

word.Visible=true;

word.Text=str;

word.Height=word.Font.Height; file://设置文本的高度

word.Width=word.Text.Length*(int)word.Font.Size*2; file://设置文本的宽度

PlayScreenSaver();

}

private void PlayScreenSaver() file://自定义函数

{

file://下面设置文本显示框的位置坐标

word.Location =new System.Drawing.Point(width1-iDistance,word.Location.Y);

word.Visible=true; file://设置为可见

iDistance+=iSpeed;

if(word.Location.X=-(word.Width))

{

iDistance=0;

if(word.Location.Y==0)

word.Location=new System.Drawing.Point(word.Location.X,height1/2);

else if(word.Location.Y==height1/2)

word.Location=new System.Drawing.Point(word.Location.X,height1-word.Height);

else

word.Location=new System.Drawing.Point(word.Location.X,0);

}

file://下面是计算图片框移动坐标

speed++;

if(speed=2*height1)

{

x1=System.Math.Abs(width1-speed);

y1=System.Math.Abs(height1-speed);

}

else if(speed2*height1 speed=2*width1)

{

x1=System.Math.Abs(width1-speed);

y1=System.Math.Abs(height1-(speed-speed/height1*height1));

}

else if(speed2*width1 speed=3*height1)

{

x1=System.Math.Abs(width1-(speed-speed/width1*width1));

y1=System.Math.Abs(height1-(speed-speed/height1*height1));

}

else if(speed3*height1 speed4*height1)

{

x1=System.Math.Abs(width1-(speed-speed/width1*width1));

y1=System.Math.Abs(speed-speed/height1*height1);

}

else if(speed=4*height1 speed5*height1)

{

x1=System.Math.Abs(speed-speed/width1*width1);

y1=System.Math.Abs(height1-(speed-speed/height1*height1));

}

else if(speed=5*height1 speed4*width1)

{

x1=System.Math.Abs(speed-speed/width1*width1);

y1=System.Math.Abs(speed-speed/height1*height1);

}

else if(speed=4*width1 speed6*height1)

{

x1=System.Math.Abs(width1-(speed-speed/width1*width1));

y1=System.Math.Abs(speed-speed/height1*height1);

}

else if(speed=6*height1 speed5*width1)

{

x1=System.Math.Abs(width1-(speed-speed/width1*width1));

y1=System.Math.Abs(height1-(speed-speed/height1*height1));

}

else if(speed=5*width1 speed7*height1)

{

x1=System.Math.Abs(speed-speed/width1*width1);

y1=System.Math.Abs(height1-(speed-speed/height1*height1));

}

else if(speed=7*height1 speed6*width1)

{

x1=System.Math.Abs(speed-speed/width1*width1);

y1=System.Math.Abs(speed-speed/height1*height1);

}

if(speed==6*width1)

speed=0;

picture1.Location=new System.Drawing.Point(x1,y1);

}

private void StopScreenSaver() file://停止屏幕保护程序运行

{

System.Windows.Forms.Cursor.Show();

timerSaver.Enabled=false;

Application.Exit();

}

private void screen_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)

file://鼠标移动事件

{

if(ixStart==0 iyStart==0)

{

ixStart=e.X;

iyStart=e.Y;

return;

}

else if(e.X!=ixStart||e.Y!=iyStart)

StopScreenSaver();

}

private void screen_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)

file://鼠标按下事件

{

StopScreenSaver(); file://停止运行屏幕保护程序

}

private void screen_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)

file://键盘按下事件

{

StopScreenSaver(); file://停止运行屏幕保护程序

}

}

}

最后运行该程序,把screen_saver.exe改为screen_saver.scr,拷入Windows系统目录中,这样就可以运行该屏幕

如何用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屏幕保护 vbs锁定窗口
标题路径:http://bjjierui.cn/article/doesiio.html

其他资讯