Results 1 to 7 of 7

Thread: Image Monitor

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,945

    Image Monitor

    Image Monitor is a program that captures any image copied to the clipboard and saves it in a directory specified by the user. It's also a demonstration of how to write vb6 programs that display a system tray icon and balloon tooltips.

    EDIT:
    -Removed the WaitMessage API call because it prevents the program from actively monitoring the clipboard.
    -Replaced the number verification procedue with a much simpler check.
    Last edited by Peter Swinkels; Dec 14th, 2012 at 10:21 AM.

  2. #2
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Question Re: Image Monitor

    Hi! I would just like to discuss a few points about your code:

    • In the NOTIFYICONDATA Type, the members uTimeout and uVersion are both Integers and simultaneously available. However, in the MSDN documentation, they are declared as a Union which means only one member name can be used at a time.
    • In order for uVersion = NOTIFYICON_VERSION to have an effect, MSDN says that Shell_NotifyIcon should send the NIM_SETVERSION message.
    • Shouldn't the Form's ScaleMode be vbPixels instead of vbCharacters?
    • What's the difference between the IsNumber function and VB's IsNumeric function?
    • Lastly, how is the outermost Do...Loop block in the Sub StartMonitor exited?
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,945

    Re: Image Monitor

    Quote Originally Posted by Bonnie West View Post
    Hi! I would just like to discuss a few points about your code:

    • In the NOTIFYICONDATA Type, the members uTimeout and uVersion are both Integers and simultaneously available. However, in the MSDN documentation, they are declared as a Union which means only one member name can be used at a time.
    • In order for uVersion = NOTIFYICON_VERSION to have an effect, MSDN says that Shell_NotifyIcon should send the NIM_SETVERSION message.
    • Shouldn't the Form's ScaleMode be vbPixels instead of vbCharacters?
    • What's the difference between the IsNumber function and VB's IsNumeric function?
    • Lastly, how is the outermost Do...Loop block in the Sub StartMonitor exited?
    Thank you for the comments, to answer your questions:
    • I fixed the NOTIFYICONDATA structure. It should now be correctly defined.
    • I decided to ignore the version setting and only set a timeout value.
    • I don't see why this is important in this case. Even though the form contains no interface except for a menu, I usually change several form properties to values I prefer to use.
    • The difference is that my IsNumber function doesn't just check whether a value is numeric, but whether it contains nothing else except for the digits 0-9. Perhaps I should rename it and clarify the comments.
    • I changed this now to use a global flag indicating whether the monitor should stop. The original method was a bit crude, the program simply was forced to quit using the End statement when the window was unloaded.


    I have uploaded several other projects to this form. I would be interested to hear your comments.
    Last edited by Peter Swinkels; Dec 4th, 2012 at 03:42 AM.

  4. #4
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Thumbs up Re: Image Monitor

    Thank you too for the response!

    I would just like to clarify why I asked why your Form's ScaleMode was in vbCharacters. The reason is because I don't understand how the Form was able to popup the menu when the tray icon was right-clicked considering that the ScaleMode was vbCharacters and Windows API in general use Pixels for coordinates.

    I would also like to offer a couple of suggestions:

    1. Call SetForegroundWindow before showing the popup menu to enable it to be dismissed by clicking elsewhere.
    2. Insert WaitMessage right before DoEvents to prevent high CPU usage.


    That's all!


    P.S.

    I've checked out some of your other projects and they're good!
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,945

    Re: Image Monitor

    WaitMessage works. SetForegroundWindow doesn't work (returns a zero value). Probably because the window it is used on is invisible.

  6. #6
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: Image Monitor

    SetForegroundWindow ought to work because when the tray icon was right-clicked, the focus transferred to that icon's owner hWnd (set by NOTIFYICONDATA.hWnd). It is a known bug with tray icons and context menus. If SetForegroundWindow isn't called, the context menu is left open even when clicking other windows. SetForegroundWindow fixes that. Google other examples of tray icons and you'll see what I mean.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,945

    Re: Image Monitor

    Quote Originally Posted by Bonnie West View Post
    SetForegroundWindow ought to work because when the tray icon was right-clicked, the focus transferred to that icon's owner hWnd (set by NOTIFYICONDATA.hWnd). It is a known bug with tray icons and context menus. If SetForegroundWindow isn't called, the context menu is left open even when clicking other windows. SetForegroundWindow fixes that. Google other examples of tray icons and you'll see what I mean.
    SetForegroundWindow works now. Must have overlooked something. I did do a search and found other sites where SetForegroundWindow was recommended. Thanks.

Tags for this Thread

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