c语言程序设计---屏保程序

c语言程序设计---屏保程序,第1张

在Win_TC里运行 #include<stdio.h>

#include<stdlib.h>

#include<graphics.h>

char a[100]="zhangyafei"

char b[100]

char str[100]=""

int p=1

int i

void main()

{

int gdriver=DETECT, gmode

initgraph(&gdriver, &gmode, " ")

randomize()

do

{

while(!kbhit())

{

i++

if(i==300)

{

i=0

cleardevice()

}setcolor(rand()%16)

circle(rand()%600,rand()%450,rand()%50)

setcolor(rand()%16)

moveto(rand()%getmaxx(),rand()%getmaxy())

lineto(rand()%getmaxx(),rand()%getmaxy())

/*

setbkcolor(rand()%16)

sleep(1)

*/setcolor(rand()%16)

arc(rand()%getmaxx(),rand()%getmaxy(),rand()%getmaxx(),rand()%360,rand()%360) }

cleardevice()

setcolor(6)

settextstyle(0,0,3)

outtextxy(80,getmaxy()/2,"Please Input Password!")

scanf("%s",&b)

cleardevice()

if(strcmp(a,b))

{

p=1

outtextxy(100,getmaxy()/2,"Password is Wrong!")

sleep(1)

}

else

{

p=0

outtextxy(100,getmaxy()/2,"Password is Correct")

sleep(1)

}

}

while(p)

closegraph()

return 0

}

enum SaverMode

{

 sm_config,

 sm_preview,

 sm_full,

 sm_test,

 sm_passwordchange

}

//命令行过滤函数,命令行获渣枣碰得函数是用API GetCommandLine( )。

SaverMode ParseCommandLine( TCHAR* pstrCommandLine )

