Last active
July 2, 2020 05:00
-
-
Save PBfordev/445539115204cc2f29ede5498720c3cc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <wx/wx.h> | |
#include <wx/datectrl.h> | |
#ifdef __WXMSW__ | |
#include <wx/msw/wrapcctl.h> | |
#endif; | |
// wxDatePickerNoToday is a wxDatePickerCtrl with wxDP_DROPDOWN style | |
// which on MSW does not display the today circle and today date | |
// in the drop down calendar | |
class wxDatePickerNoToday : public wxDatePickerCtrl | |
{ | |
public: | |
wxDatePickerNoToday(wxWindow *parent, | |
wxWindowID id, | |
const wxDateTime& date = wxDefaultDateTime, | |
const wxPoint& pos = wxDefaultPosition, | |
const wxSize& size = wxDefaultSize, | |
const wxValidator& validator = wxDefaultValidator, | |
const wxString& name = wxDatePickerCtrlNameStr) | |
: wxDatePickerCtrl(parent, id, date, pos, size, wxDP_DROPDOWN, validator, name) | |
{} | |
#ifdef __WXMSW__ | |
bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) override | |
{ | |
static const bool canSetMCSNoToday = wxApp::GetComCtl32Version() >= 570; | |
if ( canSetMCSNoToday && LPNMHDR(lParam)->code == DTN_DROPDOWN ) | |
{ | |
const HWND hWndCalendar = DateTime_GetMonthCal(GetHWND()); | |
if ( hWndCalendar ) | |
{ | |
LONG style = ::GetWindowLong(hWndCalendar, GWL_STYLE); | |
if ( style != 0 ) | |
{ | |
style |= MCS_NOTODAYCIRCLE | MCS_NOTODAY; | |
::SetWindowLong(hWndCalendar, GWL_STYLE, style); | |
} | |
} | |
} | |
return wxDatePickerCtrl::MSWOnNotify(idCtrl, lParam, result); | |
} | |
#endif | |
}; | |
class MyDialog : public wxDialog | |
{ | |
public: | |
MyDialog() : wxDialog(nullptr, wxID_ANY, "Test") | |
{ | |
wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL); | |
wxDateTime dt(wxDateTime::Today()); | |
short day = dt.GetDay(); | |
if ( day == 1 ) | |
day++; | |
else | |
day--; | |
dt.SetDay(day); | |
// wxDatePickerNoToday: this one will not have today circle and today date in the drop down calendar | |
mainSizer->Add(new wxDatePickerNoToday(this, wxID_ANY, dt), wxSizerFlags().Border()); | |
// regular wxDatePicker | |
mainSizer->Add(new wxDatePickerCtrl(this, wxID_ANY, dt, wxDefaultPosition, wxDefaultSize, wxDP_DROPDOWN), wxSizerFlags().Border()); | |
SetSizerAndFit(mainSizer); | |
} | |
}; | |
class MyApp : public wxApp | |
{ | |
public: | |
bool OnInit() override | |
{ | |
MyDialog().ShowModal(); | |
return false; | |
} | |
}; wxIMPLEMENT_APP(MyApp); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment