Notitie
Voor toegang tot deze pagina is autorisatie vereist. U kunt proberen u aan te melden of de directory te wijzigen.
Voor toegang tot deze pagina is autorisatie vereist. U kunt proberen de mappen te wijzigen.
In dit onderwerp wordt gedemonstreerd hoe u dynamisch een maandkalenderbeheer maakt met behulp van de functie CreateWindowEx.
Wat u moet weten
Technologieën
Voorwaarden
- C/C++
- Programmeren van Windows-gebruikersinterface
Aanwijzingen
Als u een maandkalenderbeheer wilt maken, gebruikt u de functie CreateWindowEx en geeft u MONTHCAL_CLASS op als de vensterklasse. U moet eerst de vensterklasse registreren door de functie InitCommonControlsEx aan te roepen, waarbij u de ICC_DATE_CLASSES bit opgeeft in de bijbehorende INITCOMMONCONTROLSEX- structuur.
Het volgende voorbeeld laat zien hoe u een maandkalenderbesturingselement maakt in een bestaand modeless dialoogvenster. Houd er rekening mee dat de groottewaarden die worden doorgegeven aan CreateWindowEx- allemaal nullen zijn. Omdat de minimale vereiste grootte afhankelijk is van het lettertype dat door het besturingselement wordt gebruikt, gebruikt het voorbeeld de MonthCal_GetMinReqRect macro om groottegegevens aan te vragen en vervolgens het formaat van het besturingselement aan te roepen door SetWindowPos-aan te roepen. Als u vervolgens het lettertype wijzigt met WM_SETFONT, worden de afmetingen van het controlelement niet gewijzigd. U moet MonthCal_GetMinReqRect opnieuw aanroepen en het formaat van het besturingselement aanpassen aan het nieuwe lettertype.
// Child window identifier of the month calendar.
#define IDC_MONTHCAL 101
// Symbols used by SetWindowPos function (arbitrary values).
#define LEFT 35
#define TOP 40
// Description:
// Creates a month calendar control in a dialog box.
// Parameters:
// hwndOwner - handle of the owner window.
// Nonlocal variables:
// MonthCalDlgProc - window procedure of the dialog box that
// contains the month calendar.
// g_hInst - global instance handle.
//
HRESULT CreateMonthCalDialog(HWND hwndOwner)
{
RECT rc;
INITCOMMONCONTROLSEX icex;
HWND hwndDlg = NULL;
HWND hwndMonthCal = NULL;
// Return an error code if the owner handle is invalid.
if (hwndOwner == NULL)
return E_INVALIDARG;
// Load the window class.
icex.dwSize = sizeof(icex);
icex.dwICC = ICC_DATE_CLASSES;
InitCommonControlsEx(&icex);
// Create a modeless dialog box to hold the control.
hwndDlg = CreateDialog(g_hInst,
MAKEINTRESOURCE(IDD_DATE_PICKER),
hwndOwner,
MonthCalDlgProc);
// Return if creating the dialog box failed.
if (hwndDlg == NULL)
return HRESULT_FROM_WIN32(GetLastError());
// Create the month calendar.
hwndMonthCal = CreateWindowEx(0,
MONTHCAL_CLASS,
L"",
WS_BORDER | WS_CHILD | WS_VISIBLE | MCS_DAYSTATE,
0,0,0,0, // resize it later
hwndDlg,
(HMENU) IDC_MONTHCAL,
g_hInst,
NULL);
// Return if creating the month calendar failed.
if (hwndMonthCal == NULL)
return HRESULT_FROM_WIN32(GetLastError());
// Get the size required to show an entire month.
MonthCal_GetMinReqRect(hwndMonthCal, &rc);
// Resize the control now that the size values have been obtained.
SetWindowPos(hwndMonthCal, NULL, LEFT, TOP,
rc.right, rc.bottom, SWP_NOZORDER);
// Set the calendar to the annual view.
MonthCal_SetCurrentView(hwndMonthCal, MCMV_YEAR);
// Make the window visible.
ShowWindow(hwndDlg, SW_SHOW);
return S_OK;
}
Verwante onderwerpen