I've been trying to figure out how to change the font color when using a common dialog box. I've tried a bunch of stuff but nothing seems to have worked. Unfortunately, I don't know much about programming in C (or any other language for that matter), so that hasn't help much either. Anyhow, here's the code I have so far.
Code:
#define INCLUDE_COMMDLG_H 1
#include <windows.h>
static LOGFONT lf; /* logical font structure */
static HFONT hFont; /* Handle */
HDC hdc; /* display device context of owner window */
/* DWORD rgbCurrent = RGB(255, 0, 0); */ /* current text color set to red */
COLORREF rgbCurrent; /* current text color */
/****************************************************************************
* *
* FUNCTION : FontChooseFont() *
* *
* PURPOSE : Invokes the Font dialog box. *
* *
****************************************************************************/
BOOL FontChooseFont (HWND hwnd)
{
CHOOSEFONT cf; /* common dialog box structure */
/* Set all structure fields to zero */
memset(&cf, 0, sizeof(CHOOSEFONT));
cf.lStructSize = sizeof (CHOOSEFONT);
cf.hwndOwner = hwnd;
cf.lpLogFont = &lf;
cf.Flags = CF_INITTOLOGFONTSTRUCT | CF_SCREENFONTS | CF_EFFECTS;
cf.rgbColors = rgbCurrent; /* was 0L ; */
cf.nFontType = 0; /* Returned from ChooseFont */
rgbCurrent = cf.rgbColors;
return ChooseFont (&cf);
}
/****************************************************************************
* *
* FUNCTION : FontInitialize () *
* *
* PURPOSE : Gets the current active font. *
* *
****************************************************************************/
void PASCAL FontInitialize (HWND hwndEdit)
{
GetObject (GetStockObject (SYSTEM_FONT), sizeof (LOGFONT),
(PSTR) &lf);
hFont = CreateFontIndirect (&lf);
SendMessage (hwndEdit, WM_SETFONT, (WPARAM) hFont, 0);
}
/****************************************************************************
* *
* FUNCTION : FontSetFont () *
* *
* PURPOSE : Sets the new user defined font in the active window. *
* *
****************************************************************************/
void PASCAL FontSetFont (HWND hwndEdit)
{
HFONT hFontNew;
RECT rect;
DWORD dwColor;
/* dwColor = GetTextColor(hdc);
if (dwColor == RGB(0, 0, 0)) */ /* if current color is black */
/* SetTextColor(hdc, RGB(255, 0, 0)); */ /* sets color to red */
/* SetTextColor(hdc, rgbCurrent); */
hFontNew = CreateFontIndirect (&lf);
SendMessage (hwndActiveEdit, WM_SETFONT, (WPARAM) hFontNew, 0);
DeleteObject (hFont);
hFont = hFontNew;
GetClientRect (hwndEdit, &rect);
InvalidateRect (hwndEdit, &rect, TRUE);
}
/****************************************************************************
* *
* FUNCTION : FontDeinitialize () *
* *
* PURPOSE : Deinitializes font attributes upon close. *
* *
****************************************************************************/
void PASCAL FontDeinitialize (void)
{
DeleteObject (hFont);
}