/* static */ int wxApp::GetComCtl32Version() { // cache the result // // NB: this is MT-ok as in the worst case we'd compute s_verComCtl32 twice, // but as its value should be the same both times it doesn't matter static int s_verComCtl32 = -1; if ( s_verComCtl32 == -1 ) { // we're prepared to handle the errors wxLogNull noLog; // we don't want to load comctl32.dll, it should be already loaded but, // depending on the OS version and the presence of the manifest, it can // be either v5 or v6 and instead of trying to guess it just get the // handle of the already loaded version wxLoadedDLL dllComCtl32(wxT("comctl32.dll")); if ( !dllComCtl32.IsLoaded() ) { s_verComCtl32 = 0; return 0; } // try DllGetVersion() for recent DLLs s_verComCtl32 = CallDllGetVersion(dllComCtl32); // if DllGetVersion() is unavailable either during compile or // run-time, try to guess the version otherwise if ( !s_verComCtl32 ) { // InitCommonControlsEx is unique to 4.70 and later void *pfn = dllComCtl32.GetSymbol(wxT("InitCommonControlsEx")); if ( !pfn ) { // not found, must be 4.00 s_verComCtl32 = 400; } else // 4.70+ { // many symbols appeared in comctl32 4.71, could use any of // them except may be DllInstall() pfn = dllComCtl32.GetSymbol(wxT("InitializeFlatSB")); if ( !pfn ) { // not found, must be 4.70 s_verComCtl32 = 470; } else { // found, must be 4.71 or later s_verComCtl32 = 471; } } } } return s_verComCtl32; }
bool wxMSWDateControls::CheckInitialization() { // although we already call InitCommonControls() in app.cpp which is // supposed to initialize all common controls, in comctl32.dll 4.72 (and // presumably earlier versions 4.70 and 4.71, date time picker not being // supported in < 4.70 anyhow) it does not do it and we have to initialize // it explicitly // this is initially set to -1 to indicate that we need to perform the // initialization and gets set to false or true depending on its result static int s_initResult = -1; // MT-ok: used from GUI thread only if ( s_initResult == -1 ) { // in any case do nothing the next time, the result won't change and // it's enough to give the error only once s_initResult = false; if ( wxApp::GetComCtl32Version() < 470 ) { wxLogError(_("This system doesn't support date controls, please upgrade your version of comctl32.dll")); return false; } #if wxUSE_DYNLIB_CLASS INITCOMMONCONTROLSEX icex; icex.dwSize = sizeof(icex); icex.dwICC = ICC_DATE_CLASSES; // see comment in wxApp::GetComCtl32Version() explaining the // use of wxLoadedDLL wxLoadedDLL dllComCtl32(wxT("comctl32.dll")); if ( dllComCtl32.IsLoaded() ) { wxLogNull noLog; typedef BOOL (WINAPI *ICCEx_t)(INITCOMMONCONTROLSEX *); wxDYNLIB_FUNCTION( ICCEx_t, InitCommonControlsEx, dllComCtl32 ); if ( pfnInitCommonControlsEx ) { s_initResult = (*pfnInitCommonControlsEx)(&icex); } } #endif // wxUSE_DYNLIB_CLASS } return s_initResult != 0; }
bool wxDatePickerCtrl::Create(wxWindow *parent, wxWindowID id, const wxDateTime& dt, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator, const wxString& name) { // although we already call InitCommonControls() in app.cpp which is // supposed to initialize all common controls, in comctl32.dll 4.72 (and // presumably earlier versions 4.70 and 4.71, date time picker not being // supported in < 4.70 anyhow) it does not do it and we have to initialize // it explicitly static bool s_initDone = false; // MT-ok: used from GUI thread only if ( !s_initDone ) { #ifndef __WXWINCE__ if ( wxApp::GetComCtl32Version() < 470 ) { wxLogError(_("This system doesn't support date picker control, please upgrade your version of comctl32.dll")); return false; } #endif #if wxUSE_DYNLIB_CLASS INITCOMMONCONTROLSEX icex; icex.dwSize = sizeof(icex); icex.dwICC = ICC_DATE_CLASSES; wxDynamicLibrary dllComCtl32( #ifdef __WXWINCE__ _T("commctrl.dll") #else _T("comctl32.dll") #endif , wxDL_VERBATIM); if ( dllComCtl32.IsLoaded() ) { typedef BOOL (WINAPI *ICCEx_t)(INITCOMMONCONTROLSEX *); wxDYNLIB_FUNCTION( ICCEx_t, InitCommonControlsEx, dllComCtl32 ); if ( pfnInitCommonControlsEx ) { (*pfnInitCommonControlsEx)(&icex); } s_initDone = true; } #endif } // use wxDP_SPIN if wxDP_DEFAULT (0) was given as style if ( !(style & wxDP_DROPDOWN) ) style |= wxDP_SPIN; // initialize the base class if ( !CreateControl(parent, id, pos, size, style, validator, name) ) return false; // create the native control if ( !MSWCreateControl(DATETIMEPICK_CLASS, wxEmptyString, pos, size) ) return false; if ( dt.IsValid() || (style & wxDP_ALLOWNONE) ) SetValue(dt); else SetValue(wxDateTime::Today()); return true; }