VB6 - Add exception to TopMost - exception

I have been searching this for few hours, but without proper results. What I want to do, is make an external window to topmost, over my form1. So my form1 is topmost, but when default browser is opened via shellexecute, it should stay on top, until closed.
My code is:
Dim r As Long
r = ShellExecute(0, "open", "http://www.google.com", 0, 0, 1)
And when "google.com" is opened, the default browser should stay on top, until closed as I mentioned earlier.
Is there any decent solution available? If so, I would appreciate if anybody could tell me how to do it.

Use WaitForSingleObject winapi function to wait till the browser window is closed. Check the following links for the same:
How to wait for a shell process to finish before executing further code in VB6
http://www.ex-designz.net/apidetail.asp?api_id=539
http://us.generation-nt.com/answer/how-start-notepad-modal-dialog-vb-application-help-54054422.html

have a look at the SetWindowPos API
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

If both your window, and the browser window are top most. then you can put code in your application's activation event so that:
SetWindowPos(browserHandle, Me.hwnd, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE);
for getting the browser handle you need to use ShellExecuteEx instead of ShellExecute. That will give you an hProcess. Using that you EnumWindows() and see which windows have that GetWindowThreadProcessID(). Then you store those windows in a list, and iterate over them calling the SetWindowPos api so that they go behind your form's handle.
If your form is an MDI parent, you can consider making the browser an MDI Child as any window can become an MDI child.

Related

LWJGL Game loop pauses whenever the GLFW window head is clicked

I have a very simple game loop.
public void gameLoop() {
long now;
long updateTime;
long wait;
final int TARGET_FPS = 60;
final long OPTIMAL_TIME = 1000000000 / TARGET_FPS;
while (!window.shouldClose()) {
now = System.nanoTime();
update();
render();
frame++;
updateTime = System.nanoTime() - now;
wait = (OPTIMAL_TIME - updateTime) / 1000000;
try {
Thread.sleep(wait);
} catch (Exception e) {
}
}
glfwTerminate();
}
Whenever I click the head of the window (the bar where the close and minimize buttons are), the loop for some reason pauses. The sounds in game continue to play (I use AL10), so this causes music and sounds to get out of sync with the game. I want to pause the window whenever this happens.
I but looking through the GLFW callbacks, there doesn't seem to be one which fixes this. The focus callback only works if I click outside of the window, and the windowPos callback only works whenever the window is moved, NOT when you simply click and hold the window head.
Is there a way to fix this problem.
This is actually expected behaviour on some platforms like Windows, where effectively glfwPollEvents will block inside of a Win32 API call for as long as you hold down the mouse button and/or potentially drag/move the window around.
In order to fix this, you should make your game loop independent of the window event processing loop, by using separate threads.
The main thread must be the one that is doing the window event processing (glfwPollEvents or glfwWaitEvents) to stay consistent with the requirements of some other platforms like macOS where this is a requirement, while another thread can do the game update and rendering.

ActiveX hosted by IE: how to render DirectShow EVR inside an IE's HTML dom object

I'm trying to display a video in Internet Explorer with my own ActiveX control.
I created the ActiveX control and a demo HTML page creating the control using the OBJECT tag (and setting a width/height on it). I can call simple methods on this control through javascript, it works.
I also created a working directshow graph to display the video. The graph contains a "Enhanced Video Renderer" (EVR) renderer filter.
But i am stuck : i can not find a way to link these 2 technologies. Some MSDN doc says the EVR should use WindowLess activation. But this activation requires a hWnd and a rectangle inside the hWnd. My ActiveX is hosted in Internet Explorer, how can i get the hWnd and make the renderer render at the correct position/size in this window ?
Note that I know how to get the object's absolute rectangle in javascript and give it to the ActiveX. But this rectangle may move with the scrollbar ? And how to get this damn hWnd ?
EDIT
It seems the ActiveX needs to implement the IOleInPlaceObjectWindowless interface which has a SetObjectRects methods called by the host, and should query the host for the IOleWindow interface which has a GetWindow method returning the hWnd.
EDIT 2
It seems all you have to do is implmenet IComponent to retreive an ISite host interface on which you can query any service you need.