{

 g_hWndParent = NULL//全局变量(global varibale) 在头函数或主文件开始处定义。

 // 跳过长文件名中的路径和空格。

 if (*pstrCommandLine == TEXT(’\"’))

 {

pstrCommandLine++

while (*pstrCommandLine != TEXT(’\0’) &&*pstrCommandLine != TEXT(’\"’))

 pstrCommandLine++

 If( *pstrCommandLine == TEXT(’\"’) )

pstrCommandLine++

 }

 else

 {

while (*pstrCommandLine != TEXT(’\0’) &&*pstrCommandLine != TEXT(’ ’))

 pstrCommandLine++

 岩前if( *pstrCommandLine == TEXT(’ ’) )

pstrCommandLine++

 }

 // 跳过"/" 或 "-"

 while ( *pstrCommandLine != TEXT(’\0’) &&*pstrCommandLine != TEXT(’/’) &&*pstrCommandLine != TEXT(’-’) )

pstrCommandLine++

 // 如果没有任何参数,为设置模式。

 if ( *pstrCommandLine == TEXT(’\0’) )

return sm_config

 // 如果有参数,查看参数内容。

 switch ( *(++pstrCommandLine) )

 {

case ’c’:

case ’C’:

 pstrCommandLine++

 while ( *pstrCommandLine &&!isdigit(*pstrCommandLine) )

pstrCommandLine++

 if ( isdigit(*pstrCommandLine) )

 {

#ifdef _WIN64 //考虑64位编译情况。

 CHAR strCommandLine[2048]

 DXUtil_ConvertGenericStringToAnsiCb( strCommandLine, pstrCommandLine, sizeof(strCommandLine))

 //该函数仅在64位编译情况下使用。

如谈 g_hWndParent = (HWND)(_atoi64(strCommandLine))

#else

 g_hWndParent = (HWND)LongToHandle(_ttol(pstrCommandLine))//数字串变为/Window句柄

#endif

 }

else

{

 g_hWndParent = NULL

 }

 return sm_config

 case ’t’:

 case ’T’:

return sm_test

 case ’p’:

 case ’P’:

//预览模式,后面有Window句柄,为十进制数字

pstrCommandLine++

while ( *pstrCommandLine &&!isdigit(*pstrCommandLine) )

 pstrCommandLine++

if ( isdigit(*pstrCommandLine) )

{

 #ifdef _WIN64

CHAR strCommandLine[2048]

DXUtil_ConvertGenericStringToAnsiCb(strCommandLine, pstrCommandLine, sizeof(strCommandLine))

g_hWndParent = (HWND)(_atoi64(strCommandLine))

 #else

g_hWndParent = (HWND)LongToHandle(_ttol(pstrCommandLine))

 #endif

}

return sm_preview

case ’a’:

case ’A’:

 //密码设置模式,后面有Window句柄,为十进制数字

 pstrCommandLine++

 while ( *pstrCommandLine &&!isdigit(*pstrCommandLine) )

pstrCommandLine++

 if ( isdigit(*pstrCommandLine) )

 {

#ifdef _WIN64

 CHAR strCommandLine[2048]

 DXUtil_ConvertGenericStringToAnsiCb(strCommandLine, pstrCommandLine, sizeof(strCommandLine))

 g_hWndParent = (HWND)(_atoi64(strCommandLine))

#else

 g_hWndParent = (HWND)LongToHandle(_ttol(pstrCommandLine))

#endif

 }

 return sm_passwordchange

default:

 //其他选项,屏保实际运行模式(通常/s)

 return sm_full

 }

}

'要生成文件的后缀名为scr

'窗体样式要改为Me.BorderStyle = 0

Dim X1, Y1, X2, Y2 As Integer

Dim I As Integer

Dim J As Boolean

Dim K As Integer

Dim WithEvents Label1 As Label '声明一个label

Dim WithEvents Timer1 As Timer '声明一个timer

Private Sub Form_Activate()

I = 100

K = 100

X1 = Me.Width / 2

Y1 = Me.Height / 3

X2 = X1

Y2 = Y1

Rem 设置label的位置

Label1.Top = Me.Height / 2 - Label1.Height / 2

Label1.Left = Me.Width / 2 - Label1.Width / 2

End Sub

Private Sub Form_Load()

Me.BackColor = &H0&'窗体的背景色为黑色

Me.FillColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255) '窗体的填充色为随机

Me.ForeColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255) '窗体的前景色为随机

Me.DrawMode = 13 '窗体输出的外观为13

Me.DrawWidth = 2 '窗体输出的线条宽度为2

Me.FillStyle = 7 '窗体的填充样式为7

Set Label1 = Me.Controls.Add("VB.Label"槐旁迟, "启亮Label1") '设置label

Set Timer1 = Me.Controls.Add("VB.Timer", "Timer1") '设置timer

Label1.Visible = True 'label可见性为true

Label1.AutoSize = True 'label自动调整大小

Label1.BackStyle = 0 'label背景色为透明

Label1.Caption = "I LOVE YOU" '设置标题

Label1.Font.Size = 60 '字体大小为60

Label1.ForeColor = &HFF00&'label前景色为黑色

Timer1.Enabled = True 'timer为有效

Timer1.Interval = 10 'timer时间 间隔为0.001秒

Me.WindowState = 2 '窗体展开样式

End Sub

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

Static currentX, currentY As Single

Dim orignX, orignY As Single

'把当前的鼠标值赋给orignX和orignY

orignX = X

orignY = Y

'初始化currentX和currentY

If currentX = 0 And currentY = 0 Then

currentX = orignX

currentY = orignY

Exit Sub

End If

If Abs(orignX - currentX) >1 Or Abs(orignY - currentY) >1 Then

End

End If

End Sub

Private Sub Timer1_Timer()

Me.Circle (X1, Y1), 250 '在窗体上画圆

Me.Circle (X2, Y2), 250 '在窗铅李体上画圆

If Y1 <= Me.Height - 1200 Then '在指定高度运行

X1 = X1 + K

Y1 = Y1 - I

X2 = X2 - K

Y2 = Y2 - I

I = I - 2

If Y1 <= Me.Height / 3 Then

K = K - 1

ElseIf Y1 >= Me.Height / 3 Then

K = K - 5

End If

Else

I = 100

K = 100

X1 = Me.Width / 2

Y1 = Me.Height / 3

X2 = X1

Y2 = Y1

Me.FillColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255) '窗体的填充色为随机

Me.ForeColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255) '窗体的前景色为随机

End If

Me.DrawWidth = 3 '窗体输出的线条宽度为3

'在窗体上随机画点

Me.PSet (Rnd * Me.Width, Rnd * Me.Height), RGB(Rnd * 225, Rnd * 225, Rnd * 225)

Me.DrawWidth = 2 '窗体输出的线条宽度为2

End Sub

''''''''''''''''''''''''''''''

'在窗体上单击鼠标时退出程序

Private Sub Form_Click()

End

End Sub

'在窗体上按下按键时退出程序

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

End

End Sub

'在窗体上移动鼠标时退出程序

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

Static currentX, currentY As Single

Dim orignX, orignY As Single

'把当前的鼠标值赋给orignX和orignY

orignX = X

orignY = Y

'初始化currentX和currentY

If currentX = 0 And currentY = 0 Then

currentX = orignX

currentY = orignY

Exit Sub

End If

If Abs(orignX - currentX) >1 Or Abs(orignY - currentY) >1 Then

End

End If

End Sub


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/12410074.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-23
下一篇2023-05-23

发表评论

登录后才能评论

评论列表(0条)

    保存