saratkumar43 Absent Member.
Absent Member.
885 views

Launch an application(website) and send it to second monitor

Jump to solution

Hi,

 

I am trying to open a website and send it to second monitor from my visual cobol winforms application.

So i have tried "System.Diagnostics.Process::Start" to launch a website, but i am not able to send it to second monitor. By default website gets triggered in primary monitor.

I have read an article that using WinApi.SetWindowPos , i can switch the monitor positions but in visual cobol i do not see this WinApi class.

If this is not supported, is there any other way to fulfill my requirement ?

 

Thank you.

0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Launch an application(website) and send it to second monitor

Jump to solution

You can call directly to a WinAPI function like you would in native COBOL using the call program syntax.

 program-id. Program1.
special-names.
call-convention 74 is winapi.
working-storage section.
78 SWP_NOSIZE value h'0001'.
78 SWP_NOOWNERZORDER value h'0200'.

01 pp procedure-pointer.
01 proc type System.Diagnostics.Process.
01 hwnd type IntPtr.

01 xpos binary-long.
01 ypos binary-long.

procedure division.
     set proc to type System.Diagnostics.Process::Start("notepad.exe")
     invoke proc::WaitForInputIdle()
     set hwnd to proc::MainWindowHandle

     set xpos to 10
     set ypos to 12

     set pp to entry "User32"
     call winapi "SetWindowPos" using by value hwnd
                              by value 0
     by value xpos
     by value ypos
     by value 0
     by value 0
     by value SWP_NOSIZE b-or SWP_NOOWNERZORDER
    goback.
end program.
0 Likes
3 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Launch an application(website) and send it to second monitor

Jump to solution

You can call directly to a WinAPI function like you would in native COBOL using the call program syntax.

 program-id. Program1.
special-names.
call-convention 74 is winapi.
working-storage section.
78 SWP_NOSIZE value h'0001'.
78 SWP_NOOWNERZORDER value h'0200'.

01 pp procedure-pointer.
01 proc type System.Diagnostics.Process.
01 hwnd type IntPtr.

01 xpos binary-long.
01 ypos binary-long.

procedure division.
     set proc to type System.Diagnostics.Process::Start("notepad.exe")
     invoke proc::WaitForInputIdle()
     set hwnd to proc::MainWindowHandle

     set xpos to 10
     set ypos to 12

     set pp to entry "User32"
     call winapi "SetWindowPos" using by value hwnd
                              by value 0
     by value xpos
     by value ypos
     by value 0
     by value 0
     by value SWP_NOSIZE b-or SWP_NOOWNERZORDER
    goback.
end program.
0 Likes
saratkumar43 Absent Member.
Absent Member.

RE: Launch an application(website) and send it to second monitor

Jump to solution
Hi Ted,

Thanks for the sample code. It works as expected for notepad but when i tried to fire google.com, website was invoked but there was an exception in the next line of code

After launching the website, my app throws an exception "Object reference not set to an instance of an object" at
invoke proc::WaitForInputIdle()

So i have commented the above line, the same exception was raised at "set hwnd to proc::MainWindowHandle"


I have modified the code as below assuming that the object proc is not set to an instance

set proc to new System.Diagnostics.Process()
set proc::StartInfo::FileName to "http://google.com/search?q=dog pics"
invoke proc::Start()

But now after invoking the website new exception is raised "No process is associated with this object"

Thanks in advance for your help...
0 Likes
Micro Focus Expert
Micro Focus Expert

RE: Launch an application(website) and send it to second monitor

Jump to solution
That's strange, when I try it, proc is set to the process of the browser that the URL opened in. I am not sure why it wouldn't work.

As this issue is Windows, .NET specific, you might be able to find an answer on StackOverflow. The answers to the following post might be of some help:
stackoverflow.com/.../process-start-returns-null
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.