<?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>Windows CE Programming &#187; CodeProject</title>
	<atom:link href="http://www.hjgode.de/wp/category/codeproject/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.hjgode.de/wp</link>
	<description>Windows Mobile Development and usage</description>
	<lastBuildDate>Thu, 29 Jul 2010 14:32:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<!--CodeProjectFeeder channel--><category>CodeProject</category><generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Mobile Development: A battery monitor for the taskbar</title>
		<link>http://www.hjgode.de/wp/2010/07/29/mobile-development-a-battery-monitor-for-the-taskbar/</link>
		<comments>http://www.hjgode.de/wp/2010/07/29/mobile-development-a-battery-monitor-for-the-taskbar/#comments</comments>
		<pubDate>Thu, 29 Jul 2010 14:30:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://www.hjgode.de/wp/?p=720</guid>
		<description><![CDATA[A battery status monitor for the windows mobile taskbar]]></description>
			<content:encoded><![CDATA[<p>Hello</p>
<p>this time I will show how I did a battery monitor that shows on the taskbar. The C source code uses the drawing functions DrawRect and Polygon to draw a battery symbol onto the taskbar. The drawing is updated every second by a background thread, that queries the battery status using GetSystemPowerStatusEx2. The thread then sends the battery flag reading using SendMessage with WM_USER.</p>
<p><a rel="attachment wp-att-722" href="http://www.hjgode.de/wp/2010/07/29/mobile-development-a-battery-monitor-for-the-taskbar/screenshot2_taskbaraddon2/"><img class="alignnone size-full wp-image-722" title="screenshot2_taskbaraddon2" src="http://www.hjgode.de/wp/wp-content/uploads/2010/07/screenshot2_taskbaraddon2.gif" alt="" width="48" height="48" /></a></p>
<p>Why did I write an app that already exists? If you look at your windows mobile taskbar, you will find, that the battery or the clock disappear from the taskbar. They will not be visible in all programs, depending on the space left on the taskbar. If you need to have a battery monitor that is shown all the time, this one may be for you. It will just show all the time on top of the taskbar.</p>
<h2>The code</h2>
<p>The drawings are done from arrays of POINT or RECT structures. So it is easy to change the drawings:</p>
<p><span id="more-720"></span></p>
<pre language="cplusplus" escaped="true">POINT pointsBatt[]={
	{22, 3},
	{4, 3},
	{4, 8},
	{2, 8},
	{2, 16},
	{4, 16},
	{4, 21},
	{22, 21},
	{22, 19},
	{6, 19},
	{6, 5},
	{22, 5}
};

//4 different bars inside batt
RECT rectBatt2[] = {
	{ 7, 7, 10, 17},
	{11, 7, 14, 17},
	{15, 7, 18, 17},
	{19, 7, 22, 17}
};
// a flash sign build as polygon
POINT pointsFlash[] = {
	{13, 2},
	{ 9,12},
	{14,10},
	{13,21},
	{17, 8},
	{12,10},
	{13, 2}
};
</pre>
<p>The drawings were first created on paper and then I entered the coordinates in these arrays (do you know an app, that will allow to draw on screen and then shows/saves an array of points? Let me know).</p>
<p>Depending on the return code send from the background thread, only parts of the drawing are done on the screen to reflect the actual status:</p>
<pre language="cplusplus" escaped="true">		case WM_UPDATESIGNAL: //background thread message, signal is in wParam
			iSignal = (int)wParam;
			DEBUGMSG(1, (L"Received WM_UPDATESIGNAL: %i\n", iSignal));
			//force a wm_paint message
			RECT rtUpdate;
			GetClientRect(g_hWnd, &amp;rtUpdate);
			InvalidateRect(g_hWnd, &amp;rtUpdate, true);
			break;
		case WM_PAINT:

			RECT rt;
			hdc = BeginPaint(hWnd, &amp;ps);
				GetClientRect(hWnd, &amp;rt); //draw text

				//the batt polygon
				hPen = CreatePen(PS_SOLID, 0, colorBatt);
				SelectObject(hdc, hBrBatt);
				SelectObject(hdc, hPen);
				x = sizeof(pointsBatt)/sizeof(POINT);
				Polygon(hdc, pointsBatt, x);

				switch(iSignal){
					case BATTERY_FLAG_HIGH:
						//draw all bars
						// the right bar
						FillRect(hdc, &amp;rectBatt2[0], hbrGreen);
						// the mid bar
						FillRect(hdc, &amp;rectBatt2[1], hbrGreen);
						// the left bars
						FillRect(hdc, &amp;rectBatt2[2], hbrGreen);
						FillRect(hdc, &amp;rectBatt2[3], hbrGreen);
						break;
					case BATTERY_FLAG_LOW:
						//draw two bar
						// the right bar
						FillRect(hdc, &amp;rectBatt2[0], hbrYellow);
						// the mid yellow bar
						FillRect(hdc, &amp;rectBatt2[1], hbrYellow);
						break;
					case BATTERY_FLAG_CRITICAL:
						//draw one bar
						// the right red bar
						FillRect(hdc, &amp;rectBatt2[0], hbrRed);
						break;
					case BATTERY_FLAG_CHARGING:
						//draw flash sign
						//the flash symbol
						hPen = CreatePen(PS_SOLID, 0, colorYellow);
						SelectObject(hdc, hbrYellow);
						SelectObject(hdc, hPen);
						x = sizeof(pointsFlash)/sizeof(POINT);
						Polygon(hdc, pointsFlash, x);
						break;
					case BATTERY_FLAG_NO_BATTERY:
						//draw no bar
					case BATTERY_FLAG_UNKNOWN:
						//draw no bar
					default:
						//draw no bar
						//the batt polygon
						hPen = CreatePen(PS_SOLID, 0, colorUnknown);
						SelectObject(hdc, hbrUnknown);
						SelectObject(hdc, hPen);
						x = sizeof(pointsBatt)/sizeof(POINT);
						Polygon(hdc, pointsBatt, x);
						break;
				};
			EndPaint(hWnd, &amp;ps);
			return 0;
</pre>
<p>I first searched a way to have a free floating window on top of all others before I realized, that I can use the window handle of the taskbar as the parent window handle of my window.</p>
<p><a rel="attachment wp-att-723" href="http://www.hjgode.de/wp/2010/07/29/mobile-development-a-battery-monitor-for-the-taskbar/screenshot_taskbaraddon2/"><img class="alignnone size-medium wp-image-723" title="screenshot_taskbaraddon2" src="http://www.hjgode.de/wp/wp-content/uploads/2010/07/screenshot_taskbaraddon2-225x300.gif" alt="" width="225" height="300" /></a></p>
<p>When you tap and release the stylus on the battery window, you will get a popup menu and there you can exit the application or open the options dialog. The current option dialog only controls the horizontal position of the battery window on the taskbar. Maybe you like to extend the options and enable the user to change colors etc.</p>
<p>The position itself is saved/loaded from the registry. If the rekistry key is missing, it will be created automatically:</p>
<pre language="cplusplus" escaped="true">void saveReg(DWORD dwVal){
	HKEY hKeyRes;
	DWORD dwDispo=0;
	LONG lRes=0;

	//ensure the regKey exists
	lRes = RegCreateKeyEx(HKEY_LOCAL_MACHINE, szRegKey, 0, NULL, REG_OPTION_NON_VOLATILE, 0, NULL, &amp;hKeyRes, &amp;dwDispo);
	//RegOpenKeyEx(HKEY_LOCAL_MACHINE, szRegKey, 0,0, &amp;hKey);
	if( lRes == ERROR_SUCCESS ){
		//save the value
		DWORD dwType = REG_DWORD;
		lRes = RegSetValueEx(hKeyRes, L"position", 0, dwType, (byte*)&amp;dwVal, sizeof(DWORD));
		if(lRes != ERROR_SUCCESS)
			DEBUGMSG(1, (L"RegSetValueEx failed: lRes=0x%0x\n", lRes));
		RegCloseKey(hKeyRes);
	}
	else{
		DEBUGMSG(1, (L"RegCreateKeyEx failed: lRes=0x%0x\n", lRes));
	}
}

DWORD readReg(){
	DWORD dwVal=80;
	HKEY hKey;
	DWORD dwDispo=0;
	LONG lRes=0;

	//ensure the regKey exists
	lRes = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szRegKey, 0,0, &amp;hKey);
	if( lRes == ERROR_SUCCESS ){
		//load the value
		DWORD dwType = REG_DWORD;
		DWORD dwSize = sizeof(DWORD);
		lRes = RegQueryValueEx (hKey, L"position", 0, &amp;dwType, (byte*) &amp;dwVal, &amp;dwSize);
		if(lRes != ERROR_SUCCESS)
			DEBUGMSG(1, (L"RegGetValueEx failed: lRes=0x%0x\n", lRes));
		RegCloseKey(hKey);
		return dwVal;
	}
	else{
		DEBUGMSG(1, (L"RegOpenKeyEx failed: lRes=0x%0x\n", lRes));
		return 80;
	}
}
</pre>
<p>The code is written in Embedded Visual C 4, but you can use it in VS2005/2008 too.</p>
<b>DOWNLOAD:</b><a href="http://www.hjgode.de/wp/wp-content/plugins/download-monitor/download.php?id=110" title="Downloaded 5 times">TaskbarAddon2</a> - A simple battery monitor for the windows mobile taskbar (Hits: 5, size: 15.04 kB)
<p>If you only like to use the app, here is the ArmV4i executable (WM5/6 compatible)</p>
<b>DOWNLOAD:</b><a href="http://www.hjgode.de/wp/wp-content/plugins/download-monitor/download.php?id=111" title="Downloaded 3 times">TaskbarAddon2 executable</a> - A battery status monitor for the windows mobile 5/6 taskbar (Hits: 3, size: 3.9 kB)
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F07%2F29%2Fmobile-development-a-battery-monitor-for-the-taskbar%2F&amp;title=Mobile+Development%3A+A+battery+monitor+for+the+taskbar" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F07%2F29%2Fmobile-development-a-battery-monitor-for-the-taskbar%2F&amp;title=Mobile+Development%3A+A+battery+monitor+for+the+taskbar" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F07%2F29%2Fmobile-development-a-battery-monitor-for-the-taskbar%2F&amp;title=Mobile+Development%3A+A+battery+monitor+for+the+taskbar" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F07%2F29%2Fmobile-development-a-battery-monitor-for-the-taskbar%2F&amp;T=Mobile+Development%3A+A+battery+monitor+for+the+taskbar" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F07%2F29%2Fmobile-development-a-battery-monitor-for-the-taskbar%2F" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F07%2F29%2Fmobile-development-a-battery-monitor-for-the-taskbar%2F&amp;t=Mobile+Development%3A+A+battery+monitor+for+the+taskbar" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.hjgode.de/wp/2010/07/29/mobile-development-a-battery-monitor-for-the-taskbar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>keyToggleChar &#8211; a tool to enter UTF-8 national chars via keyboard</title>
		<link>http://www.hjgode.de/wp/2010/07/19/keytogglechar-a-tool-to-enter-utf-8-national-chars-via-keyboard/</link>
		<comments>http://www.hjgode.de/wp/2010/07/19/keytogglechar-a-tool-to-enter-utf-8-national-chars-via-keyboard/#comments</comments>
		<pubDate>Mon, 19 Jul 2010 11:28:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[Keyboard]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[GetForegroundKeyboardTarget]]></category>
		<category><![CDATA[keyboard]]></category>
		<category><![CDATA[keytogglechar]]></category>
		<category><![CDATA[unicode]]></category>
		<category><![CDATA[utf-8]]></category>

		<guid isPermaLink="false">http://www.hjgode.de/wp/?p=713</guid>
		<description><![CDATA[As you may know my keyToggle app to be able to use the number keys on a windows mobile device as function keys, here is another one that enables you to enter special national chars, like Å, Ä Æ etc. directly via the keyboard. You must specify 10 keys and there UTF-8 replacements. Configuration is done [...]]]></description>
			<content:encoded><![CDATA[<p>As you may know my keyToggle app to be able to use the number keys on a windows mobile device as function keys, here is another one that enables you to enter special national chars, like Å, Ä Æ etc. directly via the keyboard. You must specify 10 keys and there UTF-8 replacements. Configuration is done via the registry:</p>
<pre>3.0        added code for read/write reg for CharTable and KeyTable
 REGEDIT4

 [HKEY_LOCAL_MACHINE\Software\Intermec\KeyToggleChar]
 "KeyTable"=hex:\
 30,31,32,33,34,35,36,37,38,39
 "CharTable"=hex:\
 C6,00,E6,00,D8,00,F8,00,C5,00,E5,00,C2,00,E2,00,C4,00,E4,00
 "LEDid"=dword:00000001
 "autoFallback"=dword:00000000
 "Timeout"=dword:00000003
 "StickyKey"=dword:00000074

 <strong>KeyTable</strong>     holds a list of 10 keys which will be 'remapped'
 <strong>CharTable </strong>   holds  list of UniChar codes to use as replacement
 <strong>LEDid </strong>       defines the ID of the LED to use for showing sticky state
 <strong>autoFallback </strong>defines, if the sticky state is reset after a mapped key is pressed.
              Use 0, if you dont want the sticky state to fallback after keypress
 <strong>TimeOut </strong>     defines a timout after which sticky state will be reset</pre>
<p>To get the UTF-8 word entries for Unicode chars, see for example here: http://www.unicode.org/charts/charindex.html</p>
<p>The default mapping used here is defined as follows and maps the keys 0-9 to:</p>
<pre>0x00c6, 0x00e6, 0x00d8, 0x00f8, 0x00C5, 0x00e5, 0x00c2, 0x00e2, 0x00c4, 0x00e4
 AE        ae     O/       o/      A°      a°      A^      a^      Ä       ä</pre>
<p>The main problem I had was finding a function to get the window handle of the current input active window. Finally I found GetForegroundKeyboardTarget() (after some days of searching).</p>
<p><span id="more-713"></span></p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">void</span> sendKey<span style="color: #009900;">&#40;</span>UINT vKey<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
 TCHAR<span style="color: #339933;">*</span> lpText<span style="color: #339933;">;</span>
 lpText <span style="color: #339933;">=</span> new TCHAR<span style="color: #009900;">&#91;</span>MAX_PATH<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
 TCHAR strClass<span style="color: #009900;">&#91;</span>MAX_PATH<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
 <span style="color: #993333;">int</span> iRes<span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #666666; font-style: italic;">// hWndActive = GetFocusEx(); // a trick that does not deliver the focusses window</span>
 hWndActive <span style="color: #339933;">=</span> GetForegroundKeyboardTarget<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
 GetWindowText<span style="color: #009900;">&#40;</span>hWndActive<span style="color: #339933;">,</span> lpText<span style="color: #339933;">,</span> MAX_PATH<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 iRes <span style="color: #339933;">=</span> GetClassName<span style="color: #009900;">&#40;</span>hWndActive<span style="color: #339933;">,</span> strClass<span style="color: #339933;">,</span> MAX_PATH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 DEBUGMSG<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span>L<span style="color: #ff0000;">&quot;### GetFocusEx() window, handle=0x%x, text='%s', class='%s'<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> hWndActive<span style="color: #339933;">,</span> lpText<span style="color: #339933;">,</span> strClass<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>hWndActive <span style="color: #339933;">==</span> NULL<span style="color: #009900;">&#41;</span>
 <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//no window found</span>
&nbsp;
 WPARAM wParam <span style="color: #339933;">=</span> getCharForKey<span style="color: #009900;">&#40;</span>vKey<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// charTable[vKey-0x30];// 0x00c6; //AE</span>
 LPARAM lParam <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//flags: repeat=1</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/*
 wm_keydown, wParam=0, lParam=1
 wm_char, wParam=char code, lParam=1
 wm_keyup, wParam=0, lParam=c0000001;
*/</span>
&nbsp;
 LRESULT lRes<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
 lRes <span style="color: #339933;">=</span> SendMessage<span style="color: #009900;">&#40;</span>hWndActive<span style="color: #339933;">,</span> WM_KEYDOWN<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 DEBUGMSG<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span>L<span style="color: #ff0000;">&quot;SendMessage1 for 'WM_KEYDOWN' returned 0x%0x<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> lRes<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 lRes <span style="color: #339933;">=</span> SendMessage<span style="color: #009900;">&#40;</span>hWndActive<span style="color: #339933;">,</span> WM_CHAR<span style="color: #339933;">,</span> wParam<span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 DEBUGMSG<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span>L<span style="color: #ff0000;">&quot;SendMessage2 for '0x%04x' returned 0x%0x<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> wParam<span style="color: #339933;">,</span> lRes<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 lRes <span style="color: #339933;">=</span> SendMessage<span style="color: #009900;">&#40;</span>hWndActive<span style="color: #339933;">,</span> WM_KEYUP<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #208080;">0xc0000001</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 DEBUGMSG<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span>L<span style="color: #ff0000;">&quot;SendMessage3 for 'WM_KEYUP' returned 0x%0x<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> lRes<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>I leaved my different finding in code (commented out), so you can see, what functions I have tried. <br class="spacer_" /></p>
<b>DOWNLOAD:</b><a href="http://www.hjgode.de/wp/wp-content/plugins/download-monitor/download.php?id=108" title="Downloaded 17 times">keyToggleChar</a> -  (Hits: 17, size: 6 kB)
<b>DOWNLOAD:</b><a href="http://www.hjgode.de/wp/wp-content/plugins/download-monitor/download.php?id=109" title="Downloaded 12 times">keyToggleChar Source (C/C++, VS2005, Mobile 6 SDK)</a> -  (Hits: 12, size: 35.92 kB)
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F07%2F19%2Fkeytogglechar-a-tool-to-enter-utf-8-national-chars-via-keyboard%2F&amp;title=keyToggleChar+%26%238211%3B+a+tool+to+enter+UTF-8+national+chars+via+keyboard" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F07%2F19%2Fkeytogglechar-a-tool-to-enter-utf-8-national-chars-via-keyboard%2F&amp;title=keyToggleChar+%26%238211%3B+a+tool+to+enter+UTF-8+national+chars+via+keyboard" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F07%2F19%2Fkeytogglechar-a-tool-to-enter-utf-8-national-chars-via-keyboard%2F&amp;title=keyToggleChar+%26%238211%3B+a+tool+to+enter+UTF-8+national+chars+via+keyboard" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F07%2F19%2Fkeytogglechar-a-tool-to-enter-utf-8-national-chars-via-keyboard%2F&amp;T=keyToggleChar+%26%238211%3B+a+tool+to+enter+UTF-8+national+chars+via+keyboard" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F07%2F19%2Fkeytogglechar-a-tool-to-enter-utf-8-national-chars-via-keyboard%2F" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F07%2F19%2Fkeytogglechar-a-tool-to-enter-utf-8-national-chars-via-keyboard%2F&amp;t=keyToggleChar+%26%238211%3B+a+tool+to+enter+UTF-8+national+chars+via+keyboard" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.hjgode.de/wp/2010/07/19/keytogglechar-a-tool-to-enter-utf-8-national-chars-via-keyboard/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mobile Development-Using Layout Managers</title>
		<link>http://www.hjgode.de/wp/2010/07/17/mobile-development-using-layout-managers/</link>
		<comments>http://www.hjgode.de/wp/2010/07/17/mobile-development-using-layout-managers/#comments</comments>
		<pubDate>Sat, 17 Jul 2010 06:15:00 +0000</pubDate>
		<dc:creator>josef</dc:creator>
				<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[DotNet]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[Landscape]]></category>
		<category><![CDATA[Layout Manager]]></category>
		<category><![CDATA[Portrait]]></category>
		<category><![CDATA[QVGA]]></category>
		<category><![CDATA[Smart Device]]></category>
		<category><![CDATA[VGA]]></category>

		<guid isPermaLink="false">http://www.hjgode.de/wp/?p=660</guid>
		<description><![CDATA[Using layout managers for compact framework apps that are orientation aware]]></description>
			<content:encoded><![CDATA[<p>Hi there</p>
<p>I would like to bring back to mind the advantages of using a layout manager (LM) for your smart device .Net projects.</p>
<p>None of the layout Managers mentioned here are developed by me, I dont have the time to do so, especially, when there are great free solutions on the net.</p>
<p>On full .net framework you have the tablelayout panel where you can place your GUI elements and the elements will be arranged automatically, when the main form is resized.<br />
 OK, on smart devices, there will be less form resizing as mostly the forms are full screen by design (QVGA:240&#215;320 or VGA:480&#215;640) . But what happens to your form design, when the user rotates the screen from portrait to landscape orientation?</p>
<p><a rel="attachment wp-att-686" href="http://www.hjgode.de/wp/2010/07/17/mobile-development-using-layout-managers/screenshot-dialogtest/"><img class="alignnone size-medium wp-image-686" title="Screenshot-DialogTest" src="http://www.hjgode.de/wp/wp-content/uploads/1999/11/Screenshot-DialogTest-225x300.png" alt="" width="225" height="300" /></a> <a rel="attachment wp-att-687" href="http://www.hjgode.de/wp/2010/07/17/mobile-development-using-layout-managers/screenshot-dialogtest-1/"><img class="alignnone size-medium wp-image-687" title="Screenshot-DialogTest-1" src="http://www.hjgode.de/wp/wp-content/uploads/1999/11/Screenshot-DialogTest-1-300x225.png" alt="" width="300" height="225" /></a></p>
<p><span id="more-660"></span>Sample Code:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">		<span style="color: #0600FF;">public</span> DialogTest2 <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #FF0000;">int</span> iWidth<span style="color: #008000;">=</span><span style="color: #FF0000;">240</span><span style="color: #008000;">-</span><span style="color: #FF0000;">26</span><span style="color: #008000;">;</span>
			<span style="color: #FF0000;">int</span> iMaxHeight<span style="color: #008000;">=</span><span style="color: #FF0000;">320</span><span style="color: #008000;">-</span><span style="color: #FF0000;">26</span><span style="color: #008000;">-</span><span style="color: #FF0000;">13</span><span style="color: #008000;">;</span>
			<span style="color: #FF0000;">int</span> iLeft<span style="color: #008000;">=</span><span style="color: #FF0000;">6</span><span style="color: #008000;">;</span>
			<span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Size</span><span style="color: #008000;">=</span><span style="color: #008000;">new</span> Size<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">240</span>,<span style="color: #FF0000;">320</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
			TextBox textbox <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> TextBox<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
			textbox.<span style="color: #0000FF;">Multiline</span><span style="color: #008000;">=</span>true<span style="color: #008000;">;</span>
			textbox.<span style="color: #0000FF;">Size</span><span style="color: #008000;">=</span><span style="color: #008000;">new</span> Size<span style="color: #000000;">&#40;</span>iWidth,<span style="color: #FF0000;">180</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
			textbox.<span style="color: #0000FF;">Top</span><span style="color: #008000;">=</span><span style="color: #FF0000;">6</span><span style="color: #008000;">;</span>
			textbox.<span style="color: #0000FF;">Left</span><span style="color: #008000;">=</span>iLeft<span style="color: #008000;">;</span>
&nbsp;
			Button btnExit<span style="color: #008000;">=</span><span style="color: #008000;">new</span> Button<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
			btnExit.<span style="color: #0000FF;">Text</span><span style="color: #008000;">=</span><span style="color: #666666;">&quot;Back&quot;</span><span style="color: #008000;">;</span>
			btnExit.<span style="color: #0000FF;">Click</span><span style="color: #008000;">+=</span><span style="color: #008000;">new</span> EventHandler<span style="color: #000000;">&#40;</span>btnExit_Click<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
			btnExit.<span style="color: #0000FF;">Top</span><span style="color: #008000;">=</span>iMaxHeight<span style="color: #008000;">-</span><span style="color: #FF0000;">26</span><span style="color: #008000;">;</span>
			btnExit.<span style="color: #0000FF;">Left</span><span style="color: #008000;">=</span>iLeft<span style="color: #008000;">;</span>
			btnExit.<span style="color: #0000FF;">Size</span><span style="color: #008000;">=</span><span style="color: #008000;">new</span> Size<span style="color: #000000;">&#40;</span>iWidth,<span style="color: #FF0000;">26</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
			btnExit.<span style="color: #0000FF;">BackColor</span><span style="color: #008000;">=</span>Color.<span style="color: #0000FF;">Gray</span><span style="color: #008000;">;</span>
&nbsp;
			Button btnSwitch<span style="color: #008000;">=</span><span style="color: #008000;">new</span> Button<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
			btnSwitch.<span style="color: #0000FF;">Text</span><span style="color: #008000;">=</span><span style="color: #666666;">&quot;Switch&quot;</span><span style="color: #008000;">;</span>
			btnSwitch.<span style="color: #0000FF;">Click</span><span style="color: #008000;">+=</span><span style="color: #008000;">new</span> EventHandler<span style="color: #000000;">&#40;</span>btnSwitch_Click<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
			btnSwitch.<span style="color: #0000FF;">Top</span><span style="color: #008000;">=</span>iMaxHeight<span style="color: #008000;">-</span><span style="color: #FF0000;">26</span><span style="color: #008000;">-</span><span style="color: #FF0000;">26</span><span style="color: #008000;">-</span><span style="color: #FF0000;">13</span><span style="color: #008000;">;</span>
			btnSwitch.<span style="color: #0000FF;">Left</span><span style="color: #008000;">=</span>iLeft<span style="color: #008000;">;</span>
			btnSwitch.<span style="color: #0000FF;">Size</span><span style="color: #008000;">=</span><span style="color: #008000;">new</span> Size<span style="color: #000000;">&#40;</span>iWidth,<span style="color: #FF0000;">26</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
			btnSwitch.<span style="color: #0000FF;">BackColor</span><span style="color: #008000;">=</span>Color.<span style="color: #0000FF;">Gray</span><span style="color: #008000;">;</span>
&nbsp;
			<span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>textbox<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>btnSwitch<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>btnExit<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
			<span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">BackColor</span><span style="color: #008000;">=</span>Color.<span style="color: #0000FF;">Aqua</span><span style="color: #008000;">;</span>
			<span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Text</span><span style="color: #008000;">=</span><span style="color: #666666;">&quot;DialogTest&quot;</span><span style="color: #008000;">;</span>
			<span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">AutoScroll</span><span style="color: #008000;">=</span>true<span style="color: #008000;">;</span>
		<span style="color: #000000;">&#125;</span></pre></div></div>

<p>To adjust the positions and sizes of these 3 elements, you would need to change top, left and size property of every element in the forms resize event handler.<br class="spacer_" /></p>
<h3>Positioning and sizing your GUI elements by hand</h3>
<p>Now, you write code for the Form Resize event and set top, left and size of all your GUI elements by hand. That are three statements for every element and again for the two possible orientations. Having only four elements on your form, that will be 24 lines to code! Stupid coding, I thought and remembered the LMs available for JAVA. So I tried to find JAVA-like layout managers for DotNet. First, I did not find any, as the full framework already provides a LM and knowone seems to have a need for writing there own LM. But finally I found three LMs in the internet.</p>
<h2>What is the purpose of a layout manager</h2>
<p>A LM should arrange GUI elements inside a container (a form or dialog) according to some well known layout pattern. Instead of writing many code lines to position and resize your GUI elements, the LM will do this for you and place and size the elements according to the LMs rules. Of course you have to write additional statements to get an automatic layout, but you need only write once and it will work for portrait and landscape orientation.</p>
<h2>Coding</h2>
<p>All the LMs I found work similar. You have to add a container, possibly specify a layout, and then add your GUI elements to the LM.</p>
<h2>The layout of your GUI elements</h2>
<p>There are different layouts available:</p>
<ul>
<li>Flow Layout &#8211; positions GUI elements like written text, from left to right and top to bottom</li>
<li>Table or Grid Layout &#8211; provides a table of cells in rows and columns. Each element is added to the next free cell</li>
<li>Border Layout &#8211; the available space is devided into 5 zones, north, west, center, east and south. You can have one element (also containers with several elements) at each of these locations</li>
</ul>
<h2>The Layout Managers I found</h2>
<ol>
<li>Drop-dead easy LM (<a href="http://www.codeproject.com/KB/miscctrl/RavSoftLayoutManager.aspx?df=100&amp;foru" target="_blank">Link</a>) (no further use here)</li>
<li>Grid Layout (<a href="http://www.koders.com/csharp/fidAA62ACAC4341C6306BA83E8390A69698134049A5.aspx" target="_blank">Link</a>) (no further use here, uses OnLayout)</li>
<li>Single Column FlowLayout (<a href="http://www.java2s.com/Code/CSharp/GUI-Windows-Form/LayoutManager.htm" target="_blank">Link</a>)(no further use here)</li>
<li><strong>Layout Managers in C# (<a href="http://www.csharphelp.com/2005/11/layout-managers-in-c/" target="_blank">Link</a>)(great compact framework compatible LM)</strong></li>
<li>Simple Layout Managers (<a href="http://dotnet.jku.at/projects/slm/" target="_blank">Link</a>)(looks also impressive)</li>
<li>FlowLayoutPanel for CF (<a href="http://junmeng.blogspot.com/2010/02/flowlayoutpanel-for-net-compact.html" target="_blank">Link</a>)(This was the first one I found in the net)</li>
<li>DotNetLayout (SourceForge <a href="http://sourceforge.net/projects/dotnetlayout/" target="_blank">Link</a>)</li>
<li>GridLayout (<a title="Link" href="// http://dnetgridlayout.sourceforge.net/" target="_blank">Link</a>)<strong>(easy to use GridLayout Manager, I only miss RowSpan feature)</strong></li>
</ol>
<p>Be aware of compact framework does not support OnLayout event. So some of the LMs listed above are not comaptible with CF.</p>
<h2>Sample Codes</h2>
<p><strong>Example 1 using LayoutManagers</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Drawing</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Windows.Forms</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">Layout</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> PanelTest2
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> DialogTest <span style="color: #008000;">:</span> Form
    <span style="color: #000000;">&#123;</span>
        AreaPane panel<span style="color: #008000;">;</span>
        Button button<span style="color: #008000;">;</span>
        Button btn_Size<span style="color: #008000;">;</span>
        TextBox textbox<span style="color: #008000;">;</span>
        Label label<span style="color: #008000;">;</span>
        PictureBox picturebox<span style="color: #008000;">;</span>
        Panel panel1<span style="color: #008000;">;</span>
        <span style="color: #0600FF;">public</span> DialogTest <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">SuspendLayout</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Text</span><span style="color: #008000;">=</span><span style="color: #666666;">&quot;PanelTest&quot;</span><span style="color: #008000;">;</span>
            panel <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ResizeablePane<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>, ClientRectangle, <span style="color: #008000;">new</span> BorderLayout<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008080;">#region north</span>
            Panel panelNorth<span style="color: #008000;">=</span><span style="color: #008000;">new</span> Panel<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            ContainerBox boxNorth<span style="color: #008000;">=</span><span style="color: #008000;">new</span> ContainerBox<span style="color: #000000;">&#40;</span>panelNorth<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            label<span style="color: #008000;">=</span><span style="color: #008000;">new</span> Label<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span> label.<span style="color: #0000FF;">Name</span><span style="color: #008000;">=</span><span style="color: #666666;">&quot;label&quot;</span><span style="color: #008000;">;</span>
            label.<span style="color: #0000FF;">Text</span><span style="color: #008000;">=</span><span style="color: #666666;">&quot;Label:&quot;</span><span style="color: #008000;">;</span>
            label.<span style="color: #0000FF;">Top</span><span style="color: #008000;">=</span><span style="color: #FF0000;">26</span><span style="color: #008000;">;</span> label.<span style="color: #0000FF;">Left</span><span style="color: #008000;">=</span><span style="color: #FF0000;">26</span><span style="color: #008000;">;</span>
            label.<span style="color: #0000FF;">Size</span><span style="color: #008000;">=</span><span style="color: #008000;">new</span> Size<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">100</span>, <span style="color: #FF0000;">26</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            boxNorth.<span style="color: #0000FF;">LayoutManager</span><span style="color: #008000;">=</span><span style="color: #008000;">new</span> GridLayout<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1</span>,<span style="color: #FF0000;">2</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            boxNorth.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>label<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><span style="color: #008080; font-style: italic;">//, BorderLayout.Direction.East);</span>
&nbsp;
            textbox<span style="color: #008000;">=</span><span style="color: #008000;">new</span> TextBox<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span> textbox.<span style="color: #0000FF;">Name</span><span style="color: #008000;">=</span><span style="color: #666666;">&quot;textbox&quot;</span><span style="color: #008000;">;</span>
            textbox.<span style="color: #0000FF;">Left</span><span style="color: #008000;">=</span><span style="color: #FF0000;">150</span><span style="color: #008000;">;</span> textbox.<span style="color: #0000FF;">Top</span><span style="color: #008000;">=</span><span style="color: #FF0000;">26</span><span style="color: #008000;">;</span>
            textbox.<span style="color: #0000FF;">Size</span><span style="color: #008000;">=</span><span style="color: #008000;">new</span> Size<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">100</span>, <span style="color: #FF0000;">26</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            boxNorth.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>textbox<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><span style="color: #008080; font-style: italic;">//, BorderLayout.Direction.West);</span>
<span style="color: #008080;">#endregion</span>
<span style="color: #008080;">#region south</span>
            Panel panelSouth<span style="color: #008000;">=</span><span style="color: #008000;">new</span> Panel<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            ContainerBox boxSouth<span style="color: #008000;">=</span><span style="color: #008000;">new</span> ContainerBox<span style="color: #000000;">&#40;</span>panelSouth<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            button<span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Button<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span> button.<span style="color: #0000FF;">Name</span><span style="color: #008000;">=</span><span style="color: #666666;">&quot;button&quot;</span><span style="color: #008000;">;</span>
            button.<span style="color: #0000FF;">Location</span><span style="color: #008000;">=</span><span style="color: #008000;">new</span> Point<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">26</span>,<span style="color: #FF0000;">84</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            button.<span style="color: #0000FF;">Size</span><span style="color: #008000;">=</span><span style="color: #008000;">new</span> Size<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">52</span>,<span style="color: #FF0000;">26</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            button.<span style="color: #0000FF;">Text</span><span style="color: #008000;">=</span><span style="color: #666666;">&quot;Exit&quot;</span><span style="color: #008000;">;</span>
            button.<span style="color: #0000FF;">Click</span><span style="color: #008000;">+=</span><span style="color: #008000;">new</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">EventHandler</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">button_clicked</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            btn_Size<span style="color: #008000;">=</span><span style="color: #008000;">new</span> Button<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span> btn_Size.<span style="color: #0000FF;">Name</span><span style="color: #008000;">=</span><span style="color: #666666;">&quot;btn_size&quot;</span><span style="color: #008000;">;</span>
            btn_Size.<span style="color: #0000FF;">Location</span><span style="color: #008000;">=</span><span style="color: #008000;">new</span> Point<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">108</span>,<span style="color: #FF0000;">84</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            btn_Size.<span style="color: #0000FF;">Size</span><span style="color: #008000;">=</span><span style="color: #008000;">new</span> Size<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">52</span>,<span style="color: #FF0000;">26</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            btn_Size.<span style="color: #0000FF;">Text</span><span style="color: #008000;">=</span><span style="color: #666666;">&quot;Resize&quot;</span><span style="color: #008000;">;</span>
            btn_Size.<span style="color: #0000FF;">Click</span><span style="color: #008000;">+=</span><span style="color: #008000;">new</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">EventHandler</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">btn_Size_clicked</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            Button btnTest<span style="color: #008000;">=</span><span style="color: #008000;">new</span> Button<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            btnTest.<span style="color: #0000FF;">Text</span><span style="color: #008000;">=</span><span style="color: #666666;">&quot;Test&quot;</span><span style="color: #008000;">;</span>
            btnTest.<span style="color: #0000FF;">Click</span> <span style="color: #008000;">+=</span> <span style="color: #008000;">new</span> EventHandler<span style="color: #000000;">&#40;</span>btnTest_Click<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            boxSouth.<span style="color: #0000FF;">LayoutManager</span><span style="color: #008000;">=</span><span style="color: #008000;">new</span> GridLayout<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1</span>,<span style="color: #FF0000;">3</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            boxSouth.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>btnTest<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            boxSouth.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>btn_Size<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><span style="color: #008080; font-style: italic;">//, BorderLayout.Direction.East);</span>
&nbsp;
            boxSouth.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>button<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><span style="color: #008080; font-style: italic;">//, BorderLayout.Direction.East);</span>
<span style="color: #008080;">#endregion</span>
<span style="color: #008080;">#region center</span>
            Panel panelCenter<span style="color: #008000;">=</span><span style="color: #008000;">new</span> Panel<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            ContainerBox boxCenter<span style="color: #008000;">=</span><span style="color: #008000;">new</span> ContainerBox<span style="color: #000000;">&#40;</span>panelCenter<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            boxCenter.<span style="color: #0000FF;">LayoutManager</span><span style="color: #008000;">=</span><span style="color: #008000;">new</span> GridLayout<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1</span>,<span style="color: #FF0000;">2</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            panel1<span style="color: #008000;">=</span><span style="color: #008000;">new</span> Panel<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span> panel1.<span style="color: #0000FF;">Name</span><span style="color: #008000;">=</span><span style="color: #666666;">&quot;panel1&quot;</span><span style="color: #008000;">;</span>
            panel1.<span style="color: #0000FF;">BackColor</span><span style="color: #008000;">=</span>Color.<span style="color: #0000FF;">Pink</span><span style="color: #008000;">;</span>
            panel1.<span style="color: #0000FF;">Top</span><span style="color: #008000;">=</span><span style="color: #FF0000;">26</span><span style="color: #008000;">;</span>
            panel1.<span style="color: #0000FF;">Left</span><span style="color: #008000;">=</span><span style="color: #FF0000;">180</span><span style="color: #008000;">;</span>
            panel1.<span style="color: #0000FF;">Size</span><span style="color: #008000;">=</span><span style="color: #008000;">new</span> Size<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">26</span>,<span style="color: #FF0000;">100</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            picturebox<span style="color: #008000;">=</span><span style="color: #008000;">new</span> PictureBox<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span> picturebox.<span style="color: #0000FF;">Name</span><span style="color: #008000;">=</span><span style="color: #666666;">&quot;picturebox&quot;</span><span style="color: #008000;">;</span>
            picturebox.<span style="color: #0000FF;">BackColor</span><span style="color: #008000;">=</span>Color.<span style="color: #0000FF;">Azure</span><span style="color: #008000;">;</span>
            picturebox.<span style="color: #0000FF;">ForeColor</span><span style="color: #008000;">=</span>Color.<span style="color: #0000FF;">Red</span><span style="color: #008000;">;</span>
            picturebox.<span style="color: #0000FF;">Size</span><span style="color: #008000;">=</span><span style="color: #008000;">new</span> Size<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">26</span>,<span style="color: #FF0000;">84</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            picturebox.<span style="color: #0000FF;">Left</span><span style="color: #008000;">=</span><span style="color: #FF0000;">108</span><span style="color: #008000;">;</span>
            picturebox.<span style="color: #0000FF;">Top</span><span style="color: #008000;">=</span><span style="color: #FF0000;">168</span><span style="color: #008000;">;</span>
&nbsp;
            boxCenter.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>panel1<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            boxCenter.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>picturebox<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008080;">#endregion</span>
            panel.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>boxSouth, BorderLayout.<span style="color: #0000FF;">Direction</span>.<span style="color: #0000FF;">South</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            panel.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>boxNorth, BorderLayout.<span style="color: #0000FF;">Direction</span>.<span style="color: #0000FF;">North</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            panel.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>boxCenter, BorderLayout.<span style="color: #0000FF;">Direction</span>.<span style="color: #0000FF;">Center</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">ResumeLayout</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>The code above will produce this automatic layout:</p>
<p><a rel="attachment wp-att-667" href="http://www.hjgode.de/wp/2010/07/17/mobile-development-using-layout-managers/screenshot-paneltest-portrait/"><img class="alignnone size-medium wp-image-667" title="Screenshot-PanelTest-portrait" src="http://www.hjgode.de/wp/wp-content/uploads/1999/11/Screenshot-PanelTest-portrait-225x300.png" alt="" width="225" height="300" /></a> <a rel="attachment wp-att-668" href="http://www.hjgode.de/wp/2010/07/17/mobile-development-using-layout-managers/screenshot-paneltest-landscape/"><img class="alignnone size-medium wp-image-668" title="Screenshot-PanelTest-landscape" src="http://www.hjgode.de/wp/wp-content/uploads/1999/11/Screenshot-PanelTest-landscape-300x225.png" alt="" width="300" height="225" /></a></p>
<p>In the above code all GUI elements are created and sized manually. You can also design your Form with the Form designer in Visual Studio and then add the existing elements to the layout panels. But dont use foreach with the form elements, as the order is reversed or unwanted.</p>
<p>The code sample shows how to use a BorderLayout, panels to group elements and nesting layouts using a different LM like a grid layout.</p>
<p><strong>Example 2 using <a title="GridLayout" href="// http://dnetgridlayout.sourceforge.net/" target="_blank">GridLayout</a></strong></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">...
<span style="color: #0600FF;">using</span> <span style="color: #008080;">LayoutManagers</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// &lt;a class=&quot;linkification-ext&quot; title=&quot;Linkification: http://dnetgridlayout.sourceforge.net/&quot; href=&quot;http://dnetgridlayout.sourceforge.net/&quot;&gt;http://dnetgridlayout.sourceforge.net/&lt;/a&gt;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">partial</span> <span style="color: #FF0000;">class</span> Form1 <span style="color: #008000;">:</span> Form
    <span style="color: #000000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">//PanelWithLayout panelWithLayout1;</span>
        TextBox txtBox1<span style="color: #008000;">;</span>
        TextBox txtBox2<span style="color: #008000;">;</span>
        Button btnTest<span style="color: #008000;">;</span>
        <span style="color: #0600FF;">public</span> Form1<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            InitializeComponent<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008080; font-style: italic;">//Create a layout with 0 rows and 2 columns</span>
            GridLayout myGridlayout <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> GridLayout<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span>, <span style="color: #FF0000;">2</span>, <span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">//the spacing between the elements</span>
            myGridlayout.<span style="color: #0000FF;">intHorizontalSpacing</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">4</span><span style="color: #008000;">;</span>
            <span style="color: #008080; font-style: italic;">//the elements width should fill the column</span>
            myGridlayout.<span style="color: #0000FF;">bFillColumn</span> <span style="color: #008000;">=</span> true<span style="color: #008000;">;</span>
            myGridlayout.<span style="color: #0000FF;">dblRequiredHeight</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">26</span><span style="color: #008000;">;</span>
&nbsp;
            panelWithLayout1.<span style="color: #0000FF;">AutoScroll</span> <span style="color: #008000;">=</span> true<span style="color: #008000;">;</span>
            panelWithLayout1.<span style="color: #0000FF;">setLayout</span><span style="color: #000000;">&#40;</span>myGridlayout<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            txtBox1 <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> TextBox<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            txtBox1.<span style="color: #0000FF;">Width</span> <span style="color: #008000;">=</span> panelWithLayout1.<span style="color: #0000FF;">Width</span> <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">;</span>
            txtBox1.<span style="color: #0000FF;">Height</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">26</span><span style="color: #008000;">;</span>
&nbsp;
            txtBox2 <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> TextBox<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            txtBox2.<span style="color: #0000FF;">Width</span> <span style="color: #008000;">=</span> panelWithLayout1.<span style="color: #0000FF;">Width</span> <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">;</span>
            txtBox2.<span style="color: #0000FF;">Height</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">26</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">//add a text box (in first row, as long as they fit)</span>
            panelWithLayout1.<span style="color: #0000FF;">addControl</span><span style="color: #000000;">&#40;</span>txtBox1<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">//add a button</span>
            btnTest <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Button<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            btnTest.<span style="color: #0000FF;">Height</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">26</span><span style="color: #008000;">;</span>
            btnTest.<span style="color: #0000FF;">Width</span> <span style="color: #008000;">=</span> panelWithLayout1.<span style="color: #0000FF;">Width</span> <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">;</span>
            btnTest.<span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Test&quot;</span><span style="color: #008000;">;</span>
            panelWithLayout1.<span style="color: #0000FF;">addControl</span><span style="color: #000000;">&#40;</span>btnTest<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">//add the button click event handler</span>
            btnTest.<span style="color: #0000FF;">Click</span> <span style="color: #008000;">+=</span> <span style="color: #008000;">new</span> EventHandler<span style="color: #000000;">&#40;</span>btnTest_Click<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">//add the existing datagrid1 (see designer) spanning 2 columns</span>
            dataGrid1.<span style="color: #0000FF;">Width</span> <span style="color: #008000;">=</span> panelWithLayout1.<span style="color: #0000FF;">Width</span><span style="color: #008000;">;</span>
            dataGrid1.<span style="color: #0000FF;">Height</span> <span style="color: #008000;">=</span> <span style="color: #008000;">&lt;</span>a <span style="color: #FF0000;">class</span><span style="color: #008000;">=</span><span style="color: #666666;">&quot;linkification-ext&quot;</span> title<span style="color: #008000;">=</span><span style="color: #666666;">&quot;Linkification: http://panelWithLayout1.Height/3&quot;</span> href<span style="color: #008000;">=</span><span style="color: #666666;">&quot;http://panelWithLayout1.Height/3&quot;</span><span style="color: #008000;">&gt;</span>panelWithLayout1.<span style="color: #0000FF;">Height</span><span style="color: #008000;">/</span><span style="color: #FF0000;">3</span><span style="color: #008000;">&lt;/</span>a<span style="color: #008000;">&gt;;</span>
            <span style="color: #008080; font-style: italic;">//add another textbox</span>
            panelWithLayout1.<span style="color: #0000FF;">addControl</span><span style="color: #000000;">&#40;</span>txtBox2<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
...</pre></div></div>

<p>Here are the screens of the gridLayout Test</p>
<p><a rel="attachment wp-att-706" href="http://www.hjgode.de/wp/2010/07/17/mobile-development-using-layout-managers/gridlayout_port/"><img class="alignnone size-medium wp-image-706" title="gridlayout_port" src="http://www.hjgode.de/wp/wp-content/uploads/2010/07/gridlayout_port-225x300.gif" alt="" width="225" height="300" /></a> <a rel="attachment wp-att-707" href="http://www.hjgode.de/wp/2010/07/17/mobile-development-using-layout-managers/gridlayout_land/"><img class="alignnone size-medium wp-image-707" title="gridlayout_land" src="http://www.hjgode.de/wp/wp-content/uploads/2010/07/gridlayout_land-300x225.gif" alt="" width="300" height="225" /></a></p>
<p>As you can see, this also easy to use.</p>
<p><strong>Example 3 also using GridLayout</strong></p>
<p>This example uses the already available GUI elements of a form designed with VS2005 visual designer. So, this time you dont have to set sizes or positions, just add the existing GUI elements.</p>
<pre lange="csharp" escaped="true">...
        public start_frm()
        {
            InitializeComponent();
            this.SuspendLayout();
            ResizeablePane LayoutPanel = new ResizeablePane(this, ClientRectangle, new GridLayout(0, 1, 4, 4));
            LayoutPanel.Add(btn_barcode);
            LayoutPanel.Add(btn_camera);
            LayoutPanel.Add(btnMSCamera);
            LayoutPanel.Add(btnSignature);
            LayoutPanel.Add(btnExit);
            LayoutPanel.Add(sStatusPos);
            LayoutPanel.Add(status);
            LayoutPanel.Add(lblVersion);
            this.ResumeLayout(true);
...
</pre>
<p>Here is the portrait screen view of the above code:</p>
<p><a rel="attachment wp-att-710" href="http://www.hjgode.de/wp/2010/07/17/mobile-development-using-layout-managers/screen01-2/"><img class="alignnone size-medium wp-image-710" title="Screen01" src="http://www.hjgode.de/wp/wp-content/uploads/2010/07/Screen01-225x300.jpg" alt="" width="225" height="300" /></a></p>
<p><strong>Conclusion</strong></p>
<p>If you ever need to design GUIs for mobile devices with automatic portrait and landscape switching consider to use one of the Layout Managers available.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F07%2F17%2Fmobile-development-using-layout-managers%2F&amp;title=Mobile+Development-Using+Layout+Managers" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F07%2F17%2Fmobile-development-using-layout-managers%2F&amp;title=Mobile+Development-Using+Layout+Managers" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F07%2F17%2Fmobile-development-using-layout-managers%2F&amp;title=Mobile+Development-Using+Layout+Managers" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F07%2F17%2Fmobile-development-using-layout-managers%2F&amp;T=Mobile+Development-Using+Layout+Managers" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F07%2F17%2Fmobile-development-using-layout-managers%2F" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F07%2F17%2Fmobile-development-using-layout-managers%2F&amp;t=Mobile+Development-Using+Layout+Managers" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.hjgode.de/wp/2010/07/17/mobile-development-using-layout-managers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mobile Development: Hooking the keyboard &#8211; KeyToggle</title>
		<link>http://www.hjgode.de/wp/2010/07/16/mobile-development-hooking-the-keyboard-keytoggle/</link>
		<comments>http://www.hjgode.de/wp/2010/07/16/mobile-development-hooking-the-keyboard-keytoggle/#comments</comments>
		<pubDate>Fri, 16 Jul 2010 04:02:33 +0000</pubDate>
		<dc:creator>josef</dc:creator>
				<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[Int*rm*c]]></category>
		<category><![CDATA[Keyboard]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[function keys]]></category>
		<category><![CDATA[hook]]></category>
		<category><![CDATA[keyboard]]></category>
		<category><![CDATA[simulate keys]]></category>
		<category><![CDATA[windows mobile]]></category>

		<guid isPermaLink="false">http://www.hjgode.de/wp/?p=675</guid>
		<description><![CDATA[Using keyboard hook to remap keys to function keys on windows mobile.]]></description>
			<content:encoded><![CDATA[<p><strong>KeyToggle</strong></p>
<p>Extend your keyboard to get function keys by pressing numbers.</p>
<p>With keytoggle you can define a &#8216;sticky&#8217; key that will change the beahviour of the number keys. As long as the sticky key is &#8216;active&#8217;, number keys from 1 to 0 will produce the function keys F1 to F10. If sticky key is active, the left LED will light in green.</p>
<p>To start keytoggle just tap it or let it start by a link in StartUp. If keytoggle is loaded, you can see a small yellow arrow sign in the taskbar.</p>
<p><a rel="attachment wp-att-676" href="http://www.hjgode.de/wp/2010/07/16/mobile-development-hooking-the-keyboard-keytoggle/keytoggle-3/"><img class="alignnone size-full wp-image-676" title="keytoggle" src="http://www.hjgode.de/wp/wp-content/uploads/2010/07/keytoggle.gif" alt="" width="23" height="24" /></a></p>
<p>If you tap this symbol, you are asked, if you want to unload the app. If the registry does not have values defined for keytoggle, it will use default values. If you try to launch keytoggle a second time you will get a message box. Only one instance of keytoggle can run at a time.</p>
<p>Using the registry you can define the behaviour of the sticky key. In example, you can have the sticky key remain active until it is pressed again, let it &#8216;go off&#8217; or &#8216;fallback&#8217; after a period of time or let it fallback after a number key has been pressed. If the sticky key is pressed again, it will always fallback.</p>
<p><span id="more-675"></span>REGEDIT4<br />
 [HKEY<em>LOCAL</em>MACHINE\SOFTWARE\Intermec\KeyToggle]<br />
 &#8220;Timeout&#8221;=dword:00000000<br />
 &#8220;autoFallback&#8221;=dword:00000001<br />
 &#8220;StickyKey&#8221;=dword:00000090</p>
<p>The values:</p>
<pre><code>  StickyKey:
  default "144", decimal (VK_NUMLOCK)
  the VK_ value of the sticky key. Here you define, what you will have as the sticky key. VK_ values are defined as in winuser.h. In example the VK_ value for the NumLock key is 0x90 (144 decimal, see VK_NUMLOCK). The sticky key will be consumed by keytoggle and is not visible to the system any more. That means, that you should choose key value that you do not need in any app you use.

  Timeout:
  default "3", three seconds
  number of seconds the sticky key will remain active. If 0, the sticky key will not fallback automatically by time

  autoFallback:
  default "0"
  if 0 the sticky key will not fallback after pressing a number key. If 1 the sticky key will fallback after a number key is pressed
</code></pre>
<p><strong>Launch arguments</strong></p>
<pre><code>  Keytoggle only supports one argument: "-writereg". This will create the registry keys used by keytoggle and fill them with the default values.
</code></pre>
<p><strong>Usage Sample Scenario</strong></p>
<p>You have a ITC Color device  with a numeric keyboard but no function keys. You need the function keys to be able to use a web application within iBrowse. With keytoggle you can now for example use the Gold key as sticky key. You have to download the device reource kit to get a keyboard remapper tool from the ITC site and assign the Gold key to NUMLOCK.</p>
<p><a rel="attachment wp-att-677" href="http://www.hjgode.de/wp/2010/07/16/mobile-development-hooking-the-keyboard-keytoggle/cpkbdmap-3/"><img class="alignnone size-medium wp-image-677" title="cpkbdmap" src="http://www.hjgode.de/wp/wp-content/uploads/2010/07/cpkbdmap-225x300.gif" alt="" width="225" height="300" /></a></p>
<p>With this remapping and keytoggle running you will to get a function keystroke simulated if you press the Gold key and then a number key.</p>
<p>Download installer: <b>DOWNLOAD:</b><a href="http://www.hjgode.de/wp/wp-content/plugins/download-monitor/download.php?id=107" title="Downloaded 24 times">KeyToggle Installer CAB</a> -  (Hits: 24, size: 5.19 kB)</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F07%2F16%2Fmobile-development-hooking-the-keyboard-keytoggle%2F&amp;title=Mobile+Development%3A+Hooking+the+keyboard+%26%238211%3B+KeyToggle" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F07%2F16%2Fmobile-development-hooking-the-keyboard-keytoggle%2F&amp;title=Mobile+Development%3A+Hooking+the+keyboard+%26%238211%3B+KeyToggle" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F07%2F16%2Fmobile-development-hooking-the-keyboard-keytoggle%2F&amp;title=Mobile+Development%3A+Hooking+the+keyboard+%26%238211%3B+KeyToggle" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F07%2F16%2Fmobile-development-hooking-the-keyboard-keytoggle%2F&amp;T=Mobile+Development%3A+Hooking+the+keyboard+%26%238211%3B+KeyToggle" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F07%2F16%2Fmobile-development-hooking-the-keyboard-keytoggle%2F" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F07%2F16%2Fmobile-development-hooking-the-keyboard-keytoggle%2F&amp;t=Mobile+Development%3A+Hooking+the+keyboard+%26%238211%3B+KeyToggle" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.hjgode.de/wp/2010/07/16/mobile-development-hooking-the-keyboard-keytoggle/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automated Login for Remote Desktop Mobile II</title>
		<link>http://www.hjgode.de/wp/2010/06/23/automated-login-for-remote-desktop-mobile-ii/</link>
		<comments>http://www.hjgode.de/wp/2010/06/23/automated-login-for-remote-desktop-mobile-ii/#comments</comments>
		<pubDate>Wed, 23 Jun 2010 08:00:12 +0000</pubDate>
		<dc:creator>josef</dc:creator>
				<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[mstsc]]></category>
		<category><![CDATA[rdp]]></category>
		<category><![CDATA[rdp_autologin]]></category>
		<category><![CDATA[remote desktop mobile]]></category>
		<category><![CDATA[terminal service client]]></category>
		<category><![CDATA[tsc]]></category>
		<category><![CDATA[windows mobile]]></category>
		<category><![CDATA[wpctsc.exe]]></category>

		<guid isPermaLink="false">http://www.hjgode.de/wp/?p=534</guid>
		<description><![CDATA[Tool to have Remote Desktop Mobile login automatically to a terminal server]]></description>
			<content:encoded><![CDATA[<p><strong>UPDATE 23 june 2010</strong>: new registry option to switch between MouseClick and Keyboard simulation:</p>
<pre>REGEDIT4
[HKEY_LOCAL_MACHINE\Software\RDP_autologin]
"FitToScreen"="1"
"FullScreen"="1"
"Status"="connecting..."
"Save Password"="1"
"Domain"=""
"Password"="Intermec+2004"
"Username"="rdesktop"
"Computer"="192.168.0.130"
"DesktopWidth"=640
"DesktopHeight"=480
"startOnExit"="\rdp_keepBusy.exe"
"execargs"="noRDPstart"
"<strong>UseMouseClick"="0"</strong>    //added with version 3 to switch between mouse and keyboard simulation</pre>
<p><br class="spacer_" /></p>
<p>Some days ago I published my RDP_Autologin code: <a href="http://www.hjgode.de/wp/2010/01/21/automated-login-for-remote-desktop-mobile/">RDP_Autologin</a></p>
<p>As there were some screen metrics hardcoded and more and more devices come with a VGA screen the hardcoded QVGA values will not match. So I extended the first version and implemented some additional logic and settings.</p>
<p><span id="more-534"></span></p>
<p>First, the emulated screen tap has been adjusted to depend on the device screen width and height. For that I included the HIRES_AWARE resource to get the real screen size.</p>
<pre language="cplusplus">...
	DWORD dX = (0xFFFF / iScreenWidth) * (80); // changed from 13 to width=240, 1/3=80
	DWORD dY = (0xFFFF / iScreenHeight) * (iScreenHeight - 13);
...
BOOL getScreenSize(){
	int iScreenX = GetSystemMetrics(SM_CXSCREEN);
	int iScreenY = GetSystemMetrics(SM_CYSCREEN);
	DEBUGMSG(1, (L"\ngetScreenSize: x=%i, y=%i\n", iScreenX, iScreenY));
	if(iScreenX&gt;0)
		iScreenWidth=iScreenX;
	if(iScreenY&gt;0)
		iScreenHeight=iScreenY;
	if(iScreenX+iScreenY &gt; 0){
		_itow(iScreenWidth, sScreenWidth, 10);
		_itow(iScreenHeight, sScreenHeight, 10);
		return TRUE;
	}
	else
		return FALSE;
}
...
</pre>
<p>The rdp file defaults for desktop width and height will also be calculated but you can set the default to use via the registry.</p>
<pre>REGEDIT4

[HKEY_LOCAL_MACHINE\SOFTWARE\RDP_autologin]
<strong>"startOnExit"="\Windows\rdp_keepbusy.exe"
"DesktopHeight"=dword:000001E0
"DesktopWidth"=dword:00000280</strong>
"Computer"="192.168.0.2"
"FitToScreen"="0"
"FullScreen"="0"
"Username"="rdesktop"
"Password"="xxxx"
"Domain"=""
"Save Password"="1"
"Status"="connecting..."
</pre>
<p>As you can see, I added a line where you can specify an application that will be started at the end of the autoconnect process: startOnExit.</p>
<p>Downloads:</p>
<p>evc4 source code: <b>DOWNLOAD:</b><a href="http://www.hjgode.de/wp/wp-content/plugins/download-monitor/download.php?id=94" title="Downloaded 91 times">rdp autologin 2 evc4 source code</a> -  (Hits: 91, size: 113.37 KB)</p>
<p>Armv4i executable: <b>DOWNLOAD:</b><a href="http://www.hjgode.de/wp/wp-content/plugins/download-monitor/download.php?id=95" title="Downloaded 98 times">rdp autologin 2 Armv4i executable</a> -  (Hits: 98, size: 6.47 KB)</p>
<p>NEW: Version 3 adds new option to let the app use MouseClick or Keyboard Simulation</p>
<p>Exe File (ArmV4i) <b>DOWNLOAD:</b><a href="http://www.hjgode.de/wp/wp-content/plugins/download-monitor/download.php?id=105" title="Downloaded 8 times">RDP Autologin Version 3</a> - New version with Mouse or Keyboard simulation switch in registry:
UseMouseClick=DWORD 0/1 (Hits: 8, size: 6.56 kB)</p>
<p>eVC4 source code <b>DOWNLOAD:</b><a href="http://www.hjgode.de/wp/wp-content/plugins/download-monitor/download.php?id=106" title="Downloaded 10 times">RDP AutoLogin version 3 source code</a> - eVC4 source code for my RDP_AutoLogin version 3 (Hits: 10, size: 131.73 kB)</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F06%2F23%2Fautomated-login-for-remote-desktop-mobile-ii%2F&amp;title=Automated+Login+for+Remote+Desktop+Mobile+II" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F06%2F23%2Fautomated-login-for-remote-desktop-mobile-ii%2F&amp;title=Automated+Login+for+Remote+Desktop+Mobile+II" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F06%2F23%2Fautomated-login-for-remote-desktop-mobile-ii%2F&amp;title=Automated+Login+for+Remote+Desktop+Mobile+II" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F06%2F23%2Fautomated-login-for-remote-desktop-mobile-ii%2F&amp;T=Automated+Login+for+Remote+Desktop+Mobile+II" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F06%2F23%2Fautomated-login-for-remote-desktop-mobile-ii%2F" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F06%2F23%2Fautomated-login-for-remote-desktop-mobile-ii%2F&amp;t=Automated+Login+for+Remote+Desktop+Mobile+II" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.hjgode.de/wp/2010/06/23/automated-login-for-remote-desktop-mobile-ii/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Enhanced GPS sample update</title>
		<link>http://www.hjgode.de/wp/2010/06/11/enhanced-gps-sample-update/</link>
		<comments>http://www.hjgode.de/wp/2010/06/11/enhanced-gps-sample-update/#comments</comments>
		<pubDate>Fri, 11 Jun 2010 13:22:42 +0000</pubDate>
		<dc:creator>josef</dc:creator>
				<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.hjgode.de/wp/?p=634</guid>
		<description><![CDATA[The modded MS GPS_Sample application with the addition to support streamed serial raw GPS data like available on Intermec CN50]]></description>
			<content:encoded><![CDATA[<p>Some times ago I published my modded GPS_Sample code (see http://www.hjgode.de/wp/2009/05/12/enhanced-gps-sampe/), which is based on a MS GPSsample.</p>
<p>This time I added support for Int*rm*c CN50, which does NOT support reading raw GPS data using a serial connection. Instead the CN50 streams the data to the &#8216;communication&#8217; port.</p>
<p><a rel="attachment wp-att-635" href="http://www.hjgode.de/wp/2010/06/11/enhanced-gps-sample-update/clipboard01/"><img class="alignnone size-medium wp-image-635" title="CN50 running GPS sample with RAW data" src="http://www.hjgode.de/wp/wp-content/uploads/2010/06/Clipboard01-153x300.gif" alt="" width="153" height="300" /></a></p>
<p>BTW: did you know how easy it is to create skins for use with MyMobiler?</p>
<p><span id="more-634"></span>The stream reader part is outsourced into a thread, which is based on my background thread class bgThread2 (see <a class="linkification-ext" title="Linkification: http://www.hjgode.de/wp/2010/06/01/mobile-development-easy-to-use-background-thread-with-gui-update/" href="http://www.hjgode.de/wp/2010/06/01/mobile-development-easy-to-use-background-thread-with-gui-update/">http://www.hjgode.de/wp/2010/06/01/mobile-development-easy-to-use-background-thread-with-gui-update/</a>). It was very easy to implement the stream reading within the thread, so the GUI is not blocked during read waits.</p>
<pre code="csharp" escaped="true">        #region TheTHREAD
        private void myThreadStart()
        {
            System.Diagnostics.Debug.WriteLine("Entering thread proc");
            int _i=0;
            try
            {
                do
                {
                    //The blocking function...
                    char[] cSep = new char[] { '\r', '\n' };
                    int iRes = 0;
                    do
                    {
                        string sRes = "";
                        iRes = GPS_Sample8.ReadFileClass.readFile(_sCOM, ref sRes);
                        string[] sAll = sRes.Split(cSep);
                        foreach (string s1 in sAll)
                        {
                            SendData(bgWnd.Hwnd, iRes, s1);
                        }
                        //Application.DoEvents();
                        Thread.Sleep(100);
                    } while (iRes == 0);

                    System.Diagnostics.Debug.WriteLine("Thread sleeps...");
                    _i++;
                    Thread.Sleep(100);
                } while (bRunThread);
            }
            catch (ThreadAbortException)
            {
                System.Diagnostics.Debug.WriteLine("Thread will abort");
                bRunThread = false;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception in ThreadStart: " + ex.Message);
            }
            System.Diagnostics.Debug.WriteLine("ThreadProc ended");
        }
        #endregion
</pre>
<p>The main form code has some new functions to check for iCN50 and start/stop the stream reader background thread:</p>
<pre code="csharp" escaped="true">        #region CN50raw
        bgThread2 myStreamReaderThread;
        private void OpenStream()
        {
            //background thread already running?
            if (myStreamReaderThread == null)
            {
                string szPort="";
                szPort = GetGPSPort();
                if (szPort != "")
                {
                    //start a new thread
                    myStreamReaderThread = new bgThread2(szPort);
                    myStreamReaderThread.bgThread2Event += new bgThread2.bgThread2EventHandler(myStreamReaderThread_bgThread2Event);
                }
                else
                    AddRawText("No raw GPS port found");
            }
        }

        void myStreamReaderThread_bgThread2Event(object sender, bgThread2.BgThreadEventArgs bte)
        {
            AddRawText(bte.sString);
        }
        private void CloseStream()
        {
            if (myStreamReaderThread != null)
            {
                myStreamReaderThread.Dispose();
                Application.DoEvents();
                myStreamReaderThread = null;
            }
            Application.DoEvents();
            mnuRAWStart.Enabled = true;
            mnuRAWStop.Enabled = false;
        }
        #endregion
</pre>
<h3>Downloads (VS2008 solution targeting WM6 SDK):</h3>
<b>DOWNLOAD:</b><a href="http://www.hjgode.de/wp/wp-content/plugins/download-monitor/download.php?id=104" title="Downloaded 77 times">GPS C# sample code</a> -  (Hits: 77, size: 352.99 KB)
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F06%2F11%2Fenhanced-gps-sample-update%2F&amp;title=Enhanced+GPS+sample+update" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F06%2F11%2Fenhanced-gps-sample-update%2F&amp;title=Enhanced+GPS+sample+update" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F06%2F11%2Fenhanced-gps-sample-update%2F&amp;title=Enhanced+GPS+sample+update" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F06%2F11%2Fenhanced-gps-sample-update%2F&amp;T=Enhanced+GPS+sample+update" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F06%2F11%2Fenhanced-gps-sample-update%2F" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F06%2F11%2Fenhanced-gps-sample-update%2F&amp;t=Enhanced+GPS+sample+update" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.hjgode.de/wp/2010/06/11/enhanced-gps-sample-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Writing a tftp server windows service</title>
		<link>http://www.hjgode.de/wp/2010/06/09/writing-a-tftp-server-windows-service/</link>
		<comments>http://www.hjgode.de/wp/2010/06/09/writing-a-tftp-server-windows-service/#comments</comments>
		<pubDate>Wed, 09 Jun 2010 17:00:47 +0000</pubDate>
		<dc:creator>josef</dc:creator>
				<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[CSharp]]></category>
		<category><![CDATA[tftp]]></category>
		<category><![CDATA[tftp daemon]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[windows service]]></category>

		<guid isPermaLink="false">http://www.hjgode.de/wp/?p=620</guid>
		<description><![CDATA[A tftp server running as service on windows. Includes tftpUtil class library and service control source code in csharp.]]></description>
			<content:encoded><![CDATA[<p>For an actual project I needed a tftp server service for a Windows 2003 server. I looked around in internet and only found tftp servers running in user space, no real windows service. So I searched for source code applications I could use and found tftpUtil at sourceforge.net (http://sourceforge.net/projects/tftputil/). Although the short description states it would implement a service, it does not in reality. But the tftpUtil class was more or less easy to use and so I started to write a service &#8216;wrapper&#8217; around it.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> OnStart<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> args<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            AddLog<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;OnStart entered...&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            StartTFTPServer<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
...
        <span style="color: #000000;">&#125;</span></pre></div></div>

<p><span id="more-620"></span></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> OnStop<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            tftp.<span style="color: #0000FF;">StopListener</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>TFTPServerThread <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
                TFTPServerThread.<span style="color: #0000FF;">Abort</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            TFTPServerThread <span style="color: #008000;">=</span> null<span style="color: #008000;">;</span>
            timerEvents.<span style="color: #0000FF;">Stop</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            StopTFTPServer<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            GC.<span style="color: #0000FF;">Collect</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #000000;">&#125;</span></pre></div></div>

<p>The StartTFTPServer code uses the same class file ServerSettings.cs as used in the desktop app project (tftpUtilSvcSettings), this is easier to manage:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">            <span style="color: #0600FF;">try</span>
            <span style="color: #000000;">&#123;</span>
                AddLog<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;CreateTFTPFromReg reading path&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                Path <span style="color: #008000;">=</span> svcSettings.<span style="color: #0000FF;">sPath</span><span style="color: #008000;">;</span>
                LoggingLevel <span style="color: #008000;">=</span> svcSettings.<span style="color: #0000FF;">LoggingLevel</span><span style="color: #008000;">;</span>
                DisplayLevel <span style="color: #008000;">=</span> svcSettings.<span style="color: #0000FF;">SendEventLevel</span><span style="color: #008000;">;</span>
                FileAccess <span style="color: #008000;">=</span> svcSettings.<span style="color: #0000FF;">FileAccess</span><span style="color: #008000;">;</span>
                AllowOptions <span style="color: #008000;">=</span> svcSettings.<span style="color: #0000FF;">AllowOptions</span><span style="color: #008000;">;</span>
                RRQWRQStateCheck <span style="color: #008000;">=</span> svcSettings.<span style="color: #0000FF;">RRQWRQStateCheck</span><span style="color: #008000;">;</span>
&nbsp;
                AddLog<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;CreateTFTPFromReg reading IPstring&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #FF0000;">string</span> IPstring <span style="color: #008000;">=</span> svcSettings.<span style="color: #0000FF;">ServerIPAddr</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>IPstring.<span style="color: #0000FF;">ToLower</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;any&quot;</span><span style="color: #000000;">&#41;</span>
                    ServerIPAddr <span style="color: #008000;">=</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Net</span></span>.<span style="color: #0000FF;">IPAddress</span>.<span style="color: #0000FF;">Any</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">else</span>
                    <span style="color: #000000;">System.<span style="color: #0000FF;">Net</span></span>.<span style="color: #0000FF;">IPAddress</span>.<span style="color: #0000FF;">TryParse</span><span style="color: #000000;">&#40;</span>IPstring, <span style="color: #0600FF;">out</span> ServerIPAddr<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                AddLog<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;CreateTFTPFromReg reading ServerUDPPort&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                ServerUDPPort <span style="color: #008000;">=</span> Convert.<span style="color: #0000FF;">ToInt32</span><span style="color: #000000;">&#40;</span>svcSettings.<span style="color: #0000FF;">ServerUDPPort</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                iTimeout <span style="color: #008000;">=</span> Convert.<span style="color: #0000FF;">ToInt32</span><span style="color: #000000;">&#40;</span>svcSettings.<span style="color: #0000FF;">Timeout</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                Resend <span style="color: #008000;">=</span> Convert.<span style="color: #0000FF;">ToInt32</span><span style="color: #000000;">&#40;</span>svcSettings.<span style="color: #0000FF;">Resend</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                AddLog<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;CreateTFTPFromReg reading LoggingMethodInfo&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                LoggingMethodInfo<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> svcSettings.<span style="color: #0000FF;">LoggingMethod</span><span style="color: #008000;">;</span>
                LoggingMethodInfo<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> svcSettings.<span style="color: #0000FF;">LoggingOptions</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">//bool ShowAlert = false;</span>
                AddLog<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;CreateTFTPFromReg reading BlockedIPs&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                BlockedIPs <span style="color: #008000;">=</span> svcSettings.<span style="color: #0000FF;">BlockedIPs</span><span style="color: #008000;">;</span>
&nbsp;
                AddLog<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;CreateTFTPFromReg starting new TFTPServer(...)&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>ServerIPAddr <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
                    tftp <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> TFTPServer<span style="color: #000000;">&#40;</span>ServerUDPPort, Path, LoggingLevel, DisplayLevel, FileAccess, AllowOptions, RRQWRQStateCheck, Resend, iTimeout, LoggingMethodInfo, BlockedIPs<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">else</span>
                    tftp <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> TFTPServer<span style="color: #000000;">&#40;</span>ServerUDPPort, Path, LoggingLevel, DisplayLevel, FileAccess, AllowOptions, RRQWRQStateCheck, Resend, iTimeout, LoggingMethodInfo, BlockedIPs, ServerIPAddr<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                returnval <span style="color: #008000;">=</span> true<span style="color: #008000;">;</span>
                AddLog<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;CreateTFTPFromReg everything seems to be OK&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0600FF;">catch</span> <span style="color: #000000;">&#40;</span>Exception ex<span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                AddLog<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;CreateTFTPFromReg EXCEPTION:&quot;</span> <span style="color: #008000;">+</span> ex.<span style="color: #0000FF;">Message</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0600FF;">return</span> returnval<span style="color: #008000;">;</span></pre></div></div>

<p><strong>Changing service settings</strong></p>
<p>As I would like to control the service later and change settings, I needed a way to &#8216;communicate&#8217; with the server. I started with using the registry, but that did not work first. The service was unable to access [HKLM]Software\tftpUtilSvc. I researched and found the idea to use [HKU].Default\Software\tftpUtilSvc. Although the registry location location does not look nice (I mean service parameters have to reside below HKLM, but who cares), I tried the HKEY_USER.Default location and the service was able to load the values from the registry. Did not find any reference, why the service cannot access other root registry trees.</p>
<p>Here is my ugly &#8220;tftpUtilSvcSettings&#8221; application:</p>
<p><a rel="attachment wp-att-623" href="http://www.hjgode.de/wp/2010/06/09/writing-a-tftp-server-windows-service/tftputilsvccontrol/"><img class="alignnone size-full wp-image-623" title="tftpUtilSvcControl" src="http://www.hjgode.de/wp/wp-content/uploads/2010/06/tftpUtilSvcControl.gif" alt="" width="573" height="334" /></a></p>
<p>Although the tftpUtil code from sourceforge already contained code to write/read tftp settings to/from registry, it was not very clear and straight. I implemented a ServerSettings class and changed all direct references to the registry to this class. Inside the class, ServerSettings.cs, the values are saved/restored to the registry. As I did not like to change to much of the original tftpUtil class, there may be strange looking contructs and possible duplicate internal values.</p>
<p>During my debugging tests, the service did not start/stop correctly sometimes, due to errors in code. As the service remained in a disabled state, I had to rename all tftpUtilSvc service names to be able to test one more time without having to reboot my PC. If a service gets into this state, the service control manager is unable to remove the service as &#8220;InstallUtil.exe /u&#8221; was unable to uninstall the &#8216;broken&#8217; service.</p>
<p><strong>The service installer and controller</strong></p>
<p>The tftp server service should later run on a Windows 2003 server and as I did not like to copy InstallUtil and possibly other files onto the server and then run InstallUtil.exe to install the service, I researched and found some cool CSharp code to install/uninstall/start/stop/restart a servce from code. This code has been integrated into the tftpUtilSvcSettings application (see ServiceUtils.cs) and so there is no real need for an installer. It is possible to just copy the files</p>
<p>nspring.dll<br />
 TFTPUtil.dll<br />
 tftpUtilSvc.exe<br />
 tftpUtilSvcSettings.exe</p>
<p>into one directory and then launch tftpUtilSvcSettings from there (assumed the DotNet runtimes are already installed). Then you can install and start the service directly from the tftpUtilSettings application.</p>
<p><strong>A tftp test client</strong></p>
<p>Included with the source code of tftpUtil of sourceforge is a project called &#8220;TFTPUtil Client GUI&#8221;. The name made me thing this is a tftp client I could use to test the server. BUT this is not a tftp client, it is just a dialog driven tftpUtil server. To test the tftp server I finally used also code found in internet: tftpClient at CodeProject.com. It is very simple code, no threading, no events, no progress indicator. I added a very simple interface and included the tftpClient class file to be able to do simple tests against the tftpUtil service. The tftpClient project is available as separate download for interested readers.</p>
<p><a rel="attachment wp-att-622" href="http://www.hjgode.de/wp/2010/06/09/writing-a-tftp-server-windows-service/tftpclient/"><img class="alignnone size-full wp-image-622" title="tftpClient" src="http://www.hjgode.de/wp/wp-content/uploads/2010/06/tftpClient.gif" alt="" width="323" height="217" /></a></p>
<p><strong>Downloads (Visual Studio 2008)</strong></p>
<b>DOWNLOAD:</b><a href="http://www.hjgode.de/wp/wp-content/plugins/download-monitor/download.php?id=102" title="Downloaded 136 times">tftpUtil service C# code</a> - a tftp service written with tftpUtil (sourceforge) (Hits: 136, size: 422.84 KB)
<b>DOWNLOAD:</b><a href="http://www.hjgode.de/wp/wp-content/plugins/download-monitor/download.php?id=103" title="Downloaded 117 times">tftpClient C# source code</a> - A simple GUI for the CodeProject tftpClient class (Hits: 117, size: 38.29 KB)
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F06%2F09%2Fwriting-a-tftp-server-windows-service%2F&amp;title=Writing+a+tftp+server+windows+service" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F06%2F09%2Fwriting-a-tftp-server-windows-service%2F&amp;title=Writing+a+tftp+server+windows+service" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F06%2F09%2Fwriting-a-tftp-server-windows-service%2F&amp;title=Writing+a+tftp+server+windows+service" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F06%2F09%2Fwriting-a-tftp-server-windows-service%2F&amp;T=Writing+a+tftp+server+windows+service" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F06%2F09%2Fwriting-a-tftp-server-windows-service%2F" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F06%2F09%2Fwriting-a-tftp-server-windows-service%2F&amp;t=Writing+a+tftp+server+windows+service" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.hjgode.de/wp/2010/06/09/writing-a-tftp-server-windows-service/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mobile Development: Easy to use background thread with GUI update</title>
		<link>http://www.hjgode.de/wp/2010/06/01/mobile-development-easy-to-use-background-thread-with-gui-update/</link>
		<comments>http://www.hjgode.de/wp/2010/06/01/mobile-development-easy-to-use-background-thread-with-gui-update/#comments</comments>
		<pubDate>Tue, 01 Jun 2010 17:55:06 +0000</pubDate>
		<dc:creator>josef</dc:creator>
				<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Background Thread]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Compact Framework]]></category>
		<category><![CDATA[DotNet]]></category>
		<category><![CDATA[event handler]]></category>
		<category><![CDATA[GUI thread]]></category>
		<category><![CDATA[Invoke]]></category>
		<category><![CDATA[MessageWindow]]></category>
		<category><![CDATA[Mobile Development]]></category>
		<category><![CDATA[SendMessage]]></category>
		<category><![CDATA[WM_COPYDATA]]></category>
		<category><![CDATA[WndProc]]></category>
		<category><![CDATA[Worker Thread]]></category>

		<guid isPermaLink="false">http://www.hjgode.de/wp/?p=555</guid>
		<description><![CDATA[How to update GUI elements from inside a worker thread without using Invoke. Uses MessageWindow, WndProc and SendMessage with WM_COPYDATA.]]></description>
			<content:encoded><![CDATA[<p>Although there are well know ways to update the GUI from a background thread not running in the GUI thread, I looked for an easiest to use solution. After some experiments I got a background thread class that is very easy to use. No BeginInvoke or Control.Invoke needed any more to update a GUI element.</p>
<p>The final solution uses a MessageWindow inside a control based class with a worker thread. As the control and the MessageWindow is part of the GUI thread, there is no need to use Invokes.</p>
<p>Inside the thread I use SendMessage to transfer background thread informations to the control, which then fires an event you can subscribe in the GUI thread.</p>
<p>The test app attached shows three threads running independently and all update the GUI frequently without blocking the GUI.</p>
<p><a rel="attachment wp-att-579" href="http://www.hjgode.de/wp/2010/06/01/mobile-development-easy-to-use-background-thread-with-gui-update/threadtest2_demo/"><img class="alignnone size-full wp-image-579" title="ThreadTest2_demo" src="http://www.hjgode.de/wp/wp-content/uploads/2010/06/ThreadTest2_demo.gif" alt="" width="240" height="317" /></a></p>
<p><br class="spacer_" /></p>
<p><span style="font-size: x-large;"><strong>Here is my try to visualize my idea and solution</strong></span></p>
<p><a rel="attachment wp-att-556" href="http://www.hjgode.de/wp/2010/06/01/mobile-development-easy-to-use-background-thread-with-gui-update/bgthread/"><img class="alignnone size-full wp-image-556" title="bgThread" src="http://www.hjgode.de/wp/wp-content/uploads/2010/06/bgThread.png" alt="" width="584" height="411" /></a></p>
<p><span id="more-555"></span>Normally you have to use such a construction:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// this variable will hold some text set by the worker thread</span>
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> Message <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;&quot;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// Create a worker thread and then add items to the ListBox from the</span>
<span style="color: #008080; font-style: italic;">// UI thread</span>
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> DoThreading<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// Create the worker thread and start it</span>
    ThreadStart starter <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ThreadStart<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">UpdateListBox</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    Thread t <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Thread<span style="color: #000000;">&#40;</span>starter<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    t.<span style="color: #0000FF;">Start</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">// Loop 4 times, adding a message to the ListBox each time</span>
    <span style="color: #0600FF;">for</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">4</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">listBox1</span>.<span style="color: #0000FF;">Items</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Message from UI thread&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">listBox1</span>.<span style="color: #0000FF;">Update</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008080; font-style: italic;">// Process any queued events on the UI thread</span>
        Application.<span style="color: #0000FF;">DoEvents</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008080; font-style: italic;">// Suspend processing for 1 second</span>
        Thread.<span style="color: #0000FF;">Sleep</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1000</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
    <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">listBox1</span>.<span style="color: #0000FF;">Items</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Last message from UI thread&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">listBox1</span>.<span style="color: #0000FF;">Update</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> UpdateListBox<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">for</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> j <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> j <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">5</span><span style="color: #008000;">;</span> j<span style="color: #008000;">++</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">// Set the message to be added to the ListBox from the worker</span>
        <span style="color: #008080; font-style: italic;">// thread</span>
        <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Message</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Worker thread loop count = &quot;</span> <span style="color: #008000;">+</span> j.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008080; font-style: italic;">// Invoke the WorkerUpdate method in the ListBox’s thread</span>
        <span style="color: #008080; font-style: italic;">// context</span>
        <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">listBox1</span>.<span style="color: #0000FF;">Invoke</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> EventHandler<span style="color: #000000;">&#40;</span>WorkerUpdate<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        Thread.<span style="color: #0000FF;">Sleep</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">700</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #008080; font-style: italic;">// The delegate that’s called from the worker thread</span>
<span style="color: #008080; font-style: italic;">// to update the ListBox</span>
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> WorkerUpdate<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, EventArgs e<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">listBox1</span>.<span style="color: #0000FF;">Items</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Message</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">listBox1</span>.<span style="color: #0000FF;">Update</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>As you can see from the code you need to inform the worker thread about the delegate to use for GUI updates. An GUI update from the worker thread is done with the help of UpdateListBox() and that invokes WorkerUpdate and that function finally updates the GUI. So four places are tight together with function names and definitions.</p>
<p>There are also other  ways to do it. For example with declaring a delegate first and then Invoke from background thread (see <a title="Make Thread-Safe Calls to Windows Forms Controls" href="http://msdn.microsoft.com/en-us/library/ms171728.aspx" target="_blank">here</a>):</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #FF0000;">delegate</span> <span style="color: #0600FF;">void</span> setText<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> sText<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
...
<span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> ThreadProcSafe<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">SetText</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;This text was set safely.&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #000000;">&#125;</span>
...
		<span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> SetText<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> text<span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #008080; font-style: italic;">// InvokeRequired required compares the thread ID of the</span>
			<span style="color: #008080; font-style: italic;">// calling thread to the thread ID of the creating thread.</span>
			<span style="color: #008080; font-style: italic;">// If these threads are different, it returns true.</span>
			<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">textBox1</span>.<span style="color: #0000FF;">InvokeRequired</span><span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				SetTextCallback d <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SetTextCallback<span style="color: #000000;">&#40;</span>SetText<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
				<span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Invoke</span><span style="color: #000000;">&#40;</span>d, <span style="color: #008000;">new</span> <span style="color: #FF0000;">object</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#123;</span> text <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0600FF;">else</span>
			<span style="color: #000000;">&#123;</span>
				<span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">textBox1</span>.<span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> text<span style="color: #008000;">;</span>
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span></pre></div></div>

<p>But this solution also needs your background thread to know the delegate name (<strong>SetText(string s)</strong>).</p>
<p>I also used this patterns  often, but finally I thought, I need an easy to use class that is independent from the main gui thread code and easy to re-use.</p>
<p>With my bgThread classes (yes there are three predefined ones), you can simply use this construction:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">partial</span> <span style="color: #FF0000;">class</span> ThreadTest2 <span style="color: #008000;">:</span> Form
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">private</span> bgThread _bgThread<span style="color: #008000;">;</span>
...
        <span style="color: #008080; font-style: italic;">//start and link the thread</span>
        <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> btn_bgThreadTest_Click<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, EventArgs e<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            _bgThread <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> bgThread<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;192.168.128.5&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            _bgThread.<span style="color: #0000FF;">bgThreadEvent</span> <span style="color: #008000;">+=</span> <span style="color: #008000;">new</span> bgThread.<span style="color: #0000FF;">bgThreadEventHandler</span><span style="color: #000000;">&#40;</span>_bgThread_bgThreadEvent<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">void</span> _bgThread_bgThreadEvent<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, bgThread.<span style="color: #0000FF;">BgThreadEventArgs</span> bte<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            listBox1.<span style="color: #0000FF;">Items</span>.<span style="color: #0000FF;">Insert</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span>, <span style="color: #666666;">&quot;bgThread: &quot;</span> <span style="color: #008000;">+</span> bte.<span style="color: #0000FF;">iStatus</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
...
        <span style="color: #008080; font-style: italic;">//in your exit function you MUST dispose existing threads</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>_bgThread <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
                _bgThread.<span style="color: #0000FF;">Dispose</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            Application.<span style="color: #0000FF;">Exit</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
...</pre></div></div>

<p>As you can see, you have only a bgThread object and after creating a new instance just add the eventhandler. From the eventhandler you can directly update the GUI. You don&#8217;t have to define  a delegate.</p>
<p>All three bgThread classes work fine. They differ in the amount and type of data you have to transfer from the background thread to the GUI and so the BgThreadEventArgs differ in there definition.</p>
<p>The first class, bgThread1 class, only uses the IntPtr&#8217;s usable with SendMessage to transfer data. So you can transfer a maximum of two integers or so. That is enough for the most usage scenarios, where you only need to know status codes from the background thread. The attached bgThread1 class only impements one DWORD (or int).</p>
<p>The second class, bgThread class, uses a global lock and can transfer the data you desire. You have to redefine only the bgThreadEventArgs class to include the data types you would like to transfer. This class uses PostMessage and NOT SendMessage. It may happen, that the data and the message will get out of sync as PostMessage works asynchron.</p>
<p>The third class, bgThread2 class, uses WM_COPYDATA to transfer strutured data from the background thread. It is more complicated to use and extend than bgThread1 but uses SendMessage and no lock objects. Your data is delivered with SendMessage and so there will be no problem with data and message syncronization.</p>
<p>All classes define a class based on Component.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> bgThread <span style="color: #008000;">:</span> Component
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">delegate</span> <span style="color: #0600FF;">void</span> bgThreadEventHandler<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, BgThreadEventArgs bte<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">event</span> bgThreadEventHandler bgThreadEvent<span style="color: #008000;">;</span>
...
        <span style="color: #0600FF;">internal</span> BgThreadEventArgs _BGeventArgs<span style="color: #008000;">;</span>
        <span style="color: #0600FF;">private</span> Thread myThread<span style="color: #008000;">;</span>
...
        <span style="color: #0600FF;">internal</span> <span style="color: #FF0000;">class</span> bgThreadWndProc <span style="color: #008000;">:</span> MessageWindow
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">public</span> bgThreadWndProc<span style="color: #000000;">&#40;</span>bgThread Parent<span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">this</span>._bgThread <span style="color: #008000;">=</span> Parent<span style="color: #008000;">;</span>
                hwndControl <span style="color: #008000;">=</span> Hwnd<span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> WndProc<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">ref</span> Message m<span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #FF0000;">int</span> iMsg <span style="color: #008000;">=</span> m.<span style="color: #0000FF;">Msg</span><span style="color: #008000;">;</span>
                <span style="color: #000000;">System.<span style="color: #0000FF;">Diagnostics</span></span>.<span style="color: #0000FF;">Debug</span>.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;WndProc called...&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">switch</span> <span style="color: #000000;">&#40;</span>iMsg<span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    <span style="color: #0600FF;">case</span> msgID<span style="color: #008000;">:</span>
                        <span style="color: #000000;">&#123;</span>
                            <span style="color: #0600FF;">this</span>._bgThread.<span style="color: #0000FF;">NotifyData</span><span style="color: #000000;">&#40;</span>m.<span style="color: #0000FF;">WParam</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                            break<span style="color: #008000;">;</span>
                        <span style="color: #000000;">&#125;</span>
                    <span style="color: #0600FF;">default</span><span style="color: #008000;">:</span>
                        <span style="color: #000000;">&#123;</span>
                            <span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">WndProc</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">ref</span> m<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                            break<span style="color: #008000;">;</span>
                        <span style="color: #000000;">&#125;</span>
                <span style="color: #000000;">&#125;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span><span style="color: #008080; font-style: italic;">//MsgWnd</span></pre></div></div>

<p>Within the bgThread class there is a nested class based on MessageWindow.</p>
<p>The bgThread class constructor:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">        <span style="color: #0600FF;">public</span> bgThread<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            bgWnd <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> bgThreadWndProc<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            myThread <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Thread<span style="color: #000000;">&#40;</span>myThreadStart<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            bRunThread <span style="color: #008000;">=</span> true<span style="color: #008000;">;</span>
            myThread.<span style="color: #0000FF;">Start</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span></pre></div></div>

<p>The thread proc itself. It may contain more or less blocking functions  calls.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">       <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> myThreadStart<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">try</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">do</span>
                <span style="color: #000000;">&#123;</span>
                    <span style="color: #008080; font-style: italic;">//The blocking function...</span>
                    <span style="color: #008080; font-style: italic;">//sample: call ping and return number of pings answered</span>
                    <span style="color: #FF0000;">int</span> iReply <span style="color: #008000;">=</span> myPing.<span style="color: #0000FF;">Ping</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Net</span></span>.<span style="color: #0000FF;">IPAddress</span>.<span style="color: #0000FF;">Parse</span><span style="color: #000000;">&#40;</span>_sIP<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    <span style="color: #008080; font-style: italic;">//create a msg and send it to the messagewindow, the messagewindow will then inform the event subscribers</span>
                    <span style="color: #008080; font-style: italic;">//we only need the number of ping replies (0 or 1) for the ping</span>
                    Microsoft.<span style="color: #0000FF;">WindowsCE</span>.<span style="color: #0000FF;">Forms</span>.<span style="color: #0000FF;">Message</span> msg <span style="color: #008000;">=</span> Message.<span style="color: #0000FF;">Create</span><span style="color: #000000;">&#40;</span>bgWnd.<span style="color: #0000FF;">Hwnd</span>, msgID, <span style="color: #008000;">new</span> IntPtr<span style="color: #000000;">&#40;</span>iReply<span style="color: #000000;">&#41;</span>, IntPtr.<span style="color: #0000FF;">Zero</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    MessageWindow.<span style="color: #0000FF;">SendMessage</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">ref</span> msg<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">//async Message send</span>
                    Thread.<span style="color: #0000FF;">Sleep</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1000</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">//if you have fast 'blocking' functions you should sleep</span>
                <span style="color: #000000;">&#125;</span> <span style="color: #0600FF;">while</span> <span style="color: #000000;">&#40;</span>bRunThread<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0600FF;">catch</span> <span style="color: #000000;">&#40;</span>ThreadAbortException<span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #000000;">System.<span style="color: #0000FF;">Diagnostics</span></span>.<span style="color: #0000FF;">Debug</span>.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Thread will abort&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                bRunThread <span style="color: #008000;">=</span> false<span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0600FF;">catch</span> <span style="color: #000000;">&#40;</span>Exception ex<span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #000000;">System.<span style="color: #0000FF;">Diagnostics</span></span>.<span style="color: #0000FF;">Debug</span>.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Exception in ThreadStart: &quot;</span> <span style="color: #008000;">+</span> ex.<span style="color: #0000FF;">Message</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #000000;">System.<span style="color: #0000FF;">Diagnostics</span></span>.<span style="color: #0000FF;">Debug</span>.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;ThreadProc ended&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span></pre></div></div>

<p>The code that fires the event is not called from the thread. Instead it is called from the MessageWindow. The thread itself sends its &#8216;data&#8217; via SendMessage to the bgThread &#8216;Component&#8217; (which is part of the GUI!):</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">        <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> NotifyData<span style="color: #000000;">&#40;</span>IntPtr i1<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            BgThreadEventArgs _bgThreadEventArgs<span style="color: #008000;">;</span>
            <span style="color: #008080; font-style: italic;">//is there any subscriber</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">bgThreadEvent</span> <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                return<span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0600FF;">try</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #FF0000;">int</span> i <span style="color: #008000;">=</span> i1.<span style="color: #0000FF;">ToInt32</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                _bgThreadEventArgs <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> BgThreadEventArgs<span style="color: #000000;">&#40;</span>i<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">bgThreadEvent</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>, _bgThreadEventArgs<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0600FF;">catch</span> <span style="color: #000000;">&#40;</span>MissingMethodException<span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span></pre></div></div>

<p>The above code snippets are taken from bgThread1 class, the one that only &#8216;transfers&#8217; an integer to the GUI.</p>
<p><strong>Possible extensions</strong></p>
<ul>
<li>extend bgThread to Stop (pause) a bgThread</li>
<li>extend bgThread and let it invoke a eventhandler that does the blocking stuff. Similar to the BackgroundWorker class available in internet. So you can define your background function inside the main code.</li>
</ul>
<b>DOWNLOAD:</b><a href="http://www.hjgode.de/wp/wp-content/plugins/download-monitor/download.php?id=100" title="Downloaded 99 times">bgThread classes, a ping class and a demo application (VS2005, target WM6SDK)</a> -  (Hits: 99, size: 20.06 KB)
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 1512px; width: 1px; height: 1px;">
<pre><span style="color: blue;">delegate</span> <span style="color: blue;">void</span> SetTextCallback(<span style="color: blue;">string</span> text);
</pre>
</div>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F06%2F01%2Fmobile-development-easy-to-use-background-thread-with-gui-update%2F&amp;title=Mobile+Development%3A+Easy+to+use+background+thread+with+GUI+update" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F06%2F01%2Fmobile-development-easy-to-use-background-thread-with-gui-update%2F&amp;title=Mobile+Development%3A+Easy+to+use+background+thread+with+GUI+update" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F06%2F01%2Fmobile-development-easy-to-use-background-thread-with-gui-update%2F&amp;title=Mobile+Development%3A+Easy+to+use+background+thread+with+GUI+update" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F06%2F01%2Fmobile-development-easy-to-use-background-thread-with-gui-update%2F&amp;T=Mobile+Development%3A+Easy+to+use+background+thread+with+GUI+update" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F06%2F01%2Fmobile-development-easy-to-use-background-thread-with-gui-update%2F" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F06%2F01%2Fmobile-development-easy-to-use-background-thread-with-gui-update%2F&amp;t=Mobile+Development%3A+Easy+to+use+background+thread+with+GUI+update" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.hjgode.de/wp/2010/06/01/mobile-development-easy-to-use-background-thread-with-gui-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Transmit data from WinMo device to PC: SocketWedge and SocketSend</title>
		<link>http://www.hjgode.de/wp/2010/05/27/transmit-data-from-winmo-device-to-pc-socketwedge-and-socketsend/</link>
		<comments>http://www.hjgode.de/wp/2010/05/27/transmit-data-from-winmo-device-to-pc-socketwedge-and-socketsend/#comments</comments>
		<pubDate>Thu, 27 May 2010 13:41:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[communication]]></category>
		<category><![CDATA[keyboard wedge]]></category>
		<category><![CDATA[ping]]></category>
		<category><![CDATA[SendInput]]></category>
		<category><![CDATA[sockets]]></category>
		<category><![CDATA[threads]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[windows mobile]]></category>

		<guid isPermaLink="false">http://www.hjgode.de/wp/?p=546</guid>
		<description><![CDATA[Source Code for Windows Mobile and PC showing socket communication and keyboard input emulation]]></description>
			<content:encoded><![CDATA[<p>Although you may find this combination useless, here is something that will transmit data from a Windows Mobile device to a PC and the PC will type (like a barcode scanner keyboard wedge) the transmitted data.</p>
<p><strong>The workflow theory is: </strong></p>
<ol>
<li>You scan a barcode or RFID TAG and the data is wedged into the SocketSend input textbox or you type some text into the textbox.</li>
<li>You connect your mobile device to the network, where you have a Windows PC running SocketWedge.</li>
<li>On the mobile within SocketSend you tap the transmit button and the data is send to SocketWedge.</li>
<li>SocketWedge receives the data and puts it in the keyboard message queue of a defined application.</li>
<li>The data is typed into the target application.</li>
</ol>
<p><span id="more-546"></span></p>
<p><a rel="attachment wp-att-547" href="http://www.hjgode.de/wp/2010/05/27/transmit-data-from-winmo-device-to-pc-socketwedge-and-socketsend/socketsend_01/"><img class="alignnone size-full wp-image-547" title="SocketSend_01" src="http://www.hjgode.de/wp/wp-content/uploads/2010/05/SocketSend_01.gif" alt="" width="240" height="320" /></a> <a rel="attachment wp-att-548" href="http://www.hjgode.de/wp/2010/05/27/transmit-data-from-winmo-device-to-pc-socketwedge-and-socketsend/screen1/"><img class="alignnone size-full wp-image-548" title="screen1" src="http://www.hjgode.de/wp/wp-content/uploads/2010/05/screen1.gif" alt="" width="338" height="321" /></a></p>
<p><a rel="attachment wp-att-549" href="http://www.hjgode.de/wp/2010/05/27/transmit-data-from-winmo-device-to-pc-socketwedge-and-socketsend/notepad/"><img class="alignnone size-full wp-image-549" title="notepad" src="http://www.hjgode.de/wp/wp-content/uploads/2010/05/notepad.gif" alt="" width="465" height="438" /></a></p>
<p><strong><span style="font-size: small;">There are some code snippets you may find usefull for your apps:</span></strong></p>
<p><strong>On the Mobile (SocketSend)</strong></p>
<ul>
<li>A background task that does ping a server and gives status back</li>
<li>A ping coded for compact framework</li>
</ul>
<p><strong>On the PC (SocketWedge)</strong></p>
<ul>
<li>Background threads that accept socket connections</li>
<li>A nice keyboard input emulation using SendInput</li>
<li>A hex encoder/decoder, yo you can use \xHH for hex input of special chars</li>
</ul>
<p>Attached are the source codes for Visual Studio 2005 targeting Windows or Windows Mobile 6 SDK:</p>
<b>DOWNLOAD:</b><a href="http://www.hjgode.de/wp/wp-content/plugins/download-monitor/download.php?id=96" title="Downloaded 149 times">SocketWedge VS2005 PC Source Code</a> -  (Hits: 149, size: 21.56 KB)
<b>DOWNLOAD:</b><a href="http://www.hjgode.de/wp/wp-content/plugins/download-monitor/download.php?id=97" title="Downloaded 139 times">SocketSend VS2005 WM6 source code</a> -  (Hits: 139, size: 29.35 KB)
<p>Executables:</p>
<b>DOWNLOAD:</b><a href="http://www.hjgode.de/wp/wp-content/plugins/download-monitor/download.php?id=98" title="Downloaded 21 times">SocketSend2 Windows Mobile executable</a> -  (Hits: 21, size: 12.51 KB)
<b>DOWNLOAD:</b><a href="http://www.hjgode.de/wp/wp-content/plugins/download-monitor/download.php?id=99" title="Downloaded 20 times">SocketWedge Windows PC executable</a> -  (Hits: 20, size: 9.77 KB)
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F05%2F27%2Ftransmit-data-from-winmo-device-to-pc-socketwedge-and-socketsend%2F&amp;title=Transmit+data+from+WinMo+device+to+PC%3A+SocketWedge+and+SocketSend" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F05%2F27%2Ftransmit-data-from-winmo-device-to-pc-socketwedge-and-socketsend%2F&amp;title=Transmit+data+from+WinMo+device+to+PC%3A+SocketWedge+and+SocketSend" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F05%2F27%2Ftransmit-data-from-winmo-device-to-pc-socketwedge-and-socketsend%2F&amp;title=Transmit+data+from+WinMo+device+to+PC%3A+SocketWedge+and+SocketSend" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F05%2F27%2Ftransmit-data-from-winmo-device-to-pc-socketwedge-and-socketsend%2F&amp;T=Transmit+data+from+WinMo+device+to+PC%3A+SocketWedge+and+SocketSend" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F05%2F27%2Ftransmit-data-from-winmo-device-to-pc-socketwedge-and-socketsend%2F" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F05%2F27%2Ftransmit-data-from-winmo-device-to-pc-socketwedge-and-socketsend%2F&amp;t=Transmit+data+from+WinMo+device+to+PC%3A+SocketWedge+and+SocketSend" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.hjgode.de/wp/2010/05/27/transmit-data-from-winmo-device-to-pc-socketwedge-and-socketsend/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows CE and Mobile SetupDll with unzip support</title>
		<link>http://www.hjgode.de/wp/2010/04/27/windows-ce-and-mobile-setupdll-with-unzip-support/</link>
		<comments>http://www.hjgode.de/wp/2010/04/27/windows-ce-and-mobile-setupdll-with-unzip-support/#comments</comments>
		<pubDate>Tue, 27 Apr 2010 13:55:27 +0000</pubDate>
		<dc:creator>josef</dc:creator>
				<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[7za]]></category>
		<category><![CDATA[batch]]></category>
		<category><![CDATA[cabwiz]]></category>
		<category><![CDATA[ce_setup.h]]></category>
		<category><![CDATA[iniutil]]></category>
		<category><![CDATA[patch]]></category>
		<category><![CDATA[sed]]></category>
		<category><![CDATA[setupdll]]></category>
		<category><![CDATA[unzip]]></category>
		<category><![CDATA[windows ce]]></category>
		<category><![CDATA[windows mobile]]></category>

		<guid isPermaLink="false">http://www.hjgode.de/wp/?p=522</guid>
		<description><![CDATA[Create windows ce cab files which install a complete directory structure onto a device]]></description>
			<content:encoded><![CDATA[<p><strong>SetupDll_Zip</strong></p>
<p>Create windows ce cab files which install a complete directory structure onto a device. I created<br />
 this small tool, as I needed an easy to use tool to create a pseudo installation cab.</p>
<p>The DLL will unzip a archiv file with all dirs onto a device. To build a new cab use the directory<br />
 structure you will find below cabdir.</p>
<p><a rel="attachment wp-att-524" href="http://www.hjgode.de/wp/2010/04/27/windows-ce-and-mobile-setupdll-with-unzip-support/setupdll_zip/"><img class="alignnone size-full wp-image-524" title="SetupDll_zip" src="http://www.hjgode.de/wp/wp-content/uploads/2010/04/SetupDll_zip.gif" alt="" width="240" height="320" /></a> <a rel="attachment wp-att-525" href="http://www.hjgode.de/wp/2010/04/27/windows-ce-and-mobile-setupdll-with-unzip-support/setupdll_zip2/"><img class="alignnone size-full wp-image-525" title="SetupDll_zip2" src="http://www.hjgode.de/wp/wp-content/uploads/2010/04/SetupDll_zip2.gif" alt="" width="240" height="320" /></a></p>
<p><span id="more-522"></span></p>
<p><strong>Create your own install</strong></p>
<p>First cleanup all files below cabdir\source. Then place all files into this directory as they should be<br />
 unpacked onto the device. For example for an application called barcodegame, I created the following<br />
 structure below source:</p>
<pre>source
	+---Program Files
	¦   +---barcodegame
	¦       +---de
	¦       +---en
	+---Temp
	+---windows
		+---Start Menu
			+---Programs
</pre>
<p>Then let cabbuild.bat create a new archive with all files and then a cab with this packed file. For example<br />
 change to the cabdir (cd cabdir) and then launch</p>
<pre>Buildcab.bat "BarcodeGame3"</pre>
<p>The batch file will patch an inf file needed for cabwiz and zip all files below source. The batch will also<br />
 patch the file SetupDll_zip2.ini.tmpl which is used to specify the install location and the zip filename:</p>
<pre>;SetupDll_zip2.ini
;directory values have to end with a \

[unzip]
basedir=\
reboot=0
zipfile=!APPNAME!.zip
</pre>
<p>The unzip directory could also be controlled by the registry but the ini file is looked up first.</p>
<p>If you like to control the unzip by the registry, you have to change the template file &#8220;cabtemplate.inf&#8221; and use these<br />
 settings:</p>
<pre>"HKLM\Software\SetupDll_ZIP2"
	registry entries (all REG_SZ):
	unzipbasedir: "\"
	zipfilename: "install.zip"
	doreboot:"0"|"1"
</pre>
<p>Currently the batch and everything is adjusted to work with the ini template file &#8220;SetupDll_zip2.ini.tmpl&#8221;.</p>
<p><strong>Dependencies</strong></p>
<ul>
<li>The ini and inf template files are patched using the GNU tool sed.</li>
<li>The zip file is created with 7za</li>
<li>The cab is created with the MS SDK tool cabwiz.</li>
<li>The setupdll is written with the help of iniutil.cpp/h and unzip.cpp/h</li>
</ul>
<p><strong>Coding techiques</strong></p>
<ul>
<li>Windows native API.</li>
<li>CreateWindow from DLL.</li>
<li>Read ini files on Windows CE.</li>
<li>Unzip file on Windwos Mobile.</li>
<li>Update window from thread.</li>
</ul>
<p><strong>Advantages and Disadvantages</strong></p>
<ul>
<li>No national windows support. No shellfolders  <img src='http://www.hjgode.de/wp/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' />  </li>
<li>Very easy to use  <img src='http://www.hjgode.de/wp/wp-includes/images/smilies/icon_cool.gif' alt='8-)' class='wp-smiley' /> </li>
</ul>
<p><strong>Download (source and ready to use): </strong><b>DOWNLOAD:</b><a href="http://www.hjgode.de/wp/wp-content/plugins/download-monitor/download.php?id=92" title="Downloaded 146 times">SetupDll_Zip</a> -  (Hits: 146, size: 2.4 MB)</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F04%2F27%2Fwindows-ce-and-mobile-setupdll-with-unzip-support%2F&amp;title=Windows+CE+and+Mobile+SetupDll+with+unzip+support" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F04%2F27%2Fwindows-ce-and-mobile-setupdll-with-unzip-support%2F&amp;title=Windows+CE+and+Mobile+SetupDll+with+unzip+support" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F04%2F27%2Fwindows-ce-and-mobile-setupdll-with-unzip-support%2F&amp;title=Windows+CE+and+Mobile+SetupDll+with+unzip+support" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F04%2F27%2Fwindows-ce-and-mobile-setupdll-with-unzip-support%2F&amp;T=Windows+CE+and+Mobile+SetupDll+with+unzip+support" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F04%2F27%2Fwindows-ce-and-mobile-setupdll-with-unzip-support%2F" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F04%2F27%2Fwindows-ce-and-mobile-setupdll-with-unzip-support%2F&amp;t=Windows+CE+and+Mobile+SetupDll+with+unzip+support" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.hjgode.de/wp/2010/04/27/windows-ce-and-mobile-setupdll-with-unzip-support/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
