home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CODE_UPLOAD7449752000.psc / frmMain.frm (.txt) next >
Encoding:
Visual Basic Form  |  2000-07-06  |  13.5 KB  |  303 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "- Set BackGround Image For IE/Explorer -"
  4.    ClientHeight    =   4530
  5.    ClientLeft      =   165
  6.    ClientTop       =   450
  7.    ClientWidth     =   5910
  8.    KeyPreview      =   -1  'True
  9.    LinkTopic       =   "Form1"
  10.    ScaleHeight     =   4530
  11.    ScaleWidth      =   5910
  12.    StartUpPosition =   3  'Windows Default
  13.    Begin VB.PictureBox Picture1 
  14.       Height          =   375
  15.       Left            =   2760
  16.       ScaleHeight     =   315
  17.       ScaleWidth      =   555
  18.       TabIndex        =   7
  19.       Top             =   120
  20.       Visible         =   0   'False
  21.       Width           =   615
  22.    End
  23.    Begin VB.Timer Timer1 
  24.       Enabled         =   0   'False
  25.       Interval        =   2000
  26.       Left            =   4080
  27.       Top             =   4080
  28.    End
  29.    Begin VB.CommandButton Command1 
  30.       Caption         =   "Set Image"
  31.       Height          =   375
  32.       Left            =   4560
  33.       TabIndex        =   0
  34.       Top             =   4080
  35.       Width           =   1215
  36.    End
  37.    Begin VB.CommandButton Command3 
  38.       Caption         =   "Del Shortcut"
  39.       Height          =   375
  40.       Left            =   1560
  41.       TabIndex        =   5
  42.       ToolTipText     =   "Click to remove program shortcut"
  43.       Top             =   4080
  44.       Width           =   1095
  45.    End
  46.    Begin VB.CommandButton Command2 
  47.       Caption         =   "Create Shortcut"
  48.       Height          =   375
  49.       Left            =   120
  50.       TabIndex        =   4
  51.       ToolTipText     =   "Creating a shortcut will allow you to quickly open this program through Internet Explorers ""Links"" Menu"
  52.       Top             =   4080
  53.       Width           =   1335
  54.    End
  55.    Begin VB.FileListBox File1 
  56.       Height          =   2040
  57.       Left            =   120
  58.       Pattern         =   "*.bmp"
  59.       TabIndex        =   3
  60.       Top             =   1920
  61.       Width           =   2415
  62.    End
  63.    Begin VB.DirListBox Dir1 
  64.       Height          =   1215
  65.       Left            =   120
  66.       TabIndex        =   2
  67.       Top             =   600
  68.       Width           =   2415
  69.    End
  70.    Begin VB.DriveListBox Drive1 
  71.       Height          =   315
  72.       Left            =   120
  73.       TabIndex        =   1
  74.       Top             =   120
  75.       Width           =   2415
  76.    End
  77.    Begin VB.Label Label1 
  78.       BackStyle       =   0  'Transparent
  79.       Height          =   375
  80.       Left            =   2640
  81.       TabIndex        =   6
  82.       Top             =   120
  83.       Width           =   3135
  84.    End
  85.    Begin VB.Image Image1 
  86.       BorderStyle     =   1  'Fixed Single
  87.       Height          =   3315
  88.       Left            =   2640
  89.       OLEDragMode     =   1  'Automatic
  90.       OLEDropMode     =   1  'Manual
  91.       Stretch         =   -1  'True
  92.       Top             =   600
  93.       Width           =   3135
  94.    End
  95.    Begin VB.Menu mnuScroll 
  96.       Caption         =   "sdfds"
  97.       Visible         =   0   'False
  98.       Begin VB.Menu mnuAutoScroll 
  99.          Caption         =   "Auto Scroll"
  100.       End
  101.    End
  102. Attribute VB_Name = "Form1"
  103. Attribute VB_GlobalNameSpace = False
  104. Attribute VB_Creatable = False
  105. Attribute VB_PredeclaredId = True
  106. Attribute VB_Exposed = False
  107. 'What this code does is set a bitmap (only works with bitmaps) image to be the
  108. 'background in all Explorer/My Computer/Internet Explorer windows. It works just by
  109. 'change a registry value, so it was very easy to code. You can drag and drop bitmaps
  110. 'from explorer and it will load them and change the dirlistbox to the dir it
  111. 'was dragged from. Ive added lots of fancy stuff but the main functionality is 3 or so lines
  112. 'Ive included a few textures which i found on my hardrive. The wood one looks
  113. 'quite good, or you could always just use a pic of a girl in a bikini ;)
  114. 'BTW Ive only tested it one my home win98 computer, so I dont know if it'll work for any other versions.
  115. 'You must have rights to write to the registry, other wise it wont work
  116. Dim strBitmap As String
  117. Dim strURL As String
  118. Dim strDir As String
  119. Dim strData As String
  120. Dim strDragDir As String
  121. Dim strFileName As String
  122. Dim strCurrent As String
  123. Dim strCheck As String
  124. Dim intCheck As Integer
  125. Dim intSlash As String
  126. Private Sub Command1_Click()
  127. On Error GoTo err
  128. If File1.FileName = "" Then
  129.     MsgBox "Please select a bitmap file first", vbExclamation, App.Title
  130.     'no files been selected
  131.     Exit Sub
  132.     strExtension = File1.FileName
  133.     length = Len(strExtension)
  134.     where = InStr(strExtension, ".") 'find where the . is
  135.     strExtension = Right$(strExtension, length - where) 'chops string to only the letters after the "." eg JPG GIF etc
  136.     strExtension = LCase(strExtension) 'changes string to lower case
  137.     If strExtension = "jpg" Or strExtension = "gif" Or strExtension = "jpeg" Or strExtension = "jpe" Then
  138.     'checks to see what the extension of the file is, We want to trap all jpg's and gif's
  139.             If MsgBox("The selected file is not a bitmap. Do you wish to convert it to a bitmap?", vbYesNo, App.Title) = vbYes Then
  140.                 ConvertToBMP (File1.path & "\" & File1.FileName) 'calls function which saves selected picture to a bitmap
  141.                 strBitmap = File1.path & "\" & File1.List(File1.ListIndex)
  142.                 Call UpdateKey(HKEY_CURRENT_USER, "Software\Microsoft\Internet Explorer\Toolbar", "BackBitmap", strBitmap)
  143.                 'this updates the registry key which specifies what file explorer uses for its background (skin)
  144.                 'thats all you have to change to make it work!
  145.                 MsgBox "Skin set." & vbCrLf & "You will notice the change when you  a open a new browser window.", vbInformation, App.Title
  146.             Else
  147.                 Exit Sub
  148.             End If
  149.     Else
  150.         strBitmap = File1.path & "\" & File1.FileName
  151.         Call UpdateKey(HKEY_CURRENT_USER, "Software\Microsoft\Internet Explorer\Toolbar", "BackBitmap", strBitmap)
  152.         'this updates the registry key which specifies what file explorer uses for its background (skin)
  153.         'thats all you have to change to make it work! **This one is only called when the originally selected file is a bitmap
  154.         MsgBox "Skin set." & vbCrLf & "You will notice the change when you  a open a new browser window.", vbInformation, App.Title
  155.     End If
  156. End If
  157. Exit Sub
  158. MsgBox err.Description, vbCritical, App.Title
  159. End Sub
  160. Private Sub Command2_Click()
  161. strDir = WinDir(False) ' cant presume windows is installed in "C:\windows", this function finds where windows is installed
  162. FileCopy App.path & "\" & App.EXEName & ".exe", strDir & "\Favorites\Links\Skin.exe"
  163. 'copies a copy of the exe to a windows dir (windows\Favorites\Links\) which will create a shortcut you can see in IE
  164. 'NOTE: if your running this in the VB IDE the above line will crash.
  165. 'You have to be using the exe (or at least have the exe compiled in same dir as project) for it to work
  166. strMsg = "Shortcut has been created. " & vbCrLf
  167. strMsg = strMsg & "To use the shortcut, right click on your toolbar in Internet Explorer and make sure 'Links' are turned on." & vbCrLf
  168. strMsg = strMsg & "You should now be able to see the shortcut, 'Skin.exe'. Click on it and it will open this program"
  169. MsgBox strMsg, vbInformation, App.Title 'build a string to message
  170. End Sub
  171. Private Sub Command3_Click()
  172. On Error GoTo err
  173. strDir = WinDir(False) ' cant presume windows is installed in "C:\windows"
  174. Kill strDir & "\Favorites\Links\Skin.exe" 'delete exe from links dir
  175. MsgBox "Shortcut removed", vbInformation, App.Title
  176. Exit Sub
  177. MsgBox "No shortcut to remove", vbExclamation, App.Title 'error is reached if file isnt found
  178. End Sub
  179. Private Sub Command4_Click()
  180. frmBatch.Show
  181. frmBatch.Dir1.path = Dir1.path
  182. End Sub
  183. Private Sub Dir1_Change()
  184. File1.path = Dir1.path
  185. End Sub
  186. Private Sub Drive1_Change()
  187. On Error GoTo err
  188. Dir1.path = Drive1.Drive
  189. Exit Sub
  190. MsgBox err.Description, vbCritical, App.Title 'need to trap this error
  191. End Sub
  192. Private Sub File1_Click()
  193. Dim strExtension As String
  194. On Error GoTo err:
  195. Image1.Picture = LoadPicture(File1.path & "\" & File1.FileName) 'loads the file clicked in the file list box into the image control
  196. Command1.ToolTipText = "Click to set " & File1.path & "\" & File1.FileName & " to be your new skin"
  197. 'make the tooltip say which file is going to be set.. not very useful
  198. Label1.Caption = File1.path & "\" & File1.FileName
  199. Exit Sub
  200. MsgBox err.Description, vbCritical, App.Title
  201. End Sub
  202. Private Sub File1_KeyDown(KeyCode As Integer, Shift As Integer)
  203. Select Case KeyCode
  204.     Case 46:
  205.     If MsgBox("Are you sure you want to delete this file?", vbYesNo, App.Title) = vbYes Then
  206.         Kill (File1.path & "\" & File1.FileName) 'they pressed del, so kill (delete) the file
  207.         File1.Refresh
  208.     End If
  209. End Select
  210. End Sub
  211. Private Sub File1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  212. If Button = 2 Then 'clicked right mouse button
  213.      PopupMenu mnuScroll
  214. End If
  215. End Sub
  216. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
  217.  If KeyCode = 27 And Timer1.Enabled = True Then
  218.     Timer1.Enabled = False
  219.     mnuAutoScroll.Checked = False
  220.  End If
  221. End Sub
  222. Private Sub Form_Load()
  223. On Error GoTo err:
  224. Dim strOrigPic As String
  225. File1.Pattern = "*.jpeg;*.jpe;*.gif;*.jpg;*.bmp"
  226. 'MsgBox "Make sure you close all open Explorer/IE Windows before changing skin!", vbExclamation, App.Title
  227. '<-- uncomment above line to tell users to explorer windows
  228. strCurrent = GetKeyValue(HKEY_CURRENT_USER, "Software\Microsoft\Internet Explorer\Toolbar", "BackBitmap")
  229. 'get the path of the current backgorund/skin
  230. Label1.Caption = strCurrent
  231. intSlash = LastSlash(Label1.Caption) 'find out where the last backslash is using a function i wrote
  232. Dir1.path = Left$(strCurrent, intSlash) 'chops everything from where the last backslash is found; this returns the path, and chops of the filename
  233. Image1.Picture = LoadPicture(strCurrent)
  234. strOrigPic = Replace(strCurrent, Dir1.path, "") 'chop the path from the string and your left with just the filename
  235. strOrigPic = Replace(strOrigPic, "\", "") 'get rid of backslashes
  236. For i = 0 To File1.ListCount - 1
  237.     If File1.List(i) = strOrigPic Then 'goes through all the files in the filelistbox to see if the they match the filename pulled from the registry
  238.         File1.ListIndex = i 'if filename in listbox is same as one from registry, select it
  239.     End If
  240. Next i
  241. Exit Sub
  242. If err.Number = 53 Then 'file cant be found
  243.     MsgBox "Unable to find the file specified in the registry. I may have been deleted or moved", vbCritical, App.Title
  244. Else 'any other error
  245.     MsgBox "Unable to load current background."
  246. End If
  247. End Sub
  248. Private Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  249. If Image1.Picture = 0 Then 'no picture is loaded, so tell 'em what to do
  250.     Image1.ToolTipText = "Locate a bitmap file on your computer using the navigation tools to the left. You can also drag and drop bitmaps from explorer"
  251.     Image1.ToolTipText = "" 'genius's must of worked out how to load files =)
  252. End If
  253. End Sub
  254. Private Sub Image1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
  255. On Error Resume Next
  256. strData = Data.Files(1) 'puts the file name being dragged into program into a variable
  257. strCheck = LCase(Data.Files(1)) 'changes file name to lower case in case file was .BMP instead of .bmp
  258. intCheck = InStr(strCheck, ".bmp") 'checks to see if file name contains ".bmp" thus being a bitmap
  259. If intCheck <> 0 Then ' .bmp was found in name of dragged file
  260.     intSlash = LastSlash(strData) 'calls function LastSlash, which returns where the last backslash in a string is
  261.     strFileName = Left$(strData, intSlash) 'read above
  262.     strDragDir = Replace(Data.Files(1), strFileName, "")
  263.     Dir1.path = strDragDir 'sets dir path to same path as file being dragged
  264.     Image1.Picture = LoadPicture(Data.Files(1)) 'loads dragged bitmap
  265.     MsgBox "You must drag valid bitmap files", vbCritical, App.Title 'bmp wasnt found in filename being dragged
  266. End If
  267. End Sub
  268. Private Sub Label1_Change()
  269. Label1.Caption = LCase(Label1.Caption) 'I hate capitals, its rude =)
  270. End Sub
  271. Private Sub mnuAutoScroll_Click()
  272.    If Timer1.Enabled = True Then
  273.         Timer1.Enabled = False 'turn auto scrolling off
  274.         mnuAutoScroll.Checked = False
  275.     Else
  276.         Timer1.Enabled = True 'turn auto scrolling on
  277.         mnuAutoScroll.Checked = True
  278.     End If
  279. End Sub
  280. Private Sub Timer1_Timer()
  281. 'On Error GoTo Err:
  282. File1.ListIndex = File1.ListIndex + 1 'select next item in filelistbox
  283. 'maybe someones to lazy to press arrow keys/click mouse so they might use this
  284. End Sub
  285. Function ConvertToBMP(strFileName)
  286. Picture1.Picture = LoadPicture(strFileName) 'loads the file clicked in the file list box into the image control
  287. strFileName = LCase(strFileName)
  288. strFileName = Replace(strFileName, ".jpg", "")
  289. strFileName = Replace(strFileName, ".gif", "")
  290. strFileName = strFileName & ".bmp" ' get rid of the extension and change it to bmp instead
  291. SavePicture Picture1.Picture, strFileName 'save the contents on picture1 to disk, as strFileName
  292. File1.Refresh
  293. For i = 0 To File1.ListCount - 1
  294.     strMatch = File1.path & "\" & File1.List(i)
  295.     strMatch = LCase(strMatch)
  296.     If strMatch = strFileName Then 'goes thru the filelistbox until the file selected is equal to the name of the
  297.     'bitmap saved above. Stops when it matches them, then selects that item
  298.         File1.ListIndex = i
  299.         Exit Function
  300.     End If
  301. Next i
  302. End Function
  303.