• Welcome to Valhalla Legends Archive.
 

Custom fonts

Started by Okee, May 16, 2005, 01:08 AM

Previous topic - Next topic

Okee

I've been moving my connection code out of my console bot, and into the Win32 GUI shell I created awhile ago, for it. I wanted to add the ability to let the user select the font and font size of the richtext box. How should I go about making that font select pop up window appear, and then changing the font of the window?

MyndFyre

#1
To create a standard font dialog, if you're using MFC, you can use the CFontDialog window object, or if not, the Standard Font Dialog Box.

Then to change the font of a window, if you're using MFC, you can use CWnd::SetFont or if not, use the WM_SETFONT message.

You may also want to read The Logical Font.

[edit: Thanks UL for the message info :)]
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

UserLoser.

Quote from: MyndFyre on May 16, 2005, 06:14 PMI can't find a "SetWindowFont' function in MSDN.

Use WM_SETFONT message

Okee

Alright, I've been passing my CHOOSEFONT items to ChooseFont, and im working on what comes after calling ChooseFont. I'm not sure what the HDC paramater of SelectObject should be though. Should it be the window handle to my richtext box? I haven't made use of HDC in my program so far, so I don't know what the "handle to my device context" should be?

My code..


case ID_CONFIGURATION_FONTSETUP_CHANNELTEXT:
ZeroMemory(&FontChannelCf, sizeof(FontChannelCf));
FontChannelCf.lStructSize = sizeof (FontChannelCf);
FontChannelCf.hwndOwner = hDlg;
FontChannelCf.lpLogFont = &FontChannelLf;
FontChannelCf.rgbColors = FontChannelCrgb;
FontChannelCf.Flags = CF_SCREENFONTS | CF_EFFECTS;

if(ChooseFont(&FontChannelCf) == TRUE) {
FontChannelHf = CreateFontIndirect(FontChannelCf.lpLogFont);
FontChannelHfprev = SelectObject((HDC)GetDlgItem(hDlg, IDC_BNCHAT), FontChannelHf);
FontChannelCrgb = FontChannelCf.rgbColors;
FontChannelRgbprev = SetTextColor((HDC)GetDlgItem(hDlg, IDC_BNCHAT), FontChannelCrgb);
}
break;

Adron

SelectObject is used to pick that font as the active font on a device context. It's done right before you write text to that device context. It's probably not what you want to do.

UserLoser.

You could use the CHARFORMAT struct.  Use EM_SETCHARFORMAT.  I don't know why I didn't see you say rich text box earlier

Okee

Yeah I was looking at the CHARFORMAT struct, and EM_SETCHARFORMAT. I stopped looking at it though, because I don't think you can use the GetFont function, or make a similar font selection dialog box appear. How do you integrate the font select box with the CHARFORMAT struct, and messages? Should I just make my own (which would suck for taking away from the clean look im going for)?