📄 132-137.html
字号:
<INPUT TYPE="hidden" NAME="Collection" VALUE="ITK">
<INPUT TYPE="hidden" NAME="ResultTemplate" VALUE="itk-simple-intrabook.hts">
<INPUT TYPE="hidden" NAME="ViewTemplate" VALUE="view.hts">
<font face="arial, helvetica" size=2><b>Search this book:</b></font><br>
<INPUT NAME="queryText" size=50 VALUE=""> <input type="submit" name="submitbutton" value="Go!">
<INPUT type=hidden NAME="section_on" VALUE="on">
<INPUT type=hidden NAME="section" VALUE="http://www.itknowledge.com/reference/standard/0471327476/">
</form>
<!-- Empty Reference Subhead -->
<!--ISBN=0471327476//-->
<!--TITLE=Essential Windows CE Application Programming//-->
<!--AUTHOR=Robert Burdick//-->
<!--PUBLISHER=John Wiley & Sons, Inc.//-->
<!--IMPRINT=Wiley Computer Publishing//-->
<!--CHAPTER=5//-->
<!--PAGES=132-137//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="131-132.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="137-140.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<P><B>main.cpp</B></P>
<!-- CODE //-->
<PRE>
#include <windows.h>
#include <commctrl.h>
#include "datetime.h"
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
RECT rc;
INITCOMMONCONTROLSEX icex;
WNDCLASS wc;
ghInst = hInstance;
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = NULL;
wc.hCursor = NULL;
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = NULL;
wc.lpszClassName = pszAppName;
RegisterClass(&wc);
icex.dwSize = sizeof(icex);
icex.dwICC = ICC_DATE_CLASSES;
InitCommonControlsEx(&icex);
SystemParametersInfo(SPI_GETWORKAREA,NULL,
&rc, NULL);
nWidth = rc.right;
nHeight = rc.bottom;
hwndMain = CreateWindow(pszAppName,
pszTitle,
WS_VISIBLE|WS_BORDER|WS_CAPTION,
0,0,nWidth,nHeight,
NULL, NULL, hInstance, NULL);
hwndExit = CreateWindow(TEXT("BUTTON"),
TEXT("Exit"),
WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON,
0,0,65,35,
hwndMain, (HMENU)IDC_EXIT,
hInstance,NULL);
hwndDateTime = CreateWindow(DATETIMEPICK_CLASS,
TEXT("DateTime"),
WS_VISIBLE|WS_BORDER|WS_CHILD|
DTS_LONGDATEFORMAT|DTS_APPCANPARSE|DTS_UPDOWN,
70,0,300,35,
hwndMain, (HMENU)IDC_DATETIME,
hInstance,NULL);
SendMessage(hwndDateTime, DTM_SETFORMAT, 0,
(LPARAM)TEXT(`The Date: `ddddMMMdd', `yyy"));
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage (&msg);
DispatchMessage(&msg);
}
return(msg.wParam);
}
LRESULT CALLBACK WndProc(HWND hwnd,
UINT message,
WPARAM wParam,
LPARAM lParam)
{
UINT nID;
LPNMHDR lpnmhdr;
switch(message)
{
case WM_NOTIFY:
nID = (UINT)wParam;
switch(nID)
{
case IDC_DATETIME:
lpnmhdr = (LPNMHDR)lParam;
switch(lpnmhdr->code)
{
case DTN_USERSTRING:
LPNMDATETIMESTRING lpstr;
lpstr = (LPNMDATETIMESTRING)lParam;
if (!lstrcmp(lpstr->pszUserString, TEXT("Today")))
{
GetLocalTime(&lpstr->st);
lpstr->dwFlags = GDT_NONE;
}
break;
default:
break;
} //End of switch(lpnmhdr->code) block
return (0);
default:
return (0);
} //End of switch(nID) block
case WM_COMMAND:
nID = LOWORD(wParam);
switch(nID)
{
case IDC_EXIT:
DestroyWindow(hwnd);
PostQuitMessage(0);
break;
default:
break;
} //End of switch(nID) statement
return (0);
default:
return (DefWindowProc(hwnd, message, wParam, lParam));
} //End of switch(message) statement
}
</PRE>
<!-- END CODE //-->
<H3><A NAME="Heading4"></A><FONT COLOR="#000077">Rebar Controls</FONT></H3>
<P>Rebar controls are those nice little draggable strips with buttons or other controls that appear all over applications like Microsoft Developer Studio and Microsoft Word. Applications use rebar controls as an attractive and flexible way to group and arrange related sets of child controls. Figure 5.4 shows this section’s sample application using a rebar control.
</P>
<P><A NAME="Fig4"></A><A HREF="javascript:displayWindow('images/05-04.jpg',480,240 )"><IMG SRC="images/05-04t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/05-04.jpg',480,240)"><FONT COLOR="#000077"><B>Figure 5.4</B></FONT></A> Rebar control with two bands.</P>
<P>Rebar controls act as containers for other Windows CE child controls. A rebar control can contain one or more <I>bands</I>, each of which in turn can contain one child control. The control contained by a rebar band can be a toolbar, giving the impression of multiple controls in a single band. Rebar controls can also include image lists. Bands in a rebar control can display a particular image list bitmap.</P>
<P>Each band in a rebar control can also include a <I>gripper bar</I>. A gripper bar appears as two vertical lines that can be used to drag the band.</P>
<P><FONT SIZE="+1"><B>Rebar Control Styles</B></FONT></P>
<P>There are seven styles that can be used to specify various rebar control characteristics:
</P>
<DL>
<DD><B>CCS_VERT.</B> Causes the control and the bands it contains to display vertically instead of horizontally.
<DD><B>RBS_AUTOSIZE.</B> Rebar band layout automatically updates when child control size or position changes.
<DD><B>RBS_BANDBORDERS.</B> Draws borders around rebar bands.
<DD><B>RBS_FIXEDORDER.</B> Bands can be moved to different rows, but band order is fixed.
<DD><B>RBS_SMARTLABELS.</B> If a band has an icon, the icon is only displayed when the band is minimized. If a band has a text label, the label is only displayed when the band is either in its restored or maximized state.
<DD><B>RBS_VARHEIGHT.</B> Displays bands at the minimum required height if possible. If this style is not set, the height of all bands in the control is set to the height of the tallest band.
<DD><B>RBS_VERTICALGGRIPPER.</B> Displays the gripper bar vertically instead of horizontally. Style is ignored if the rebar does not also have the CCS_VERT style.
</DL>
<P>Applications interact with the controls contained by rebar bands in the same way as with any other child control. The application can send the same child control messages to rebar band child controls. The child controls in rebar bands send WM_COMMAND messages to the parent of the rebar control. As this is normally the main application window, applications can respond to user interaction with the child controls as they would if the controls were not contained by a rebar control band.
</P>
<P>As with most Windows CE controls, there are a number of messages and notifications used by rebar controls. These include functionality for inserting and deleting bands, getting the number of bands in a rebar control, resizing the rebar control, and the like. Text and background bitmaps can also be added to rebar control bands to further customize their appearance.</P>
<P>It’s a safe bet that on the majority of occasions that you choose to use rebar controls, you will use them to group the child controls that drive the functionality of your Windows CE applications, relying on the default behavior of rebar controls to provide other functionality such as moving them with the gripper bar. It is therefore most useful to discuss the procedure for creating rebar controls and inserting bands with child controls into them. This will be the focus of this section.</P>
<P>The sample application for this section demonstrates a rebar control with two bands (see Figure 5.4). The first band contains the omnipotent “Exit” button. The second band contains a combo box. This combo box provides us some relief from the monotony of listing the messages and notifications supported by rebar controls at the end of chapter. Instead, the combo box lists all of the rebar control messages and notifications. Selecting an item in the combo box causes the application to display a description of the corresponding message or notification.</P>
<P>All of the new functionality presented in the sample application is related to creating rebar controls and inserting bands. Since this is described in detail in the pages that follow, listing the entire sample application at the end of the chapter is unnecessary.</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="131-132.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="137-140.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<!-- all of the reference materials (books) have the footer and subfoot reveresed -->
<!-- reference_subfoot = footer -->
<!-- reference_footer = subfoot -->
<!-- BEGIN SUB FOOTER -->
<br><br>
</TD>
</TR>
</TABLE>
<table width="640" border=0 cellpadding=0 cellspacing=0>
<tr>
<td align="left" width=135><img src="/images/white.gif" width=100 height="1" alt="" border="0"></td>
<!-- END SUB FOOTER -->
<!-- all of the books have the footer and subfoot reveresed -->
<!-- reference_subfoot = footer -->
<!-- reference_footer = subfoot -->
<!-- FOOTER -->
<td width="515" align="left" bgcolor="#FFFFFF">
<font face="arial, helvetica" size="1"><b><a href="/products.html"><font color="#006666">Products</font></a> | <a href="/contactus.html"><font color="#006666">Contact Us</font></a> | <a href="/aboutus.html"><font color="#006666">About Us</font></a> | <a href="http://www.earthweb.com/corporate/privacy.html" target="_blank"><font color="#006666">Privacy</font></a> | <a href="http://www.itmarketer.com/" target="_blank"><font color="#006666">Ad Info</font></a> | <a href="/"><font color="#006666">Home</font></a></b>
<br><br>
Use of this site is subject to certain <a href="/agreement.html">Terms & Conditions</a>, <a href="/copyright.html">Copyright © 1996-1999 EarthWeb Inc.</a><br>
All rights reserved. Reproduction whole or in part in any form or medium without express written permision of EarthWeb is prohibited.</font><p>
</td>
</tr>
</table>
</BODY>
</HTML>
<!-- END FOOTER -->
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -