Practical
Learning: Adding the Common Controls Library
|
|
- On the main menu, click Project -> Add Existing Item...
- Locate the directory where Microsoft Visual C++ libraries are
installed. By default, for Microsoft Visual C++ 2010, this should be
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Lib\
- Select ComCtl32.Lib
- Click Add
- In the empty document, type: #define IDC_DATETIMEPICKER
2012 and press Enter
Practical
Learning: Programmatically Creating the Control
|
|
- Access the
Exercise.cpp file
- To programmatically create a date time picker, change the code as
follows:
#include <windows.h>
#include <commctrl.h>
#include "Resource.h"
No Change . . .
//---------------------------------------------------------------------------
LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
INITCOMMONCONTROLSEX icex;
icex.dwSize = sizeof(icex);
icex.dwICC = ICC_DATE_CLASSES;
InitCommonControlsEx(&icex);
switch(msg)
{
case WM_INITDIALOG:
CreateWindowEx(0,
DATETIMEPICK_CLASS,
TEXT("DateTime"),
WS_BORDER | WS_CHILD | WS_VISIBLE | DTS_SHOWNONE,
10,10,220,20,
hWndDlg,
NULL,
hInstGlobal,
NULL);
return TRUE;
case WM_COMMAND:
switch(wParam)
{
case IDOK:
EndDialog(hWndDlg, 0);
return TRUE;
}
break;
case WM_CLOSE:
PostQuitMessage(WM_QUIT);
break;
}
return FALSE;
}
//---------------------------------------------------------------------------
- Execute the application to see the result
- Close the dialog box and return to your programming environment
Practical
Learning: Manually Creating a Data Time Picker
|
|
- In the Exercise.cpp file, delete the code in the WM_INITDIALOG
event:
#include <windows.h>
#include <commctrl.h>
#include "Resource.h"
//---------------------------------------------------------------------------
HWND hWnd;
HINSTANCE hInstGlobal;
LRESULT CALLBACK DlgProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
//---------------------------------------------------------------------------
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
hInstGlobal = hInstance;
DialogBox(hInstGlobal, MAKEINTRESOURCE(IDD_EXERCISE_DLG),
hWnd, reinterpret_cast<DLGPROC>(DlgProc));
return FALSE;
}
//---------------------------------------------------------------------------
LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
INITCOMMONCONTROLSEX icex;
icex.dwSize = sizeof(icex);
icex.dwICC = ICC_DATE_CLASSES;
InitCommonControlsEx(&icex);
switch(msg)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
switch(wParam)
{
case IDOK:
EndDialog(hWndDlg, 0);
return TRUE;
}
break;
case WM_CLOSE:
PostQuitMessage(WM_QUIT);
break;
}
return FALSE;
}
//---------------------------------------------------------------------------
- Access the Exercise.rc file and change it as follows:
#include <afxres.h>
#include "Resource.h"
IDD_EXERCISE_DLG DIALOG 260, 200, 158, 140
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Date Time Picker"
FONT 8, "MS Shell Dlg"
BEGIN
CONTROL "", IDC_DATETIMEPICKER, "SysDateTimePick32",
WS_CHILD | WS_TABSTOP, 10, 10, 140, 14
DEFPUSHBUTTON "OK", IDOK, 100, 120, 50, 14
END
- Execute the application to see the result
- Close the dialog box and return to your programming environment
|
|