<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>家有小虎 &#187; 窗口</title>
	<atom:link href="http://jiahu.net/tag/%e7%aa%97%e5%8f%a3/feed" rel="self" type="application/rss+xml" />
	<link>http://jiahu.net</link>
	<description>我在路上, 你不在身旁. 想你的时候, 温暖依然.</description>
	<lastBuildDate>Sun, 15 Jan 2012 03:12:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>SBO 调用模态与非模态窗体</title>
		<link>http://jiahu.net/sbo-%e8%b0%83%e7%94%a8%e6%a8%a1%e6%80%81%e4%b8%8e%e9%9d%9e%e6%a8%a1%e6%80%81%e7%aa%97%e4%bd%93.htm</link>
		<comments>http://jiahu.net/sbo-%e8%b0%83%e7%94%a8%e6%a8%a1%e6%80%81%e4%b8%8e%e9%9d%9e%e6%a8%a1%e6%80%81%e7%aa%97%e4%bd%93.htm#comments</comments>
		<pubDate>Fri, 25 Jan 2008 10:28:07 +0000</pubDate>
		<dc:creator>@ouc</dc:creator>
				<category><![CDATA[工作]]></category>
		<category><![CDATA[技术]]></category>
		<category><![CDATA[SAP]]></category>
		<category><![CDATA[代码]]></category>
		<category><![CDATA[窗口]]></category>

		<guid isPermaLink="false">http://cngator.net/?p=249</guid>
		<description><![CDATA[SBO显示非模态窗体 “itemEvent” viewWinForm vWForm =new ViewWinForm(); Thread T=new Thread(new ThreadStart(vWForm.view)); t.SetApartmentState(ApartmentState.STA); t.start(); CLASS ViewWinForm { Private bool run; Form oForm; public ViewWinForm() { //构造函数 oForm=new Form(); oForm.FormClosed+=new ormClosedEventHandler(form_FormClosed); } public void view() { run = true; form.Show(); while (run) { &#8230; <a href="http://jiahu.net/sbo-%e8%b0%83%e7%94%a8%e6%a8%a1%e6%80%81%e4%b8%8e%e9%9d%9e%e6%a8%a1%e6%80%81%e7%aa%97%e4%bd%93.htm">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>SBO显示非模态窗体<br />
“itemEvent”<br />
viewWinForm vWForm =new ViewWinForm();<br />
Thread T=new Thread(new ThreadStart(vWForm.view));<br />
t.SetApartmentState(ApartmentState.STA);<br />
t.start();</p>
<p>CLASS ViewWinForm<br />
{</p>
<p>Private bool run;<br />
Form oForm;</p>
<p>public ViewWinForm()<br />
{<br />
//构造函数<br />
oForm=new Form();<br />
oForm.FormClosed+=new ormClosedEventHandler(form_FormClosed);</p>
<p>}</p>
<p>public void view()<br />
{<br />
run = true;<br />
form.Show();<br />
while (run)<br />
{<br />
Application.DoEvents();<br />
Thread.Sleep(1);<br />
}<br />
}</p>
<p>void form_FormClosed(object sender, FormClosedEventArgs e)<br />
{<br />
run = false;<br />
}<br />
}</p>
<p>SBO中显示模态窗体（如:对话框)<br />
摘自https://www.sdn.sap.com/irj/sdn/thread?threadID=45710&amp;tstart=0</p>
<p>After searching the forums for a way to reliably open an open file dialog I didn&#8217;t really find any examples showing what I needed. Anyway, here&#8217;s what I came up with.</p>
<p>There are two problems to deal with:</p>
<p>1. The dialog must be run on a separate thread.<br />
2. The dialog must be modal for the CORRECT INSTANCE of the SAP client window.</p>
<p>With my item events I invoke the dialog with the following code example for an excel file. I was using the try/catch for debugging purposes.</p>
<p>I hope this helps someone out in the future.</p>
<p>GetFileNameClass oGetFileName = new GetFileNameClass();<br />
oGetFileName.Filter = “Excel files (*.xls)|*.xls”;<br />
oGetFileName.InitialDirectory =<br />
Environment.GetFolderPath(Environment.SpecialFolder.Personal);<br />
Thread threadGetExcelFile = new Thread(new ThreadStart(oGetFileName.GetFileName));<br />
threadGetExcelFile.ApartmentState = ApartmentState.STA;<br />
try<br />
{<br />
threadGetExcelFile.Start();<br />
while (!threadGetExcelFile.IsAlive); // Wait for thread to get started<br />
Thread.Sleep(1);  // Wait a sec more<br />
threadGetExcelFile.Join();    // Wait for thread to end</p>
<p>// Use file name as you will here<br />
string strValue = oGetFileName.FileName;</p>
<p>}<br />
catch(Exception ex)<br />
{<br />
_SBO_Application.MessageBox(ex.Message,1,”OK”,”",”");<br />
}<br />
threadGetExcelFile = null;<br />
oGetFileName = null;</p>
<p>The following is my GetFileName class. More properties can be easily added like FileName, Filter, and InitialDirectory were. Change the namespace as appropriate.</p>
<p>using System;<br />
using System.Diagnostics;<br />
using System.Windows.Forms;<br />
using System.Runtime.InteropServices;</p>
<p>namespace MyNamespace<br />
{<br />
///<br />
/// Wrapper for OpenFileDialog<br />
///<br />
public class GetFileNameClass<br />
{<br />
[DllImport( "user32.dll" )]<br />
private static extern IntPtr GetForegroundWindow();</p>
<p>OpenFileDialog _oFileDialog;</p>
<p>// Properties<br />
public string FileName<br />
{<br />
get { return _oFileDialog.FileName; }<br />
set { _oFileDialog.FileName = value; }<br />
}</p>
<p>public string Filter<br />
{<br />
get { return _oFileDialog.Filter; }<br />
set { _oFileDialog.Filter = value; }<br />
}</p>
<p>public string InitialDirectory<br />
{<br />
get { return _oFileDialog.InitialDirectory; }<br />
set { _oFileDialog.InitialDirectory = value; }<br />
}</p>
<p>// Constructor<br />
public GetFileNameClass()<br />
{<br />
_oFileDialog = new OpenFileDialog();<br />
}</p>
<p>// Methods</p>
<p>public void GetFileName()<br />
{<br />
IntPtr ptr = GetForegroundWindow();<br />
WindowWrapper oWindow = new WindowWrapper(ptr);<br />
if (_oFileDialog.ShowDialog(oWindow) != DialogResult.OK)<br />
{<br />
_oFileDialog.FileName = string.Empty;<br />
}<br />
oWindow = null;<br />
} // End of GetFileName<br />
}<br />
}</p>
<p>Edit: Changed namespace to “MyNamespace”</p>
<p>Whoops, I forgot the window wrapper:</p>
<p>using System;</p>
<p>namespace MyNamespace<br />
{<br />
public class WindowWrapper : System.Windows.Forms.IWin32Window<br />
{<br />
private IntPtr _hwnd;</p>
<p>// Property<br />
public virtual IntPtr Handle<br />
{<br />
get { return _hwnd; }<br />
}</p>
<p>// Constructor<br />
public WindowWrapper(IntPtr handle)<br />
{<br />
_hwnd = handle;<br />
}<br />
}<br />
}</p>
<p>来源: <a href="http://www.cnblogs.com/el-net/articles/1036863.html" target="_blank">http://www.cnblogs.com/el-net/articles/1036863.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://jiahu.net/sbo-%e8%b0%83%e7%94%a8%e6%a8%a1%e6%80%81%e4%b8%8e%e9%9d%9e%e6%a8%a1%e6%80%81%e7%aa%97%e4%bd%93.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

