Author Topic: Whoosh ... back down the WinApi rabbit hole I went ...  (Read 1642 times)

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 1966
    • View Profile
Whoosh ... back down the WinApi rabbit hole I went ...
« on: January 08, 2020, 11:53:55 AM »
While exploring the effect of adding a DPI manifest to some of the GUI samples, I discovered that the
CALENDAR sample no longer displayed any of the custom colors that I assigned to it all those years ago.

That made me unhappy ...  :'(   

It turns out that the macro MonthCal_SetColor() that is used to set the various Calendar colors
have no effect (anymore) if Windows themes and DPI awareness are set.  Actually, it is possible to set
the background color of the Calendar regardless of themes ... that does little to pacify me. 

The next question I had is whether it is possible to disable themes on a per-application basis -- turns out
there is a function to do that.  To access that function requires including the uxtheme.h header and uxtheme.lib
That seemed like a hassle to me, so I opted for the following solution which might come in handy for other apps.

' Disable THEMES for this app 

Code: [Select]
LOCAL dummy as wchar_t   
SetWindowTheme(lib "uxtheme.dll", MyCalendar, &dummy, &dummy)

The attached graphic shows the effects of DPI awareness with and without theme turned on.
« Last Edit: January 08, 2020, 11:59:31 AM by MrBcx »

Jeff

  • Administrator
  • Newbie
  • *****
  • Posts: 40
    • View Profile
Re: Whoosh ... back down the WinApi rabbit hole I went ...
« Reply #1 on: January 09, 2020, 01:01:29 PM »
Thanks for sharing this.  I haven't messed with themes at all, so this gives me something else to consider while I'm working on DPI awareness.

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 1966
    • View Profile
Re: Whoosh ... back down the WinApi rabbit hole I went ...
« Reply #2 on: January 09, 2020, 08:30:58 PM »
Glad to help Jeff ...

If there is one thing I've learned recently, it's that DPI awareness is a much broader subject than I would have ever guessed.

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 1966
    • View Profile
The Little Calendar Demo That Could ...
« Reply #3 on: October 04, 2023, 10:43:15 AM »
I last updated the Calendar Demo in \GUI_DEMOS\ in 2020 by learning how to disable THEMES.
See 2020 posts above for a refresher on that.

Today's update adds the ability to adjust the FONT attributes, to account for higher resolution screens.

I refuse to let this demo die ...

Code: [Select]

GUI "BCX_Calendar_Demo", DPI

GLOBAL MyForm      AS CONTROL
GLOBAL MyCalendar  AS CONTROL
GLOBAL cxClient    AS INTEGER
GLOBAL cyClient    AS INTEGER


SUB FORMLOAD
    '============================================================================
    LOCAL iccex AS INITCOMMONCONTROLSEX
    '============================================================================
    iccex.dwSize = SIZEOF(INITCOMMONCONTROLSEX)
    iccex.dwICC  = ICC_DATE_CLASSES
    InitCommonControlsEx(&iccex)
    '============================================================================
    MyForm     = BCX_FORM    ("BCX Calendar"             ,    10, 0, 950, 820 )
    MyCalendar = BCX_CONTROL ("sysmonthcal32", MyForm, "", 0, 10, 0, 950, 800 )
    '============================================================================
    MonthCal_SetColor(MyCalendar, MCSC_BACKGROUND   , RGB(190, 255, 255))
    MonthCal_SetColor(MyCalendar, MCSC_TITLETEXT    , RGB(0, 0, 0))
    MonthCal_SetColor(MyCalendar, MCSC_TITLEBK      , RGB(245, 175, 0))
    MonthCal_SetColor(MyCalendar, MCSC_MONTHBK      , RGB(248, 245, 225))
    MonthCal_SetColor(MyCalendar, MCSC_TEXT         , RGB(0, 0, 225))
    MonthCal_SetColor(MyCalendar, MCSC_TRAILINGTEXT , RGB(0, 225, 0))
 
    '============================================================================
    '                            Added in 2020 by MrBcx
    '============================================================================
    DECLARE FUNCTION SetWindowTheme LIB "uxtheme.dll" ALIAS "SetWindowTheme" _
    (hWnd AS HWND, A AS WCHAR PTR, B AS WCHAR PTR) AS INTEGER

    LOCAL dummy AS wchar_t
    SetWindowTheme ( MyCalendar, &dummy, & dummy) ' Disable THEMES for this app
 
    '============================================================================
    '                            Added in 2023 by MrBcx
    '============================================================================
    SendMessage (MyCalendar, WM_SETFONT, BCX_SET_FONT ( "Verdana" , 12, 1, 1), 1)
    '============================================================================
    CENTER (MyForm)
    SHOW   (MyForm)
END SUB


BEGIN EVENTS
    SELECT CASE CBMSG
    CASE WM_SIZE  THEN
        cxClient = LOWORD (lParam)
        cyClient = HIWORD (lParam)
        SetWindowPos(MyCalendar, 0, 0, 0, cxClient, cyClient, SWP_NOMOVE)
    END SELECT
END EVENTS


jbk

  • Full Member
  • ***
  • Posts: 197
    • View Profile
Re: Whoosh ... back down the WinApi rabbit hole I went ...
« Reply #4 on: October 04, 2023, 10:59:58 AM »
nice
you think that there's a way to make Saturdays bold?

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 1966
    • View Profile
Re: Whoosh ... back down the WinApi rabbit hole I went ...
« Reply #5 on: October 04, 2023, 11:22:33 AM »
nice
you think that there's a way to make Saturdays bold?

I don't know ... the place to start is commctrl.h in your compiler's \include\ folder

Searching for "SysMonthCal32" should take you to the start of the #defines.



MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 1966
    • View Profile
Re: Whoosh ... back down the WinApi rabbit hole I went ...
« Reply #7 on: October 04, 2023, 12:12:15 PM »
I am not Windows SDK savvy but I may give it a try https://learn.microsoft.com/en-us/dotnet/desktop/winforms/controls/display-specific-days-in-bold-with-wf-monthcalendar-control?view=netframeworkdesktop-4.8

That's dotnet.  That's not going to be much help to you. 

It's probably not even based on the SysMonthCal32 control.