VBA IE Automation: Get URL from within element

I am trying to get the URL from inside the second element in the "pShowMore" class.
I have this:
For Each wd In CreateObject("Shell.Application").Windows
If InStr(wd.LocationName, "Institution") <> 0 Then
Exit For
End If
Next wd
Dim newURL As String
newURL = wd.document.getElementsByClassName("pShowMore").getElementsByTagName("a")(1).getAttribute("href")
And I get the error: 438-"Object doesn't support the property or method" for the retrieval (i.e., wd.document.....)
What can I do to get the URL in the href?
Also, why does it not support the property or method?
It turns out I was just getting an error cycling through the open windows.
I used
On Error Resume Next
This solved the specific problem I was having.

What does __ mean when it is part of a function name

I have been looking for a way to code the popup window to perform some action in the parent window here on SO. Somewhere in one of the posts I read a suggestion that the "inspect element" option in browsers is a good way to learn. With this option I got the code for the session timeout popup from my host. Here is the part that I am trying to understand:
function fireTimeoutEvent()
{
__doPostBack('','#####forceSessionTimeout');
}
function __doPostBack(eventTarget, eventArgument)
{
var theform = document.Form1;
theform.__EVENTTARGET.value = eventTarget;
theform.__EVENTARGUMENT.value = eventArgument;
theform.submit();
}
What do the "__" mean in the four lines of the code? Do they have a special significance? Am I correct in thinking this is javascript? I ask because I am not familiar enough with the niceties of javascript, jquery and the rest to be able to recognize the difference.
Also, from this script, is it possible to tell what it is going to do? Though the popup is essentially meant to extend the session, it has some other functions besides this one, but none of the others have any under-scores in them.
Usually library writers use _ or __ to indicate private functions or methods. So this is probably something that the person didn't want people to call directly.

Implement anchor onclick event using HTML document object from Excel VBA

I am trying to implement an onclick event for an anchor tag on a website from Excel VBA. The following code gives me error message.
Set iePage = ieApp.document
Set ieAnchor = iePage.getElementsByTagName("A").Item(5)
ieAnchor.onclick = true
The error message is a run time error that says Not Implemented
Can someone please advise on getting this event to fire?
BTW, I've used the basic iePage.Links(1).click event without a problem...
but I need to execute a javascript function called from the anchor onclick event.
If I understand your question correctly, you are trying to respond in VBA to the user clicking an anchor? If so you need to create an EventHandler for OnClick event. To do this you must restructure your code to meet the following criteria:
You must declare said Anchor variable using the "WithEvents" keyword in order to respond to events.
To use the "WithEvents" keyword you must declare your Anchor variable at the module level.
You must also be inside a Class module to use the WithEvents keyword.
Finally you need to create the Event Handler itself via the drop down menus in the top of the VBE or just paste in the code below. How to use the code:
Create a Class Module named "MyClass" and paste in the following:
Option Explicit
Private WithEvents ieAnchor As MSHTML.HTMLAnchorElement
Public Sub Main()
Dim iePage As MSHTML.HTMLDocument
Set iePage = ieApp.document
Set ieAnchor = iePage.getElementsByTagName("A").Item(5)
End Sub
Private Function mobjMyAnchor_onclick() As Boolean
''//Your Code Here
End Function
To use the code in the class you can then add a standard module and call the code like this:
Public Sub Example()
Dim objMyClassVariable As MyClass
Set objMyClassVariable = New MyClass
objMyClassVariable.Main
End Sub
Edit:
To call a JavaScript function you can just use the JavaScript URL scheme with the InternetExplorer.Navigate method. Ex: ie.Navigate "JavaScript:SomeFunc()". Or you can actually just cause the click to occur using the HTMLAnchorElement.Click method: ieAnchor.Click.