Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Win32 + C is a very low-level approach, which has its advantages and disadvantages. That said, there are ways to make things easier.</p> <p>First, regarding bit-shifts, there are <a href="http://msdn.microsoft.com/en-us/library/dd469352.aspx" rel="nofollow noreferrer">several macros to work with WPARAMs and LPARAMs</a>. You probably shouldn't be writing bit-shifts, in fact, because the <a href="http://blogs.msdn.com/oldnewthing/archive/2003/11/25/55850.aspx" rel="nofollow noreferrer">size of WPARAM and LPARAM has changed over the years</a>, and you might be creating a future bug.</p> <p>Secondly, regarding the giant switch statement in your WindowProc function, while that will be there, there's a way to make it a bit more manageable. <code>#include &lt;windowsx.h&gt;</code> to get a whole bunch of useful macros, most notably HANDLE_MSG. Instead of needing to write</p> <pre><code>LRESULT CALLBACK MyWindowProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) { switch(Message) { case WM_COMMAND: ... } } </code></pre> <p>You can instead write:</p> <pre><code>void MyOnCommand(HWND hwnd, int controlID, HWND hwndCtl, UINT codeNotify); LRESULT CALLBACK MyWindowProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) { switch(Message) { HANDLE_MSG(hwnd, WM_COMMAND, MyOnCommand); } } </code></pre> <p>and the macro automatically casts and separates all the different parameters for that message type into the appropriately named &amp; typed variables. Browse <code>windowsx.h</code> to see the messages that are handled, and the function prototypes it requires. Not all the different messages are handled, but quite a few are.</p> <p>As for having multiple windows at once, there shouldn't be anything stopping you from calling CreateWindow or its relatives multiple times. While you only have one <code>HINSTANCE</code> (given to you in your <code>WinMain</code>), you can have as many <code>HWND</code>s as you want.</p> <p>You may find <a href="http://blogs.msdn.com/oldnewthing/archive/2003/07/23/54576.aspx" rel="nofollow noreferrer">Raymond Chen's scratch program</a> useful, as it should give you a decent skeleton to start from. You might also consider making your application use a <a href="http://msdn.microsoft.com/en-us/library/ms632588.aspx" rel="nofollow noreferrer">dialog box</a> instead of just a window; you get a bunch of stuff for free, and you can use a resource editor to design the window and all its controls. <a href="http://msdn.microsoft.com/en-us/library/hs24szh9.aspx" rel="nofollow noreferrer">Visual C++ Standard and above</a> include a resource editor, and there are also several free ones: <a href="http://www.wilsonc.demon.co.uk/d10resourceeditor.htm" rel="nofollow noreferrer">XN Resource Editor</a> seems to be a popular open-source editor, and I'm sure you can find more on Google. All of these produce a resource script, and you should have a resource compiler in your toolchain: <a href="http://msdn.microsoft.com/en-us/library/aa381042.aspx" rel="nofollow noreferrer">rc.exe</a> for Visual Studio (including the Express Editions, or available as part of the SDK), or <a href="http://sourceware.org/binutils/docs/binutils/windres.html" rel="nofollow noreferrer">windres</a> as part of the GNU BinUtils in cygwin or mingw.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload