Results 1 to 8 of 8

Thread: [RESOLVED] [2005] Win32Exception

  1. #1

    Thread Starter
    Fanatic Member Jumpercables's Avatar
    Join Date
    Jul 2005
    Location
    Colorado
    Posts
    592

    Resolved [RESOLVED] [2005] Win32Exception

    I have used this code in many of my applications but now it seems to be erroring and I'm not sure what is causing the error. Basically when I click on the NotifyIcon I want o show the form and when its minimized i want to not show up in the taskbar.

    VB Code:
    1. Private Sub Main_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.SizeChanged
    2.         If Me.WindowState = FormWindowState.Minimized Then
    3.             Me.ShowInTaskbar = False
    4.             NotifyIcon.Visible = True
    5.         Else
    6.            [COLOR=Red] Me.ShowInTaskbar = True 'Error[/COLOR]
    7.             NotifyIcon.Visible = False
    8.         End If
    9.     End Sub

    Here is the execption that is getting thrown.
    System.ComponentModel.Win32Exception was unhandled ErrorCode=-2147467259 Message="Error creating window handle." Source="System.Windows.Forms"

    Any ideas for a solution?

    Thanks In Advance

    C# - .NET 1.1 / .NET 2.0

    "Take everything I say with a grain of salt, sometimes I'm right, sometimes I'm wrong but in the end we've both learned something."
    _____________________
    Regular Expressions Library
    Connection String
    API Functions
    Database FAQ & Tutorial

  2. #2
    Hyperactive Member ZaNi's Avatar
    Join Date
    Jun 2006
    Location
    Australia
    Posts
    360

    Re: [2005] Win32Exception

    Instead of having a form that has the showInTaskbar property changed, consider having one form that always shows in the taskbar. Then when you click the NotifyIcon, open a new instance of that form, and when minimising, close the instance of that form. That may solve your problem.
    * Don't limit yourself to sanity
    * I'd rather be optimistic and naive than pessimistic and right
    * Ask good questions, get good answers.

    My Codebank submissions:
    How to write one rountine to handle many events
    Accessing and Using variables across multiple forms
    Printing/Previewing a form or control

    Links I've "borrowed" from other people:
    vbdotnetboy - Awesome site for tips

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2005] Win32Exception

    I disagree with ZaNi's solution. What you're doing is the appropriate way to do things. I can't tell you why you're getting that issue because I've done what you're doing many times before and it's been fine. Have you tried the same thing with a different form? Have you tried rebuilding (not just building) your project? How are you restoring the form? Are you using the DoubleClick event of the NotifyIcon something like this:
    VB Code:
    1. Private Sub NotifyIcon1_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NotifyIcon.DoubleClick
    2.     Me.WindowState = FormWindowState.Normal
    3. End Sub
    Are you Closing the form before that point?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    Lively Member
    Join Date
    Jun 2006
    Posts
    115

    Re: [2005] Win32Exception

    how about
    VB Code:
    1. Private Sub Main_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.SizeChanged
    2.        If Me.WindowState = FormWindowState.Minimized Then
    3.             Me.ShowInTaskbar = False
    4.             NotifyIcon.Visible = True
    5.         Else
    6.             Me.Show()
    7.             WindowState = FormWindowState.Normal
    8.         End If
    9.     End Sub

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2005] Win32Exception

    Quote Originally Posted by one_&_only
    how about
    VB Code:
    1. Private Sub Main_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.SizeChanged
    2.        If Me.WindowState = FormWindowState.Minimized Then
    3.             Me.ShowInTaskbar = False
    4.             NotifyIcon.Visible = True
    5.         Else
    6.             Me.Show()
    7.             WindowState = FormWindowState.Normal
    8.         End If
    9.     End Sub
    The SizeChanged event is being handled. It's setting the WindowState to Normal that will raise the event, so setting the WindowState to Normal in the event handler isn't useful. Plus that doesn't change the task bar visibility of the form or the tray icon.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Fanatic Member Jumpercables's Avatar
    Join Date
    Jul 2005
    Location
    Colorado
    Posts
    592

    Re: [2005] Win32Exception

    I have tried rebuilding and tried it on a different project and works fine. I am triggering the event by using the click event.

    VB Code:
    1. Private Sub NotifyIcon_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon.MouseClick
    2.         If e.Button = Windows.Forms.MouseButtons.Left Then
    3.             Me.WindowState = FormWindowState.Normal
    4.         End If
    5.     End Sub

    C# - .NET 1.1 / .NET 2.0

    "Take everything I say with a grain of salt, sometimes I'm right, sometimes I'm wrong but in the end we've both learned something."
    _____________________
    Regular Expressions Library
    Connection String
    API Functions
    Database FAQ & Tutorial

  7. #7

    Thread Starter
    Fanatic Member Jumpercables's Avatar
    Join Date
    Jul 2005
    Location
    Colorado
    Posts
    592

    Re: [2005] Win32Exception

    I seems I have fixed this problem by removing a minimize on lostfocus event within a textbox.

    C# - .NET 1.1 / .NET 2.0

    "Take everything I say with a grain of salt, sometimes I'm right, sometimes I'm wrong but in the end we've both learned something."
    _____________________
    Regular Expressions Library
    Connection String
    API Functions
    Database FAQ & Tutorial

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [RESOLVED] [2005] Win32Exception

    As the documentation says, don't use the GotFocus or LostFocus events except under the very specific circumstances that it mentions. Use Enter and Leave for most controls and Activated and Deactivate for forms.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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