<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>sim0n</title>
	<atom:link href="http://sim0n.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://sim0n.wordpress.com</link>
	<description>i__h4x programming?</description>
	<lastBuildDate>Thu, 29 Dec 2011 11:12:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='sim0n.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>sim0n</title>
		<link>http://sim0n.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://sim0n.wordpress.com/osd.xml" title="sim0n" />
	<atom:link rel='hub' href='http://sim0n.wordpress.com/?pushpress=hub'/>
		<item>
		<title>[C++] Numbers with 6 divisors where none of the divisors are primes &gt; 5</title>
		<link>http://sim0n.wordpress.com/2009/05/19/314/</link>
		<comments>http://sim0n.wordpress.com/2009/05/19/314/#comments</comments>
		<pubDate>Tue, 19 May 2009 21:49:44 +0000</pubDate>
		<dc:creator>sim0n</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[divisor]]></category>
		<category><![CDATA[factor]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[Prime]]></category>

		<guid isPermaLink="false">http://sim0n.wordpress.com/?p=314</guid>
		<description><![CDATA[My uncle phoned me up to day with a question: N is a number that has exactly 6 factors. One of the factors is 1, and another is the number itself. None of the prime factors of N can be greater than 5 Find a method for calculating a set of vales that would suit [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sim0n.wordpress.com&amp;blog=6301650&amp;post=314&amp;subd=sim0n&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>My uncle phoned me up to day with a question:</p>
<p>N is a number that has exactly 6 factors.<br />
One of the factors is 1, and another is the number itself.<br />
None of the prime factors of N can be greater than 5<br />
Find a method for calculating a set of vales that would suit N.</p>
<p>Well. To be honest, after literally hours of trying to work out how to do this, I gave up and decided to program a brute force algorithm that would do this for me:</p>
<div style="border:#660000 5px solid;color:#000000;">
<pre style="background-color:#ffffff;line-height:15px;color:#000000;font-family:Courier New!important;font-size:11px!important;padding:3px;"><span style="color:#0000ff;">#include</span><span style="color:#000000;"> </span><span style="color:#a31515;">"stdafx.h"
</span><span style="color:#0000ff;">#include</span><span style="color:#000000;"> </span><span style="color:#a31515;">"math.h"

</span><span style="color:#0000ff;">int</span><span style="color:#000000;"> main()
{
	</span><span style="color:#008000;">//Algorithm to calculate numbers where
</span><span style="color:#000000;">	</span><span style="color:#008000;">//Number of divisors &lt; 7
</span><span style="color:#000000;">	</span><span style="color:#008000;">//None of the prime divisors &gt; 5
</span><span style="color:#000000;">	</span><span style="color:#0000ff;">for</span><span style="color:#000000;">(</span><span style="color:#0000ff;">int</span><span style="color:#000000;"> i=1;i&lt;100;i++) {
		</span><span style="color:#0000ff;">int</span><span style="color:#000000;"> dc = 0; </span><span style="color:#008000;">//divisor count
</span><span style="color:#000000;">		</span><span style="color:#0000ff;">bool</span><span style="color:#000000;"> pc = </span><span style="color:#0000ff;">true</span><span style="color:#000000;">; </span><span style="color:#008000;">//prime check
</span><span style="color:#000000;">		</span><span style="color:#0000ff;">for</span><span style="color:#000000;">(</span><span style="color:#0000ff;">int</span><span style="color:#000000;"> k=1;k&lt;(i/2)+1;k++) { </span><span style="color:#008000;">//loop through all the numbers up to (n/2)+1
</span><span style="color:#000000;">			</span><span style="color:#0000ff;">if</span><span style="color:#000000;">(i%k==0) { </span><span style="color:#008000;">//check to see if divides with no remainder
</span><span style="color:#000000;">				dc++; </span><span style="color:#008000;">//increase divisor count
</span><span style="color:#000000;">				</span><span style="color:#0000ff;">if</span><span style="color:#000000;">(dc &gt; 5) { </span><span style="color:#008000;">//if divisor count greater than 5, then quit - this number is not valid
</span><span style="color:#000000;">					dc++;
					</span><span style="color:#0000ff;">break</span><span style="color:#000000;">;
				} </span><span style="color:#0000ff;">else</span><span style="color:#000000;"> { </span><span style="color:#008000;">//else we need to check the divisor
</span><span style="color:#000000;">					</span><span style="color:#0000ff;">if</span><span style="color:#000000;">(k&gt;5) {</span><span style="color:#008000;">//if the divisor is bigger than 5, we need to check if it is prime
</span><span style="color:#000000;">						</span><span style="color:#0000ff;">bool</span><span style="color:#000000;"> ip = </span><span style="color:#0000ff;">true</span><span style="color:#000000;">; </span><span style="color:#008000;">//is prime?
</span><span style="color:#000000;">						</span><span style="color:#0000ff;">for</span><span style="color:#000000;">(</span><span style="color:#0000ff;">int</span><span style="color:#000000;"> j = 2; j &lt;= sqrt((</span><span style="color:#0000ff;">double</span><span style="color:#000000;">)k); j++)  </span><span style="color:#008000;">//loop through the possible values
</span><span style="color:#000000;">							</span><span style="color:#0000ff;">if</span><span style="color:#000000;">(k % j == 0) </span><span style="color:#008000;">//check remainder
</span><span style="color:#000000;">								ip=</span><span style="color:#0000ff;">false</span><span style="color:#000000;">;
						</span><span style="color:#0000ff;">if</span><span style="color:#000000;">(ip==</span><span style="color:#0000ff;">true</span><span style="color:#000000;">) { </span><span style="color:#008000;">//sorry, its too big to be prime. quit
</span><span style="color:#000000;">							pc=</span><span style="color:#0000ff;">false</span><span style="color:#000000;">;
							</span><span style="color:#0000ff;">break</span><span style="color:#000000;">;
						}
					}
				}
			}
		}
		</span><span style="color:#0000ff;">if</span><span style="color:#000000;">(dc==5 &amp;&amp; pc==</span><span style="color:#0000ff;">true</span><span style="color:#000000;">) </span><span style="color:#008000;">//check number is prime valid and has 6 divisors
</span><span style="color:#000000;">			printf(</span><span style="color:#a31515;">"Valid Number %d, \n"</span><span style="color:#000000;">, i);
	}
	</span><span style="color:#0000ff;">return</span><span style="color:#000000;"> 0;
}</span></pre>
</div>
<p>That would produce the list of valid numbers, those being:<br />
12 : [1, 2, 3, 4, 6, 12]<br />
18 : [1, 2, 3, 6, 9, 18]<br />
20 : [1, 2, 4, 5, 10, 20]<br />
32 : [1, 2, 4, 8, 16, 32]<br />
45 : [1, 3, 5, 9, 15, 45]<br />
50 : [1, 2, 5, 10, 25, 50]<br />
75 : [1, 3, 5, 15, 25, 75]</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sim0n.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sim0n.wordpress.com/314/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sim0n.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sim0n.wordpress.com/314/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sim0n.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sim0n.wordpress.com/314/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sim0n.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sim0n.wordpress.com/314/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sim0n.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sim0n.wordpress.com/314/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sim0n.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sim0n.wordpress.com/314/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sim0n.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sim0n.wordpress.com/314/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sim0n.wordpress.com&amp;blog=6301650&amp;post=314&amp;subd=sim0n&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sim0n.wordpress.com/2009/05/19/314/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/810cb4ebed3e0db0c0d9777516931db0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sim0n</media:title>
		</media:content>
	</item>
		<item>
		<title>[C++] CBT Hook Example</title>
		<link>http://sim0n.wordpress.com/2009/05/13/c-cbt-hook-example/</link>
		<comments>http://sim0n.wordpress.com/2009/05/13/c-cbt-hook-example/#comments</comments>
		<pubDate>Wed, 13 May 2009 21:10:37 +0000</pubDate>
		<dc:creator>sim0n</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[CBT]]></category>
		<category><![CDATA[hook]]></category>
		<category><![CDATA[SetWindowsHookEx]]></category>
		<category><![CDATA[WH_CBT]]></category>

		<guid isPermaLink="false">http://sim0n.wordpress.com/?p=311</guid>
		<description><![CDATA[Got bored of doing revision and started on a HookLib, this is an example program where I was testing using a CBT Hook. header.h #include "windows.h" bool SetCBTHook(DWORD, HWND); void RemoveCBTHook(); Main.cpp #include "header.h" #define IDC_LIST 4000 HINSTANCE mhInstance; HWND mhWnd; HWND lvhWnd; LRESULT CALLBACK WindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sim0n.wordpress.com&amp;blog=6301650&amp;post=311&amp;subd=sim0n&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Got bored of doing revision and started on a HookLib, this is an example program where I was testing using a CBT Hook.</p>
<p>header.h</p>
<div style='border:#660000 5px solid;color:#000000;'>
<pre style='background-color:#ffffff;line-height:15px;color:#000000;font-family:Courier New!important;font-size:11px!important;padding:3px;'>
<span style="color:rgb(0,0,255);">#include</span><span style="color:rgb(0,0,0);"> </span><span style="color:rgb(163,21,21);">"windows.h"

</span><span style="color:rgb(0,0,255);">bool</span><span style="color:rgb(0,0,0);"> SetCBTHook(DWORD, HWND);
</span><span style="color:rgb(0,0,255);">void</span><span style="color:rgb(0,0,0);"> RemoveCBTHook();</span> </pre>
</div>
<p>Main.cpp</p>
<div style='border:#660000 5px solid;color:#000000;'>
<pre style='background-color:#ffffff;line-height:15px;color:#000000;font-family:Courier New!important;font-size:11px!important;padding:3px;'>
<span style="color:rgb(0,0,255);">#include</span><span style="color:rgb(0,0,0);"> </span><span style="color:rgb(163,21,21);">"header.h"

</span><span style="color:rgb(0,0,255);">#define</span><span style="color:rgb(0,0,0);"> IDC_LIST 4000

HINSTANCE	mhInstance;
HWND		mhWnd;
HWND		lvhWnd;

LRESULT CALLBACK WindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	</span><span style="color:rgb(0,0,255);">switch</span><span style="color:rgb(0,0,0);"> (message)
    {
		</span><span style="color:rgb(0,0,255);">case</span><span style="color:rgb(0,0,0);"> WM_COMMAND:
               </span><span style="color:rgb(0,0,255);">break</span><span style="color:rgb(0,0,0);">;
		</span><span style="color:rgb(0,0,255);">case</span><span style="color:rgb(0,0,0);"> WM_DESTROY:
			RemoveCBTHook();
			PostQuitMessage (0);
			</span><span style="color:rgb(0,0,255);">break</span><span style="color:rgb(0,0,0);">;
		</span><span style="color:rgb(0,0,255);">default</span><span style="color:rgb(0,0,0);">:
			</span><span style="color:rgb(0,0,255);">return</span><span style="color:rgb(0,0,0);"> DefWindowProc (hwnd, message, wParam, lParam);
    }
    </span><span style="color:rgb(0,0,255);">return</span><span style="color:rgb(0,0,0);"> 0;
}

BOOL RegisterClass(</span><span style="color:rgb(0,0,255);">wchar_t</span><span style="color:rgb(0,0,0);"> szClassName[])
{
    WNDCLASSEX wc;
    wc.hInstance =  mhInstance;
    wc.lpszClassName = (LPCWSTR)szClassName;
    wc.lpfnWndProc = WindowProc;
    wc.style = CS_DBLCLKS;
    wc.cbSize = </span><span style="color:rgb(0,0,255);">sizeof</span><span style="color:rgb(0,0,0);"> (WNDCLASSEX);
    wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wc.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wc.hCursor = LoadCursor (NULL, IDC_ARROW);
    wc.lpszMenuName = NULL;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
    </span><span style="color:rgb(0,0,255);">if</span><span style="color:rgb(0,0,0);"> (!RegisterClassEx (&amp;wc))
		</span><span style="color:rgb(0,0,255);">return</span><span style="color:rgb(0,0,0);"> 0;
	</span><span style="color:rgb(0,0,255);">else
</span><span style="color:rgb(0,0,0);">		</span><span style="color:rgb(0,0,255);">return</span><span style="color:rgb(0,0,0);"> 1;
}

</span><span style="color:rgb(0,0,255);">int</span><span style="color:rgb(0,0,0);"> WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPreviousInstance,LPSTR lpcmdline,</span><span style="color:rgb(0,0,255);">int</span><span style="color:rgb(0,0,0);"> nCmdShow)
{
	MSG messages;
	mhInstance = hInstance;
	</span><span style="color:rgb(0,0,255);">wchar_t</span><span style="color:rgb(0,0,0);"> ClassName[ ] = L</span><span style="color:rgb(163,21,21);">"CBTHookClass"</span><span style="color:rgb(0,0,0);">;
	</span><span style="color:rgb(0,0,255);">wchar_t</span><span style="color:rgb(0,0,0);"> WindowName[ ] = L</span><span style="color:rgb(163,21,21);">"CBTHookWindow"</span><span style="color:rgb(0,0,0);">;
	RegisterClass(ClassName);
	mhWnd = CreateWindowEx(WS_EX_CONTROLPARENT, ClassName, WindowName, WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_VISIBLE | WS_MAXIMIZEBOX, 0, 0, 500, 500, NULL, NULL, hInstance, NULL);
	lvhWnd = CreateWindow(L</span><span style="color:rgb(163,21,21);">"LISTBOX"</span><span style="color:rgb(0,0,0);">,L</span><span style="color:rgb(163,21,21);">"CBTHookListBox"</span><span style="color:rgb(0,0,0);">,WS_CHILD|WS_VISIBLE|WS_VSCROLL, 2,2,490,479,mhWnd, (HMENU)IDC_LIST,hInstance, NULL );
	SetCBTHook(GetCurrentThreadId(), mhWnd);
	</span><span style="color:rgb(0,0,255);">while</span><span style="color:rgb(0,0,0);"> (GetMessage (&amp;messages, NULL, 0, 0))
    {
		TranslateMessage(&amp;messages);
        DispatchMessage(&amp;messages);
    }
    </span><span style="color:rgb(0,0,255);">return</span><span style="color:rgb(0,0,0);"> 0;
}</span> </pre>
</div>
<p>CBTHook.cpp</p>
<div style='border:#660000 5px solid;color:#000000;'>
<pre style='background-color:#ffffff;line-height:15px;color:#000000;font-family:Courier New!important;font-size:11px!important;padding:3px;'>
<span style="color:rgb(0,0,255);">#include</span><span style="color:rgb(0,0,0);"> </span><span style="color:rgb(163,21,21);">"header.h"
</span><span style="color:rgb(0,0,255);">#include</span><span style="color:rgb(0,0,0);"> </span><span style="color:rgb(163,21,21);">&lt;stdlib.h&gt;
</span><span style="color:rgb(0,0,255);">#include</span><span style="color:rgb(0,0,0);"> </span><span style="color:rgb(163,21,21);">&lt;sstream&gt;
</span><span style="color:rgb(0,0,255);">#include</span><span style="color:rgb(0,0,0);"> </span><span style="color:rgb(163,21,21);">&lt;string&gt;

</span><span style="color:rgb(0,0,0);">HHOOK	CBT_HOOK_ID;
HWND	hWnd;

</span><span style="color:rgb(0,0,255);">using</span><span style="color:rgb(0,0,0);"> </span><span style="color:rgb(0,0,255);">namespace</span><span style="color:rgb(0,0,0);"> std;

std::wstring StringToWString(</span><span style="color:rgb(0,0,255);">const</span><span style="color:rgb(0,0,0);"> std::string&amp; s)
{
	std::wstring temp(s.length(),L</span><span style="color:rgb(163,21,21);">' '</span><span style="color:rgb(0,0,0);">);
	std::copy(s.begin(), s.end(), temp.begin());
	</span><span style="color:rgb(0,0,255);">return</span><span style="color:rgb(0,0,0);"> temp;
}

</span><span style="color:rgb(0,0,255);">void</span><span style="color:rgb(0,0,0);"> AddItem(LPCWSTR text) {
	SendDlgItemMessage(hWnd, 4000, LB_ADDSTRING, 0, (LPARAM)text);
}

</span><span style="color:rgb(0,0,255);">void</span><span style="color:rgb(0,0,0);"> AddHWND(WPARAM hwnd) {
	ostringstream oss;
	oss &lt;&lt; hex &lt;&lt; (</span><span style="color:rgb(0,0,255);">int</span><span style="color:rgb(0,0,0);">)hwnd;
	wstring Message = L</span><span style="color:rgb(163,21,21);">" ---Window Handle: 0x"</span><span style="color:rgb(0,0,0);"> + StringToWString(oss.str());
	AddItem(Message.c_str());
}

</span><span style="color:rgb(0,128,0);">//void AddRECT(RECT rect) {
//	string out;
//	ostringstream oss;
//	oss &lt;&lt; rect.top;
//	out = oss.str();
//	oss &lt;&lt; rect.bottom;
//	out = out + ", " + oss.str();
//	oss &lt;&lt; rect.left;
//	out = out + ", " + oss.str();
//	oss &lt;&lt; rect.right;
//	out = out + ", " + oss.str();
//	wstring Message = L"Window Moved/Resized: " + StringToWString(out);
//}

</span><span style="color:rgb(0,0,255);">static</span><span style="color:rgb(0,0,0);"> LRESULT CALLBACK CBTHookProc(</span><span style="color:rgb(0,0,255);">int</span><span style="color:rgb(0,0,0);"> nCode, WPARAM wParam, LPARAM lParam)
{
	</span><span style="color:rgb(0,0,255);">if</span><span style="color:rgb(0,0,0);">(nCode &gt; 0) {
		CBT_CREATEWND	*CBTHOOKCREATE;
		RECT			*CBTRECTPTR;
		RECT			CBTRECT;
		wstring			Message;

		</span><span style="color:rgb(0,0,255);">switch</span><span style="color:rgb(0,0,0);"> (nCode)
		{
			</span><span style="color:rgb(0,0,255);">case</span><span style="color:rgb(0,0,0);"> HCBT_ACTIVATE:
				AddItem(L</span><span style="color:rgb(163,21,21);">"Window Activated"</span><span style="color:rgb(0,0,0);">);
			</span><span style="color:rgb(0,0,255);">case</span><span style="color:rgb(0,0,0);"> HCBT_CREATEWND:
				CBTHOOKCREATE = (CBT_CREATEWND*) lParam;
				AddItem(L</span><span style="color:rgb(163,21,21);">"Window Created"</span><span style="color:rgb(0,0,0);">);
				Message = L</span><span style="color:rgb(163,21,21);">" ---Window Name: "</span><span style="color:rgb(0,0,0);">;
				</span><span style="color:rgb(0,0,255);">if</span><span style="color:rgb(0,0,0);">(!IsBadReadPtr(CBTHOOKCREATE-&gt;lpcs, 1)) {
					</span><span style="color:rgb(0,0,255);">if</span><span style="color:rgb(0,0,0);">(!IsBadReadPtr(CBTHOOKCREATE-&gt;lpcs-&gt;lpszName, 1))
						Message = Message + CBTHOOKCREATE-&gt;lpcs-&gt;lpszName;
				}
				AddItem(Message.c_str());

				Message = L</span><span style="color:rgb(163,21,21);">" ---Window Class: "</span><span style="color:rgb(0,0,0);">;
				</span><span style="color:rgb(0,0,255);">if</span><span style="color:rgb(0,0,0);">(!IsBadReadPtr(CBTHOOKCREATE-&gt;lpcs, 1)) {
					</span><span style="color:rgb(0,0,255);">if</span><span style="color:rgb(0,0,0);">(!IsBadReadPtr(CBTHOOKCREATE-&gt;lpcs-&gt;lpszClass, 1))
						Message = Message + CBTHOOKCREATE-&gt;lpcs-&gt;lpszClass;
				}
				AddItem(Message.c_str());
				AddHWND(wParam);
			</span><span style="color:rgb(0,0,255);">case</span><span style="color:rgb(0,0,0);"> HCBT_DESTROYWND:
				AddItem(L</span><span style="color:rgb(163,21,21);">"Window Destroyed"</span><span style="color:rgb(0,0,0);">);
			</span><span style="color:rgb(0,0,255);">case</span><span style="color:rgb(0,0,0);"> HCBT_MINMAX:
				</span><span style="color:rgb(0,0,255);">switch</span><span style="color:rgb(0,0,0);">(lParam)
				{
				</span><span style="color:rgb(0,0,255);">case</span><span style="color:rgb(0,0,0);"> SW_HIDE:
					AddItem(L</span><span style="color:rgb(163,21,21);">"Window Hidden"</span><span style="color:rgb(0,0,0);">);
					</span><span style="color:rgb(0,0,255);">break</span><span style="color:rgb(0,0,0);">;
				</span><span style="color:rgb(0,0,255);">case</span><span style="color:rgb(0,0,0);"> SW_MAXIMIZE:
					AddItem(L</span><span style="color:rgb(163,21,21);">"Window Maximized"</span><span style="color:rgb(0,0,0);">);
					</span><span style="color:rgb(0,0,255);">break</span><span style="color:rgb(0,0,0);">;
				</span><span style="color:rgb(0,0,255);">case</span><span style="color:rgb(0,0,0);"> SW_MINIMIZE:
					AddItem(L</span><span style="color:rgb(163,21,21);">"Window Minimized"</span><span style="color:rgb(0,0,0);">);
					</span><span style="color:rgb(0,0,255);">break</span><span style="color:rgb(0,0,0);">;
				</span><span style="color:rgb(0,0,255);">case</span><span style="color:rgb(0,0,0);"> SW_RESTORE:
					AddItem(L</span><span style="color:rgb(163,21,21);">"Window Restored"</span><span style="color:rgb(0,0,0);">);
					</span><span style="color:rgb(0,0,255);">break</span><span style="color:rgb(0,0,0);">;
				</span><span style="color:rgb(0,0,255);">case</span><span style="color:rgb(0,0,0);"> SW_SHOW:
					AddItem(L</span><span style="color:rgb(163,21,21);">"Window Shown"</span><span style="color:rgb(0,0,0);">);
					</span><span style="color:rgb(0,0,255);">break</span><span style="color:rgb(0,0,0);">;
				</span><span style="color:rgb(0,0,255);">case</span><span style="color:rgb(0,0,0);"> SW_SHOWDEFAULT:
					AddItem(L</span><span style="color:rgb(163,21,21);">"Window Shown Default"</span><span style="color:rgb(0,0,0);">);
					</span><span style="color:rgb(0,0,255);">break</span><span style="color:rgb(0,0,0);">;
				</span><span style="color:rgb(0,0,255);">case</span><span style="color:rgb(0,0,0);"> SW_SHOWMINIMIZED:
					AddItem(L</span><span style="color:rgb(163,21,21);">"Window Shown Minimized"</span><span style="color:rgb(0,0,0);">);
					</span><span style="color:rgb(0,0,255);">break</span><span style="color:rgb(0,0,0);">;
				</span><span style="color:rgb(0,0,255);">case</span><span style="color:rgb(0,0,0);"> SW_SHOWMINNOACTIVE:
					AddItem(L</span><span style="color:rgb(163,21,21);">"Window Shown Minimized (Not Active)"</span><span style="color:rgb(0,0,0);">);
					</span><span style="color:rgb(0,0,255);">break</span><span style="color:rgb(0,0,0);">;
				</span><span style="color:rgb(0,0,255);">case</span><span style="color:rgb(0,0,0);"> SW_SHOWNA:
					AddItem(L</span><span style="color:rgb(163,21,21);">"Window Shown (Not Active)"</span><span style="color:rgb(0,0,0);">);
					</span><span style="color:rgb(0,0,255);">break</span><span style="color:rgb(0,0,0);">;
				</span><span style="color:rgb(0,0,255);">case</span><span style="color:rgb(0,0,0);"> SW_SHOWNOACTIVATE:
					AddItem(L</span><span style="color:rgb(163,21,21);">"Window Shown (Not Active)"</span><span style="color:rgb(0,0,0);">);
					</span><span style="color:rgb(0,0,255);">break</span><span style="color:rgb(0,0,0);">;
				</span><span style="color:rgb(0,0,255);">case</span><span style="color:rgb(0,0,0);"> SW_SHOWNORMAL:
					AddItem(L</span><span style="color:rgb(163,21,21);">"Window Shown"</span><span style="color:rgb(0,0,0);">);
					</span><span style="color:rgb(0,0,255);">break</span><span style="color:rgb(0,0,0);">;
				}
				AddHWND(wParam);
			</span><span style="color:rgb(0,0,255);">case</span><span style="color:rgb(0,0,0);"> HCBT_MOVESIZE:
				</span><span style="color:rgb(0,128,0);">//CBTRECTPTR = (RECT*) lParam;
</span><span style="color:rgb(0,0,0);">				</span><span style="color:rgb(0,128,0);">//memcpy(&amp;CBTRECT, CBTRECTPTR, sizeof(RECT));
</span><span style="color:rgb(0,0,0);">				</span><span style="color:rgb(0,128,0);">//AddRECT(CBTRECT);
</span><span style="color:rgb(0,0,0);">				</span><span style="color:rgb(0,0,255);">break</span><span style="color:rgb(0,0,0);">;
		}
	}
	</span><span style="color:rgb(0,0,255);">return</span><span style="color:rgb(0,0,0);"> CallNextHookEx(CBT_HOOK_ID, nCode, wParam, lParam);
}

</span><span style="color:rgb(0,0,255);">bool</span><span style="color:rgb(0,0,0);"> SetCBTHook(DWORD ThreadID, HWND ThisMainWindow) {
	hWnd = ThisMainWindow;
	HHOOK CBT_HOOK_ID = ::SetWindowsHookEx(WH_CBT, CBTHookProc, 0, ThreadID);
	MessageBox(NULL, L</span><span style="color:rgb(163,21,21);">"Hey"</span><span style="color:rgb(0,0,0);">, L</span><span style="color:rgb(163,21,21);">"There"</span><span style="color:rgb(0,0,0);">, 1);
	</span><span style="color:rgb(0,0,255);">if</span><span style="color:rgb(0,0,0);">(CBT_HOOK_ID)
		</span><span style="color:rgb(0,0,255);">return</span><span style="color:rgb(0,0,0);"> </span><span style="color:rgb(0,0,255);">true</span><span style="color:rgb(0,0,0);">;
	</span><span style="color:rgb(0,0,255);">else
</span><span style="color:rgb(0,0,0);">		</span><span style="color:rgb(0,0,255);">return</span><span style="color:rgb(0,0,0);"> </span><span style="color:rgb(0,0,255);">false</span><span style="color:rgb(0,0,0);">;
}

</span><span style="color:rgb(0,0,255);">void</span><span style="color:rgb(0,0,0);"> RemoveCBTHook() {
	UnhookWindowsHookEx(CBT_HOOK_ID);
}</span> </pre>
</div>
<p>Its just a quick throw-together of setting a cbt hook on your window, the HookLib exports the hook function, allowing you to hook any process/the entire system.<br />
Also note that the IsBadReadPtr is just there to ensure that the structure returned by the hook is valid, as sometimes it isnt causing the function to die.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sim0n.wordpress.com/311/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sim0n.wordpress.com/311/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sim0n.wordpress.com/311/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sim0n.wordpress.com/311/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sim0n.wordpress.com/311/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sim0n.wordpress.com/311/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sim0n.wordpress.com/311/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sim0n.wordpress.com/311/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sim0n.wordpress.com/311/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sim0n.wordpress.com/311/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sim0n.wordpress.com/311/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sim0n.wordpress.com/311/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sim0n.wordpress.com/311/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sim0n.wordpress.com/311/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sim0n.wordpress.com&amp;blog=6301650&amp;post=311&amp;subd=sim0n&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sim0n.wordpress.com/2009/05/13/c-cbt-hook-example/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/810cb4ebed3e0db0c0d9777516931db0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sim0n</media:title>
		</media:content>
	</item>
		<item>
		<title>[C++] Read External Treeview</title>
		<link>http://sim0n.wordpress.com/2009/05/09/c-read-external-treeview/</link>
		<comments>http://sim0n.wordpress.com/2009/05/09/c-read-external-treeview/#comments</comments>
		<pubDate>Sat, 09 May 2009 22:31:09 +0000</pubDate>
		<dc:creator>sim0n</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[external]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[privileges]]></category>
		<category><![CDATA[process]]></category>
		<category><![CDATA[read]]></category>
		<category><![CDATA[SendMessage]]></category>
		<category><![CDATA[treeview]]></category>
		<category><![CDATA[VirtualAllocEx]]></category>

		<guid isPermaLink="false">http://sim0n.wordpress.com/?p=303</guid>
		<description><![CDATA[After quite some time and a lot of research, I finally got it to work. The method is summarised below: xProcess = eXternal Process Find xProc Window Find Treeview in window Get xProcess ID Set Debug Privelages Open xProcess Allocate Memory in xProc Get Root Node Loop: Create and fill TVITEM structure Write TVITEM to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sim0n.wordpress.com&amp;blog=6301650&amp;post=303&amp;subd=sim0n&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>After quite some time and a lot of research, I finally got it to work. The method is summarised below:</p>
<pre style="font-size:10px;font-family:Arial;">xProcess = eXternal Process
Find xProc Window
Find Treeview in window
Get xProcess ID
Set Debug Privelages
Open xProcess
Allocate Memory in xProc
Get Root Node
Loop:
	Create and fill TVITEM structure
	Write TVITEM to xprocess
	Send GET_ITEM to get Node name
	Read string from xprocess memory
	print
	Get Next Node
Free Memory
Close Handle</pre>
<p>I also had some trouble in some processes with trying to open them, so the code includes a setDebug function that changes your privileges and is used in the printTreeviewNodes function before attempting to open the process. Below is the code, including an example of how to use it (Using Teamspeak 2 as a target program):</p>
<div style="border:#660000 5px solid;color:#000000;">
<pre style="white-space:pre!important;overflow:scroll;background-color:#ffffff;line-height:15px;color:#000000;font-family:Courier New!important;font-size:11px!important;padding:3px;"><span style="color:#008000;">// Read External Treeview.cpp : Defines the entry point for the console application.
//
</span><span style="color:#0000ff;">#include</span><span style="color:#000000;"> </span><span style="color:#a31515;">"stdafx.h"
</span><span style="color:#0000ff;">#include</span><span style="color:#000000;"> </span><span style="color:#a31515;">"windows.h"
</span><span style="color:#0000ff;">#include</span><span style="color:#000000;"> </span><span style="color:#a31515;">"commctrl.h"
</span><span style="color:#0000ff;">#include</span><span style="color:#000000;"> </span><span style="color:#a31515;">&lt;iostream&gt;

</span><span style="color:#0000ff;">using</span><span style="color:#000000;"> </span><span style="color:#0000ff;">namespace</span><span style="color:#000000;"> std;

</span><span style="color:#0000ff;">bool</span><span style="color:#000000;"> setDebug() {
	HANDLE hToken;
	</span><span style="color:#0000ff;">if</span><span style="color:#000000;">(OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &amp;hToken)) {
		TOKEN_PRIVILEGES tp;
		LUID luid;
		TOKEN_PRIVILEGES tpPrevious;
		DWORD cbPrevious = </span><span style="color:#0000ff;">sizeof</span><span style="color:#000000;">(TOKEN_PRIVILEGES);
		</span><span style="color:#0000ff;">if</span><span style="color:#000000;">(LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &amp;luid)) {
			tp.PrivilegeCount = 1;
			tp.Privileges[0].Luid = luid;
			tp.Privileges[0].Attributes = 0;
			</span><span style="color:#0000ff;">if</span><span style="color:#000000;">(AdjustTokenPrivileges(hToken, FALSE, &amp;tp, </span><span style="color:#0000ff;">sizeof</span><span style="color:#000000;">(TOKEN_PRIVILEGES), &amp;tpPrevious, &amp;cbPrevious)) {
				tpPrevious.PrivilegeCount = 1;
				tpPrevious.Privileges[0].Luid = luid;
				tpPrevious.Privileges[0].Attributes |= (SE_PRIVILEGE_ENABLED);
				</span><span style="color:#0000ff;">if</span><span style="color:#000000;">(AdjustTokenPrivileges( hToken, FALSE, &amp;tpPrevious, cbPrevious, NULL, NULL )) {
					CloseHandle(hToken);
					</span><span style="color:#0000ff;">return</span><span style="color:#000000;"> </span><span style="color:#0000ff;">true</span><span style="color:#000000;">;
				}
			}
		}
	}
	CloseHandle(hToken);
	</span><span style="color:#0000ff;">return</span><span style="color:#000000;"> </span><span style="color:#0000ff;">false</span><span style="color:#000000;">;
}

</span><span style="color:#0000ff;">void</span><span style="color:#000000;"> printTreeviewNodes(HWND treeview) {
	DWORD pID;
	GetWindowThreadProcessId(treeview, &amp;pID);
	</span><span style="color:#0000ff;">if</span><span style="color:#000000;">(pID) {
		</span><span style="color:#0000ff;">if</span><span style="color:#000000;">(setDebug()) {
			HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, </span><span style="color:#0000ff;">false</span><span style="color:#000000;">, pID);
			</span><span style="color:#0000ff;">if</span><span style="color:#000000;">(hProcess) {
			</span><span style="color:#008000;">/*
				Memory allocation:
			   0---------|---------|----------------14F
				 TVITEM    rBuffer       pszText
				  (28)      (28)          (FF)
			*/
</span><span style="color:#000000;">				DWORD remoteBuffer = (DWORD)::VirtualAllocEx(hProcess, NULL, 335, MEM_COMMIT, PAGE_READWRITE);
				</span><span style="color:#0000ff;">if</span><span style="color:#000000;">(remoteBuffer) {
					HTREEITEM Root = (HTREEITEM)::SendMessage(treeview, TVM_GETNEXTITEM, TVGN_ROOT, 0);
					</span><span style="color:#0000ff;">while</span><span style="color:#000000;">(Root) {
						TVITEM tvItem;
						tvItem.mask = TVIF_TEXT;
						tvItem.hItem = Root;
						tvItem.pszText = (LPWSTR)remoteBuffer + </span><span style="color:#0000ff;">sizeof</span><span style="color:#000000;">(TVITEM);
						tvItem.cchTextMax = 255;
						</span><span style="color:#0000ff;">if</span><span style="color:#000000;">(WriteProcessMemory(hProcess, (LPVOID)remoteBuffer, (LPCVOID)&amp;tvItem, </span><span style="color:#0000ff;">sizeof</span><span style="color:#000000;">(TVITEM), 0)) {
							SendMessage(treeview, TVM_GETITEM, 0, remoteBuffer);
							</span><span style="color:#0000ff;">wchar_t</span><span style="color:#000000;"> bytRtn[255];
							</span><span style="color:#0000ff;">int</span><span style="color:#000000;"> rAdd = remoteBuffer + </span><span style="color:#0000ff;">sizeof</span><span style="color:#000000;">(TVITEM)*2;
							</span><span style="color:#0000ff;">if</span><span style="color:#000000;">(ReadProcessMemory(hProcess, (LPCVOID)rAdd, (LPVOID)&amp;bytRtn, 255, 0)) {
								wcout &lt;&lt; bytRtn &lt;&lt; endl;
							}
							Root = (HTREEITEM)::SendMessage(treeview, TVM_GETNEXTITEM, TVGN_NEXTVISIBLE, (LPARAM)Root);
						}
					}
					VirtualFreeEx(hProcess, (LPVOID)remoteBuffer, 335, MEM_RELEASE);
				}
			}
			CloseHandle(hProcess);
		}
	}
}

