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

<channel>
	<title>gabehabe &#187; c++</title>
	<atom:link href="http://www.gabehabe.com/blog/tags/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.gabehabe.com/blog</link>
	<description>Cool blog, bro.</description>
	<lastBuildDate>Wed, 29 Jun 2011 01:26:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>wxWidgets: Loading Symbols from a DLL (and using ::Connect)</title>
		<link>http://www.gabehabe.com/blog/wxwidgets-loading-symbols-from-a-dll-and-using-connect/</link>
		<comments>http://www.gabehabe.com/blog/wxwidgets-loading-symbols-from-a-dll-and-using-connect/#comments</comments>
		<pubDate>Fri, 09 Apr 2010 20:20:08 +0000</pubDate>
		<dc:creator>Danny</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Snippets]]></category>
		<category><![CDATA[wxWidgets]]></category>
		<category><![CDATA[c++]]></category>

		<guid isPermaLink="false">http://www.gabehabe.com/blog/wxwidgets-loading-symbols-from-a-dll-and-using-connect/</guid>
		<description><![CDATA[[Apologies if the entry is a little unclear, I just threw this together in about 10 minutes, I wanna get it out there... it's fucking hard to find any sort of information when it comes to this at the moment] Quick entry, gonna turn this into a tutorial soon. The code is a bit of [...]]]></description>
			<content:encoded><![CDATA[<p>[Apologies if the entry is a little unclear, I just threw this together in about 10 minutes, I wanna get it out there... it's fucking hard to find any sort of information when it comes to this at the moment]</p>
<p>Quick entry, gonna turn this into a tutorial soon. The code is a bit of a mess, since I was just throwing stuff together while I was figuring this out. I&#8217;ll tidy it up when it&#8217;s tutorial tiems.</p>
<p>Basically, I recently developed a [url=http://snip.gd/plugins.php]plugin system[/url] for my [url=http://snip.gd/]snippet manager[/url]. The way it works is simple: It loads symbols from a DLL into the application, which can be called from a dynamically created menu. First off, the main code [this is the messy bit for the time being]</p>
<p>This code opens a subdirectory within the working directory called &#8220;plugins&#8221;, and grabs all the DLLs from them. If the DLL contains a symbol called SnippetManagerPluginMain (the only required symbol for the plugins, I kept them simple) it will add it to the menu.</p>
<p>Additionally, it also checks for two optional optional symbols, which are pretty cool. They simply return strings, which assign the name and the keyboard shortcut for the plugin. If neither is set, it has no keyboard shortcut, and the name defaults to the name of the DLL file.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">    <span style="color: #666666;">/// &lt;plugin SYSTEM&gt; &lt;!-- ALPHA! --&gt;</span>
    <span style="color: #339900;">#if defined(__WXMSW__) // windows plugins - load ./plugins/*.dll</span>
    <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>wxDir<span style="color: #008080;">::</span><span style="color: #007788;">Exists</span><span style="color: #008000;">&#40;</span>wxT<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;./plugins/&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        wxDir plugin_dir<span style="color: #008000;">&#40;</span>wxT<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;./plugins/&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>plugin_dir.<span style="color: #007788;">HasFiles</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
            wxArrayString files<span style="color: #008080;">;</span>
            wxDir<span style="color: #008080;">::</span><span style="color: #007788;">GetAllFiles</span><span style="color: #008000;">&#40;</span>wxT<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;./plugins/&quot;</span><span style="color: #008000;">&#41;</span>, <span style="color: #000040;">&amp;</span>files<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
            wxMenu<span style="color: #000040;">*</span> plugin_menu <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> wxMenu<span style="color: #008000;">&#40;</span>wxT<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
            wxDynamicLibrary<span style="color: #000040;">*</span> lib<span style="color: #008080;">;</span>
            wxString label<span style="color: #008080;">;</span>
            <span style="color: #0000ff;">char</span><span style="color: #000040;">*</span> ks<span style="color: #008080;">;</span>
            <span style="color: #0000ff;">bool</span> showmenu <span style="color: #000080;">=</span> <span style="color: #0000ff;">false</span><span style="color: #008080;">;</span>
            <span style="color: #0000ff;">for</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> i <span style="color: #000080;">&lt;</span> files.<span style="color: #007788;">GetCount</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> i<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
                lib <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> wxDynamicLibrary<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
                <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>files.<span style="color: #007788;">Item</span><span style="color: #008000;">&#40;</span>i<span style="color: #008000;">&#41;</span>.<span style="color: #007788;">Find</span><span style="color: #008000;">&#40;</span>wxT<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;.dll&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">!</span><span style="color: #000080;">=</span> <span style="color: #000040;">-</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
                    lib<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>Load<span style="color: #008000;">&#40;</span>files<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
                    <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>lib<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>HasSymbol<span style="color: #008000;">&#40;</span>L<span style="color: #FF0000;">&quot;SnippetManagerPluginMain&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
                        showmenu <span style="color: #000080;">=</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span>
                        <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>lib<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>HasSymbol<span style="color: #008000;">&#40;</span>L<span style="color: #FF0000;">&quot;SnippetManagerPluginName&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
                            label <span style="color: #000080;">=</span> wxString<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>SnippetManagerPluginName<span style="color: #008000;">&#41;</span>lib<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>GetSymbol<span style="color: #008000;">&#40;</span>L<span style="color: #FF0000;">&quot;SnippetManagerPluginName&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, wxConvUTF8<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
                        <span style="color: #008000;">&#125;</span> <span style="color: #0000ff;">else</span> <span style="color: #008000;">&#123;</span>
                            label <span style="color: #000080;">=</span> files<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span>.<span style="color: #007788;">AfterFirst</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">'\<span style="color: #000099; font-weight: bold;">\'</span>).AfterFirst('</span>\\<span style="color: #FF0000;">').BeforeLast('</span>.<span style="color: #FF0000;">');
                        }
                        this-&gt;plugins.push_back((SnippetManagerPlugin)lib-&gt;GetSymbol(L&quot;SnippetManagerPluginMain&quot;));
&nbsp;
                        if(lib-&gt;HasSymbol(L&quot;SnippetManagerKeyboardShortcut&quot;)) {
                            ks = ((SnippetManagerKeyboardShortcut)lib-&gt;GetSymbol(L&quot;SnippetManagerKeyboardShortcut&quot;))();
                            label += L&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot; + wxString(ks, wxConvUTF8);
&nbsp;
                        }
                        plugin_menu-&gt;Append(wxID_PLUGIN + i, label);
                        Connect(wxID_PLUGIN + i, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(Snippet_ManagerFrame::handle_plugin));
                    }
                }
            }
            if(showmenu) {
                mbar-&gt;Append(plugin_menu, wxT(&quot;&amp;Plugins&quot;));
            }
        }
    }
    #endif
    /// &lt;/plugin&gt;[</span></pre></div></div>

<p>In order to bind the events to the menu, the ::Connect method is called. This is an alternative to using EVENT_TABLE, and allows events to be allocated dynamically at runtime. wxID_PLUGIN is a custom variable, and basically, any of the menu items within the menu will call the main frame&#8217;s [il]handle_plugin[/il] method. The important part, however, is the fact that each one has a different ID, even though they use the same method.</p>
<p>The method itself then uses the ID of the event calling it to lookup the DLL&#8217;s symbol, which were added in <code>this->plugins</code>.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">void</span> Snippet_ManagerFrame<span style="color: #008080;">::</span><span style="color: #007788;">handle_plugin</span><span style="color: #008000;">&#40;</span>wxCommandEvent <span style="color: #000040;">&amp;</span>e<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>plugins<span style="color: #008000;">&#91;</span>e.<span style="color: #007788;">GetId</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">-</span> wxID_PLUGIN<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#40;</span>this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>ui<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>uid.<span style="color: #007788;">mb_str</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, fill_p_snip<span style="color: #008000;">&#40;</span>this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>ui<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>get_active_stc<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>snip, this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>ui<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>get_active_stc<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>GetText<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>Of course, some of the code here doesn&#8217;t really mean jack all, since there are custom methods and stuff used in it. But the base of it is clear. I&#8217;ll try to write another (small) application and a tutorial covering the steps over the weekend.</p>
<p>Until then, have fun! :)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gabehabe.com/blog/wxwidgets-loading-symbols-from-a-dll-and-using-connect/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>wxWidgets: Threading, and using the Clipboard</title>
		<link>http://www.gabehabe.com/blog/wxwidgets-threading-and-using-the-clipboard/</link>
		<comments>http://www.gabehabe.com/blog/wxwidgets-threading-and-using-the-clipboard/#comments</comments>
		<pubDate>Sat, 31 Oct 2009 17:11:12 +0000</pubDate>
		<dc:creator>Danny</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[wxWidgets]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[clipboard]]></category>
		<category><![CDATA[gui design]]></category>
		<category><![CDATA[threading]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.gabehabe.com/blog/wxwidgets-threading-and-using-the-clipboard/</guid>
		<description><![CDATA[wxWidgets: Threading, and using the Clipboard Two for one in this tutorial. We're going to create a thread using wxWidgets, and make it monitor the clipboard for text. Then, if we detect a change, we're going to add the new contents to a list. It's a relatively simple process, but unfortunately wxWidgets isn't the most [...]]]></description>
			<content:encoded><![CDATA[<h3>wxWidgets: Threading, and using the Clipboard</h3>

Two for one in this tutorial. We're going to create a thread using wxWidgets, and make it monitor the clipboard for text. Then, if we detect a change, we're going to add the new contents to a list.

It's a relatively simple process, but unfortunately wxWidgets isn't the most documented GUI toolkit out there.

So, let's get started. I'm gonna pile all the code into a single file instead of breaking my classes up into seperate files, just for ease of navigation in this tutorial. The code is relatively short anyway, with only 62 lines.

First off, as with any other program, we're going to want to get our includes done. We'll be needing three: The standard wx header, the clipboard header, and the thread header.


<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include &lt;wx/wx.h&gt; // standard wx header</span>
<span style="color: #339900;">#include &lt;wx/clipbrd.h&gt; // clipboard - we'll monitor the clipboard for text</span>
<span style="color: #339900;">#include &lt;wx/thread.h&gt; // include threads!</span></pre></div></div>



The next thing we need to do is declare our <code>ClipLogger</code> class - this will inherit wxThread, and have two variables: One to hold the most recent text that we got from the clipboard, and one which is a pointer to a <code>wxListBox</code> object -- the object on the main window which we'll be updating.


<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">class</span> ClipLogger <span style="color: #008080;">:</span> <span style="color: #0000ff;">public</span> wxThread <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
        ClipLogger<span style="color: #008000;">&#40;</span>wxListBox<span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">private</span><span style="color: #008080;">:</span>
        <span style="color: #0000ff;">void</span><span style="color: #000040;">*</span> Entry<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #666666;">// the entry point to the thread</span>
&nbsp;
        wxString LatestText<span style="color: #008080;">;</span> <span style="color: #666666;">// store the last text so we can check for changes</span>
        wxListBox<span style="color: #000040;">*</span> list<span style="color: #008080;">;</span> <span style="color: #666666;">// the list to update on a text change</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span></pre></div></div>



The constructor is <em>very</em> simple. All it does is take a wxListBox*, and assign it to a variable stored by the class - this is the list that we want to update on clipboard text changes.


<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">ClipLogger<span style="color: #008080;">::</span><span style="color: #007788;">ClipLogger</span><span style="color: #008000;">&#40;</span>wxListBox<span style="color: #000040;">*</span> l<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>list <span style="color: #000080;">=</span> l<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>



Next up is the main part of this tutorial. When we create a thread, we need to override the <code>Entry()</code> method of the class, like so:


<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">void</span><span style="color: #000040;">*</span> ClipLogger<span style="color: #008080;">::</span><span style="color: #007788;">Entry</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span></pre></div></div>



To save time and memory, rather than creating a variable every time we loop, we'll create it before and simply overwrite it inside the loop.


<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">wxTextDataObject temp<span style="color: #008080;">;</span></pre></div></div>



wxTextDataObject is the type of object that the clipboard will store.
Next, since our thread is a constant "monitor" for the clipboard, we want it to loop.


<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">while</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">true</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span></pre></div></div>



Then, we need to think about how we can help our application not be CPU-hungry. The simple solution is to make the thread sleep each time it loops. We can do this with <code>wxSleep(int time)</code>, where time is the length of time to sleep in <strong>seconds</strong>.


<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">wxSleep<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>



The rest of the loop is the clipboard. It's very simple, so rather than break it up line-by-line, I've added comments along the way. We basically need to do the following:
 - Open the clipboard
 - If the clipboard is text, get it into our <code>temp</code> variable
 - Update the list and remember this is the most recent (so as not to constantly add the same data to the list)
 - Close the clipboard


<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">        <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>wxTheClipboard<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>Open<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> <span style="color: #666666;">// try to open the clipboard</span>
            <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>wxTheClipboard<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>IsSupported<span style="color: #008000;">&#40;</span>wxDF_TEXT<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> <span style="color: #666666;">// if the clipboard contains text</span>
                wxTheClipboard<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>GetData<span style="color: #008000;">&#40;</span>temp<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #666666;">// get the data from the clipboard</span>
                <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>LatestText <span style="color: #000040;">!</span><span style="color: #000080;">=</span> temp.<span style="color: #007788;">GetText</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> <span style="color: #666666;">// if it's changed, we want to update</span>
                    <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>temp.<span style="color: #007788;">GetText</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">!</span><span style="color: #000080;">=</span> wxT<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> <span style="color: #666666;">// if it's not an empty string</span>
                        this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>LatestText <span style="color: #000080;">=</span> temp.<span style="color: #007788;">GetText</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>  <span style="color: #666666;">// update the &quot;LatestText&quot;</span>
                        this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>list<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>Append<span style="color: #008000;">&#40;</span>temp.<span style="color: #007788;">GetText</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #666666;">// append to the list</span>
                    <span style="color: #008000;">&#125;</span>
                <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
        wxTheClipboard<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>Close<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #666666;">// close the clipboard</span></pre></div></div>



The last thing left to do in the thread is simply close it off, and close off the loop.


<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>



Simple, huh? :)

And that's our thread defined. Now all we need to do is create the app itself, which is a simple process. I hope that you already know how to do it, so we can blitz through the majority of it.

Create the app:


<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">class</span> threaded_app <span style="color: #008080;">:</span> <span style="color: #0000ff;">public</span> wxApp <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
        <span style="color: #0000ff;">bool</span> OnInit<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">void</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span></pre></div></div>



The beginning of the <code>OnInit()</code> should be nothing new at this point either.


<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">bool</span> threaded_app<span style="color: #008080;">::</span><span style="color: #007788;">OnInit</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">void</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #666666;">// quickly create a wxFrame to display a window</span>
    wxFrame<span style="color: #000040;">*</span> f <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> wxFrame<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">NULL</span>, wxID_ANY, wxT<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;Threaded App!&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #666666;">// add a list to the frame we created</span>
    wxListBox<span style="color: #000040;">*</span> list <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> wxListBox<span style="color: #008000;">&#40;</span>f, wxID_ANY<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #666666;">// display the frame</span>
    f<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>Show<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>



The last part of <code>OnInit()</code> that we need to do is actually create an instance of our thread and run it, like so:


<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">    <span style="color: #666666;">// pass the list to the clipboard monitor so it knows what to update</span>
    ClipLogger<span style="color: #000040;">*</span> cl <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> ClipLogger<span style="color: #008000;">&#40;</span>list<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #666666;">// construct our thread</span>
    cl<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>Create<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #666666;">// we have to create a thread before we can run it</span>
    cl<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>Run<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #666666;">// run our thread</span></pre></div></div>



And we can simply finish off the <code>OnInit()</code> and IMPLEMENT_APP:


<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">    <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
IMPLEMENT_APP<span style="color: #008000;">&#40;</span>threaded_app<span style="color: #008000;">&#41;</span></pre></div></div>




And that's all there is to threading and using the clipboard in wxWidgets!

Here's the complete code:


<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include &lt;wx/wx.h&gt; // standard wx header</span>
<span style="color: #339900;">#include &lt;wx/clipbrd.h&gt; // clipboard - we'll monitor the clipboard for text</span>
<span style="color: #339900;">#include &lt;wx/thread.h&gt; // include threads!</span>
&nbsp;
<span style="color: #0000ff;">class</span> ClipLogger <span style="color: #008080;">:</span> <span style="color: #0000ff;">public</span> wxThread <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
        ClipLogger<span style="color: #008000;">&#40;</span>wxListBox<span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">private</span><span style="color: #008080;">:</span>
        <span style="color: #0000ff;">void</span><span style="color: #000040;">*</span> Entry<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #666666;">// the entry point to the thread</span>
&nbsp;
        wxString LatestText<span style="color: #008080;">;</span> <span style="color: #666666;">// store the last text so we can check for changes</span>
        wxListBox<span style="color: #000040;">*</span> list<span style="color: #008080;">;</span> <span style="color: #666666;">// the list to update on a text change</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
&nbsp;
ClipLogger<span style="color: #008080;">::</span><span style="color: #007788;">ClipLogger</span><span style="color: #008000;">&#40;</span>wxListBox<span style="color: #000040;">*</span> l<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>list <span style="color: #000080;">=</span> l<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">void</span><span style="color: #000040;">*</span> ClipLogger<span style="color: #008080;">::</span><span style="color: #007788;">Entry</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    wxTextDataObject temp<span style="color: #008080;">;</span> <span style="color: #666666;">// create a &quot;wxTextDataObject&quot; to get the info from the clipboard</span>
    <span style="color: #0000ff;">while</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">true</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> <span style="color: #666666;">// our thread will loop</span>
        wxSleep<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #666666;">// sleep for 1 second, make the thread less cpu-hungry</span>
        <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>wxTheClipboard<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>Open<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> <span style="color: #666666;">// try to open the clipboard</span>
            <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>wxTheClipboard<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>IsSupported<span style="color: #008000;">&#40;</span>wxDF_TEXT<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> <span style="color: #666666;">// if the clipboard contains text</span>
                wxTheClipboard<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>GetData<span style="color: #008000;">&#40;</span>temp<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #666666;">// get the data from the clipboard</span>
                <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>LatestText <span style="color: #000040;">!</span><span style="color: #000080;">=</span> temp.<span style="color: #007788;">GetText</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> <span style="color: #666666;">// if it's changed, we want to update</span>
                    <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>temp.<span style="color: #007788;">GetText</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">!</span><span style="color: #000080;">=</span> wxT<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> <span style="color: #666666;">// if it's not an empty string</span>
                        this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>LatestText <span style="color: #000080;">=</span> temp.<span style="color: #007788;">GetText</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>  <span style="color: #666666;">// update the &quot;LatestText&quot;</span>
                        this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>list<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>Append<span style="color: #008000;">&#40;</span>temp.<span style="color: #007788;">GetText</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #666666;">// append to the list</span>
                    <span style="color: #008000;">&#125;</span>
                <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
        wxTheClipboard<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>Close<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #666666;">// close the clipboard</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">class</span> threaded_app <span style="color: #008080;">:</span> <span style="color: #0000ff;">public</span> wxApp <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
        <span style="color: #0000ff;">bool</span> OnInit<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">void</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">bool</span> threaded_app<span style="color: #008080;">::</span><span style="color: #007788;">OnInit</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">void</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #666666;">// quickly create a wxFrame to display a window</span>
    wxFrame<span style="color: #000040;">*</span> f <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> wxFrame<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">NULL</span>, wxID_ANY, wxT<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;Threaded App!&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #666666;">// add a list to the frame we created</span>
    wxListBox<span style="color: #000040;">*</span> list <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> wxListBox<span style="color: #008000;">&#40;</span>f, wxID_ANY<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #666666;">// display the frame</span>
    f<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>Show<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #666666;">// pass the list to the clipboard monitor so it knows what to update</span>
    ClipLogger<span style="color: #000040;">*</span> cl <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> ClipLogger<span style="color: #008000;">&#40;</span>list<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #666666;">// construct our thread</span>
    cl<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>Create<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #666666;">// we have to create a thread before we can run it</span>
    cl<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>Run<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #666666;">// run our thread</span>
&nbsp;
    <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
IMPLEMENT_APP<span style="color: #008000;">&#40;</span>threaded_app<span style="color: #008000;">&#41;</span></pre></div></div>



Happy coding! :)

]]></content:encoded>
			<wfw:commentRss>http://www.gabehabe.com/blog/wxwidgets-threading-and-using-the-clipboard/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>wxWidgets: Keyboard Shortcuts without a Menu</title>
		<link>http://www.gabehabe.com/blog/wxwidgets-keyboard-shortcuts-without-a-menu/</link>
		<comments>http://www.gabehabe.com/blog/wxwidgets-keyboard-shortcuts-without-a-menu/#comments</comments>
		<pubDate>Thu, 10 Sep 2009 22:25:08 +0000</pubDate>
		<dc:creator>Danny</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[wxWidgets]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[gui design]]></category>

		<guid isPermaLink="false">http://www.gabehabe.com/blog/?p=44</guid>
		<description><![CDATA[Quick entry. Sort of a preview. I&#8217;m working on a tutorial for dream.in.code about creating keyboard shortcuts in a wxWidgets application (particularly using C++), and figured I&#8217;d share the code here, too. (After I&#8217;ve finally gotten around to installing this syntax highlighting plugin for WordPress) Aaaaannddd&#8230; Done! Right. Back onto the original topic. Damn sidetracked [...]]]></description>
			<content:encoded><![CDATA[<p>Quick entry. Sort of a preview. I&#8217;m working on a tutorial for <a href="http://dreamincode.net" target="_blank">dream.in.code</a> about creating keyboard shortcuts in a wxWidgets application (particularly using C++), and figured I&#8217;d share the code here, too.</p>
<p>(After I&#8217;ve finally gotten around to installing <a href="http://wordpress.org/extend/plugins/wp-syntax" target="_blank">this syntax highlighting plugin</a> for WordPress)</p>
<p>Aaaaannddd&#8230; Done!</p>
<p>Right. Back onto the original topic. Damn sidetracked mind. So, when I write a tutorial, I write a whole chunk of code first, and then add the tutorial content around it. Here&#8217;s the code for allocating keyboard shortcuts to do different stuff in wxWidgets <strong>without</strong> using menu items.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">// basic setup code, I'll fly past this. If you're not familiar, check out this tutorial:</span>
<span style="color: #666666;">// http://www.dreamincode.net/forums/showtopic66948.htm</span>
&nbsp;
<span style="color: #339900;">#include &lt;wx/wx.h&gt;</span>
&nbsp;
<span style="color: #0000ff;">class</span> app <span style="color: #008080;">:</span> <span style="color: #0000ff;">public</span> wxApp <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
        <span style="color: #0000ff;">virtual</span> <span style="color: #0000ff;">bool</span> OnInit<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">private</span><span style="color: #008080;">:</span>
        wxTextCtrl<span style="color: #000040;">*</span> txt<span style="color: #008080;">;</span>
        wxCheckBox<span style="color: #000040;">*</span> chk<span style="color: #008080;">;</span>
&nbsp;
        <span style="color: #0000ff;">void</span> key_shortcut<span style="color: #008000;">&#40;</span>wxKeyEvent<span style="color: #000040;">&amp;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        DECLARE_EVENT_TABLE<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #666666;">// if you're not familiar with events, check out this tutorial:</span>
<span style="color: #666666;">// http://www.dreamincode.net/forums/showtopic67058.htm</span>
&nbsp;
BEGIN_EVENT_TABLE<span style="color: #008000;">&#40;</span>app, wxApp<span style="color: #008000;">&#41;</span>
    EVT_KEY_DOWN<span style="color: #008000;">&#40;</span>app<span style="color: #008080;">::</span><span style="color: #007788;">key_shortcut</span><span style="color: #008000;">&#41;</span>
END_EVENT_TABLE<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
&nbsp;
<span style="color: #0000ff;">bool</span> app<span style="color: #008080;">::</span><span style="color: #007788;">OnInit</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    wxFrame<span style="color: #000040;">*</span> win <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> wxFrame<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">NULL</span>, wxID_ANY, wxT<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;Keyboard Shortcuts, No Menu!&quot;</span><span style="color: #008000;">&#41;</span>, wxDefaultPosition, wxSize<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">250</span>, <span style="color: #0000dd;">125</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    win<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>Show<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>txt <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> wxTextCtrl<span style="color: #008000;">&#40;</span>win, wxID_ANY, wxT<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;Press Ctrl+G to append text to me&quot;</span><span style="color: #008000;">&#41;</span>, wxPoint<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">0</span>,<span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span>, wxSize<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">250</span>, <span style="color: #0000dd;">50</span><span style="color: #008000;">&#41;</span>, wxTE_MULTILINE<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>chk <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> wxCheckBox<span style="color: #008000;">&#40;</span>win, wxID_ANY, wxT<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;Press Ctrl+Left to toggle me.&quot;</span><span style="color: #008000;">&#41;</span>, wxPoint<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">0</span>, <span style="color: #0000dd;">55</span><span style="color: #008000;">&#41;</span>, wxDefaultSize<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #666666;">// this is the method I'll be focusing on. The key_shortcut event which we create</span>
<span style="color: #666666;">// to do fancy stuff without adding billions of menu items</span>
&nbsp;
<span style="color: #0000ff;">void</span> app<span style="color: #008080;">::</span><span style="color: #007788;">key_shortcut</span><span style="color: #008000;">&#40;</span>wxKeyEvent<span style="color: #000040;">&amp;</span> e<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #666666;">// of course, it doesn't have to be the control key. You can use others:</span>
    <span style="color: #666666;">// http://docs.wxwidgets.org/stable/wx_wxkeyevent.html</span>
    <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>e.<span style="color: #007788;">GetModifiers</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">==</span> wxMOD_CONTROL<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        <span style="color: #0000ff;">switch</span><span style="color: #008000;">&#40;</span>e.<span style="color: #007788;">GetKeyCode</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
            <span style="color: #0000ff;">case</span> <span style="color: #FF0000;">'G'</span><span style="color: #008080;">:</span> <span style="color: #666666;">// can return the upper ASCII value of a key</span>
                <span style="color: #666666;">// do whatever you like for a Ctrl+G event here!</span>
                this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>txt<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>AppendText<span style="color: #008000;">&#40;</span>wxT<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot; gabehabe ftw!&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
                <span style="color: #0000ff;">break</span><span style="color: #008080;">;</span>
            <span style="color: #0000ff;">case</span> WXK_LEFT<span style="color: #008080;">:</span> <span style="color: #666666;">// we also have special keycodes for non-ascii values.</span>
                <span style="color: #666666;">// get a full list of special keycodes here:</span>
                <span style="color: #666666;">// http://docs.wxwidgets.org/stable/wx_keycodes.html</span>
                this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>chk<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>SetValue<span style="color: #008000;">&#40;</span><span style="color: #000040;">!</span>this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>chk<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>GetValue<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
                <span style="color: #0000ff;">break</span><span style="color: #008080;">;</span>
            <span style="color: #0000ff;">default</span><span style="color: #008080;">:</span> <span style="color: #666666;">// do nothing</span>
                <span style="color: #0000ff;">break</span><span style="color: #008080;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
IMPLEMENT_APP<span style="color: #008000;">&#40;</span>app<span style="color: #008000;">&#41;</span></pre></div></div>

<p>Link to follow when the tutorial is completed and approved.</p>
<p>As promised, here&#8217;s the tutorial in all it&#8217;s glory:<br />
<a href="http://www.dreamincode.net/forums/showtopic125264.htm" target="_blank">wxWidgets keyboard shortcuts with no menu</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gabehabe.com/blog/wxwidgets-keyboard-shortcuts-without-a-menu/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

