📄 119-124.html
字号:
#define IsMultiSelect(hwnd) \
(GetWindowLong(hwnd, GWL_STYLE) & MCS_MULTISELECT)
/Child control IDs
#define IDC_EXIT 1024
#define IDC_TODAY 1025
#define IDC_MONTH 1026
#define ONE 0x01
TCHAR pszAppName[] = TEXT("MONTHSAMPLE");
TCHAR pszTitle[] = TEXT("Windows CE Month Calendar Control");
HINSTANCE ghInst;
int nWidth;
int nHeight;
/* Define the various windows used in this application:
hwndMain —> The main application window.
hwndExit —> Exit button
hwndToday —> Goto Today button
hwndMonth —> Month calendar control
*/
HWND hwndMain;
HWND hwndExit;
HWND hwndToday;
HWND hwndMonth;
//MONTHDAYSTATEs for holidays
MONTHDAYSTATE mdsHoliday[12] = {(ONE | (ONE<<21)), //January
(ONE<<13), //February
(ONE<<16), //March
0, //April
0, //May
0, //June
(ONE<<3), //July
0, //August
0, //September
(ONE<<30), //October
0, //November
(ONE<<24) //December};
void OnInitMonthCalendar(HWND hwndCal, int nLeft, int nTop);
void OnSelect(HWND hwndCal,
HWND hwndParent,
LPNMSELCHANGE lpsel);
void OnGetDayState(LPNMDAYSTATE lpds);
void OnGotoToday(HWND hwndCal);
LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam);
#endif
</PRE>
<!-- END CODE //-->
<P><B>main.cpp</B></P>
<!-- CODE //-->
<PRE>
#include <windows.h>
#include <commctrl.h>
#include "month.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)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = szAppName;
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(szAppName, szTitle,
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);
hwndToday = CreateWindow(TEXT("BUTTON"),
TEXT("Today"),
WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON,
0,37,65,35,
hwndMain, (HMENU)IDC_TODAY,
hInstance,NULL);
hwndMonth = CreateWindowEx(MONTHCAL_CLASS,
NULL,
WS_VISIBLE|WS_BORDER|WS_CHILD|MCS_DAYSTATE,
0,0,0,0,
hwndMain,(HMENU)IDC_MONTH,
hInstance, NULL);
OnInitMonthCalendar(hwndMonth, 70, 0);
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;
switch(message)
{
case WM_NOTIFY:
LPNMHDR lpnmhdr;
nID = (UINT)wParam;
switch(nID)
{
case IDC_MONTH:
lpnmhdr = (LPNMHDR)lParam;
switch(lpnmhdr->code)
{
case MCN_SELCHANGE:
LPNMSELCHANGE lpsel;
lpsel = (LPNMSELCHANGE)lParam;
OnSelect(lpnmhdr->hwndFrom, hwndMain, lpsel);
break;
case MCN_GETDAYSTATE:
LPNMDAYSTATE lpds;
lpds = (LPNMDAYSTATE)lParam;
OnGetDayState(lpds);
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_TODAY:
OnGotoToday(hwndMonth);
break;
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
}
void OnInitMonthCalendar(HWND hwndCal, int nLeft, int nTop)
{
RECT r;
SendMessage(hwndCal, MCM_SETCOLOR, MCSC_MONTHBK,
(LPARAM)RGB(192,192,192));
SendMessage(hwndCal, MCM_SETCOLOR, MCSC_TITLEBK,
(LPARAM)RGB(0,0,0));
SendMessage(hwndCal, MCM_SETCOLOR, MCSC_BACKGROUND,
(LPARAM)RGB(128,128,128));
SendMessage(hwndCal, MCM_GETMINREQRECT,
0,(LPARAM)(LPRECT)&r);
SetWindowPos(hwndCal, NULL, nLeft,nTop,
r.right, r.bottom, SWP_NOZORDER);
}
void OnSelect(HWND hwndCal,
HWND hwndParent,
LPNMSELCHANGE lpsel)
{
TCHAR pszText[64];
//Set caption text only if control is single select
if (!IsMultiSelect(hwndCal))
{
wsprintf(pszText, TEXT("Selected Date: %d\\%d\\%d"),
lpsel->stSelStart.wMonth,
lpsel->stSelStart.wDay,
lpsel->stSelStart.wYear);
SetWindowText(hwndParent, pszText);
}
}
void OnGetDayState(LPNMDAYSTATE lpds)
{
int i, nStart;
nStart = lpds->stStart.wMonth-1;
for (i=0; i<lpds->cDayState; i++)
{
//Account for month roll over, i.e., nStart > 11.
if (nStart>11)
{
nStart = 0;
}
lpds->prgDayState[i] = mdsHoliday[nStart++];
}
}
void OnGotoToday(HWND hwndCal)
{
SYSTEMTIME stToday;
SendMessage(hwndCal, MCM_GETTODAY, 0, (LPARAM)&stToday);
SendMessage(hwndCal, MCM_SETCURSEL, 0, (LPARAM)&stToday);
}
</PRE>
<!-- END CODE //-->
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="116-119.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="124-127.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 + -