</span><span style="color:#0000ff;">int</span><span style="color:#000000;"> _tmain(</span><span style="color:#0000ff;">int</span><span style="color:#000000;"> argc, _TCHAR* argv[])
{
	HWND tsmhWnd = FindWindow(L</span><span style="color:#a31515;">"TMainForm"</span><span style="color:#000000;">, L</span><span style="color:#a31515;">"TeamSpeak 2"</span><span style="color:#000000;">);
	tsmhWnd = FindWindowEx(tsmhWnd, NULL, L</span><span style="color:#a31515;">"TPanel"</span><span style="color:#000000;">, NULL);
	HWND tsTVhWnd = FindWindowEx(tsmhWnd, NULL, L</span><span style="color:#a31515;">"TTreeView"</span><span style="color:#000000;">, NULL);
	printTreeviewNodes(tsTVhWnd);
	</span><span style="color:#0000ff;">return</span><span style="color:#000000;"> 0;
}</span></pre>
</div>
<p>If anybody has a better method than this or any comments, I&#8217;d be more than happy for input ^^</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sim0n.wordpress.com/303/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sim0n.wordpress.com/303/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sim0n.wordpress.com/303/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sim0n.wordpress.com/303/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sim0n.wordpress.com/303/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sim0n.wordpress.com/303/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sim0n.wordpress.com/303/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sim0n.wordpress.com/303/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sim0n.wordpress.com/303/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sim0n.wordpress.com/303/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sim0n.wordpress.com/303/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sim0n.wordpress.com/303/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sim0n.wordpress.com/303/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sim0n.wordpress.com/303/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sim0n.wordpress.com&amp;blog=6301650&amp;post=303&amp;subd=sim0n&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sim0n.wordpress.com/2009/05/09/c-read-external-treeview/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/810cb4ebed3e0db0c0d9777516931db0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sim0n</media:title>
		</media:content>
	</item>
		<item>
		<title>[VB.Net] FindWindowsIndexOf &#8211; .Netish Version</title>
		<link>http://sim0n.wordpress.com/2009/05/05/vbnet-findwindowsindexof-netish/</link>
		<comments>http://sim0n.wordpress.com/2009/05/05/vbnet-findwindowsindexof-netish/#comments</comments>
		<pubDate>Tue, 05 May 2009 19:51:15 +0000</pubDate>
		<dc:creator>sim0n</dc:creator>
				<category><![CDATA[VB.Net]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[EnumWindows]]></category>
		<category><![CDATA[FindWindow]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[indexOf]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://sim0n.wordpress.com/?p=300</guid>
		<description><![CDATA[A more .net style function for getting a window using an indexOf: ''API Imports &#60;Runtime.InteropServices.DllImport("user32.dll", CharSet:=Runtime.InteropServices.CharSet.Auto)&#62; Private Shared Sub GetClassName(ByVal hWnd As System.IntPtr, ByVal lpClassName As System.Text.StringBuilder, ByVal nMaxCount As Integer) End Sub &#60;Runtime.InteropServices.DllImport("user32.dll", CharSet:=Runtime.InteropServices.CharSet.Auto)&#62; Private Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr End Function ''FoundWindow stricture Public Structure FoundWindow [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sim0n.wordpress.com&amp;blog=6301650&amp;post=300&amp;subd=sim0n&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A more .net style function for getting a window using an indexOf:</p>
<div style="border:#660000 5px solid;color:#000000;">
<pre style="background-color:#ffffff;line-height:15px;color:#000000;font-family:Courier New!important;font-size:11px!important;padding:3px;"><span style="color:#000000;">    </span><span style="color:#008000;">''API Imports
</span><span style="color:#000000;">    &lt;Runtime.InteropServices.DllImport(</span><span style="color:#a31515;">"user32.dll"</span><span style="color:#000000;">, CharSet:=Runtime.InteropServices.CharSet.Auto)&gt; </span><span style="color:#0000ff;">Private</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Shared</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Sub</span><span style="color:#000000;"> GetClassName(</span><span style="color:#0000ff;">ByVal</span><span style="color:#000000;"> hWnd </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> System.IntPtr, </span><span style="color:#0000ff;">ByVal</span><span style="color:#000000;"> lpClassName </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> System.Text.StringBuilder, </span><span style="color:#0000ff;">ByVal</span><span style="color:#000000;"> nMaxCount </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Integer</span><span style="color:#000000;">)
    </span><span style="color:#0000ff;">End</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Sub
</span><span style="color:#000000;">    &lt;Runtime.InteropServices.DllImport(</span><span style="color:#a31515;">"user32.dll"</span><span style="color:#000000;">, CharSet:=Runtime.InteropServices.CharSet.Auto)&gt; </span><span style="color:#0000ff;">Private</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Shared</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Function</span><span style="color:#000000;"> FindWindow(</span><span style="color:#0000ff;">ByVal</span><span style="color:#000000;"> lpClassName </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> </span><span style="color:#0000ff;">String</span><span style="color:#000000;">, </span><span style="color:#0000ff;">ByVal</span><span style="color:#000000;"> lpWindowName </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> </span><span style="color:#0000ff;">String</span><span style="color:#000000;">) </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> IntPtr
    </span><span style="color:#0000ff;">End</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Function

</span><span style="color:#000000;">    </span><span style="color:#008000;">''FoundWindow stricture
</span><span style="color:#000000;">    </span><span style="color:#0000ff;">Public</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Structure</span><span style="color:#000000;"> FoundWindow
        </span><span style="color:#0000ff;">Dim</span><span style="color:#000000;"> strWindowName </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> </span><span style="color:#0000ff;">String
</span><span style="color:#000000;">        </span><span style="color:#0000ff;">Dim</span><span style="color:#000000;"> strClassName </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> </span><span style="color:#0000ff;">String
</span><span style="color:#000000;">        </span><span style="color:#0000ff;">Dim</span><span style="color:#000000;"> hWnd </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> IntPtr
    </span><span style="color:#0000ff;">End</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Structure

</span><span style="color:#000000;">    </span><span style="color:#008000;">''' </span><span style="color:#808080;">&lt;summary&gt;
</span><span style="color:#000000;">    </span><span style="color:#008000;">''' This function is used to loop through all running processes, checking their main windows to see which ones contain a specific string
</span><span style="color:#000000;">    </span><span style="color:#008000;">''' </span><span style="color:#808080;">&lt;/summary&gt;
</span><span style="color:#000000;">    </span><span style="color:#008000;">''' </span><span style="color:#808080;">&lt;param name="strIndexOf"&gt;</span><span style="color:#008000;">The string that you wish to check for in the window captions</span><span style="color:#808080;">&lt;/param&gt;
</span><span style="color:#000000;">    </span><span style="color:#008000;">''' </span><span style="color:#808080;">&lt;param name="boolCase"&gt;</span><span style="color:#008000;">Whether the function is should check for case</span><span style="color:#808080;">&lt;/param&gt;
</span><span style="color:#000000;">    </span><span style="color:#008000;">''' </span><span style="color:#808080;">&lt;returns&gt;</span><span style="color:#008000;">A list of FoundWindow's containing the window name, class and handle</span><span style="color:#808080;">&lt;/returns&gt;
</span><span style="color:#000000;">    </span><span style="color:#008000;">''' </span><span style="color:#808080;">&lt;remarks&gt;</span><span style="color:#008000;">As this function only loops through running processes main windows, it may miss some windows.</span><span style="color:#808080;">&lt;/remarks&gt;
</span><span style="color:#000000;">    </span><span style="color:#0000ff;">Public</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Function</span><span style="color:#000000;"> FindWindowsIndexOf(</span><span style="color:#0000ff;">ByVal</span><span style="color:#000000;"> strIndexOf </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> </span><span style="color:#0000ff;">String</span><span style="color:#000000;">, </span><span style="color:#0000ff;">ByVal</span><span style="color:#000000;"> boolCase </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Boolean</span><span style="color:#000000;">) </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> List(</span><span style="color:#0000ff;">Of</span><span style="color:#000000;"> FoundWindow)
        </span><span style="color:#0000ff;">Dim</span><span style="color:#000000;"> foundWindows </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> </span><span style="color:#0000ff;">New</span><span style="color:#000000;"> List(</span><span style="color:#0000ff;">Of</span><span style="color:#000000;"> FoundWindow)
        </span><span style="color:#0000ff;">If</span><span style="color:#000000;"> boolCase = </span><span style="color:#0000ff;">False</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Then
</span><span style="color:#000000;">            strIndexOf = strIndexOf.ToLower
        </span><span style="color:#0000ff;">End</span><span style="color:#000000;"> </span><span style="color:#0000ff;">If
</span><span style="color:#000000;">        </span><span style="color:#0000ff;">For</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Each</span><span style="color:#000000;"> p </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> Process </span><span style="color:#0000ff;">In</span><span style="color:#000000;"> Process.GetProcesses
            </span><span style="color:#0000ff;">Dim</span><span style="color:#000000;"> windowCaption </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> </span><span style="color:#0000ff;">String</span><span style="color:#000000;"> = p.MainWindowTitle
            </span><span style="color:#0000ff;">If</span><span style="color:#000000;"> boolCase = </span><span style="color:#0000ff;">False</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Then
</span><span style="color:#000000;">                windowCaption = windowCaption.ToLower
            </span><span style="color:#0000ff;">End</span><span style="color:#000000;"> </span><span style="color:#0000ff;">If
</span><span style="color:#000000;">            </span><span style="color:#0000ff;">If</span><span style="color:#000000;"> windowCaption.IndexOf(strIndexOf) &gt; -1 </span><span style="color:#0000ff;">Then
</span><span style="color:#000000;">                </span><span style="color:#0000ff;">Dim</span><span style="color:#000000;"> foundWindow </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> </span><span style="color:#0000ff;">New</span><span style="color:#000000;"> FoundWindow
                foundWindow.hWnd = FindWindow(vbNullString, p.MainWindowTitle)
                foundWindow.strWindowName = p.MainWindowTitle
                </span><span style="color:#0000ff;">Dim</span><span style="color:#000000;"> sbClassName </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> </span><span style="color:#0000ff;">New</span><span style="color:#000000;"> System.Text.StringBuilder(</span><span style="color:#a31515;">""</span><span style="color:#000000;">, 256)
                GetClassName(foundWindow.hWnd, sbClassName, 256)
                foundWindow.strClassName = sbClassName.ToString
                foundWindows.Add(foundWindow)
            </span><span style="color:#0000ff;">End</span><span style="color:#000000;"> </span><span style="color:#0000ff;">If
</span><span style="color:#000000;">        </span><span style="color:#0000ff;">Next
</span><span style="color:#000000;">        </span><span style="color:#0000ff;">Return</span><span style="color:#000000;"> foundWindows
    </span><span style="color:#0000ff;">End</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Function

</span><span style="color:#000000;">    </span><span style="color:#0000ff;">Private</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Sub</span><span style="color:#000000;"> Form1_Load(</span><span style="color:#0000ff;">ByVal</span><span style="color:#000000;"> sender </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> System.Object, </span><span style="color:#0000ff;">ByVal</span><span style="color:#000000;"> e </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> System.EventArgs) </span><span style="color:#0000ff;">Handles</span><span style="color:#000000;"> </span><span style="color:#0000ff;">MyBase</span><span style="color:#000000;">.Load
        </span><span style="color:#0000ff;">For</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Each</span><span style="color:#000000;"> fWnd </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> FoundWindow </span><span style="color:#0000ff;">In</span><span style="color:#000000;"> FindWindowsIndexOf(</span><span style="color:#a31515;">"TeST"</span><span style="color:#000000;">, </span><span style="color:#0000ff;">False</span><span style="color:#000000;">)
            Debug.WriteLine(fWnd.strWindowName &amp; </span><span style="color:#a31515;">" : "</span><span style="color:#000000;"> &amp; fWnd.hWnd.ToString)
        </span><span style="color:#0000ff;">Next
</span><span style="color:#000000;">    </span><span style="color:#0000ff;">End</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Sub</span></pre>
</div>
<p>Same as the last function, you can choose whether or not the function is case sensitive.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sim0n.wordpress.com/300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sim0n.wordpress.com/300/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sim0n.wordpress.com/300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sim0n.wordpress.com/300/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sim0n.wordpress.com/300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sim0n.wordpress.com/300/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sim0n.wordpress.com/300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sim0n.wordpress.com/300/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sim0n.wordpress.com/300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sim0n.wordpress.com/300/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sim0n.wordpress.com/300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sim0n.wordpress.com/300/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sim0n.wordpress.com/300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sim0n.wordpress.com/300/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sim0n.wordpress.com&amp;blog=6301650&amp;post=300&amp;subd=sim0n&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sim0n.wordpress.com/2009/05/05/vbnet-findwindowsindexof-netish/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/810cb4ebed3e0db0c0d9777516931db0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sim0n</media:title>
		</media:content>
	</item>
		<item>
		<title>[VB.Net] FindWindowsIndexOf &#8211; API Version</title>
		<link>http://sim0n.wordpress.com/2009/05/05/vbnet-findwindowsindexof-api-version/</link>
		<comments>http://sim0n.wordpress.com/2009/05/05/vbnet-findwindowsindexof-api-version/#comments</comments>
		<pubDate>Tue, 05 May 2009 18:29:19 +0000</pubDate>
		<dc:creator>sim0n</dc:creator>
				<category><![CDATA[VB.Net]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[EnumWindows]]></category>
		<category><![CDATA[FindWindow]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[indexOf]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://sim0n.wordpress.com/?p=298</guid>
		<description><![CDATA[Somebody on VBForums was asking how to do something similar to this, so after answering his question, I created this fairly useful function &#8211; for windows that names change each time you load them up or something&#8230; ''API Declarations Private Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As EnumWindowProc, ByVal lParam As IntPtr) As Integer [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sim0n.wordpress.com&amp;blog=6301650&amp;post=298&amp;subd=sim0n&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Somebody on VBForums was asking how to do something similar to this, so after answering his question, I created this fairly useful function &#8211; for windows that names change each time you load them up or something&#8230;</p>
<div style="border:#660000 5px solid;color:#000000;">
<pre style="background-color:#ffffff;line-height:15px;color:#000000;font-family:Courier New!important;font-size:11px!important;padding:3px;"><span style="color:#000000;">    </span><span style="color:#008000;">''API Declarations
</span><span style="color:#000000;">    </span><span style="color:#0000ff;">Private</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Declare</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Function</span><span style="color:#000000;"> EnumWindows </span><span style="color:#0000ff;">Lib</span><span style="color:#000000;"> </span><span style="color:#a31515;">"user32"</span><span style="color:#000000;"> (</span><span style="color:#0000ff;">ByVal</span><span style="color:#000000;"> lpEnumFunc </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> EnumWindowProc, </span><span style="color:#0000ff;">ByVal</span><span style="color:#000000;"> lParam </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> IntPtr) </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Integer
</span><span style="color:#000000;">    </span><span style="color:#0000ff;">Private</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Declare</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Function</span><span style="color:#000000;"> GetWindowText </span><span style="color:#0000ff;">Lib</span><span style="color:#000000;"> </span><span style="color:#a31515;">"user32"</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Alias</span><span style="color:#000000;"> </span><span style="color:#a31515;">"GetWindowTextA"</span><span style="color:#000000;"> (</span><span style="color:#0000ff;">ByVal</span><span style="color:#000000;"> hwnd </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Integer</span><span style="color:#000000;">, </span><span style="color:#0000ff;">ByVal</span><span style="color:#000000;"> lpString </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> System.Text.StringBuilder, </span><span style="color:#0000ff;">ByVal</span><span style="color:#000000;"> cch </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Integer</span><span style="color:#000000;">) </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Integer
</span><span style="color:#000000;">    </span><span style="color:#0000ff;">Private</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Declare</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Function</span><span style="color:#000000;"> GetWindowTextLength </span><span style="color:#0000ff;">Lib</span><span style="color:#000000;"> </span><span style="color:#a31515;">"user32"</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Alias</span><span style="color:#000000;"> </span><span style="color:#a31515;">"GetWindowTextLengthA"</span><span style="color:#000000;"> (</span><span style="color:#0000ff;">ByVal</span><span style="color:#000000;"> hwnd </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Integer</span><span style="color:#000000;">) </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Integer
</span><span style="color:#000000;">    &lt;Runtime.InteropServices.DllImport(</span><span style="color:#a31515;">"user32.dll"</span><span style="color:#000000;">, CharSet:=Runtime.InteropServices.CharSet.Auto)&gt; </span><span style="color:#0000ff;">Private</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Shared</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Sub</span><span style="color:#000000;"> GetClassName(</span><span style="color:#0000ff;">ByVal</span><span style="color:#000000;"> hWnd </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> System.IntPtr, </span><span style="color:#0000ff;">ByVal</span><span style="color:#000000;"> lpClassName </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> System.Text.StringBuilder, </span><span style="color:#0000ff;">ByVal</span><span style="color:#000000;"> nMaxCount </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Integer</span><span style="color:#000000;">)
    </span><span style="color:#0000ff;">End</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Sub

</span><span style="color:#000000;">    </span><span style="color:#008000;">''EnumWindow Callback Delegate Function
</span><span style="color:#000000;">    </span><span style="color:#0000ff;">Private</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Delegate</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Function</span><span style="color:#000000;"> EnumWindowProc(</span><span style="color:#0000ff;">ByVal</span><span style="color:#000000;"> hwnd </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Integer</span><span style="color:#000000;">, </span><span style="color:#0000ff;">ByVal</span><span style="color:#000000;"> lParam </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> IntPtr) </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Boolean

</span><span style="color:#000000;">    </span><span style="color:#008000;">''Found Window Structures
</span><span style="color:#000000;">    </span><span style="color:#0000ff;">Public</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Structure</span><span style="color:#000000;"> FoundWindows
        </span><span style="color:#0000ff;">Dim</span><span style="color:#000000;"> boolCase </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Boolean
</span><span style="color:#000000;">        </span><span style="color:#0000ff;">Dim</span><span style="color:#000000;"> strFindWindow </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> </span><span style="color:#0000ff;">String
</span><span style="color:#000000;">        </span><span style="color:#0000ff;">Dim</span><span style="color:#000000;"> lstFoundWindows </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> List(</span><span style="color:#0000ff;">Of</span><span style="color:#000000;"> FoundWindow)
    </span><span style="color:#0000ff;">End</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Structure
</span><span style="color:#000000;">    </span><span style="color:#0000ff;">Public</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Structure</span><span style="color:#000000;"> FoundWindow
        </span><span style="color:#0000ff;">Dim</span><span style="color:#000000;"> strWindowName </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> </span><span style="color:#0000ff;">String
</span><span style="color:#000000;">        </span><span style="color:#0000ff;">Dim</span><span style="color:#000000;"> strClassName </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> </span><span style="color:#0000ff;">String
</span><span style="color:#000000;">        </span><span style="color:#0000ff;">Dim</span><span style="color:#000000;"> hWnd </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> IntPtr
    </span><span style="color:#0000ff;">End</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Structure

</span><span style="color:#000000;">    </span><span style="color:#008000;">''' </span><span style="color:#808080;">&lt;summary&gt;
</span><span style="color:#000000;">    </span><span style="color:#008000;">''' ''EnumWindow Callback Function
</span><span style="color:#000000;">    </span><span style="color:#008000;">''' </span><span style="color:#808080;">&lt;/summary&gt;
</span><span style="color:#000000;">    </span><span style="color:#008000;">''' </span><span style="color:#808080;">&lt;param name="hwnd"&gt;</span><span style="color:#008000;">Current windows handle</span><span style="color:#808080;">&lt;/param&gt;
</span><span style="color:#000000;">    </span><span style="color:#008000;">''' </span><span style="color:#808080;">&lt;param name="lParam"&gt;</span><span style="color:#008000;">Contains the FoundWindows structure</span><span style="color:#808080;">&lt;/param&gt;
</span><span style="color:#000000;">    </span><span style="color:#008000;">''' </span><span style="color:#808080;">&lt;returns&gt;</span><span style="color:#008000;">The function passes the currently found windows in the lParam using a GCHandle to reform the data</span><span style="color:#808080;">&lt;/returns&gt;
</span><span style="color:#000000;">    </span><span style="color:#008000;">''' </span><span style="color:#808080;">&lt;remarks&gt;</span><span style="color:#008000;">This function is called for each of the windows found, and is where the indexOf is called</span><span style="color:#808080;">&lt;/remarks&gt;
</span><span style="color:#000000;">    </span><span style="color:#0000ff;">Public</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Function</span><span style="color:#000000;"> EnumWindowsProc(</span><span style="color:#0000ff;">ByVal</span><span style="color:#000000;"> hwnd </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Integer</span><span style="color:#000000;">, </span><span style="color:#0000ff;">ByVal</span><span style="color:#000000;"> lParam </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> IntPtr) </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Boolean
</span><span style="color:#000000;">        </span><span style="color:#0000ff;">Dim</span><span style="color:#000000;"> foundWindows </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> FoundWindows = </span><span style="color:#0000ff;">CType</span><span style="color:#000000;">(System.Runtime.InteropServices.GCHandle.FromIntPtr(lParam).Target, FoundWindows)
        </span><span style="color:#0000ff;">Dim</span><span style="color:#000000;"> windowTitle </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> </span><span style="color:#0000ff;">String</span><span style="color:#000000;"> = foundWindows.strFindWindow
        </span><span style="color:#0000ff;">Dim</span><span style="color:#000000;"> wndTxtLen </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Integer</span><span style="color:#000000;"> = GetWindowTextLength(hwnd)
        </span><span style="color:#0000ff;">If</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Not</span><span style="color:#000000;"> wndTxtLen = 0 </span><span style="color:#0000ff;">Then
</span><span style="color:#000000;">            </span><span style="color:#0000ff;">Dim</span><span style="color:#000000;"> sb </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> </span><span style="color:#0000ff;">New</span><span style="color:#000000;"> System.Text.StringBuilder(</span><span style="color:#a31515;">""</span><span style="color:#000000;">, wndTxtLen + 1)
            GetWindowText(hwnd, sb, sb.Capacity)
            </span><span style="color:#0000ff;">Dim</span><span style="color:#000000;"> windowCaption </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> </span><span style="color:#0000ff;">String</span><span style="color:#000000;"> = sb.ToString
            </span><span style="color:#0000ff;">If</span><span style="color:#000000;"> foundWindows.boolCase = </span><span style="color:#0000ff;">False</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Then
</span><span style="color:#000000;">                windowCaption = windowCaption.ToLower
                windowTitle = windowTitle.ToLower
            </span><span style="color:#0000ff;">End</span><span style="color:#000000;"> </span><span style="color:#0000ff;">If
</span><span style="color:#000000;">            </span><span style="color:#0000ff;">If</span><span style="color:#000000;"> windowCaption.IndexOf(windowTitle) &gt; -1 </span><span style="color:#0000ff;">Then
</span><span style="color:#000000;">                </span><span style="color:#0000ff;">Dim</span><span style="color:#000000;"> foundWindow </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> </span><span style="color:#0000ff;">New</span><span style="color:#000000;"> FoundWindow
                foundWindow.hWnd = </span><span style="color:#0000ff;">CType</span><span style="color:#000000;">(hwnd, IntPtr)
                </span><span style="color:#0000ff;">Dim</span><span style="color:#000000;"> sbClassName </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> </span><span style="color:#0000ff;">New</span><span style="color:#000000;"> System.Text.StringBuilder(</span><span style="color:#a31515;">""</span><span style="color:#000000;">, 256)
                GetClassName(foundWindow.hWnd, sbClassName, 256)
                foundWindow.strClassName = sbClassName.ToString
                foundWindow.strWindowName = sb.ToString
                foundWindows.lstFoundWindows.Add(foundWindow)
            </span><span style="color:#0000ff;">End</span><span style="color:#000000;"> </span><span style="color:#0000ff;">If
</span><span style="color:#000000;">        </span><span style="color:#0000ff;">End</span><span style="color:#000000;"> </span><span style="color:#0000ff;">If
</span><span style="color:#000000;">        </span><span style="color:#0000ff;">Return</span><span style="color:#000000;"> </span><span style="color:#0000ff;">True
</span><span style="color:#000000;">    </span><span style="color:#0000ff;">End</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Function

</span><span style="color:#000000;">    </span><span style="color:#008000;">''' </span><span style="color:#808080;">&lt;summary&gt;
</span><span style="color:#000000;">    </span><span style="color:#008000;">''' This function is used to loop through all open windows and check which ones contain a specific string
</span><span style="color:#000000;">    </span><span style="color:#008000;">''' </span><span style="color:#808080;">&lt;/summary&gt;
</span><span style="color:#000000;">    </span><span style="color:#008000;">''' </span><span style="color:#808080;">&lt;param name="strIndexOf"&gt;</span><span style="color:#008000;">The string that you wish to check for in the window captions</span><span style="color:#808080;">&lt;/param&gt;
</span><span style="color:#000000;">    </span><span style="color:#008000;">''' </span><span style="color:#808080;">&lt;param name="boolCase"&gt;</span><span style="color:#008000;">Whether the function is should check for case</span><span style="color:#808080;">&lt;/param&gt;
</span><span style="color:#000000;">    </span><span style="color:#008000;">''' </span><span style="color:#808080;">&lt;returns&gt;</span><span style="color:#008000;">A FoundWindows structure containing a list of FoundWindow</span><span style="color:#808080;">&lt;/returns&gt;
</span><span style="color:#000000;">    </span><span style="color:#008000;">''' </span><span style="color:#808080;">&lt;remarks&gt;</span><span style="color:#008000;">The FoundWindows structure also contains the strIndexOf that was used to search the windows caption</span><span style="color:#808080;">&lt;/remarks&gt;
</span><span style="color:#000000;">    </span><span style="color:#0000ff;">Public</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Function</span><span style="color:#000000;"> FindWindowsIndexOf(</span><span style="color:#0000ff;">ByVal</span><span style="color:#000000;"> strIndexOf </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> </span><span style="color:#0000ff;">String</span><span style="color:#000000;">, </span><span style="color:#0000ff;">ByVal</span><span style="color:#000000;"> boolCase </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Boolean</span><span style="color:#000000;">) </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> FoundWindows
        </span><span style="color:#0000ff;">Dim</span><span style="color:#000000;"> foundWindows </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> </span><span style="color:#0000ff;">New</span><span style="color:#000000;"> FoundWindows
        foundWindows.boolCase = boolCase
        foundWindows.strFindWindow = strIndexOf
        foundWindows.lstFoundWindows = </span><span style="color:#0000ff;">New</span><span style="color:#000000;"> List(</span><span style="color:#0000ff;">Of</span><span style="color:#000000;"> FoundWindow)
        </span><span style="color:#0000ff;">Dim</span><span style="color:#000000;"> ListHandle </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> System.Runtime.InteropServices.GCHandle = System.Runtime.InteropServices.GCHandle.Alloc(foundWindows)
        </span><span style="color:#0000ff;">Try
</span><span style="color:#000000;">            EnumWindows(</span><span style="color:#0000ff;">AddressOf</span><span style="color:#000000;"> EnumWindowsProc, System.Runtime.InteropServices.GCHandle.ToIntPtr(ListHandle))
        </span><span style="color:#0000ff;">Finally
</span><span style="color:#000000;">            </span><span style="color:#0000ff;">If</span><span style="color:#000000;"> ListHandle.IsAllocated </span><span style="color:#0000ff;">Then</span><span style="color:#000000;"> ListHandle.Free()
        </span><span style="color:#0000ff;">End</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Try
</span><span style="color:#000000;">        </span><span style="color:#0000ff;">Return</span><span style="color:#000000;"> foundWindows
    </span><span style="color:#0000ff;">End</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Function

</span><span style="color:#000000;">    </span><span style="color:#0000ff;">Private</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Sub</span><span style="color:#000000;"> Form1_Load(</span><span style="color:#0000ff;">ByVal</span><span style="color:#000000;"> sender </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> System.Object, </span><span style="color:#0000ff;">ByVal</span><span style="color:#000000;"> e </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> System.EventArgs) </span><span style="color:#0000ff;">Handles</span><span style="color:#000000;"> </span><span style="color:#0000ff;">MyBase</span><span style="color:#000000;">.Load
        </span><span style="color:#0000ff;">For</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Each</span><span style="color:#000000;"> fWnd </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> FoundWindow </span><span style="color:#0000ff;">In</span><span style="color:#000000;"> FindWindowsIndexOf(</span><span style="color:#a31515;">"Test"</span><span style="color:#000000;">, </span><span style="color:#0000ff;">True</span><span style="color:#000000;">).lstFoundWindows
            Debug.WriteLine(fWnd.strWindowName &amp; </span><span style="color:#a31515;">" : "</span><span style="color:#000000;"> &amp; fWnd.hWnd.ToString)
        </span><span style="color:#0000ff;">Next
</span><span style="color:#000000;">    </span><span style="color:#0000ff;">End</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Sub</span></pre>
</div>
<p>The function can check for casing as well. For example if you are running two windows one named &#8220;test&#8221; and another named &#8220;Test&#8221; if you use the function like this:</p>
<div style="border:#660000 5px solid;color:#000000;">
<pre style="background-color:#ffffff;line-height:15px;color:#000000;font-family:Courier New!important;font-size:11px!important;padding:3px;"><span style="color:#000000;">FindWindowsIndexOf(</span><span style="color:#a31515;">"Test"</span><span style="color:#000000;">, </span><span style="color:#0000ff;">True</span><span style="color:#000000;">)</span></pre>
</div>
<p>It will only return one window, however if you set the boolCase to false:</p>
<div style="border:#660000 5px solid;color:#000000;">
<pre style="background-color:#ffffff;line-height:15px;color:#000000;font-family:Courier New!important;font-size:11px!important;padding:3px;"><span style="color:#000000;">FindWindowsIndexOf(</span><span style="color:#a31515;">"Test"</span><span style="color:#000000;">, </span><span style="color:#0000ff;">False</span><span style="color:#000000;">)</span></pre>
</div>
<p>It will return both windows</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sim0n.wordpress.com/298/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sim0n.wordpress.com/298/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sim0n.wordpress.com/298/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sim0n.wordpress.com/298/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sim0n.wordpress.com/298/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sim0n.wordpress.com/298/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sim0n.wordpress.com/298/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sim0n.wordpress.com/298/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sim0n.wordpress.com/298/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sim0n.wordpress.com/298/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sim0n.wordpress.com/298/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sim0n.wordpress.com/298/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sim0n.wordpress.com/298/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sim0n.wordpress.com/298/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sim0n.wordpress.com&amp;blog=6301650&amp;post=298&amp;subd=sim0n&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sim0n.wordpress.com/2009/05/05/vbnet-findwindowsindexof-api-version/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/810cb4ebed3e0db0c0d9777516931db0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sim0n</media:title>
		</media:content>
	</item>
		<item>
		<title>[VB.Net] The beginnings of a Neopets bot</title>
		<link>http://sim0n.wordpress.com/2009/05/03/vbnet-the-beginnings-of-a-neopets-bot/</link>
		<comments>http://sim0n.wordpress.com/2009/05/03/vbnet-the-beginnings-of-a-neopets-bot/#comments</comments>
		<pubDate>Sun, 03 May 2009 16:05:30 +0000</pubDate>
		<dc:creator>sim0n</dc:creator>
				<category><![CDATA[VB.Net]]></category>

		<guid isPermaLink="false">http://sim0n.wordpress.com/?p=296</guid>
		<description><![CDATA[Ive decided that I&#8217;ve had enough of javascript, and so im going to move to VB.net to attempt to create a better bot. The auction bot itself, is, very good. However, now I want an autobuyer, and I cant get that to work in javascript as firefox doesn&#8217;t want to display the image when haggling.. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sim0n.wordpress.com&amp;blog=6301650&amp;post=296&amp;subd=sim0n&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Ive decided that I&#8217;ve had enough of javascript, and so im going to move to VB.net to attempt to create a better bot. The auction bot itself, is, very good. However, now I want an autobuyer, and I cant get that to work in javascript as firefox doesn&#8217;t want to display the image when haggling..</p>
<p>Ive decided to do it using a webbrowser control, for ease of accessing the elements on the page, and below is a quick example of logging into neopets.</p>
<div style="border:#660000 5px solid;color:#000000;">
<pre style="background-color:#ffffff;line-height:15px;color:#000000;font-family:Courier New!important;font-size:11px!important;padding:3px;"><span style="color:#000000;">    </span><span style="color:#0000ff;">Private</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Enum</span><span style="color:#000000;"> Bot_State
        Initial
        LogIn
        LoggingIn1
        LoggingIn2
        LoggingIn3
        LoggedIn
    </span><span style="color:#0000ff;">End</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Enum

</span><span style="color:#000000;">    </span><span style="color:#0000ff;">Dim</span><span style="color:#000000;"> State </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> Bot_State = Bot_State.Initial
    </span><span style="color:#0000ff;">Dim</span><span style="color:#000000;"> Username </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> </span><span style="color:#0000ff;">String</span><span style="color:#000000;"> = </span><span style="color:#a31515;">"username"
</span><span style="color:#000000;">    </span><span style="color:#0000ff;">Dim</span><span style="color:#000000;"> Password </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> </span><span style="color:#0000ff;">String</span><span style="color:#000000;"> = </span><span style="color:#a31515;">"password"

</span><span style="color:#000000;">    </span><span style="color:#008000;">''web = System.Windows.Forms.WebBrowser
</span><span style="color:#000000;">    </span><span style="color:#0000ff;">Private</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Sub</span><span style="color:#000000;"> Form1_Load(</span><span style="color:#0000ff;">ByVal</span><span style="color:#000000;"> sender </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> System.Object, </span><span style="color:#0000ff;">ByVal</span><span style="color:#000000;"> e </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> System.EventArgs) </span><span style="color:#0000ff;">Handles</span><span style="color:#000000;"> </span><span style="color:#0000ff;">MyBase</span><span style="color:#000000;">.Load
        web.Navigate(</span><span style="color:#a31515;">"http://neopets.com"</span><span style="color:#000000;">)
    </span><span style="color:#0000ff;">End</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Sub

</span><span style="color:#000000;">    </span><span style="color:#0000ff;">Private</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Sub</span><span style="color:#000000;"> web_DocumentCompleted(</span><span style="color:#0000ff;">ByVal</span><span style="color:#000000;"> sender </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Object</span><span style="color:#000000;">, </span><span style="color:#0000ff;">ByVal</span><span style="color:#000000;"> e </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) </span><span style="color:#0000ff;">Handles</span><span style="color:#000000;"> web.DocumentCompleted
        </span><span style="color:#0000ff;">Select</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Case</span><span style="color:#000000;"> State
            </span><span style="color:#0000ff;">Case</span><span style="color:#000000;"> Bot_State.Initial
                </span><span style="color:#0000ff;">If</span><span style="color:#000000;"> web.Document.Body.InnerHtml.IndexOf(</span><span style="color:#a31515;">"Login"</span><span style="color:#000000;">) &lt;&gt; -1 </span><span style="color:#0000ff;">Then
</span><span style="color:#000000;">                    State = Bot_State.LogIn
                    web.Navigate(web.Url.AbsoluteUri &amp; </span><span style="color:#a31515;">"/loginpage.phtml"</span><span style="color:#000000;">)
                </span><span style="color:#0000ff;">Else
</span><span style="color:#000000;">                    State = Bot_State.LoggedIn
                </span><span style="color:#0000ff;">End</span><span style="color:#000000;"> </span><span style="color:#0000ff;">If
</span><span style="color:#000000;">            </span><span style="color:#0000ff;">Case</span><span style="color:#000000;"> Bot_State.LogIn
                </span><span style="color:#0000ff;">Dim</span><span style="color:#000000;"> UserTB </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> HtmlElement = web.Document.GetElementById(</span><span style="color:#a31515;">"txtUsername"</span><span style="color:#000000;">)
                UserTB.SetAttribute(</span><span style="color:#a31515;">"value"</span><span style="color:#000000;">, Username)
                UserTB.Parent().Parent().Parent().Parent().DomElement.Submit()
                State = Bot_State.LoggingIn1
            </span><span style="color:#0000ff;">Case</span><span style="color:#000000;"> Bot_State.LoggingIn1
                State = Bot_State.LoggingIn2
            </span><span style="color:#0000ff;">Case</span><span style="color:#000000;"> Bot_State.LoggingIn2
                </span><span style="color:#0000ff;">Dim</span><span style="color:#000000;"> PageInput </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> HtmlElementCollection = web.Document.GetElementsByTagName(</span><span style="color:#a31515;">"input"</span><span style="color:#000000;">)
                </span><span style="color:#0000ff;">For</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Each</span><span style="color:#000000;"> elem </span><span style="color:#0000ff;">As</span><span style="color:#000000;"> HtmlElement </span><span style="color:#0000ff;">In</span><span style="color:#000000;"> PageInput
                    </span><span style="color:#0000ff;">If</span><span style="color:#000000;"> elem.GetAttribute(</span><span style="color:#a31515;">"name"</span><span style="color:#000000;">) = </span><span style="color:#a31515;">"password"</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Then
</span><span style="color:#000000;">                        elem.SetAttribute(</span><span style="color:#a31515;">"value"</span><span style="color:#000000;">, Password)
                        elem.Parent().Parent().Parent().Parent().DomElement.Submit()
                    </span><span style="color:#0000ff;">End</span><span style="color:#000000;"> </span><span style="color:#0000ff;">If
</span><span style="color:#000000;">                </span><span style="color:#0000ff;">Next
</span><span style="color:#000000;">                State = Bot_State.LoggingIn3
            </span><span style="color:#0000ff;">Case</span><span style="color:#000000;"> Bot_State.LoggingIn3
                </span><span style="color:#0000ff;">If</span><span style="color:#000000;"> web.Url.AbsoluteUri.IndexOf(</span><span style="color:#a31515;">"index"</span><span style="color:#000000;">) </span><span style="color:#0000ff;">Then
</span><span style="color:#000000;">                    State = Bot_State.LoggedIn
                </span><span style="color:#0000ff;">Else
</span><span style="color:#000000;">                    State = Bot_State.LogIn
                    web.Navigate(web.Url.AbsoluteUri &amp; </span><span style="color:#a31515;">"/loginpage.phtml"</span><span style="color:#000000;">)
                </span><span style="color:#0000ff;">End</span><span style="color:#000000;"> </span><span style="color:#0000ff;">If
</span><span style="color:#000000;">        </span><span style="color:#0000ff;">End</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Select
</span><span style="color:#000000;">    </span><span style="color:#0000ff;">End</span><span style="color:#000000;"> </span><span style="color:#0000ff;">Sub</span></pre>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sim0n.wordpress.com/296/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sim0n.wordpress.com/296/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sim0n.wordpress.com/296/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sim0n.wordpress.com/296/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sim0n.wordpress.com/296/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sim0n.wordpress.com/296/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sim0n.wordpress.com/296/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sim0n.wordpress.com/296/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sim0n.wordpress.com/296/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sim0n.wordpress.com/296/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sim0n.wordpress.com/296/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sim0n.wordpress.com/296/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sim0n.wordpress.com/296/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sim0n.wordpress.com/296/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sim0n.wordpress.com&amp;blog=6301650&amp;post=296&amp;subd=sim0n&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sim0n.wordpress.com/2009/05/03/vbnet-the-beginnings-of-a-neopets-bot/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/810cb4ebed3e0db0c0d9777516931db0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sim0n</media:title>
		</media:content>
	</item>
		<item>
		<title>[Javascript/Php] Neopets Auction Bot Project (3)</title>
		<link>http://sim0n.wordpress.com/2009/05/01/javascriptphp-neopets-auction-bot-project-3/</link>
		<comments>http://sim0n.wordpress.com/2009/05/01/javascriptphp-neopets-auction-bot-project-3/#comments</comments>
		<pubDate>Fri, 01 May 2009 17:47:42 +0000</pubDate>
		<dc:creator>sim0n</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[almost complete]]></category>
		<category><![CDATA[auction bot]]></category>
		<category><![CDATA[neopets]]></category>
		<category><![CDATA[progress]]></category>
		<category><![CDATA[project]]></category>
		<category><![CDATA[update]]></category>

		<guid isPermaLink="false">http://sim0n.wordpress.com/?p=293</guid>
		<description><![CDATA[The latest update to the auction bot. *IF YOU WANT TO USE THIS, YOU HAVE TO CONTACT ME* The reason for it being private, is nothing to do with me being selfish or anything, but the fact that this script queries my MySQL database between 6-10 times a minute, and I dont want it to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sim0n.wordpress.com&amp;blog=6301650&amp;post=293&amp;subd=sim0n&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The latest update to the auction bot.</p>
<p>*IF YOU WANT TO USE THIS, YOU HAVE TO CONTACT ME*<br />
The reason for it being private, is nothing to do with me being selfish or anything, but the fact that this script queries my MySQL database between 6-10 times a minute, and I dont want it to run too slowly. Ive posted everything required to set it up here, however, if you need help, feel free to contact me (Details: <a href="http://sim0n.net46.net/#content" target="_blank">my contact details</a> -&gt; about)</p>
<p>Its almost fully automated now, refreshing, opening, closing pages correctly.<br />
There are only a few things to sort out, but to the average user these problems aren&#8217;t noticeable (check the grease monkey var for the script after running it for a while -_-)</p>
<p>Source for the PHP remains the same, so check the other posts.<br />
Below is the greasemonkey script:</p>
<div style="border:#660000 5px solid;color:#000000;">
<pre style="background-color:#ffffff;line-height:15px;color:#000000;font-family:Courier New!important;font-size:11px!important;padding:3px;"><span style="color:#008000;">// ==UserScript==
// @name           Aucti0n b0t - sim0n
// @namespace      Neopets
// @description    http://sim0n.wordpress.com
// @include        http://www.neopets.com/auctions.phtml*
// ==/UserScript==

//Functions
//------------------------------
</span><span style="color:#0000ff;">function</span><span style="color:#000000;"> getElementsByAttribute(oElm, strTagName, strAttributeName, strAttributeValue){
	</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> arrElements = (strTagName == </span><span style="color:#a31515;">"*"</span><span style="color:#000000;"> &amp;&amp; oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> arrReturnElements = </span><span style="color:#0000ff;">new</span><span style="color:#000000;"> Array();
	</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> oAttributeValue = (</span><span style="color:#0000ff;">typeof</span><span style="color:#000000;"> strAttributeValue != </span><span style="color:#a31515;">"undefined"</span><span style="color:#000000;">)? </span><span style="color:#0000ff;">new</span><span style="color:#000000;"> RegExp(</span><span style="color:#a31515;">"(^|\\s)"</span><span style="color:#000000;"> + strAttributeValue + </span><span style="color:#a31515;">"(\\s|$)"</span><span style="color:#000000;">) : </span><span style="color:#0000ff;">null</span><span style="color:#000000;">;
	</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> oCurrent;
	</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> oAttribute;
	</span><span style="color:#0000ff;">for</span><span style="color:#000000;">(</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> i=0; i&lt;arrElements.length; i++){
		oCurrent = arrElements[i];
		oAttribute = oCurrent.getAttribute &amp;&amp; oCurrent.getAttribute(strAttributeName);
		</span><span style="color:#0000ff;">if</span><span style="color:#000000;">(</span><span style="color:#0000ff;">typeof</span><span style="color:#000000;"> oAttribute == </span><span style="color:#a31515;">"string"</span><span style="color:#000000;"> &amp;&amp; oAttribute.length &gt; 0){
			</span><span style="color:#0000ff;">if</span><span style="color:#000000;">(</span><span style="color:#0000ff;">typeof</span><span style="color:#000000;"> strAttributeValue == </span><span style="color:#a31515;">"undefined"</span><span style="color:#000000;"> || (oAttributeValue &amp;&amp; oAttributeValue.test(oAttribute))){
				arrReturnElements.push(oCurrent);
			}
		}
	}
	</span><span style="color:#0000ff;">return</span><span style="color:#000000;"> arrReturnElements;
}
</span><span style="color:#0000ff;">function</span><span style="color:#000000;"> createErrorBox(docTitle, boxHeight, content, contentSize) {
	</span><span style="color:#0000ff;">if</span><span style="color:#000000;">(docTitle != </span><span style="color:#a31515;">""</span><span style="color:#000000;">) { document.title = docTitle };
	</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> size = </span><span style="color:#a31515;">"100px;"</span><span style="color:#000000;">;
	</span><span style="color:#0000ff;">if</span><span style="color:#000000;">(boxHeight != </span><span style="color:#a31515;">''</span><span style="color:#000000;">) { size = boxHeight + </span><span style="color:#a31515;">"px"</span><span style="color:#000000;">; }
	</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> darkenScreen = document.createElement(</span><span style="color:#a31515;">'div'</span><span style="color:#000000;">);
	darkenScreen.setAttribute(</span><span style="color:#a31515;">'style'</span><span style="color:#000000;">, </span><span style="color:#a31515;">'position:fixed;left:0;top:0;width:100%;height:100%;background:#000000;opacity:0.8'</span><span style="color:#000000;">);
	document.body.appendChild(darkenScreen);
	</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> errorBox = document.createElement(</span><span style="color:#a31515;">'div'</span><span style="color:#000000;">);
	</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> left = (document.documentElement.clientWidth /2)-150;
	errorBox.setAttribute(</span><span style="color:#a31515;">'style'</span><span style="color:#000000;">, </span><span style="color:#a31515;">'width:300px; '</span><span style="color:#000000;"> + size + </span><span style="color:#a31515;">' border:#990000 thick solid; background:#CCCCCC;padding:6px;position:fixed;left:'</span><span style="color:#000000;"> + left + </span><span style="color:#a31515;">'px;top:100px;'</span><span style="color:#000000;">);
	</span><span style="color:#0000ff;">for</span><span style="color:#000000;">(</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> i = 1; i&lt;contentSize; i++) {
		errorBox.appendChild(content[i]);
	}
	document.body.appendChild(errorBox);
}
</span><span style="color:#0000ff;">function</span><span style="color:#000000;"> closeWindow() {
	</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> errorTitle = document.createElement(</span><span style="color:#a31515;">'span'</span><span style="color:#000000;">);
	errorTitle.setAttribute(</span><span style="color:#a31515;">'style'</span><span style="color:#000000;">, </span><span style="color:#a31515;">'font-family:Georgia; text-align:center; font-weight:bold;z-index:9999'</span><span style="color:#000000;">);
	errorTitle.appendChild(document.createTextNode(</span><span style="color:#a31515;">'Error'</span><span style="color:#000000;">));
	</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> errorBold = document.createElement(</span><span style="color:#a31515;">'b'</span><span style="color:#000000;">);
	</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> errorItalic = document.createElement(</span><span style="color:#a31515;">'i'</span><span style="color:#000000;">);
	errorItalic.appendChild(document.createTextNode(</span><span style="color:#a31515;">'dom.allow_scripts_to_close_windows'</span><span style="color:#000000;">));
	errorBold.appendChild(errorItalic);

	</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> elemArray = {
		1 : errorTitle,
		2 : document.createElement(</span><span style="color:#a31515;">'br'</span><span style="color:#000000;">),
		3 : errorBold,
		4 : document.createTextNode(</span><span style="color:#a31515;">' is false.'</span><span style="color:#000000;">),
		5 : document.createElement(</span><span style="color:#a31515;">'br'</span><span style="color:#000000;">),
		6 : document.createTextNode(</span><span style="color:#a31515;">'To enable it, navigate to about:config and change the value from False to True'</span><span style="color:#000000;">)
	}

	createErrorBox(</span><span style="color:#a31515;">'Close error - click for details'</span><span style="color:#000000;">, </span><span style="color:#a31515;">''</span><span style="color:#000000;">, elemArray, 7);
	window.close();
}
</span><span style="color:#0000ff;">function</span><span style="color:#000000;"> removeImages() {
	</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> images=document.images;
	</span><span style="color:#0000ff;">for</span><span style="color:#000000;">(</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> x=0;x&lt;images.length;i++){
		images[x].parentNode.removeChild(images[x]);
	}
}
</span><span style="color:#0000ff;">function</span><span style="color:#000000;"> parseUrl(max_price) {
	</span><span style="color:#0000ff;">return</span><span style="color:#000000;"> String(document.location).substring(String(document.location).lastIndexOf(</span><span style="color:#a31515;">"="</span><span style="color:#000000;">)+1);
}
</span><span style="color:#0000ff;">function</span><span style="color:#000000;"> removeBidCookie(link) {
	</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> curID = link.replace(/.*auction_id=(\d*).*/, </span><span style="color:#a31515;">"$1"</span><span style="color:#000000;">);
	</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> cur = String(GM_getValue(</span><span style="color:#a31515;">'currentAuctions'</span><span style="color:#000000;">));
	cur = cur.replace(curID + </span><span style="color:#a31515;">"|"</span><span style="color:#000000;">, </span><span style="color:#a31515;">""</span><span style="color:#000000;">);
	GM_setValue(</span><span style="color:#a31515;">'currentAuctions'</span><span style="color:#000000;">, cur);
}

</span><span style="color:#008000;">//Main Page Functions
//------------------------------
</span><span style="color:#0000ff;">function</span><span style="color:#000000;"> queryNeopetItem(item, complete) {
	</span><span style="color:#008000;">//Create a httpRequest, the php script returns a list of items max price + sell price
</span><span style="color:#000000;">	</span><span style="color:#008000;">//Format:
</span><span style="color:#000000;">	</span><span style="color:#008000;">//maxprice[0]	sellprice[0]
</span><span style="color:#000000;">	</span><span style="color:#008000;">//maxprice[1]	sellprice[1]
</span><span style="color:#000000;">	</span><span style="color:#008000;">//maxprice[n-1]	sellprice[n-1]
</span><span style="color:#000000;">	</span><span style="color:#008000;">//maxprice[n]	sellprice[n]
</span><span style="color:#000000;">	</span><span style="color:#008000;">//complete is a function that parses the responseText
</span><span style="color:#000000;">	url = </span><span style="color:#a31515;">"http://myhost.com/queryv2.php?items="</span><span style="color:#000000;"> + item;
	GM_xmlhttpRequest({
		method: </span><span style="color:#a31515;">"POST"</span><span style="color:#000000;">,
		url: url,
		headers:{</span><span style="color:#a31515;">'Content-type'</span><span style="color:#000000;">:</span><span style="color:#a31515;">'application/x-www-form-urlencoded'</span><span style="color:#000000;">},
		data:encodeURI(</span><span style="color:#a31515;">""</span><span style="color:#000000;">),
		onload: </span><span style="color:#0000ff;">function</span><span style="color:#000000;">(xhr) { complete(xhr.responseText); }
	});
}
</span><span style="color:#0000ff;">function</span><span style="color:#000000;"> comp(text) {
	</span><span style="color:#008000;">//Splits each line
</span><span style="color:#000000;">	</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> items = text.split(</span><span style="color:#a31515;">"\n"</span><span style="color:#000000;">);
	</span><span style="color:#008000;">//We only want 20 lines (20 items per page)
</span><span style="color:#000000;">	</span><span style="color:#0000ff;">for</span><span style="color:#000000;">(</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> i = 0;i&lt;20;i++) {
		</span><span style="color:#0000ff;">if</span><span style="color:#000000;">(items[i] == </span><span style="color:#a31515;">""</span><span style="color:#000000;"> || String(items[i]) == </span><span style="color:#a31515;">"undefined"</span><span style="color:#000000;">) {
			</span><span style="color:#008000;">//Item not in database
</span><span style="color:#000000;">			table[0].rows[i+1].setAttribute(</span><span style="color:#a31515;">"bgcolor"</span><span style="color:#000000;">,</span><span style="color:#a31515;">"#ccffd0"</span><span style="color:#000000;">);
		} </span><span style="color:#0000ff;">else</span><span style="color:#000000;"> {
			</span><span style="color:#008000;">//Split max/min price
</span><span style="color:#000000;">			</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> item = items[i].split(</span><span style="color:#a31515;">"\t"</span><span style="color:#000000;">);
			</span><span style="color:#008000;">//Get the items current price, check its less
</span><span style="color:#000000;">			</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> cur_price = table[0].rows[i+1].cells[6].innerHTML.replace(/&lt;b&gt;(\d*)&lt;\/b&gt; NP/, </span><span style="color:#a31515;">"$1"</span><span style="color:#000000;">);
			</span><span style="color:#0000ff;">if</span><span style="color:#000000;">(Number(cur_price)&lt;=Number(item[0])) {
				</span><span style="color:#008000;">//If it is less, check if its a NF auction or not
</span><span style="color:#000000;">				</span><span style="color:#0000ff;">if</span><span style="color:#000000;">(table[0].rows[i+1].cells[3].innerHTML.toLowerCase().indexOf(</span><span style="color:#a31515;">"&lt;b&gt;[nf]&lt;/b&gt;"</span><span style="color:#000000;">) != -1) {
					</span><span style="color:#008000;">//If it is, ignore it
</span><span style="color:#000000;">					table[0].rows[i+1].setAttribute(</span><span style="color:#a31515;">"bgcolor"</span><span style="color:#000000;">,</span><span style="color:#a31515;">"#aaafa0"</span><span style="color:#000000;">);
				} </span><span style="color:#0000ff;">else</span><span style="color:#000000;"> {
					</span><span style="color:#008000;">//Else, open the page in a new tab
</span><span style="color:#000000;">					table[0].rows[i+1].setAttribute(</span><span style="color:#a31515;">"bgcolor"</span><span style="color:#000000;">,</span><span style="color:#a31515;">"#00ffff"</span><span style="color:#000000;">);
					doAuction(table[0].rows[i+1].cells[2].getElementsByTagName(</span><span style="color:#a31515;">'a'</span><span style="color:#000000;">)[0], item[0]);
				}
			} </span><span style="color:#0000ff;">else</span><span style="color:#000000;"> {
				table[0].rows[i+1].setAttribute(</span><span style="color:#a31515;">"bgcolor"</span><span style="color:#000000;">,</span><span style="color:#a31515;">"#aaffd0"</span><span style="color:#000000;">);
			}
		}
	}
}
</span><span style="color:#0000ff;">function</span><span style="color:#000000;"> doAuction(link, max_price) {
	</span><span style="color:#008000;">//Used to open the selected auction in a new tab with max price in the url
</span><span style="color:#000000;">	</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> curID = link.href.replace(/.*auction_id=(\d*)/, </span><span style="color:#a31515;">"$1"</span><span style="color:#000000;">);
	</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> cur = String(GM_getValue(</span><span style="color:#a31515;">'currentAuctions'</span><span style="color:#000000;">));
	</span><span style="color:#0000ff;">if</span><span style="color:#000000;">(cur==</span><span style="color:#a31515;">"undefined"</span><span style="color:#000000;">) {cur=</span><span style="color:#a31515;">""</span><span style="color:#000000;">;}
	</span><span style="color:#0000ff;">if</span><span style="color:#000000;">(cur.indexOf(curID) == -1) {
		</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> x = cur + curID + </span><span style="color:#a31515;">"|"</span><span style="color:#000000;">;
		GM_setValue(</span><span style="color:#a31515;">'currentAuctions'</span><span style="color:#000000;">, x);
		GM_openInTab(link.href + </span><span style="color:#a31515;">"&amp;maxprice="</span><span style="color:#000000;"> + max_price);
		GM_log(</span><span style="color:#a31515;">"Opened: "</span><span style="color:#000000;"> + curID);
	}
}

</span><span style="color:#008000;">//Script testing
//------------------------------

//Script
//------------------------------
</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> url = String(document.location);
</span><span style="color:#0000ff;">if</span><span style="color:#000000;">(url.indexOf(</span><span style="color:#a31515;">'placebid'</span><span style="color:#000000;">) == -1 &amp;&amp; url.indexOf(</span><span style="color:#a31515;">'bids'</span><span style="color:#000000;">) == -1) {

	</span><span style="color:#008000;">//The main auction page - Create list of items
</span><span style="color:#000000;">	removeImages();
	</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> table = getElementsByAttribute(document.body, </span><span style="color:#a31515;">"table"</span><span style="color:#000000;">, </span><span style="color:#a31515;">"align"</span><span style="color:#000000;">, </span><span style="color:#a31515;">"center"</span><span style="color:#000000;">);
	</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> queryString = </span><span style="color:#a31515;">""</span><span style="color:#000000;">;
	</span><span style="color:#0000ff;">for</span><span style="color:#000000;">(</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> i=1;i&lt;table[0].rows.length - 1;i++) {
		queryString = queryString + table[0].rows[i].cells[2].innerHTML.replace(/&lt;a href=\</span><span style="color:#a31515;">".*\"&gt;(.*)&lt;\/a&gt;/, "</span><span style="color:#000000;">$1</span><span style="color:#a31515;">") + "</span><span style="color:#000000;">|</span><span style="color:#a31515;">";
</span><span style="color:#000000;">	}
	queryString = queryString + table[0].rows[table[0].rows.length-1].cells[2].innerHTML.replace(/&lt;a href=\</span><span style="color:#a31515;">".*\"&gt;(.*)&lt;\/a&gt;/, "</span><span style="color:#000000;">$1</span><span style="color:#a31515;">")
</span><span style="color:#000000;">	</span><span style="color:#008000;">//Query the database
</span><span style="color:#000000;">	queryNeopetItem(queryString, comp);

	</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> minTime = 6;
	</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> maxTime = 10;
	</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> PERIOD = (maxTime * 1000 - minTime * 1000) * Math.random() + minTime * 1000;
	setTimeout(</span><span style="color:#a31515;">'location.reload(true)'</span><span style="color:#000000;">, PERIOD);

} </span><span style="color:#0000ff;">else</span><span style="color:#000000;"> </span><span style="color:#0000ff;">if</span><span style="color:#000000;">(url.indexOf(</span><span style="color:#a31515;">'bids'</span><span style="color:#000000;">) != -1 &amp;&amp; url.indexOf(</span><span style="color:#a31515;">'maxprice'</span><span style="color:#000000;">) != -1) {

	</span><span style="color:#008000;">//Place bid
</span><span style="color:#000000;">	</span><span style="color:#0000ff;">if</span><span style="color:#000000;"> ((window.find(</span><span style="color:#a31515;">"Time Left in Auction :  Closed"</span><span style="color:#000000;"> , </span><span style="color:#0000ff;">false</span><span style="color:#000000;">, </span><span style="color:#0000ff;">true</span><span style="color:#000000;">) == </span><span style="color:#0000ff;">false</span><span style="color:#000000;">) &amp;&amp; (window.find(</span><span style="color:#a31515;">"Oops! - Invalid Auction ID"</span><span style="color:#000000;">) == </span><span style="color:#0000ff;">false</span><span style="color:#000000;">)) {
		</span><span style="color:#008000;">//Valid auction
</span><span style="color:#000000;">		</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> max_price = parseUrl();
		</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> name = getElementsByAttribute(document.getElementById(</span><span style="color:#a31515;">'header'</span><span style="color:#000000;">), </span><span style="color:#a31515;">'td'</span><span style="color:#000000;">, </span><span style="color:#a31515;">'class'</span><span style="color:#000000;">, </span><span style="color:#a31515;">'user medText'</span><span style="color:#000000;">)[0].firstChild.nextSibling.textContent;
		</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> table = getElementsByAttribute(document.body, </span><span style="color:#a31515;">'table'</span><span style="color:#000000;">, </span><span style="color:#a31515;">'cellpadding'</span><span style="color:#000000;">, 4)[0];
		</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> lastbidder = </span><span style="color:#a31515;">""</span><span style="color:#000000;">;
		</span><span style="color:#0000ff;">if</span><span style="color:#000000;">(table) {
			lastbidder = table.rows[1].cells[0].textContent.substring(1);
		}
		</span><span style="color:#0000ff;">if</span><span style="color:#000000;">(lastbidder==name) {
			</span><span style="color:#008000;">//If last bidder was user reload after 2 seconds
</span><span style="color:#000000;">			setTimeout(</span><span style="color:#a31515;">'location.reload(true)'</span><span style="color:#000000;">, 3);
		} </span><span style="color:#0000ff;">else</span><span style="color:#000000;"> {
			</span><span style="color:#008000;">//Else, check to make sure its worth paying for
</span><span style="color:#000000;">			</span><span style="color:#0000ff;">if</span><span style="color:#000000;">(Number(document.getElementsByName(</span><span style="color:#a31515;">'amount'</span><span style="color:#000000;">)[0].value) &lt;= Number(max_price)) {
				</span><span style="color:#008000;">//Modify the form to add our max price
</span><span style="color:#000000;">				</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> forms = document.getElementsByTagName(</span><span style="color:#a31515;">"form"</span><span style="color:#000000;">);
				</span><span style="color:#0000ff;">for</span><span style="color:#000000;">(</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> i=0;i&lt;forms.length;i++) {
					</span><span style="color:#0000ff;">if</span><span style="color:#000000;">(forms[i].getAttribute(</span><span style="color:#a31515;">'action'</span><span style="color:#000000;">) == </span><span style="color:#a31515;">"auctions.phtml?type=placebid"</span><span style="color:#000000;">) {
						forms[i].setAttribute(</span><span style="color:#a31515;">'action'</span><span style="color:#000000;">, </span><span style="color:#a31515;">"auctions.phtml?type=placebid&amp;maxprice="</span><span style="color:#000000;"> + max_price)
					}
				}
				</span><span style="color:#008000;">//Submit the form
</span><span style="color:#000000;">				</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> button = getElementsByAttribute(document.body, </span><span style="color:#a31515;">'input'</span><span style="color:#000000;">, </span><span style="color:#a31515;">'value'</span><span style="color:#000000;">, </span><span style="color:#a31515;">'Place a Bid'</span><span style="color:#000000;">)[0];
				button.form.submit();
			} </span><span style="color:#0000ff;">else</span><span style="color:#000000;"> {
				</span><span style="color:#008000;">//too expensive */.
</span><span style="color:#000000;">				GM_log(</span><span style="color:#a31515;">"Closed: "</span><span style="color:#000000;"> + url);
				removeBidCookie(url)
				closeWindow();
			}
		}
	} </span><span style="color:#0000ff;">else</span><span style="color:#000000;"> {
		</span><span style="color:#008000;">// Will need to add in checking later on for who won the bid */.
</span><span style="color:#000000;">		removeBidCookie(url);
		GM_log(</span><span style="color:#a31515;">"Closed: "</span><span style="color:#000000;"> + url);
		closeWindow();
	}
} </span><span style="color:#0000ff;">else</span><span style="color:#000000;"> </span><span style="color:#0000ff;">if</span><span style="color:#000000;">(url.indexOf(</span><span style="color:#a31515;">'placebid'</span><span style="color:#000000;">) != -1) {

	</span><span style="color:#008000;">//After placing bid
</span><span style="color:#000000;">	</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> max_price = parseUrl();
	</span><span style="color:#0000ff;">if</span><span style="color:#000000;">(document.body.innerHTML.indexOf(</span><span style="color:#a31515;">"BID SUCCESSFUL"</span><span style="color:#000000;">) != -1) {
		</span><span style="color:#008000;">//Bid worked
</span><span style="color:#000000;">		</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> link = document.getElementsByTagName(</span><span style="color:#a31515;">'a'</span><span style="color:#000000;">);
		</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> s = </span><span style="color:#a31515;">'http://www.neopets.com/auctions.phtml?type=bids&amp;auction_id='
</span><span style="color:#000000;">		</span><span style="color:#0000ff;">for</span><span style="color:#000000;">(</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> i = 0; i &lt; link.length; i++) {
			</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> str = link[i].href;
			str = str.substr(0, 59)
			</span><span style="color:#0000ff;">if</span><span style="color:#000000;">(str == s) { document.location = link[i].href + </span><span style="color:#a31515;">"&amp;maxprice="</span><span style="color:#000000;"> + max_price; }
		}
	} </span><span style="color:#0000ff;">else</span><span style="color:#000000;"> </span><span style="color:#0000ff;">if</span><span style="color:#000000;">(document.body.innerHTML.indexOf(</span><span style="color:#a31515;">"The current asking price for this item"</span><span style="color:#000000;">) != -1) {
		</span><span style="color:#008000;">//Bid not enough error
</span><span style="color:#000000;">		</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> link = document.getElementsByTagName(</span><span style="color:#a31515;">'a'</span><span style="color:#000000;">);
		</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> s = </span><span style="color:#a31515;">'http://www.neopets.com/auctions.phtml?type=bids&amp;auction_id='
</span><span style="color:#000000;">		</span><span style="color:#0000ff;">for</span><span style="color:#000000;">(</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> i = 0; i &lt; link.length; i++) {
			</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> str = link[i].href;
			str = str.substr(0, 59)
			</span><span style="color:#0000ff;">if</span><span style="color:#000000;">(str == s) { document.location = link[i].href + </span><span style="color:#a31515;">"&amp;maxprice="</span><span style="color:#000000;"> + max_price; }
		}
	} </span><span style="color:#0000ff;">else</span><span style="color:#000000;"> </span><span style="color:#0000ff;">if</span><span style="color:#000000;">(document.body.innerHTML.indexOf(</span><span style="color:#a31515;">"You must wait a few more seconds"</span><span style="color:#000000;">) != -1) {
		</span><span style="color:#008000;">//Too fast
</span><span style="color:#000000;">		history.go(-1);
	} </span><span style="color:#0000ff;">else</span><span style="color:#000000;"> </span><span style="color:#0000ff;">if</span><span style="color:#000000;">(document.body.innerHTML.indexOf(</span><span style="color:#a31515;">"You don't have enough money to place that bid"</span><span style="color:#000000;">) != -1 || document.body.innerHTML.indexOf(</span><span style="color:#a31515;">"This auction is closed"</span><span style="color:#000000;">) != -1 || document.body.innerHTML.indexOf(</span><span style="color:#a31515;">"Invalid Auction ID"</span><span style="color:#000000;">) != -1) {
		</span><span style="color:#008000;">//Not enough money or auction is over */.
</span><span style="color:#000000;">		closeWindow();
	}

}</span></pre>
</div>
<p>Theres also a clue in this post as to how you can easily access my host if you want, its kinda&#8230; obvious.</p>
<p>Remember, this isnt the final product. Its still being worked on.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sim0n.wordpress.com/293/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sim0n.wordpress.com/293/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sim0n.wordpress.com/293/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sim0n.wordpress.com/293/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sim0n.wordpress.com/293/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sim0n.wordpress.com/293/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sim0n.wordpress.com/293/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sim0n.wordpress.com/293/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sim0n.wordpress.com/293/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sim0n.wordpress.com/293/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sim0n.wordpress.com/293/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sim0n.wordpress.com/293/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sim0n.wordpress.com/293/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sim0n.wordpress.com/293/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sim0n.wordpress.com&amp;blog=6301650&amp;post=293&amp;subd=sim0n&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sim0n.wordpress.com/2009/05/01/javascriptphp-neopets-auction-bot-project-3/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/810cb4ebed3e0db0c0d9777516931db0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sim0n</media:title>
		</media:content>
	</item>
		<item>
		<title>[Note] Neopets Autobidder Progress</title>
		<link>http://sim0n.wordpress.com/2009/04/29/note-neopets-autobidder-progress/</link>
		<comments>http://sim0n.wordpress.com/2009/04/29/note-neopets-autobidder-progress/#comments</comments>
		<pubDate>Wed, 29 Apr 2009 22:52:05 +0000</pubDate>
		<dc:creator>sim0n</dc:creator>
				<category><![CDATA[VB.Net]]></category>
		<category><![CDATA[auction bot]]></category>
		<category><![CDATA[neopets]]></category>
		<category><![CDATA[notes]]></category>
		<category><![CDATA[progress]]></category>
		<category><![CDATA[update]]></category>

		<guid isPermaLink="false">http://sim0n.wordpress.com/2009/04/29/note-neopets-autobidder-progress/</guid>
		<description><![CDATA[This is the current workup for the neopets auction bot: Currently, i have all the complex coding done, just have to work out the last few bugs here and there, and then decide how to integrate the bot with an auto stocker (wether to pass the sell price from url to url, until it reaches [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sim0n.wordpress.com&amp;blog=6301650&amp;post=292&amp;subd=sim0n&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This is the current workup for the neopets auction bot:</p>
<p>Currently, i have all the complex coding done, just have to work out the last few bugs here and there, and then decide how to integrate the bot with an auto stocker (wether to pass the sell price from url to url, until it reaches the stock, or to just query again later on).</p>
<p>Main Auction Page<br />
	Create list of items to query<br />
	Send request to php<br />
		Return list of items maxprice &amp; sell price<br />
	Parse list<br />
		Loop through each row<br />
		Check if item is in list<br />
		If it is, check if its a NF only auction<br />
		If its not, check to see if maxprice is less than the current price<br />
		If it is, check to see if the page is on the ignore list<br />
		If it isnt, open the page in a new tab with max price as an url paramater (possibly also sell price?)<br />
		Add opened page to ignore list (greasemonkey var?)<br />
	Wait between 7 and 15 seconds, refresh page</p>
<p>Bid Page<br />
	Parse max price from url<br />
	Get username from page<br />
	Check to see if the auction is over/invalid/too expensive<br />
	If it is, close the page<br />
	If it isnt, Check to see if the last bidder was the user<br />
	If it is, refresh the page<br />
	If it isnt,<br />
		modify the form to pass the maxprice in the url when submitted (possibly also sell price)<br />
		submit the bid</p>
<p>Bid Submission<br />
	Parse max price from url<br />
	Check if bid successful (find BID SUCCESSFUL)<br />
	If yes,<br />
		find link on page (loop through &#8216;a&#8217; elements)<br />
		modify link to pass the maxprice in the url when submitted (possibly also sell price)<br />
	If no, check reason<br />
		If not enough money, close<br />
		If need to wait, history back<br />
		If bid twice in a row, back : (Sorry, you are not allowed to bid on an auction two times in a row)</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sim0n.wordpress.com/292/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sim0n.wordpress.com/292/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sim0n.wordpress.com/292/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sim0n.wordpress.com/292/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sim0n.wordpress.com/292/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sim0n.wordpress.com/292/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sim0n.wordpress.com/292/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sim0n.wordpress.com/292/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sim0n.wordpress.com/292/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sim0n.wordpress.com/292/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sim0n.wordpress.com/292/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sim0n.wordpress.com/292/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sim0n.wordpress.com/292/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sim0n.wordpress.com/292/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sim0n.wordpress.com&amp;blog=6301650&amp;post=292&amp;subd=sim0n&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sim0n.wordpress.com/2009/04/29/note-neopets-autobidder-progress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/810cb4ebed3e0db0c0d9777516931db0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sim0n</media:title>
		</media:content>
	</item>
		<item>
		<title>[PHP] Hit Counter using MySQL Database</title>
		<link>http://sim0n.wordpress.com/2009/04/29/php-hit-counter-using-mysql-database/</link>
		<comments>http://sim0n.wordpress.com/2009/04/29/php-hit-counter-using-mysql-database/#comments</comments>
		<pubDate>Wed, 29 Apr 2009 09:47:22 +0000</pubDate>
		<dc:creator>sim0n</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Count]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[hit]]></category>
		<category><![CDATA[hitcount]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://sim0n.wordpress.com/?p=289</guid>
		<description><![CDATA[Little script I wrote this morning which uses a database to store number of hits on a page: &#60;?php $dbhost = '1'; $dbuser = '2'; $dbpass = '3'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('0'); $dbname = '4'; mysql_select_db($dbname); $page = $_SERVER['REQUEST_URI']; $result = mysql_query("SELECT HIT_COUNT FROM Hit_Count WHERE Page_Name = '$page'"); $any = [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sim0n.wordpress.com&amp;blog=6301650&amp;post=289&amp;subd=sim0n&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Little script I wrote this morning which uses a database to store number of hits on a page:</p>
<div style="border:#660000 5px solid;color:#000000;">
<pre style="background-color:#ffffff;line-height:15px;color:#000000;font-family:Courier New!important;font-size:11px!important;padding:3px;"><span style="color:#000000;">&lt;?php
	$dbhost = '1';
	$dbuser = '2';
	$dbpass = '3';
	$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('0');
	$dbname = '4';
	mysql_select_db($dbname);

	$page = $_SERVER['REQUEST_URI'];
	$result = mysql_query("SELECT HIT_COUNT FROM  Hit_Count WHERE Page_Name = '$page'");

	$any = false;
	while($row = mysql_fetch_array($result)) {
		$any = true;
		$counter = mysql_result($result, 0) + 1;
		$sql = "UPDATE Hit_Count SET HIT_COUNT = '$counter' WHERE Page_Name = '$page'";
		mysql_query($sql);
		echo($counter);
	}

	if($any == false) {
		$sql = "INSERT INTO Hit_Count (Page_Name, HIT_COUNT) VALUES ('$page', '1')";
		mysql_query($sql);
		echo("1");
	}

	mysql_close($conn);
?&gt;</span></pre>
</div>
<p>The script will output the current hit count, you would use the script like this:</p>
<div style="border:#660000 5px solid;color:#000000;">
<pre style="background-color:#ffffff;line-height:15px;color:#000000;font-family:Courier New!important;font-size:11px!important;padding:3px;"><span style="color:#000000;">&lt;?php include("location/hitcount.php"); ?&gt;</span></pre>
</div>
<p>The tables set up is this:</p>
<div style="border:#660000 5px solid;color:#000000;">
<pre style="background-color:#ffffff;line-height:15px;color:#000000;font-family:Courier New!important;font-size:11px!important;padding:3px;"><span style="color:#000000;">Page_Name [text]		HIT_COUNT [int(11)]
/files/Image%20Gallery.php 	2
/ 				4</span></pre>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sim0n.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sim0n.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sim0n.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sim0n.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sim0n.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sim0n.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sim0n.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sim0n.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sim0n.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sim0n.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sim0n.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sim0n.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sim0n.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sim0n.wordpress.com/289/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sim0n.wordpress.com&amp;blog=6301650&amp;post=289&amp;subd=sim0n&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sim0n.wordpress.com/2009/04/29/php-hit-counter-using-mysql-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/810cb4ebed3e0db0c0d9777516931db0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sim0n</media:title>
		</media:content>
	</item>
		<item>
		<title>[Javascript/Php] Neopets Auction Bot Project (2)</title>
		<link>http://sim0n.wordpress.com/2009/04/28/javascriptphp-neopets-auction-bot-project-2/</link>
		<comments>http://sim0n.wordpress.com/2009/04/28/javascriptphp-neopets-auction-bot-project-2/#comments</comments>
		<pubDate>Tue, 28 Apr 2009 18:39:11 +0000</pubDate>
		<dc:creator>sim0n</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[bot]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[greasemonkey]]></category>
		<category><![CDATA[httpRequest]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[neopets]]></category>
		<category><![CDATA[project]]></category>

		<guid isPermaLink="false">http://sim0n.wordpress.com/?p=286</guid>
		<description><![CDATA[A much faster script than my previous version. Instead of querying each item individually, it loops through the items in the list and uses the queryNeopetItem to send the data to another php page, which pareses the items and returns the prices of each of them. When the data is returned, it is then split [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sim0n.wordpress.com&amp;blog=6301650&amp;post=286&amp;subd=sim0n&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A much faster script than my previous version. Instead of querying each item individually, it loops through the items in the list and uses the queryNeopetItem to send the data to another php page, which pareses the items and returns the prices of each of them. When the data is returned, it is then split and the table is formatted depending on what action should be taken (light green=no data, medium green=more expensive than data, grey = neofriend only, blue = make profit)</p>
<p><a href="http://sim0n.files.wordpress.com/2009/04/neopetsauctionhighlight.jpg"><img class="alignnone size-full wp-image-287" title="Neopets auction highlight" src="http://sim0n.files.wordpress.com/2009/04/neopetsauctionhighlight.jpg?w=655" alt="Neopets auction highlight"   /></a></p>
<p><a href="http://sim0n.files.wordpress.com/2009/04/neopetsauctionhighlight.jpg"></a><br />
And below is the source for the greasemonkey script:</p>
<div style="border:#660000 5px solid;color:#000000;">
<pre style="background-color:#ffffff;line-height:15px;color:#000000;font-family:Courier New!important;font-size:11px!important;padding:3px;"><span style="color:#008000;">// ==UserScript==
// @name           AuctionBot test v2
// @namespace      Sim0n NeoPets
// @include        http://www.neopets.com/auctions.phtml
// ==/UserScript==

</span><span style="color:#0000ff;">function</span><span style="color:#000000;"> getElementsByAttribute(oElm, strTagName, strAttributeName, strAttributeValue){
	</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> arrElements = (strTagName == </span><span style="color:#a31515;">"*"</span><span style="color:#000000;"> &amp;&amp; oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> arrReturnElements = </span><span style="color:#0000ff;">new</span><span style="color:#000000;"> Array();
	</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> oAttributeValue = (</span><span style="color:#0000ff;">typeof</span><span style="color:#000000;"> strAttributeValue != </span><span style="color:#a31515;">"undefined"</span><span style="color:#000000;">)? </span><span style="color:#0000ff;">new</span><span style="color:#000000;"> RegExp(</span><span style="color:#a31515;">"(^|\\s)"</span><span style="color:#000000;"> + strAttributeValue + </span><span style="color:#a31515;">"(\\s|$)"</span><span style="color:#000000;">) : </span><span style="color:#0000ff;">null</span><span style="color:#000000;">;
	</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> oCurrent;
	</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> oAttribute;
	</span><span style="color:#0000ff;">for</span><span style="color:#000000;">(</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> i=0; i&lt;arrElements.length; i++){
		oCurrent = arrElements[i];
		oAttribute = oCurrent.getAttribute &amp;&amp; oCurrent.getAttribute(strAttributeName);
		</span><span style="color:#0000ff;">if</span><span style="color:#000000;">(</span><span style="color:#0000ff;">typeof</span><span style="color:#000000;"> oAttribute == </span><span style="color:#a31515;">"string"</span><span style="color:#000000;"> &amp;&amp; oAttribute.length &gt; 0){
			</span><span style="color:#0000ff;">if</span><span style="color:#000000;">(</span><span style="color:#0000ff;">typeof</span><span style="color:#000000;"> strAttributeValue == </span><span style="color:#a31515;">"undefined"</span><span style="color:#000000;"> || (oAttributeValue &amp;&amp; oAttributeValue.test(oAttribute))){
				arrReturnElements.push(oCurrent);
			}
		}
	}
	</span><span style="color:#0000ff;">return</span><span style="color:#000000;"> arrReturnElements;
}

</span><span style="color:#0000ff;">function</span><span style="color:#000000;"> queryNeopetItem(item, complete) {
	url = </span><span style="color:#a31515;">"myphpquery.php?items="</span><span style="color:#000000;"> + item;
	GM_xmlhttpRequest({
		method: </span><span style="color:#a31515;">"POST"</span><span style="color:#000000;">,
		url: url,
		headers:{</span><span style="color:#a31515;">'Content-type'</span><span style="color:#000000;">:</span><span style="color:#a31515;">'application/x-www-form-urlencoded'</span><span style="color:#000000;">},
		data:encodeURI(</span><span style="color:#a31515;">""</span><span style="color:#000000;">),
		onload: </span><span style="color:#0000ff;">function</span><span style="color:#000000;">(xhr) { complete(xhr.responseText); }
	});
}
</span><span style="color:#0000ff;">function</span><span style="color:#000000;"> comp(text) {
	</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> items = text.split(</span><span style="color:#a31515;">"\n"</span><span style="color:#000000;">);
	</span><span style="color:#0000ff;">for</span><span style="color:#000000;">(</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> i = 0;i&lt;20;i++) {
		</span><span style="color:#0000ff;">if</span><span style="color:#000000;">(items[i] == </span><span style="color:#a31515;">""</span><span style="color:#000000;">) {
			table[0].rows[i+1].setAttribute(</span><span style="color:#a31515;">"bgcolor"</span><span style="color:#000000;">,</span><span style="color:#a31515;">"#ccffd0"</span><span style="color:#000000;">);
		} </span><span style="color:#0000ff;">else</span><span style="color:#000000;"> {
			</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> item = items[i].split(</span><span style="color:#a31515;">"\t"</span><span style="color:#000000;">);
			</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> cur_price = table[0].rows[i+1].cells[6].innerHTML.replace(/&lt;b&gt;(\d*)&lt;\/b&gt; NP/, </span><span style="color:#a31515;">"$1"</span><span style="color:#000000;">);
			</span><span style="color:#0000ff;">if</span><span style="color:#000000;">(Number(cur_price)&lt;=Number(item[0])) {
				</span><span style="color:#0000ff;">if</span><span style="color:#000000;">(table[0].rows[i+1].cells[3].innerHTML.toLowerCase().indexOf(</span><span style="color:#a31515;">"&lt;b&gt;[nf]&lt;/b&gt;"</span><span style="color:#000000;">) != -1) {
					table[0].rows[i+1].setAttribute(</span><span style="color:#a31515;">"bgcolor"</span><span style="color:#000000;">,</span><span style="color:#a31515;">"#aaafa0"</span><span style="color:#000000;">);
				} </span><span style="color:#0000ff;">else</span><span style="color:#000000;"> {
					alert(table[0].rows[i+1].cells[3].innerHTML)
					table[0].rows[i+1].setAttribute(</span><span style="color:#a31515;">"bgcolor"</span><span style="color:#000000;">,</span><span style="color:#a31515;">"#00ffff"</span><span style="color:#000000;">);
				}
			} </span><span style="color:#0000ff;">else</span><span style="color:#000000;"> {
				table[0].rows[i+1].setAttribute(</span><span style="color:#a31515;">"bgcolor"</span><span style="color:#000000;">,</span><span style="color:#a31515;">"#aaffd0"</span><span style="color:#000000;">);
			}
		}
	}
}
</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> table = getElementsByAttribute(document.body, </span><span style="color:#a31515;">"table"</span><span style="color:#000000;">, </span><span style="color:#a31515;">"align"</span><span style="color:#000000;">, </span><span style="color:#a31515;">"center"</span><span style="color:#000000;">);
</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> queryString = </span><span style="color:#a31515;">""</span><span style="color:#000000;">;
</span><span style="color:#0000ff;">for</span><span style="color:#000000;">(</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> i=1;i&lt;table[0].rows.length - 1;i++) {
	queryString = queryString + table[0].rows[i].cells[2].innerHTML.replace(/&lt;a href=\</span><span style="color:#a31515;">".*\"&gt;(.*)&lt;\/a&gt;/, "</span><span style="color:#000000;">$1</span><span style="color:#a31515;">") + "</span><span style="color:#000000;">|</span><span style="color:#a31515;">";
</span><span style="color:#000000;">}
queryString = queryString + table[0].rows[table[0].rows.length-1].cells[2].innerHTML.replace(/&lt;a href=\</span><span style="color:#a31515;">".*\"&gt;(.*)&lt;\/a&gt;/, "</span><span style="color:#000000;">$1</span><span style="color:#a31515;">")
</span><span style="color:#000000;">queryNeopetItem(queryString, comp);</span></pre>
</div>
<p>And for the php query:</p>
<div style="border:#660000 5px solid;color:#000000;">
<pre style="background-color:#ffffff;line-height:15px;color:#000000;font-family:Courier New!important;font-size:11px!important;padding:3px;"><span style="color:#0000ff;"><span style="color:#a31515;"><span style="color:#0000ff;">&lt;?</span>php
</span><span style="color:#0000ff;">	</span><span style="color:#808080;">$dbhost = 'a';
	$dbuser = 'b';
	$dbpass = 'd';
	$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('0');
	$dbname = 'e';
	mysql_select_db($dbname);

	$items = explode("|", $_GET['items']);
	for($i=0;$i&lt;count($items);$i++) {
		$sqlQuery = "ITEM_NAME = '$items[$i]'";
		$result = mysql_query("SELECT * FROM  Neopets_Items WHERE $sqlQuery");
		$any = false;
		while($row = mysql_fetch_array($result))
  		{
			$any = true;
  			echo $row['MAX_PRICE'] . "\t" . $row['SELL_PRICE'] . "\n";
  		}
		if($any==false) {
			echo "\n";
		}
	}
	mysql_close($conn);
</span><span style="color:#0000ff;">?&gt;</span> </span></pre>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sim0n.wordpress.com/286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sim0n.wordpress.com/286/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sim0n.wordpress.com/286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sim0n.wordpress.com/286/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sim0n.wordpress.com/286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sim0n.wordpress.com/286/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sim0n.wordpress.com/286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sim0n.wordpress.com/286/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sim0n.wordpress.com/286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sim0n.wordpress.com/286/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sim0n.wordpress.com/286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sim0n.wordpress.com/286/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sim0n.wordpress.com/286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sim0n.wordpress.com/286/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sim0n.wordpress.com&amp;blog=6301650&amp;post=286&amp;subd=sim0n&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sim0n.wordpress.com/2009/04/28/javascriptphp-neopets-auction-bot-project-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/810cb4ebed3e0db0c0d9777516931db0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sim0n</media:title>
		</media:content>

		<media:content url="http://sim0n.files.wordpress.com/2009/04/neopetsauctionhighlight.jpg" medium="image">
			<media:title type="html">Neopets auction highlight</media:title>
		</media:content>
	</item>
	</channel>
</rss>
