Access Violation using Tray Icons

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
Jerry Thomas
Macro Veteran
Posts: 267
Joined: Mon Sep 27, 2010 8:57 pm
Location: Seattle, WA

Access Violation using Tray Icons

Post by Jerry Thomas » Thu Feb 17, 2011 5:17 pm

I have a script that we are running with multiple 1000 iterations (setting position for a machine tool and then verifying location = expected).

Since it is based on pushing Fwd and Back buttons on the screen, I don't want to keep showing progress in a message and then switching back to the application to push the next button.

I am trying to use the Tray icon as a crude progress indicator.
If Iteration=1/10 of run, show 10.ico
If Iteration=2/10 of run, clear 10.ico and show 20.ico
etc.

After showing 2 or 3 icons, I am getting an Access Violation in MS. (Running or stepping through manually)

Any suggestions on what/how I should fix?

Code: Select all

Let>ICONFldr=%DESKTOP_DIR%\TESTFOLDER
Let>CurTenth=10
While>CurTenth<100>SetTrayIcon
  Let>CurTenth=CurTenth+10
EndWhile

SRT>SetTrayIcon
  DelTrayIcon>CurIcon
  Let>IconFile=%CurTenth%.ico
  AddTrayIcon>%ICONFldr%\%IconFile%,CurIcon,
END>SetTrayIcon
The error seems to be in the DelTrayIcon command. This works except that it shows 10.ico and 20.ico and 30.ico etc.

Code: Select all

Let>ICONFldr=%DESKTOP_DIR%\TESTFOLDER
Let>CurTenth=10
While>CurTenth<100>SetTrayIcon
  Let>CurTenth=CurTenth+10
EndWhile

SRT>SetTrayIcon
//  DelTrayIcon>CurIcon
  Let>IconFile=%CurTenth%.ico
  AddTrayIcon>%ICONFldr%\%IconFile%,CurIcon%CurTenth%,
END>SetTrayIcon
Thanks,
Jerry

[email protected]

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Thu Feb 17, 2011 6:38 pm

Something similar to this might work for you. Windows which are minimized to the task bar usually will show a few characters of their caption. By updating the caption to show your percentage complete, this should be visible while you are actively clicking buttons in a foreground application.

I only played with this a little while. You will need to tweak it for your application. In XP is showed the percentage, but in Vista, the minimized window shrunk so small no part of the caption was visible. Your Windows7 mileage may vary.

Code: Select all

//Show progress in a minimized window caption

Dialog>Dialog1
object Dialog1: TForm
  Left = 364
  Top = 166
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'CustomDialog'
  ClientHeight = 216
  ClientWidth = 439
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = True
  PixelsPerInch = 96
  TextHeight = 13
end
EndDialog>Dialog1




SetDialogProperty>Dialog1,,Caption,10%
SetDialogProperty>Dialog1,,Autosize,True
SetDialogProperty>Dialog1,,BorderIcons,[BiSystemMenu,BiMinimize,BiMaximize]
SetDialogProperty>Dialog1,,WindowState,wsMinimized
Show>Dialog1
Wait>2
SetDialogProperty>Dialog1,,Caption,20%
Wait>2
SetDialogProperty>Dialog1,,Caption,30%
Wait>2
SetDialogProperty>Dialog1,,Caption,40%
Wait>2
SetDialogProperty>Dialog1,,Caption,50%
Wait>2
SetDialogProperty>Dialog1,,Caption,60%
Wait>2
SetDialogProperty>Dialog1,,Caption,70%
Wait>2
SetDialogProperty>Dialog1,,Caption,80%
Wait>2
SetDialogProperty>Dialog1,,Caption,90%
Wait>2
SetDialogProperty>Dialog1,,Caption,100%
Wait>2


Jerry Thomas
Macro Veteran
Posts: 267
Joined: Mon Sep 27, 2010 8:57 pm
Location: Seattle, WA

Post by Jerry Thomas » Thu Feb 17, 2011 7:23 pm

Thanks adroege!

I had tried various message approaches (MS Dialog and VB) but they end up as a flicker and can't be read.

I was trying to use the Taskbar/Tray to avoid the screen focus & refresh problem.

My latest approach (real ugly, I know) opens a batch file using a link.
The title of the link is 10%_Complete, 20%_Complete, etc.

There is 1 flicker as the old window is closed and the new one is opened, but that is only at a change - 10%, 20% etc. The rest of the time the title shows in the Task Bar.
Thanks,
Jerry

[email protected]

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Re: Access Violation using Tray Icons

Post by jpuziano » Thu Feb 17, 2011 9:12 pm

Jerry Thomas wrote:After showing 2 or 3 icons, I am getting an Access Violation in MS. (Running or stepping through manually)

Any suggestions on what/how I should fix?

Code: Select all

Let>ICONFldr=%DESKTOP_DIR%\TESTFOLDER
Let>CurTenth=10
While>CurTenth<100>SetTrayIcon
  Let>CurTenth=CurTenth+10
EndWhile

SRT>SetTrayIcon
  DelTrayIcon>CurIcon
  Let>IconFile=%CurTenth%.ico
  AddTrayIcon>%ICONFldr%\%IconFile%,CurIcon,
END>SetTrayIcon
The error seems to be in the DelTrayIcon command. This works except that it shows 10.ico and 20.ico and 30.ico etc.

Code: Select all

Let>ICONFldr=%DESKTOP_DIR%\TESTFOLDER
Let>CurTenth=10
While>CurTenth<100>SetTrayIcon
  Let>CurTenth=CurTenth+10
