eBook Display puzzle
Moderators: Alexander Halser, Tim Green
eBook Display puzzle
Hello,
I have created an eBook with separate viewer and help file.
From my program, I wish to open the ebook and show some help, then allow the ebook to be minimised. Next time the program requests help, the ebook is to open up again and display the next topic requested.
What is actually happening, and the same thing happens when I use cmd.exe to test, is that the first time the ebook is opened, the display works as expected. It is then minimised. When the next request to display is issued, the icon in the task bar flashes but does not reopen without being clicked.
Strangely, if I run the application in the Delphi debugger, it does reopen as expected.
I have had this working in a previous application. Currently I am using 7.5.1, so it may be related to this.
Has anyone else seen anything similar that might give me a clue as to what is going on ?
In my program, I am using CreateProcess rather than ShellExecute, but as cmd.exe shows the same symptoms I think that is not related. I've tried 2 different computers using cmd.exe and both show the same issue.
TIA,
Sue
I have created an eBook with separate viewer and help file.
From my program, I wish to open the ebook and show some help, then allow the ebook to be minimised. Next time the program requests help, the ebook is to open up again and display the next topic requested.
What is actually happening, and the same thing happens when I use cmd.exe to test, is that the first time the ebook is opened, the display works as expected. It is then minimised. When the next request to display is issued, the icon in the task bar flashes but does not reopen without being clicked.
Strangely, if I run the application in the Delphi debugger, it does reopen as expected.
I have had this working in a previous application. Currently I am using 7.5.1, so it may be related to this.
Has anyone else seen anything similar that might give me a clue as to what is going on ?
In my program, I am using CreateProcess rather than ShellExecute, but as cmd.exe shows the same symptoms I think that is not related. I've tried 2 different computers using cmd.exe and both show the same issue.
TIA,
Sue
- Martin Wynne
- Posts: 2656
- Joined: Mon May 12, 2003 3:21 pm
- Location: West of the Severn, UK
Re: eBook Display puzzle
Hi Sue,
You need to use SW_RESTORE in ShellExecute:
cheers,
Martin.
You need to use SW_RESTORE in ShellExecute:
Code: Select all
if ShellExecute(handle,'open',PChar(file_name),nil,nil,SW_RESTORE)<=32
then begin
ShowMessage('error......
Martin.
Re: eBook Display puzzle
Hi Martin,
Thanks for the suggestion. I tried it out, but it still doesn't work.
It seems that the difference between what I am doing, using a separate viewer and help file, and the snip you gave, which uses an integrated viewer, might be the cause of the problem.
I open the file with this, where sCmdLine gives the help file and topic id.
ShellExecute(0,'open',PChar(FHelpViewer),PChar(sCmdLine),nil,SW_SHOW);
Subsequent calls use this
ShellExecute(lProcHandle,'open',PChar(FHelpViewer),PChar(sCmdLine),nil,SW_RESTORE);
where lProcHandle is (should be) the window handle of the running instance of the HelpView.
I also tried, with the same result,
ShellExecute(0,'open',PChar(FHelpViewer),PChar(sCmdLine),nil,SW_RESTORE);
I have also tried using ShowWindow with CreateProcess and CreateProcess with SW_RESTORE in the startup info flags. According to my reading of MSDN, this should work.
Everything I have tried causes the icon in the tray to blink, but does not restore the window.
If I don't specify use a separate help file, the running instance does restore.
Cheers
Sue
Thanks for the suggestion. I tried it out, but it still doesn't work.
It seems that the difference between what I am doing, using a separate viewer and help file, and the snip you gave, which uses an integrated viewer, might be the cause of the problem.
I open the file with this, where sCmdLine gives the help file and topic id.
ShellExecute(0,'open',PChar(FHelpViewer),PChar(sCmdLine),nil,SW_SHOW);
Subsequent calls use this
ShellExecute(lProcHandle,'open',PChar(FHelpViewer),PChar(sCmdLine),nil,SW_RESTORE);
where lProcHandle is (should be) the window handle of the running instance of the HelpView.
I also tried, with the same result,
ShellExecute(0,'open',PChar(FHelpViewer),PChar(sCmdLine),nil,SW_RESTORE);
I have also tried using ShowWindow with CreateProcess and CreateProcess with SW_RESTORE in the startup info flags. According to my reading of MSDN, this should work.
Everything I have tried causes the icon in the tray to blink, but does not restore the window.
If I don't specify use a separate help file, the running instance does restore.
Cheers
Sue
- Martin Wynne
- Posts: 2656
- Joined: Mon May 12, 2003 3:21 pm
- Location: West of the Severn, UK
Re: eBook Display puzzle
Hi Sue,
Have you tried associating the help file extension with the viewer, and then ShellExecute to open the help file instead of the viewer?
cheers,
Martin.
Have you tried associating the help file extension with the viewer, and then ShellExecute to open the help file instead of the viewer?
cheers,
Martin.
Re: eBook Display puzzle
Hi Martin,
Good thought. Unfortunately the result is the same - the icon blinks but the ebook does not restore.
It must be almost working, because it doesn't create multiple instances of the ebook, either way.
Strangely, it does work if I run the app in the debugger. This makes me wonder if it is related to how the ebook is created.
Cheers
Sue
Good thought. Unfortunately the result is the same - the icon blinks but the ebook does not restore.
It must be almost working, because it doesn't create multiple instances of the ebook, either way.
Strangely, it does work if I run the app in the debugger. This makes me wonder if it is related to how the ebook is created.
Cheers
Sue
Re: eBook Display puzzle
I have encountered this issue with other applications, but in the end found other ways to achieve the desired result, because both processes were my own.
There is a discussion which describes almost exactly your symptoms, including working only under a debugger, at:
https://social.msdn.microsoft.com/Forum ... m=winforms. Yes, it's C++, but all about Win32 calls. Yes, it is ancient, but the last two posts are Win10 and this year, so persevere! But in the end, some of the suggestions appear to work only some of the time. I was not familiar with SwitchToThisWindow(), but read Raymond Chen before you try this, at: https://devblogs.microsoft.com/oldnewth ... 00/?p=9183
The last line of Raymond's article mentions 'foreground change permission', and the trail goes cold there, for me. However I do recall reading that Windows 10 introduced new rules about what applications are allowed to do to activate windows in other processes, and new barriers to making things easy.
You may also find some hints at https://stackoverflow.com/questions/231 ... pplication
There is a discussion which describes almost exactly your symptoms, including working only under a debugger, at:
https://social.msdn.microsoft.com/Forum ... m=winforms. Yes, it's C++, but all about Win32 calls. Yes, it is ancient, but the last two posts are Win10 and this year, so persevere! But in the end, some of the suggestions appear to work only some of the time. I was not familiar with SwitchToThisWindow(), but read Raymond Chen before you try this, at: https://devblogs.microsoft.com/oldnewth ... 00/?p=9183
The last line of Raymond's article mentions 'foreground change permission', and the trail goes cold there, for me. However I do recall reading that Windows 10 introduced new rules about what applications are allowed to do to activate windows in other processes, and new barriers to making things easy.
You may also find some hints at https://stackoverflow.com/questions/231 ... pplication
Re: eBook Display puzzle
Thanks for those references. I have had a look at them, and realised some of the code I was using to bring the window to the front used the wrong handle. I haven't yet fixed the code.
I'm not sure what has changed, but the behaviour now is slightly different.
The second call is causing the help window to be displayed, but it is under other screens. I have had a look at trying to get it back as the foreground window, and although I think it should be able to be done using ShowWindow or some other WinAPI function, it seems to me that the EBook should be doing this for itself.
Like you, I have programs that I control that do restore properly when requested (as a mechanism to have only one running instance).
I would like to know what the expected behaviour is in this case, and whether I need to continue to work on getting it to display, or whether it is a little bug in the Ebook code when the viewer uses a separate file.
An ebook I created in July last year for a different application does redisplay the help and bring it to the front.
Cheers
Sue
I'm not sure what has changed, but the behaviour now is slightly different.
The second call is causing the help window to be displayed, but it is under other screens. I have had a look at trying to get it back as the foreground window, and although I think it should be able to be done using ShowWindow or some other WinAPI function, it seems to me that the EBook should be doing this for itself.
Like you, I have programs that I control that do restore properly when requested (as a mechanism to have only one running instance).
I would like to know what the expected behaviour is in this case, and whether I need to continue to work on getting it to display, or whether it is a little bug in the Ebook code when the viewer uses a separate file.
An ebook I created in July last year for a different application does redisplay the help and bring it to the front.
Cheers
Sue
Re: eBook Display puzzle
A few further tests on my older application show that sometimes the EBook is brought to the front, and sometimes not. I haven't yet worked out the pattern.
Re: eBook Display puzzle
Just as I was about to give up on separate help exe and data files, and revert to the integrated viewer, I did get this working.
I do think there is an issue in the EBook not coming to the foreground and can only assume that most people use the integrated viewer. Tests run using cmd.exe continue to fail.
Sue
I do think there is an issue in the EBook not coming to the foreground and can only assume that most people use the integrated viewer. Tests run using cmd.exe continue to fail.
Sue