DataPicker
>> Thursday, October 29, 2009
#define STRICT
#include
#include
#include
#pragma comment(lib, "comctl32.lib")
static char szAppName[] = "DatePickerApp";
HINSTANCE hInst;
HWND hwnd;
LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
static SYSTEMTIME st;
static HWND hWndStartDate, hWndStartTime;
static char szDate[15], szTime[10], szStamp[20];
NMDATETIMECHANGE *Date;
switch (iMsg)
{
case WM_CREATE:
GetLocalTime(&st);
GetDateFormat(LOCALE_SYSTEM_DEFAULT, 0, &st, "yyyyMMdd", szDate, sizeof
(szDate));
GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, &st, "HHmmss", szTime, sizeof
(szTime));
hWndStartDate = CreateWindowEx(0, DATETIMEPICK_CLASS, NULL, WS_BORDER |
WS_CHILD | WS_VISIBLE, 10, 10, 100, 25, hwnd, NULL, hInst, NULL);
hWndStartTime = CreateWindowEx(0, DATETIMEPICK_CLASS, NULL, WS_BORDER |
WS_CHILD | WS_VISIBLE | DTS_TIMEFORMAT, 10, 40, 100, 25, hwnd, NULL,
hInst, NULL);
break;
case WM_NOTIFY:
switch (((LPNMHDR)lParam)->code)
{
case DTN_DATETIMECHANGE:
Date = (LPNMDATETIMECHANGE)lParam;
if (Date->nmhdr.hwndFrom == hWndStartDate || Date->nmhdr.hwndFrom ==
hWndStartTime)
{
DateTime_SetRange(hWndStartDate, GDTR_MAX, &st);
DateTime_SetRange(hWndStartTime, GDTR_MAX, &st);
}
break;
case DTN_DROPDOWN:
MonthCal_SetFirstDayOfWeek(DateTime_GetMonthCal(hWndStartDate), 0);
break;
}
break;
case WM_COMMAND:
if (IDCANCEL == LOWORD(wParam))
{
DateTime_GetSystemtime(hWndStartDate, &st);
DateTime_GetSystemtime(hWndStartTime, &st);
break;
}
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hwnd, iMsg, wParam, lParam);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine,
int iCmdShow)
{
MSG msg;
WNDCLASS wndclass;
INITCOMMONCONTROLSEX icex;
wndclass.style = 0;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(hInstance, szAppName);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
wndclass.lpszMenuName = szAppName;
wndclass.lpszClassName = szAppName;
RegisterClass(&wndclass);
icex.dwSize = sizeof(icex);
icex.dwICC = ICC_DATE_CLASSES;
InitCommonControlsEx(&icex);
hwnd = CreateWindow(szAppName, szAppName, WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0,
0, 400, 400, NULL, NULL, hInstance, szCmdLine);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
0 comments:
Post a Comment