‘一個(gè)Filelistbox控件:File1
‘以下是代碼
‘聲明
Private 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
Private Declare Function ShowCursor Lib “user32“ (ByVal bShow As Long) As Long
Private Declare Function ShowWindow Lib “user32“ (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Const SW_SHOWMAXIMIZED = 3
Dim kaiguan As Boolean
Dim PictureNum As Long
Private Sub Form_Load()
ShowWindow Me.hwnd, SW_SHOWMAXIMIZED
kaiguan = False
Timer1.Interval = 2000
File1.Path = “C:\Documents and Settings\All Users\Documents\My Pictures\示例圖片“ ‘放置圖片的文件夾
File1.Pattern = “*.jpg;*.bmp;*.gif“ ‘圖片格式
Form1.Picture = LoadPicture(File1.Path & “\“ & File1.List(PictureNum)) ‘先載入第一張
File1.Visible = False
PictureNum = 1
ShowCursor False
SetWindowPos Me.hwnd, -1, 0, 0, 0, 0, 3 ‘窗體在最上面
End Sub
‘按鍵 和鼠標(biāo)使程序結(jié)束
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If kaiguan Then End
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If kaiguan Then End
End Sub
‘換圖片
Private Sub Timer1_Timer()
If kaiguan = False Then
Timer1.Interval = 2000
kaiguan = True
End If
picturefile = File1.Path & “\“ & File1.List(PictureNum)
Form1.Picture = LoadPicture(picturefile)
PictureNum = PictureNum + 1
If PictureNum >= File1.ListCount Then PictureNum = 0
End Sub
回答采納率達(dá):23%(542個(gè)被采納)
評(píng)價(jià)已經(jīng)被關(guān)閉 目前有 0 個(gè)人評(píng)論
好不好
0% (0)0% (0)
‘要生成文件的后綴名為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 ‘聲明一個(gè)label
Dim WithEvents Timer1 As Timer ‘聲明一個(gè)timer
Private Sub Form_Activate()
I = 100
K = 100
X1 = Me.Width / 2
Y1 = Me.Height / 3
X2 = X1
Y2 = Y1
Rem 設(shè)置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) ‘窗體的填充色為隨機(jī)
Me.ForeColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255) ‘窗體的前景色為隨機(jī)
Me.DrawMode = 13 ‘窗體輸出的外觀為13
Me.DrawWidth = 2 ‘窗體輸出的線條寬度為2
Me.FillStyle = 7 ‘窗體的填充樣式為7
Set Label1 = Me.Controls.Add(“VB.Label“, “Label1“) ‘設(shè)置label
Set Timer1 = Me.Controls.Add(“VB.Timer“, “Timer1“) ‘設(shè)置timer
Label1.Visible = True ‘label可見性為true
Label1.AutoSize = True ‘label自動(dòng)調(diào)整大小
Label1.BackStyle = 0 ‘label背景色為透明
Label1.Caption = “I LOVE YOU“ ‘設(shè)置標(biāo)題
Label1.Font.Size = 60 ‘字體大小為60
Label1.ForeColor = &HFF00& ‘label前景色為黑色
Timer1.Enabled = True ‘timer為有效
Timer1.Interval = 10 ‘timer時(shí)間 間隔為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
‘把當(dāng)前的鼠標(biāo)值賦給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 ‘在指定高度運(yùn)行
X1 = X1 + K
Y1 = Y1 - I
X2 = X2 - K
Y2 = Y2 - I
I
03-17 12:51回答采納率達(dá):23%(545個(gè)被采納)
VC++可謂神通廣大,如果學(xué)到家了,或者就掌握了那么一點(diǎn)MFC,你也會(huì)感到它的方便快捷,當(dāng)然最重要的是功能強(qiáng)大。不是嗎,從最基本的應(yīng)用程序.EXE到動(dòng)態(tài)連接庫(kù)DLL,再由風(fēng)靡網(wǎng)上的ActiveX控件到Internet Server API,當(dāng)然,還有數(shù)據(jù)庫(kù)應(yīng)用程序……瞧,我都用它來(lái)做屏幕保護(hù)程序了。一般的屏幕保護(hù)程序都是以SCR作為擴(kuò)展名,并且要放在c:\windows 目錄或 c:\windows\system 目錄下,由Windows 98內(nèi)部程序調(diào)用(Windows NT 是在 c:\windows\system32 目錄下)。怎么調(diào)用?不用說(shuō)了,這誰(shuí)不知道。
好了,我們來(lái)作一個(gè)簡(jiǎn)單的。選擇MFC AppWizard(exe),Project Name 為MyScreensaver,[NEXT],對(duì)話框,再后面隨你了。打開菜單Project、Settings,在Debug頁(yè)、Executable for debug session項(xiàng),以及Link頁(yè)中Output file name項(xiàng)改為c:\windows\MyScreensaver.scr,這樣,你可以調(diào)試完后,直接在VC中運(yùn)行(Ctrl+F5),便可看到結(jié)果。當(dāng)然,這樣做的唯一缺點(diǎn)是你必須手動(dòng)清除Windows 目錄下的垃圾文件(當(dāng)然是在看到滿意結(jié)果后;還有,你可借助SafeClean 這個(gè)小東東來(lái)幫你清除,除非你的硬盤大的讓你感到無(wú)所謂……快快快回來(lái),看我跑到那里去了)。接下來(lái)用Class Wizard生成CMyWnd類,其基類為CWnd(在Base Class 中為generic CWnd)。這個(gè)類是我們所要重點(diǎn)研究的。創(chuàng)建滿屏窗口、計(jì)時(shí)器,隱藏鼠標(biāo),展示圖片,響應(yīng)鍵盤、鼠標(biāo)等等,這家伙全包了。至于MyScreensaverDlg.h與MyScreensaverDlg.cpp文件我們暫時(shí)不管。打開MyScreensaver.cpp,修改InitInstance()函數(shù):
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;
}
當(dāng)然,再這之前得先 #include “MyWnd.h“ 。后面要做的都在MyWnd.h 與 MyWnd.cpp 兩文件中了。
下面給出CMyWnd 的說(shuō)明:
class CMyWnd : public CWnd
{
public:
CMyWnd();
static LPCSTR lpszClassName; //注冊(cè)類名
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; //檢測(cè)鼠標(biāo)移動(dòng)
void DrawBitmap(CDC& dc, int nI
03-17 12:51回答采納率達(dá):26%(594個(gè)被采納)
可以隨意增減圖片!
Private Sub P1_Click()
Static a%
a = a + 1
If a = 1 Then
Picture = LoadPicture(“圖片的路徑“)
End If
If a = 2 Then
Picture = LoadPicture(“圖片的路徑“)
End If
If a = 3 Then
Picture = LoadPicture(“圖片的路徑“)
End If
If a = 4 Then
Picture = LoadPicture(“圖片的路徑“)
End If
If a = 5 Then
Picture = LoadPicture(“圖片的路徑“)
End If
If a = 6 Then
Picture = LoadPicture(“圖片的路徑“)
End If
If a = 7 Then
a = 0
End If
If a = 0 Then
Picture = LoadPicture()
End If
End Sub
聯(lián)系客服