-
Hi,
I've created my screensaver (as nearly everyone knows by now....., I've posted so many messages here reecntly.....)
I'm facing a problem when I set my .scr file as the screensaver. When I move the mouse I get a run-time error
"File access path error". But this error doesn't occur everytime. Can anyone tell me if there's an error on my code? I'm pasting the module's code below.
Code:
'This is the code in the module.
Option Explicit
Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Public Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Public Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Dim My_Rect As RECT
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Public 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
Public Const WS_CHILD = &H40000000
Public Const SWP_FRAMECHANGED = &H20 ' The frame changed: send WM_NCCALCSIZE
Public Const GWL_EXSTYLE = (-20)
Public Const GWL_HWNDPARENT = (-8)
Dim PrevHwnd As Long
Dim RetVal As Long
Sub Main()
Dim MyStr As String
Dim MyComm As String
Dim Test As Long
Dim LHwnd As Long
'If App.PrevInstance = True Then End
MyStr = Trim(Command$)
MyComm = Mid(MyStr, 1, 2)
If (MyComm = "/p") Then
ElseIf (MyComm = "/s") Then
FrmScr.Show
ElseIf (MyComm = "/c") Then
MsgBox "No setings"
ElseIf (MyComm = "/a") Then
MsgBox "Password Settings disabled"
End If
End Sub
FrmScr --> form on which I've placed an image control.
Im using a timer to get jpeg files from a .RES file and loading them into the image control.
I've used the mousedown, keydown and mousemove events of the form and the image control to unload my form and end my application.
Thanx.
-
The code you've supplied here doesn't raise the error, does it?
It's probably the code in the Timer event.
When you close your application (the Form_Unload event) set the Timer.Enabled = False.
-
more code.........
Here's the next bit of my code,
The timer's code:
Code:
Private Sub Timer1_Timer()
Image1.Picture = GetPictureFromResource(F_ID(My_ctr))
If (My_ctr < 5) Then
My_ctr = My_ctr + 1
Else
My_ctr = 0
End If
End Sub
Public Function GetPictureFromResource(F_ResourceID As Integer) As IPictureDisp
Dim bytArr() As Byte
Dim intFFN As Integer
Dim strPath As String
bytArr = LoadResData(F_ResourceID, "CUSTOM")
strPath = App.Path & IIf(Right(App.Path, 1) = "\", "MyPicture.tmp", "\MyPicture.tmp")
intFFN = FreeFile
Open strPath For Binary As intFFN
Put #intFFN, , bytArr
Close #intFFN
Set GetPictureFromResource = LoadPicture(strPath)
Kill strPath
End Function
and in the form's load event:
Private Sub Form_Load()
Code:
'To make the image control fullscreen
Image1.Top = 0
Image1.Left = 0
Image1.Width = Screen.Width
Image1.Height = Screen.Height
My_ctr = 0
F_ID(0) = "101"
F_ID(1) = "102"
F_ID(2) = "103"
F_ID(3) = "104"
F_ID(4) = "105"
F_ID(5) = "106"
Timer1.Enabled = True
Timer1_Timer
End Sub
I've loaded the jpeg files into the resource file already.
Any ideas????
Thanx.
-
hmmm File Acces Path Error doesn't it mean you can't open the specific file?
Code:
Open strPath For Binary As intFFN
Put #intFFN, , bytArr
Close #intFFN
Check if the strPath exists, otherwise that's why the error is raised.
-
thats what I was thinking...tried loading the jpeg files using a .ini file. added the filenames to the .ini file and then read the filenames from there. Then loaded the jpeg files into the image control. This didnt give me an error. But I need to read the files from the resource file coz I want the jpeg files to be a part of my VB application. Will try checking if strpath exists
Thanx Jop.