Ms Access CHM Help File Can't Get Focus - vba

I'm opening a custom help file (CHM) using VBA and the api 'HtmlHelp', eg:
hWnd = HtmlHelp(Application.hWndAccessApp, sFile, HH_HELP_CONTEXT, context_id)
The Help file opens, but it's hidden behind the Access window, and although it's icon is displayed in the Taskbar, clicking the icon still does not bring it to the foreground - it remains hidden behind Access.
When I first started testing the Help file (on a Win8.1 machine), it opened correctly in front of the Access window, but now it won't. Does anyone have any suggestions as to what is causing this behaviour?

Some thoughts only - but be careful with the first hint:
Which purpose does the file hh.dat serve?
The hh.dat file stores user-specific information on all the HTMLHelp files (*.CHM) on your system (position, favourite topics, search history, etc.), and can cause a error if it has somehow been corrupted.
Delete or rename the file hh.dat to reset all (!) CHM windows on your system to their default settings.
You should find hh.dat in this directory:
\Documents and Settings\%username%\Application Data\Microsoft\HTML Help
Windows will create a new version of hh.dat when you next open any .chm file.
According to Microsoft's HTML Help API documentation (http://msdn2.microsoft.com/en-us/library/ms644703(VS.85).aspx):
Any help window that you create through the HTML Help API is owned by the calling, or parent, program. This allows the help window to stay on top of its parent, yet not be on top of any other program that has focus.
So the fact that the help window retains focus is actually the standard behaviour.
If you look at a typical HTML Help API call, you'll see that the first parameter specifies the "handle" of the window from which help is called:
HtmlHelp(hwndCaller,"YourHelpFile.chm",HH_HELP_CONTEXT,1001);
If the developer passes "null" rather than the window handle as the first parameter of the call, the help window is no longer owned by the calling program, and so does not retain focus. Here is an example of a modified call:
HtmlHelp(0,"YourHelpFile.chm",HH_HELP_CONTEXT,1001);
There's a drawback to this, though: when called in this way, the help window is no longer bound by the actions of the calling program. So if the user closes or minimises the program, the help window isn't closed or minimised as well.

I see you have hWnd – do you think you can add a code to send the help window to the foreground programmatically?
You can call SetForegroundWindow() to do the job. Someone has solved similar problem already, you just need to port call to SetForegroundWindow() or SetForegroundWindowNative() into the VBA.
EDIT: You report weird behavior that SetForegroundWindow() makes help window to flash only briefly.
Try issuing VBA's AppActivate command – it has helped someone else.
If this problem persists, you can try some workaround like resizing your app and help window to show them side-by-side.

Related

How do we run a pharo program without instantiating an object in the playground?

I wrote a Pharo program that generates my daily task non-stop.
The program itself works fine, however I always need to instantiate my object in the playground to run it. Is there some other way of doing it automatically without having to create an object and send a message to it?
Yes, you can. Save the image after you have instantiated your application and closed everything else. Then just start pharo from the image and you will have your application started.
If you want to do it more production wise you could use pharo-launcher.
For more detailed information you could squeak wiki which you can adjust to Pharo.
I would do one of three thing here:
Add an item to the World menu, so you can bring up the menu and select your task. See a Stackoverflow Answer on that same topic.
You could write some triggering code in a .st file on your file system, then use StartupPreferencesLoader to load it on startup.
Create a window morph with a button that, once pressed, runs your code. Open the window, quit and save image changes. Never close the window.

ShowFileDialog1 Freezing

Okay, I have had the most aggravating problem with OpenFileDialog1. I have a program that I've been using for some 8 months, and in the past month, the program has begun to hang randomly when utilizing the OpenFileDialog1.ShowDialog() function. I have already read through all of the other posts about multi-threaded vs single threaded application. This did not fix it. Enabling the "Show Help" button did not fix it. I am mostly at a loss. here is a thorough walkthrough of the bug:
Run the application. I can always use the Open File button a few times with no problems. It freezes randomly after the program has been running for awhile.
The freeze happens after I push the ShowDialog button, and never displays the Open File Dialog window. The entire program locks up and hangs. If I pause it, Visual Studio doesn't show an error. It underlines the OpenFileDialog1.ShowDialog() in green, which is very odd.
I have found a way to break the freeze. Simply run a second instance of the program and use the OpenFileDialog function. As soon as it loads the file in the second instance, the first instance unfreezes. However, this is not a fix.
The only thing I can think of that may be causing this is the program also uses a WebBrowser1 control. It only seems to happen AFTER the WebBrowser control, which is on a seperate form, not the main form, has been initiated and utilized. Does this make any sense at all?
Thank you for anyone who can help me. I am about to tear my hair out.
Debug your program with dnspy, And when the software freezes, you will be able to see within the dnspy the actual code even if it is in a third party DLL.
I have solved this problem. It was quite unsolveable based on my description above, but hopefully I will help someone with this solution. The error is related to using the IE11 Emulation Control (11000) in the WebBrowser1 control. For some reason this interferes with OpenFileDialog and causes it to hang. I have no idea why. I changed my WebBrowser1 to use IE9 Emulation Control (9999) and the error has gone away. Thank you to those who looked into this. This is a registry entry in HKEY_CURRENT_USER.

How to handle external applications in a selenium-test?

I am writing a test that verifies that a warning to the user before the user opens a document. If the user says that they still would like to open the document, the document opens in an external application (pdf or word).
But now I have an external application over the browser window, and it messes up for other tests.
So, what are the best practices around this kind of issue? Rewrite of the appliction to allow for not opening documents in test?
Added description:
The problem is twofold.
1) It starts processes (word and acrobat) that fills the desctop and requires resources from the test-slave
2) The external process seems to interfer with other tests since (guessing here) it is located over the browser window.
what i understood from your post is, the document(word/pdf) is opening in the browser window hence you are not able to proceed with further steps. If so, you can verify the Title to make sure the document is opened in browser window and can navigate back using below snippet.
driver.navigate().back();
Hope this helps.
What I understand from the line
'But now I have an external application over the browser window, and it messes up for other tests.'
is that once user clicks on open button a new window opens up (Window based application) since you have mentioned PDF or Word.
You can use robot class in such cases, below code snippet will close the current active window:
Robot rbt = new Robot();
rbt.keyPress(KeyEvent.VK_ALT);
rbt.keyPress(KeyEvent.VK_F4);
rbt.keyRelease(KeyEvent.VK_ALT);
rbt.keyRelease(KeyEvent.VK_F4);
Make sure you deal with sync issues properly so that intended window is closed instead of AUT.

How can I send clicks or keys from a VB6 app to an Excel dialog box?

My employer has purchased a third-party tool, OfficeConverter from Conveter Technology that automates the conversion / repair of Office 2003-formatted files to Office 2007 format. This tool also highly automates the translation / change in macro / VBA code requirements between Office 2003 and 2007 formats.
My problem is that during this conversion the tool is opening the targeted Office product, say Excel and is then opening the target user file (ie. Report.xls) and is then examining any VBA / macro code for change requirements. The problem is that IF the Excel file code is dependent upon some external tool like an .OCX file and if that tool doesn't exist on the PC that I'm performing this action on, Excel will pop up a message that the Object has not been found, stopping the entire conversion process (thousands of files in a row) until someone comes along and MANUALLY clicks the appropriate button to close the dialogue box.
I figured that creating a small watching application in VB6 (hey, I'm old and my skills are too) could sit on the same PC and watch for these dialogue boxes and, depending on the specific message, click the appropriate button via the SendMessage API call.
The problem is that I haven't been able to get SendMessage to actually PUSH the button for me, I've tried sending it the Return key value (vbKeyReturn) or even the Space key (vbKeySpace) but the action never results in the dialogue box closing like it should. I can get the focus to tab between whichever buttons on the dialogue box are enabled, but that is about it.
I've attempted to use SendKeys, but that is far less reliable and strongly discouraged in the current documentation that I've come across.
Any suggestions? :)
If you have the hWnd for the button, and the machine is unattended, you can easily use MouseEvent to move the cursor over the button and click it. This sample includes a drop-in ready module that'll do the dirty work for you given just the window handle:
http://vb.mvps.org/samples/MouseEvent
Otherwise, the most straightforward way is probably to just send WM_LBUTTONDOWN and WM_LBUTTONUP sequentially.
EDIT: If you "just want to get it done" take Jim's advice and try Gary Chanson's Window Demon tool.
Take a look at this utility "Window Demon" by Gary Chanson
Karl: how quickly we forget our pals!
I would suggest taking a look at AutoIt.
It is perfect for this task, look for a window with a particular text on it and click a button.
Runs in the system tray as a standalone application.

How can I navigate to different webpages in the same MSIE window in VB.NET

I have code that opens a new window but I want to be able to edit the same one.
System.Diagnostics.Process.Start("iexplore.exe", "http://www.live.com")
I'm not sure exactly but a good pointer to start off might be to get the handle of the window you're interested in:
http://www.pocketpcdn.com/articles/dotnetcf_hwnd.html
And then separately investigate what interop messages you can send to IE to change the URL in tab X
In order of increasing difficulty and increased control/power:
Send input text to your IE process. Alt-D to focus on the navigation bar, then the URL, then ENTER.
Use MSAA to find the navigation bar and send it text, as above.
Use MSAA to get IHTMLDocument access to the browser, and then programmatically drive the browser with that, and the related interfaces.
I don't know your exact scenario, but if you can host your own instance of MSHTML, or a WebBrowser control, it will make it a lot easier to get the interfaces and do the manipulations mentioned in #3 above; doing that stuff cross-process is fraught with peril.
I just did a web search and turned up a WatiN tool that apparently wraps a lot of this work; perhaps it would be useful for you.
If you are using 2008 there is a feature where you could create a second form and then add a Webbrowser control
the page could then be called by
myForm.show
The page could then be changed with the
Webbrowser1.Url = New Uri("http://www.google.com")
Use the following code:
System.Diagnostics.Process.Start("http://www.live.com")
That is: do not invoke iexplore.exe directly – just let the system figure out which default browser to open.
This may yield two behaviours:
Either it opens a new tab in an existing Internet Explorer window,
or it creates a new window.
The important point is that this depends on a preference that can be controlled within the Internet Explorer application. If a new window opens, then this is the setting chosen by the user – do not try to override it: overriding the user’s preferences is considered bad manners.
If the users don’t want a new window opened, they can simply change that in their Internet Explorer preferences.