BoldDays for TDateTimePicker?

I am using Delphi7 and I would like to highlight a few days of the TDateTimePicker control.

I read that, initially, this is a descendant of TMonthCalendar , so this should be possible.

I also found some sample code, but it is in C #: http://social.msdn.microsoft.com/Forums/en/winforms/thread/03527023-694d-41ab-bffb-18c59fca1fda

Please note that I do not want to use third-party DateTimePicker controls, I would like to stay with the standard one.

+1
source share
2 answers

You are right and wrong :-)

See: http://www.experts-exchange.com/Programming/System/Windows__Programming/MFC/Q_23927552.html

You are correct that you cannot install BoldDays under XP. But you are mistaken, because in Vista / Win7 you can!

Here is the modified code:

 procedure TForm1.DateTimePicker1DropDown(Sender: TObject); const DTM_GETMCSTYLE = (DTM_FIRST + 12); DTM_SETMCSTYLE = (DTM_FIRST + 11); MCS_NOTRAILINGDATES = $0040; MCS_SHORTDAYSOFWEEK = $0080; MCS_NOSELCHANGEONNAV = $0100; var monthCalHandle: THandle; boldDates: array[0..2] of integer; style, prevstyle: LResult; begin style := SendMessage(DateTimePicker1.Handle, DTM_GETMCSTYLE, 0, 0); style := style or MCS_DAYSTATE; //or MCS_NOSELCHANGEONNAV or MCS_WEEKNUMBERS; prevstyle := SendMessage(DateTimePicker1.Handle, DTM_SETMCSTYLE, 0, style); monthCalHandle := SendMessage(dateTimePicker1.Handle, DTM_GETMONTHCAL, 0, 0); boldDates[0]:=$5a5a5a; boldDates[1]:=$5a5a5a; boldDates[2]:=$5a5a5a; SendMessage(monthCalHandle, MCM_SETDAYSTATE, 3, integer(@boldDates)); end; 

Note. Be sure to add the vista manifest to the file, because otherwise it will not work!

Constants from the updated commctrl.h file found here: http://www.koders.com/cpp/fid6A6537D52B537D0920D7A760D2073F7B65ADE310.aspx?s=WM_CAP_DRIVER_CONNECT

Thanks for the help, you lead me to a solution! :-)

+3
source

You cannot do what you want, because the MonthCalendar displayed in response to the dropDown button clicks on DateTimePicker, it is a MonthCalendar that does not have MCS_DAYSTATE styleset. This is a Microsoft solution. This is not a limitation of VCL, so as far as I know, nothing can be done to change it. The only thing that would not be to use it and create an instance of the real MonthCalendar yourself in response to a button click by a button click; or use some of the existing components.

To prove this, here is the Pascal version of the same C # code as you. This does not work, and as far as I know, this will never happen. If you want to test it, connect it to the DropDown event for DateTimePicker.

 procedure TForm1.DateTimePicker1DropDown(Sender: TObject); var monthCalHandle: THandle; boldDates: array[0..2] of integer; begin { obtain the MonthCalendar handle using the DTM_GETMONTHCAL message note that the handle returned changes for every time the drop down calendar is displayed. } monthCalHandle := SendMessage(dateTimePicker1.Handle, DTM_GETMONTHCAL, 0, 0); { Send the MCM_SETDAYSTATE message. This message takes an array of 3 MONTHDAYSTATEs. Every MONTHDAYSTATE is a bit set that represents a month. Each bit (0 through 30) represents the state of a day. Whan a bit is on, its corresponding day is emphasized in the MonthCalendar } boldDates[0]:=$5a5a5a; boldDates[1]:=$5a5a5a; boldDates[2]:=$5a5a5a; SendMessage(monthCalHandle, MCM_SETDAYSTATE, 3, integer(@boldDates)); end; 
+2
source

Source: https://habr.com/ru/post/896009/


All Articles