Nota
O acesso a esta página requer autorização. Podes tentar iniciar sessão ou mudar de diretório.
O acesso a esta página requer autorização. Podes tentar mudar de diretório.
Este tópico demonstra como criar dinamicamente um controle de calendário de mês usando a funçãoCreateWindowEx.
O que precisa de saber
Tecnologias
Pré-requisitos
- C/C++
- Programação da interface do usuário do Windows
Instruções
Para criar um controle de calendário de mês, use a função CreateWindowEx, especificando MONTHCAL_CLASS como a classe window. Você deve primeiro registar a classe de janela chamando a função InitCommonControlsEx, especificando o bit ICC_DATE_CLASSES na estrutura INITCOMMONCONTROLSEX que a acompanha.
O exemplo a seguir demonstra como criar um controle de calendário mensal em uma caixa de diálogo existente não modal. Observe que os valores de tamanho passados para CreateWindowEx são todos zeros. Como o tamanho mínimo necessário depende da fonte que o controle usa, o exemplo usa a macro MonthCal_GetMinReqRect para solicitar informações de tamanho e, em seguida, redimensiona o controle chamando SetWindowPos. Se, posteriormente, você alterar a fonte com WM_SETFONT, as dimensões do controle não serão alteradas. Você deve chamar MonthCal_GetMinReqRect novamente e redimensionar o controlo para acomodar a nova fonte.
// 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;
}
Tópicos relacionados