S
Scott
Consider the follow code snippet. Why doesn't it work?
// Initialize a CFont object with the characteristics given
// in a LOGFONT structure.
LOGFONT lf;
memset(&lf, 0, sizeof(LOGFONT)); // clear out structure
lf.lfHeight = 10; // request a 10-pixel-height font
strcpy(lf.lfFaceName, "Courier"); // request a face name "Courier"
HFONT hfont = ::CreateFontIndirect(&lf); // create the font
// Convert the HFONT to CFont*.
CFont* pfont = CFont::FromHandle(hfont);
//try to apply font to this window
pMainFrame->SetFont(pfont);
// The main window has been initialized, so show and update it.
pMainFrame->ShowWindow(m_nCmdShow);
pMainFrame->UpdateWindow();
:eleteObject(hfont);
Obviously, I'm trying to set the font for a window to Courier, but I'm
trying that as a workaround to a more difficult problem. Here's another code
snippet.
void CVoiceView::Locate(int & col, int & row)
{
CEdit& EditCtrl = GetEditCtrl();
row = EditCtrl.LineFromChar(-1) + 1 ;
col = LOWORD(EditCtrl.CharFromPos(GetCaretPos())) ;
co1l = col - EditCtrl.LineIndex(row-1)+1 ;
if (!EditCtrl.IsWindowEnabled())
{
row=-1;
col=-1;
}
}
Yes, fairly standard stuff meant to return the current column and row of the
cursor (well, actually the caret) in the edit control. The hitch is, of
course, that it doesn't always work as expected. With proportional fonts,
"i," "l," and "j" will frequently cause the column count to be one less than
what it should be. The row count is always right. This is the problem I
really need to solve, going to a fixed font was just a workaround.
// Initialize a CFont object with the characteristics given
// in a LOGFONT structure.
LOGFONT lf;
memset(&lf, 0, sizeof(LOGFONT)); // clear out structure
lf.lfHeight = 10; // request a 10-pixel-height font
strcpy(lf.lfFaceName, "Courier"); // request a face name "Courier"
HFONT hfont = ::CreateFontIndirect(&lf); // create the font
// Convert the HFONT to CFont*.
CFont* pfont = CFont::FromHandle(hfont);
//try to apply font to this window
pMainFrame->SetFont(pfont);
// The main window has been initialized, so show and update it.
pMainFrame->ShowWindow(m_nCmdShow);
pMainFrame->UpdateWindow();
:eleteObject(hfont);
Obviously, I'm trying to set the font for a window to Courier, but I'm
trying that as a workaround to a more difficult problem. Here's another code
snippet.
void CVoiceView::Locate(int & col, int & row)
{
CEdit& EditCtrl = GetEditCtrl();
row = EditCtrl.LineFromChar(-1) + 1 ;
col = LOWORD(EditCtrl.CharFromPos(GetCaretPos())) ;
co1l = col - EditCtrl.LineIndex(row-1)+1 ;
if (!EditCtrl.IsWindowEnabled())
{
row=-1;
col=-1;
}
}
Yes, fairly standard stuff meant to return the current column and row of the
cursor (well, actually the caret) in the edit control. The hitch is, of
course, that it doesn't always work as expected. With proportional fonts,
"i," "l," and "j" will frequently cause the column count to be one less than
what it should be. The row count is always right. This is the problem I
really need to solve, going to a fixed font was just a workaround.