CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Oct 2005
    Posts
    5

    Question setting button caption font

    I've got a button like this:
    Code:
    CreateWindowEx(0,
                       "BUTTON",
                       "generuj",
                       WS_CHILD | WS_VISIBLE,
                       55,
                       270,
                       80,
                       20,
                       hWnd,
                       (HMENU)1,
                       g_hInstance,
                       NULL);
    and a font like this:
    Code:
    HFONT fontArial=CreateFont(16,0,0,0,FW_NORMAL,FALSE,FALSE,FALSE,DEFAULT_CHARSET, OUT_TT_ONLY_PRECIS,CLIP_DEFAULT_PRECIS,ANTIALIASED_QUALITY, DEFAULT_PITCH,"arial");
    Can anybody tell me how to set this button's caption font to this 'fontArial'? I'm am a newbie to win32.

  2. #2
    Join Date
    Jul 2004
    Posts
    27

    Re: setting button caption font

    Use the WM_SETFONT message.

    --FCOD

  3. #3
    Join Date
    Oct 2005
    Posts
    5

    Re: setting button caption font

    but how?

  4. #4
    Join Date
    Jul 2004
    Posts
    27

    Re: setting button caption font

    Look up the WM_SETFONT message in the MSDN.

    http://msdn.microsoft.com/library/de...wm_setfont.asp

    --FCOD

    edit: Don't post your question in more than one forum...it's against the rules and bad etiquette.
    Last edited by flyingcowofdoom; October 14th, 2005 at 10:39 AM.

  5. #5
    Join Date
    Oct 2005
    Posts
    5

    Re: setting button caption font

    ok i get it, and used it already thanks. But I have a few 'windows', and do I ahve to send a message like this to each one? Is there a method using which I could change all the 'window's' fonts at once? I've got this type of situation:
    PHP Code:
    SendMessage(hDlgItem1WM_SETFONT, (WPARAM)fontArialTRUE);
    SendMessage(hDlgItem4WM_SETFONT, (WPARAM)fontArialTRUE);
    SendMessage(hDlgItem5WM_SETFONT, (WPARAM)fontArialTRUE);
    SendMessage(hDlgItem6WM_SETFONT, (WPARAM)fontArialTRUE);    
    SendMessage(hDlgItem9WM_SETFONT, (WPARAM)fontArialTRUE);

    SendMessage(hDlgItem8WM_SETFONT, (WPARAM)fontCourierTRUE);
    SendMessage(hDlgItem7WM_SETFONT, (WPARAM)fontCourierTRUE);
    SendMessage(hDlgItem3WM_SETFONT, (WPARAM)fontCourierTRUE);
    SendMessage(hDlgItem2WM_SETFONT, (WPARAM)fontCourierTRUE); 
    and I would like to send only 2 messages: to those which use fontCourier and to the fontArial ones.

  6. #6
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917

    Re: setting button caption font

    You should not cross posts in different forums.
    You get an answer in one, while other people try to help you in another without knowing that your problem has been resolved; they could use that time to help others.

    To answer your question about sending messages, unfortunately there is no way of doing it different way unless buttons have consecutive ID that you would be able to use in a loop.
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  7. #7
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: setting button caption font

    Other options to get child windows are:
    • You could use EnumChildWindows to enumerate through all child windows of a parent window
    • You could use GetWindow API to navigate through child windows ( GWL_HWNDNEXT/PREV)


    If you want to do it for buttons only, you may want to check for the class name of the window and then take action appropriately.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured