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?
To create a standard font dialog, if you're using MFC, you can use the CFontDialog (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_mfc_cfontdialog.asp) window object, or if not, the Standard Font Dialog Box (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/commondialogboxlibrary/aboutcommondialogboxes/fontdialogbox.asp).
Then to change the font of a window, if you're using MFC, you can use CWnd::SetFont (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmfc98/html/_mfc_cwnd.3a3a.setfont.asp) or if not, use the WM_SETFONT (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowmessages/wm_setfont.asp) message.
You may also want to read The Logical Font (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnprogwin/html/ch17-03.asp).
[edit: Thanks UL for the message info :)]
Quote from: MyndFyre on May 16, 2005, 06:14 PMI can't find a "SetWindowFont' function in MSDN.
Use WM_SETFONT message
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;
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.
You could use the CHARFORMAT (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/richedit/richeditcontrols/richeditcontrolreference/richeditstructures/charformat.asp) struct. Use EM_SETCHARFORMAT (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/richedit/richeditcontrols/richeditcontrolreference/richeditmessages/em_setcharformat.asp). I don't know why I didn't see you say rich text box earlier
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)?