Thread: Text in my controls is bold-ish.

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    3

    Text in my controls is bold-ish.

    For some reason, my controls' text is a little bold-ish (I believe that's how older versions of windows displayed text), this is rather annoying, as my program doesn't match other windows.

    YES I did include my manifest (Embeded via resources)
    YES I have compared my controls to others with Win Spy++
    YES I have propperly (I think) called "InitCommonControlsEx"
    Code:
    INITCOMMONCONTROLSEX icex;
     icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
     icex.dwICC  = ICC_PROGRESS_CLASS|ICC_INTERNET_CLASSES;
     InitCommonControlsEx(&icex);
    Here is a comparison of my test program VS. another.

    ~DtD
    Also, how do I properly set the window's background color to what is in the user's preferences?
    PS> Is there a good, up-to-date website that has tutorials for Windows User Interface related stuff? Not something that teaches you how to do one simple thing and too much more.
    PS2> I am using MinGW.
    Last edited by DtD; 05-14-2007 at 12:26 PM.

  2. #2
    Registered User Joelito's Avatar
    Join Date
    Mar 2005
    Location
    Tijuana, BC, México
    Posts
    310
    Easy!

    See WM_SETFONT and GetStockObject with DEFAULT_GUI_FONT.
    Yeah! Since the controls are build with CreateWindowEx, they use some system font thingy.
    * PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
    * Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.

  3. #3
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    >>set the window's background color to what is in the user's preferences<<

    GetSysColor
    GetSysColorBrush
    WM_SYSCOLORCHANGE.

    Use the latter to determine if a change has been made to the system maintained colours and use either the system brush of that colour(if appropriate) or create a brush as required from that system colour.

    Handle the WM_ERASBKGND message and apply the appropriate brush as described.

    Search the boards for specific examples of background colour changing (controls are a little different, if you need to explicitly modify their backgrounds) and for examples of changing the font as already described by Joelito above.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  4. #4
    Registered User
    Join Date
    May 2007
    Posts
    3
    @Joelito
    Hmmm... that didn't seem to do anything.
    Here is what I tried:
    Code:
    HGDIOBJ system_font;
    HWND my_window
    //...
    int main(int argc,char **app_param)
    {
    //...
    //Window creation
    //...
    //UI creation
    //...
    system_font=GetStockObject(DEFAULT_GUI_FONT);
    SendMessage(my_window,WM_SETFONT,(WPARAM)system_font,true);//I tried true and false.
    }
    I also tried putting it before "UI Creation".

    My other attempt was:
    Code:
    //Declarations, int main(), window and UI creation, ect...
    LRESULT WINAPI WndProc(HWND hwnd, UINT uMsg, WPARAM wParam,LPARAM lParam)
    {
     HDC hdc;
     PAINTSTRUCT ps;
    
     switch(uMsg)
     {
     case WM_PAINT:
      hdc = BeginPaint(hwnd, &ps);
      //Set the font
      system_font=SelectObject(hdc,GetStockObject(DEFAULT_GUI_FONT));
      SendMessage(my_window,WM_SETFONT,(WPARAM)system_font,false);
      EndPaint(hwnd, &ps);
      return 0;
     //...
     }
    @Ken Fitlike
    Got it working, thanks!
    Code:
    my_class.hbrBackground=GetSysColorBrush(COLOR_3DFACE);
    ~DtD

  5. #5
    Registered Abuser
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    591
    You have to call WM_SETFONT for each control you use. Here is another method (among many I've tried) that works nicely in setting your font to the same as used in MessageBoxes:
    Code:
    HFONT
    getSystemFont(HWND hwnd)
    {
        static HFONT systemFont = NULL;
    
        if(systemFont == NULL)
        {
            NONCLIENTMETRICS ncm = {sizeof(ncm)};
            SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncm, 0);
            systemFont = CreateFontIndirect(&ncm.lfMessageFont); /* use messagebox font */
        }
        return systemFont;
    }
    Then simply call getSystemFont whenever you need a handle to this font.

  6. #6
    Registered User
    Join Date
    Mar 2007
    Posts
    32
    I had this problem recently. I'm not sure why it is happening! A quick
    Code:
    SendMessage(hwndcontrol,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(1,0));
    in WM_CREATE sorted it our though.

  7. #7
    Registered User
    Join Date
    May 2007
    Posts
    3
    At: @nthony
    I don't understand why you are using this, just so all fonts are the same? Well, I have a set of functions for creating all my controls and windows, so I just threw the code in them.

    @chrishowarth
    Thanks! I didn't use WM_CREATE, but your code worked!

    ~DtD

  8. #8
    Registered Abuser
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    591
    The purpose of getSystemFont() is that you would call it whenever you needed a handle to the "normal" font (i.e. when you create your controls). I use it over GetStockObject(...) because that function is quirky when it comes to different OSs/themes . I.E. MSDN even mis-documents that it returns X font here, and Y font there, and when testing it, I found it did not return the font I expected in Win98 SE, so I asked around until I found a method that seemed to work properly on all OSs.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. My text doesn't display
    By joeprogrammer in forum Game Programming
    Replies: 11
    Last Post: 02-23-2006, 10:01 PM
  2. Text adventure engine idea. thoughts?
    By suzakugaiden in forum Game Programming
    Replies: 16
    Last Post: 01-15-2006, 05:13 AM
  3. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 02:59 PM
  4. Replies: 1
    Last Post: 07-13-2002, 05:45 PM
  5. Ok, Structs, I need help I am not familiar with them
    By incognito in forum C++ Programming
    Replies: 7
    Last Post: 06-29-2002, 09:45 PM