Results 1 to 8 of 8

Thread: still can't find the error in this code -- HELP?

  1. #1

    Thread Starter
    Frenzied Member wengang's Avatar
    Join Date
    Mar 2000
    Location
    Beijing, China
    Posts
    1,604
    Hi all. I know I'm being a pain, but I haven't even found a working ss on the web with a sample of picture preview.

    The code below doesn't work, but I don't know why. It doesn't show the preview and it makes the "settings" and "preview" buttons stop responding.

    Anybody know why?

    CODE FOR THE SCREENSAVER FORM:
    (one imagebox (image1 set stretch to true))
    Private Sub Form_Load()
    frmMain.Width = Screen.Width
    frmMain.Height = Screen.Height
    Image1.Left = 0
    Image1.Top = 0
    Image1.Width = Screen.Width
    Image1.Height = Screen.Height
    strFilename = App.Path & "\eol.jpg"
    Image1.Picture = LoadPicture(strFilename)
    End Sub
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    Select Case KeyCode
    Case vbKeySpace: StopSS
    End Select
    End Sub
    Private Sub StopSS()
    Unload Me
    End
    End Sub


    AND the code for the Module:

    Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
    Sub Main()
    Dim strCmdLine As String
    Dim strArguments As String
    Dim hWndPreview As Long
    strArguments = Trim(Command$)
    If App.PrevInstance = True Then End
    strCmdLine = Left(Command, 2)
    If strCmdLine = "/p" Then
    hWndPreview = Trim(Right(strArguments, Len(strArguments) - 2))
    Call SetParent(frmMain.hWnd, hWndPreview)
    frmMain.Show
    ElseIf strCmdLine = "/c" Then
    MsgBox ("There are no configuration settings for this screensaver.")
    Else
    Call Load(frmMain)
    frmMain.Show
    End If
    End Sub



  2. #2
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    this might be why:

    Code:
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
        Select Case KeyCode
            Case vbKeySpace  =  StopSS
        End Select
    End Sub
    NXSupport - Your one-stop source for computer help

  3. #3
    Member
    Join Date
    Jul 2000
    Location
    BFE in Oregon
    Posts
    33
    hWndPreview = Trim(Right(strArguments, Len(strArguments) - 2))

    is that the actual object.hWnd of the Preview window? You're passing a string to a Long, try this instead

    hWndPreview = CLng(Trim(Right$(strArguments, Len(strArguments) -2)))

    MsgBox ("There are no configuration settings for this screensaver.") 'this is specifying a Function, Remove the parenthesis and this part will work correctly. You'll get a runtime error if you don't.

    MsgBox "There are no configuration settings for this screensaver."
    Glacius Cool
    Concept Designer
    VB5sp4,VC++6sp3

  4. #4
    Member
    Join Date
    Jul 2000
    Location
    BFE in Oregon
    Posts
    33
    Sorry dimava, his code is almost correct.

    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    Select Case KeyCode
    Case vbKeySpace: StopSS
    End Select
    End Sub
    Private Sub StopSS()
    Unload Me
    End '--------Why did you put this here if you already have Unload Me ??
    '--------You only have this form to unload and no external dependencies that won't unload with Unload Me, in other words you can get rid of the End statement.
    End Sub

    Would work better if it was:

    Private sub some stuff here
    Select Case KeyCode
    Case is vbKeySpace
    StopSS
    End Select
    End sub
    Private Sub StopSS()
    Unload Me
    End Sub

    which is the same as

    Private sub some stuff here
    If KeyCode = vbKeySpace or chr$(32) then Unload Me
    end sub
    Glacius Cool
    Concept Designer
    VB5sp4,VC++6sp3

  5. #5
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    yea, I guess I was wrong, sorry
    NXSupport - Your one-stop source for computer help

  6. #6

    Thread Starter
    Frenzied Member wengang's Avatar
    Join Date
    Mar 2000
    Location
    Beijing, China
    Posts
    1,604
    Hey fellas.
    thanks for replying. I made those changes but still get the same results.

    If either of you have time or inclination, could you try the code on your machine and let me know if you get this problem?

  7. #7

    Thread Starter
    Frenzied Member wengang's Avatar
    Join Date
    Mar 2000
    Location
    Beijing, China
    Posts
    1,604
    oh, just a couple of things.
    First, that wasn't the actual code. I used Selece Case, not If block in the Module:

    Public Sub Main()
    If App.PrevInstance = True Then End
    Dim strArguments As String
    Dim hWndPreview As Long
    strArguments = Trim(Command$)
    Select Case Left(strArguments, 2)
    Case "/s"
    frmMain.Show
    Case "/p"
    hWndPreview = CLng(Trim(Right$(strArguments, Len(strArguments) - 2)))
    Call SetParent(frmMain.hWnd, hWndPreview)
    frmMain.Show
    Case "/c"
    frmDirectory.Show
    End Select
    End Sub
    =======================================================

    Second, i tested this also by replacing the screensaver in Case "/p" with just a blank form with no code whatsoever and still get the same results.

  8. #8

    Thread Starter
    Frenzied Member wengang's Avatar
    Join Date
    Mar 2000
    Location
    Beijing, China
    Posts
    1,604
    wengang
    Wen Gang, Programmer
    VB6, QB, HTML, ASP, VBScript, Visual C++, Java

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width