
How-To... - Learn By Example - Logo Changer
It
had to happen - the second Learn By Example! This LBE will teach you how to
load a graphic into a program and will use the FileCopy statement to allow
you to change your startup, shutdown and 'waiting' screens. My way of doing
it is not necessary the best way, so mess around with it until you get it
the way you want.(Any suggestions, please e-mail
me)
Ok. Make sure you have a new form. Insert the following controls onto it and name them accordingly and arrange them on the form something like the image opposite :-
|
Control
|
Name
|
|
Frame
|
fraMain
|
|
Image
|
imgLogo
(set the Stretch property to True)
|
|
Option
Button
|
optStartup
|
|
Option
Button
|
optWaiting
|
|
Option
Button
|
optShutdown
|
|
Command
Button
|
cmdLoad
|
|
Command
Button
|
cmdQuit
|
|
Common
Dialog
|
Commondialog
|
Now, copy and paste this code into the General Declerations section :-
'Declerations.... '--------------- 'Define an array of strings to store 'the location of the logos... Dim asLogos(2) As String Dim sWinLoc As String
'Function used to find location of the Windows Directory... Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" _ (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Dim Location As String Dim Length As Long Dim TempString As Long Sub GetWinDir() Length = 99 Location = String$(25, 0) TempString = GetWindowsDirectory(Location, Length) End Sub
Private Sub cmdLoad_Click()
On Error GoTo ErrorHandler
'First, setup the Dialog's filters... CommonDialog.Filter = "Bitmaps|*.bmp"
'Now, open the OpenDialog box... CommonDialog.ShowOpen
'Finally, load the picture into the Image Control... imglogo.Picture = LoadPicture(CommonDialog.filename)
'Back-up the picture...
'If optStartup is selected then... If optStartup.Value = True Then
'Copy the loaded file to C:\Logo.sys FileCopy CommonDialog.filename, asLogos(0) End If
'If optWaiting is selected then... If optWaiting.Value = True Then
'Copy the loaded file to C:\Windows\Logow.sys... FileCopy CommonDialog.filename, asLogos(1) End If
'If optShutdown is selected then... If optShutdown.Value = True Then
'Copy the loaded file to C:\Windows\Logos.sys... FileCopy CommonDialog.filename, asLogos(2) End If
ErrorHandler: 'If number 32755(Cancel) then If Err.Number = 32755 Then
'Do nothing...
End If
End Sub
Private Sub cmdQuit_Click()
MsgBox "Remember, to change your logos back, rename the *.vbh extensions to .sys", 32
End
End Sub
Private Sub Form_Load() 'If theres an error goto ErrorHandler... On Error GoTo ErrorHandler:
GetWinDir 'Find the location of the Windows directory...
'Store the locations' into arrays... asLogos(0) = "C:\logo.sys"
'This is the only way you can get 'the full path name properly.... frmMain.Caption = Location sWinLoc = frmMain.Caption '------
'Store the locations' into arrays... asLogos(1) = sWinLoc & "\logow.sys" asLogos(2) = sWinLoc & "\logos.sys"
'Backup the current logos... FileCopy sWinLoc & "\logow.sys", sWinLoc & "\logow.vbh" FileCopy sWinLoc & "\logos.sys", sWinLoc & "\logos.vbh"
'Load Logo.sys(if it exists) into the Image control... imglogo.Picture = LoadPicture(asLogos(0))
'MUST BE DONE LAST 'Because of the error handler, this file must 'be backed up last... FileCopy "C:\logo.sys", "C:\logo.vbh" 'Change the caption back to normal... frmMain.Caption = "Logo Changer"
'If C:\logo.sys doesn't exist(in some machines it doesn't) 'then the error handler exits this sub so that the program 'can continue loading(that is why logo.sys must be backed 'up last... ErrorHandler: Exit Sub
End Sub
Private Sub optShutdown_Click() 'Load the picture from asLogos(2)... imglogo.Picture = LoadPicture(asLogos(2)) End Sub
Private Sub optStartup_Click() 'Load the picture from asLogos(0)... imglogo.Picture = LoadPicture(asLogos(0)) End Sub
Private Sub optWaiting_Click() 'Load the picture from asLogos(1)... imglogo.Picture = LoadPicture(asLogos(1)) End Sub
You can download the source-code here