EndWhile

SRT>SetTrayIcon
//  DelTrayIcon>CurIcon
  Let>IconFile=%CurTenth%.ico
  AddTrayIcon>%ICONFldr%\%IconFile%,CurIcon%CurTenth%,
END>SetTrayIcon
Marcus, can you reproduce the MS Access Violation error reported above?
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

Jerry Thomas
Macro Veteran
Posts: 267
Joined: Mon Sep 27, 2010 8:57 pm
Location: Seattle, WA

Post by Jerry Thomas » Thu Feb 17, 2011 9:14 pm

This is on Win7 x64, MS=12.1.3

Part of this didn;tt paste correctly:

This line:
While>CurTenthSetTrayIcon

Should be 2 lines:

Code: Select all

While>CurTenth(lessthan)100
  Gosub>SetTrayIcon
Thanks,
Jerry

[email protected]

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Fri Feb 18, 2011 9:54 pm

Jerry Thomas wrote:Since it is based on pushing Fwd and Back buttons on the screen, I don't want to keep showing progress in a message and then switching back to the application to push the next button.
I sort of agree with what adroge inplied in his response, that using an icon in the task bar might not be a great solution for your stated need. And speaking for myself my task bar is always hidden so I'm not going to see anything going on there. Why not use a dialog with a progress bar and use the Stay-on-top technique discussed HERE

Here's a brief sample. The progress bar dialog can be unfocused and still reside on top of other windows. Therefore, focus can stay on your machine tool window.

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 475
  Top = 174
  HelpContext = 5000
  BorderIcons = []
  Caption = 'Progress'
  ClientHeight = 20
  ClientWidth = 400
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object ProgressBar1: TProgressBar
    Left = 0
    Top = 0
    Width = 400
    Height = 20
    TabOrder = 0
  end
end
EndDialog>Dialog1
Show>dialog1

LibFunc>User32,SetWindowPos,swpr,dialog1.handle,-1,0,0,0,0,83

MoveWindow>Progress,10,10
Let>percent=0

Label>Loop
  Wait>0.5
  Add>percent,5
  SetDialogProperty>Dialog1,Progressbar1,Position,percent
  If>percent=100
    Wait>2
    Exit>0
  EndIf
Goto>Loop

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Fri Feb 18, 2011 10:23 pm

JRL wrote:Here's a brief sample. The progress bar dialog can be unfocused and still reside on top of other windows. Therefore, focus can stay on your machine tool window.
Thanks for that example JRL, it works great uncompiled.

However, if one needs to run the macro compiled, it won't work, the progressbar dialog will not stay-on-top of other windows.

You could use a SetFocus> line inside the main loop that continually would keep popping the progressbar dialog back on top... but that's intrusive because it gives it keyboard focus as well... i.e. the user may be trying to switch to another window to click a button or enter something but keyboard focus would be continually be shifted back to the progressbar dialog and I'm sure that's not what is wanted.

I have asked Marcus about the possibility of getting some sort of StayOnTop: Y/N property added to a v12 dialog... Marcus, it that already or can that please be added to the wish list?

Or... does anyone else have a method to make a dialog StayOnTop even if run compiled... and without stealing keyboard focus... you should be able to switch to other apps and work with them without having keyboard focus stolen away.
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Fri Feb 18, 2011 10:35 pm

I think I stated this before but if not sorry cause I've known it since this was first discussed. All you need do to keep the dialog on top when compiled is move the dialog. Get its location and move it to the location it is already in. In the sample above, put a line in the loop that moves the dialog to 10,10 and it will stay on top when compiled.

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 475
  Top = 174
  HelpContext = 5000
  BorderIcons = []
  Caption = 'Progress'
  ClientHeight = 20
  ClientWidth = 400
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object ProgressBar1: TProgressBar
    Left = 0
    Top = 0
    Width = 400
    Height = 20
    TabOrder = 0
  end
end
EndDialog>Dialog1
Show>dialog1

LibFunc>User32,SetWindowPos,swpr,dialog1.handle,-1,0,0,0,0,83

MoveWindow>Progress,10,10
Let>percent=0

Label>Loop
  Wait>0.5
  Add>percent,5
  SetDialogProperty>Dialog1,Progressbar1,Position,percent
  If>percent=100
    Wait>2
    Exit>0
  EndIf
  MoveWindow>Progress,10,10
Goto>Loop

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Sat Feb 19, 2011 6:11 am

JRL wrote:I think I stated this before but if not sorry cause I've known it since this was first discussed. All you need do to keep the dialog on top when compiled is move the dialog. Get its location and move it to the location it is already in. In the sample above, put a line in the loop that moves the dialog to 10,10 and it will stay on top when compiled.
I tried this and it works compiled... :shock: It would be nice to know why this works... can anyone explain it?

In any case, its great to be able to make a dialog stay-on-top, even when compiled, so thanks JRL, much appreciated.
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

Jerry Thomas
Macro Veteran
Posts: 267
Joined: Mon Sep 27, 2010 8:57 pm
Location: Seattle, WA

Post by Jerry Thomas » Mon Feb 21, 2011 3:45 pm

I like this!

I can use the Caption bar % and the 'stay on top' technique to get what I need without a fluttering image.

Thanks for the help!
Thanks,
Jerry

[email protected]

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Mon Feb 21, 2011 7:06 pm

Jerry,

If you're using version 12 be sure to read the recent post by Rain located HERE. It is a much easier way to make your dialog stay on top.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts