?? winprog.html
字號:
<html>
<head>
<title>Windows Programming Tutorial</title>
<style type="text/css">
<!--
a:active {text-decoration: none}
a:hover {color:#ffffff;
text-decoration:none}
a:link {text-decoration:none}
a:visited {text-decoration:none}
td {font-family:verdana,arial,helvetica,sans-serif;
font-size:8pt}
body {font-family:verdana,arial,helvetica,sans-serif;
font-size:8pt}
-->
</style>
</head>
<body alink="#ffcc00" bgcolor="#000000" link="#ff9900" text="#a7a7a7" vlink="#ff9900">
<font face="arial" size="3">
<font size="6"><center>Windows Programming Tutorial</center></font>
<font size="4"><center>By: <a href="mailto:aztek@box.sk">AZTEK</a></center></font><br><br>
<font size="4">Contents</font><br><br>
<ul>
<a href="#1"><li><b>1. Basics</a></b></li>
<ul>
<a href="#1_1"><li>1.1 Introduction</li></a>
<a href="#1_2"><li>1.2 Simple Message</li></a>
<a href="#1_3"><li>1.3 Simple Window</li></a>
<a href="#1_4"><li>1.4 Text</li></a>
<a href="#1_5"><li>1.5 Menus</li></a>
<ul>
<a href="#1_5_1"><li>1.5.1 Resources</li></a>
<a href="#1_5_2"><li>1.5.2 On The Spot</li></a>
</ul>
<a href="#1_6"><li>1.6 Dialogs</li></a>
<a href="#1_7"><li>1.7 Controls</li></a>
</ul>
<a href="#2"><li><b>2. Intermediate</b></li></a>
<ul>
<a href="#2_1"><li>2.1 Bitmaps</li></a>
<ul>
<a href="#2_1_1"><li>2.1.1 Resource</li></a>
<a href="#2_1_2"><li>2.1.2 From a File</li></a>
</ul>
<a href="#2_2"><li>2.2 System Tray</li></a>
<a href="#2_3"><li>2.3 Toolbars</li></a>
<ul>
<a href="#2_3_1"><li>2.3.1 Custom Buttons</li></a>
<a href="#2_3_2"><li>2.3.2 Common Buttons</li></a>
</ul>
<a href="#2_4"><li>2.4 Statusbars</li></a>
</ul>
<a href="#A"><li><b>Appendix</b></li></a>
<ul>
<a href="#A_A"><li>A The Compiler</li></a>
<a href="#A_B"><li>B Tools</li></a>
<a href="#A_C"><li>C Links</li></a>
<a href="#A_D"><li>D Shoutouts</li></a>
</ul>
</ul>
<br>
<font size="5"><b><a name="1">1. Basics</a></b></font><br><br>
<font size="4"><b><a name="1_1">1.1 Introduction</a></b></font><br><br>
<p>First off if you are reading this tutorial, I am going to assume a few things.
Because windows programming is "more advanced" than console programming
I am going to have to assume you have a good grasp on C/C++. You need to know what
#include's are and how to use them, you need to know how to use arrays and pointers,
you need to know how to use switch() and case's, and you need to know what a typedef
is. These are things this tutorial will not cover. I will format my code to my style,
this to make it easier for me and you to read.</p>
<p>You are also going to need a C/C++ Compiler that supports Windows API. I used
Borlands Free C/C++ 5.5 Compiler to compile all of these examples, basically because
I am to cheap to get Microsoft Visual C++ and Borland is free alternative. For information
on getting a free compiler see the <a href="#A_B">Tools Appendix</a>. For information
on how to compile windows programs with the compiler see the <a href="#A_A">Compiler
Section</a>.</p>
<p>I like to look at the code and compiled examples before I go over what it all
means so after each example I will go over the code to clarify what it means.</p>
<font size="4"><b><a name="1_2">1.2 Simple Message</a></b></font><br>
<font size="2"><a href="http://blacksun.box.sk/aztek/winprog/examples/section_1_2.zip">Source</a> - <a href="http://blacksun.box.sk/aztek/winprog/images/section_1_2.gif">Screen Shot</a><br><br></font>
This first example is here just to make sure that your compiler does support windows.<br><br>
<table border="0" cellpadding="5" bgcolor="#26343e" align="center">
<tr>
<td nowrap>
<tt>
#include <windows.h><br>
<br>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {<br>
MessageBox (NULL, "Hello World" , "Hello", 0);<br>
return 0;<br>
}
</tt>
</td>
</tr>
</table><br><br>
<p>Put that code in a test file and compile it, any errors you get consult your
compilers help files. Now lets go through the code.<br>
<br>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)<br>
<br>
WinMain() is the windows equivalent of main() in DOS and UNIX. This is where the
program starts. WinMain() takes the following parameters:<br>
<br>
<dl>
<dt>hInstance</dt>
<dd>Identifies the programs current instance (the programs place in the memory)</dd>
<dt>hPrevInstance</dt>
<dd>Identifies the previous instance of the application. For a Win32-based application, this parameter is always NULL.</dd>
<dt>lpCmdLine</dt>
<dd>All of the command-line arguments in a string (does not include the program name)</dd>
<dt>nCmdShow</dt>
<dd>A value that can be passed to ShowWindow()</dd>
</dl><br><br>
Many of the keywords and types have windows specific definitions, like UINT is unsigned
int and LPSTR is char *, this is intended to increase portability. If you are more
comfortable using char * instead of LPSTR, feel free to do so.<br>
<br>
MessageBox() is the function that pops up a message box, hence the name. MessageBox()
takes the following parameters:<br>
<br>
<dl>
<dt>hWnd</dt>
<dl>Identifies the owner window of the message box to be created. If this parameter is NULL, the message box has no owner window.</dl>
<dt>lpText</dt>
<dl>This is the text contained in the window.</dl>
<dt>lpCaption</dt>
<dl>This is the text contained in the titlebar of the window.</dl>
<dt>uType</dt>
<dl>This is the style of the message box (like if its an error, warning, etc. and what buttons should appear. Setting this to 0 will add no icon and just a Ok button)</dl>
</dl></p>
<font size="4"><b><a name="1_3">1.3 Simple Window</a></b></font><br>
<font size="2"><a href="http://blacksun.box.sk/aztek/winprog/examples/section_1_3.zip">Source</a> - <a href="http://blacksun.box.sk/aztek/winprog/images/section_1_3.gif">Screen Shot</a><br><br></font>
On of the first questions that plagues a new windows programmer is "How Do
I make A Window?" Well I am afraid that the answer is not entirely simple.
Here is the source for a simple window.<br><br>
<table border="0" cellpadding="5" bgcolor="#26343e" align="center">
<tr>
<td nowrap>
<tt>
#include <windows.h><br>
<br>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);<br>
<br>
static char gszClassName[] = "MyWindowClass";<br>
static HINSTANCE ghInstance = NULL;<br>
<br>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {<br>
WNDCLASSEX WndClass;<br>
HWND hwnd;<br>
MSG Msg;<br>
<br>
ghInstance = hInstance;<br>
<br>
WndClass.cbSize = sizeof(WNDCLASSEX);<br>
WndClass.style = NULL;<br>
WndClass.lpfnWndProc = WndProc;<br>
WndClass.cbClsExtra = 0;<br>
WndClass.cbWndExtra = 0;<br>
WndClass.hInstance = ghInstance;<br>
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);<br>
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);<br>
WndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);<br>
WndClass.lpszMenuName = NULL;<br>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -