<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Approximatrix Forums — Behaviour of SetCurrentWindow() in Appgraphics]]></title>
	<link rel="self" href="http://forums.approximatrix.com/extern.php?action=feed&amp;tid=906&amp;type=atom" />
	<updated>2023-07-12T15:20:30Z</updated>
	<generator>PunBB</generator>
	<id>http://forums.approximatrix.com/viewtopic.php?id=906</id>
		<entry>
			<title type="html"><![CDATA[Re: Behaviour of SetCurrentWindow() in Appgraphics]]></title>
			<link rel="alternate" href="http://forums.approximatrix.com/viewtopic.php?pid=4152#p4152" />
			<content type="html"><![CDATA[<p>Great! Thanks for the help!</p>]]></content>
			<author>
				<name><![CDATA[Norseman]]></name>
				<uri>http://forums.approximatrix.com/profile.php?id=3879</uri>
			</author>
			<updated>2023-07-12T15:20:30Z</updated>
			<id>http://forums.approximatrix.com/viewtopic.php?pid=4152#p4152</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Behaviour of SetCurrentWindow() in Appgraphics]]></title>
			<link rel="alternate" href="http://forums.approximatrix.com/viewtopic.php?pid=4150#p4150" />
			<content type="html"><![CDATA[<p>We&#039;ve got a fix in for cases where the foreground window is the console.&nbsp; It should be in the next release, which will hopefully be within the next week or so.</p>]]></content>
			<author>
				<name><![CDATA[jeff]]></name>
				<uri>http://forums.approximatrix.com/profile.php?id=2</uri>
			</author>
			<updated>2023-07-12T13:06:05Z</updated>
			<id>http://forums.approximatrix.com/viewtopic.php?pid=4150#p4150</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Behaviour of SetCurrentWindow() in Appgraphics]]></title>
			<link rel="alternate" href="http://forums.approximatrix.com/viewtopic.php?pid=4148#p4148" />
			<content type="html"><![CDATA[<p>You&#039;re correct, <a href="https://simplyfortran.com/docs/appgraphics/windows.html">setcurrentwindow()</a> is documented as bringing the window to the foreground if the application is the current foreground application.&nbsp; I&#039;m not surprised that issues arise when trying to use the feature with a console window, however.&nbsp; &nbsp;The console is created and managed by the operating system, so it does represent a &quot;special case,&quot; and AppGraphics isn&#039;t actually aware of it. </p><p>Regardless, I think the graphics window should still move to the foreground.&nbsp; I&#039;ll have to see why it isn&#039;t happening.</p><p>Bringing the console to the foreground, though, is a little more complicated.&nbsp; We&#039;ll need to use two Windows API calls to make it happen.&nbsp; This routine should bring the console to the foreground:</p><div class="codebox"><pre><code>    subroutine console_to_foreground()
    use iso_c_binding
    implicit none
    
        interface
            function GetConsoleWindow() bind(c, name=&quot;GetConsoleWindow&quot;)
            use iso_c_binding
                type(c_ptr)::GetConsoleWindow
            end function GetConsoleWindow
        end interface
        
        interface
            function SetForegroundWindow(ptr) bind(c, name=&quot;SetForegroundWindow&quot;)
            use iso_c_binding
                type(c_ptr), value::ptr
                logical(kind=c_bool)::SetForegroundWindow
            end function SetForegroundWindow
        end interface
        
        if(SetForegroundWindow(GetConsoleWindow())) then
            Print *, &quot;Console in front&quot;
        else
            Print *, &quot;Console to front failed&quot;
        end if
    
    end subroutine console_to_foreground</code></pre></div><p>It compiles fine in 64-bit mode, but there is some unpleasantness needed for 32-bit mode.</p><p>I&#039;ll look into why <em>setcurrentwindow</em> is behaving the way it is, and we&#039;ll get a fix in this week.</p>]]></content>
			<author>
				<name><![CDATA[jeff]]></name>
				<uri>http://forums.approximatrix.com/profile.php?id=2</uri>
			</author>
			<updated>2023-07-12T11:56:02Z</updated>
			<id>http://forums.approximatrix.com/viewtopic.php?pid=4148#p4148</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Behaviour of SetCurrentWindow() in Appgraphics]]></title>
			<link rel="alternate" href="http://forums.approximatrix.com/viewtopic.php?pid=4147#p4147" />
			<content type="html"><![CDATA[<p>I&#039;m trying to restore an application from the past millennium, which includes handling input/output on a console, as well as intermittent plotting. In other words, it is necessary to switch back and forth (changing focus) between console and plot windows several times.</p><p>Unfortunately, the SetCurrentWindow() subroutine does not seem to work quite as described in the documentation, as can be seen from the example below. Upon initiation, the graphic window becomes active as expected, but after having intermittently activated the console by clicking on it, a subsequent call to SetCurrentWindow() will NOT give full focus back to the graphical window. Although the window accepts output, the title bar remains gray and a call to Getch() to read input does not work, without clicking it. Am I missing something here?</p><p>Also, it would be nice if there was a call to give focus back to the console, without clicking on the window.&nbsp; </p><p>PROGRAM AGtest<br />! ---------------------------------<br />! Testing windowing functions<br />! ---------------------------------<br />&nbsp; &nbsp; &nbsp; USE Appgraphics<br />&nbsp; &nbsp; &nbsp; IMPLICIT NONE<br />&nbsp; &nbsp; &nbsp; INTEGER&nbsp; &nbsp; &nbsp;:: GraphID,PlotWidth,PlotHeight,PXpos,PYpos,IOWait <br />&nbsp; &nbsp; &nbsp; CHARACTER&nbsp; &nbsp;:: GraphHeader*18<br />&nbsp; &nbsp; &nbsp; LOGICAL&nbsp; &nbsp; &nbsp;:: CloseFlag<br />&nbsp; &nbsp; &nbsp; DATA GraphHeader/&#039; * Plot window * &#039;/<br />&nbsp; &nbsp; &nbsp; DATA PlotWidth/800/,PlotHeight/600/,PXpos/600/,PYpos/50/ ! Size and location in pix<br />&nbsp; &nbsp; &nbsp; DATA CloseFlag/.FALSE./ ! I want to close myself<br />!&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Ext. console selected in project options. Write something.<br />&nbsp; &nbsp; &nbsp; WRITE (*,1000)<br />!&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Now open plot window and plot something <br />&nbsp; &nbsp; &nbsp; GraphID = InitWindow(PlotWidth, PlotHeight, GraphHeader,PXpos,PYpos,Closeflag) <br />&nbsp; &nbsp; &nbsp; CALL Setcolor(GREEN)<br />&nbsp; &nbsp; &nbsp; CALL Circle(400,200,100)<br />!&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Now I would want to bring ext. console to front again and write ID of plot window<br />!&nbsp; &nbsp; &nbsp;CALL SetCurrentWindow(How?)<br />&nbsp; &nbsp; &nbsp; WRITE (*,2000) GraphID<br />!&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Userwait in ext. console&nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; READ(*,*) <br />&nbsp; &nbsp; &nbsp; CALL SetCurrentWindow(GraphID) ! Re-focus, bring plot window to front and plot some more<br />&nbsp; &nbsp; &nbsp; CALL Circle(400,200,150)<br />!&nbsp; &nbsp; &nbsp;Use Getch for Userwait in plot window <br />&nbsp; &nbsp; &nbsp; CALL OutTextXY(300,500,&#039; Hit a key to close this window &#039;)<br />&nbsp; &nbsp; &nbsp; IOWait=Getch() <br />&nbsp; &nbsp; &nbsp; CALL CloseWindow(GraphID)<br />&nbsp; &nbsp; &nbsp; READ(*,*) ! To ensure pause when run as executable<br />&nbsp; &nbsp; &nbsp; STOP<br />1000 FORMAT(//,20X,&#039; Hello world!&#039;,///)<br />2000 FORMAT(&nbsp; &nbsp;20X,&#039; GraphID = &#039;,I3,&#039; Hit a key...&#039;)<br />END PROGRAM AGtest</p>]]></content>
			<author>
				<name><![CDATA[Norseman]]></name>
				<uri>http://forums.approximatrix.com/profile.php?id=3879</uri>
			</author>
			<updated>2023-07-12T11:33:49Z</updated>
			<id>http://forums.approximatrix.com/viewtopic.php?pid=4147#p4147</id>
		</entry>
</feed>
