Skip to content

Commit

Permalink
fix #26
Browse files Browse the repository at this point in the history
  • Loading branch information
katahiromz committed Jun 5, 2018
1 parent c23868c commit 0f89454
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 8 deletions.
4 changes: 2 additions & 2 deletions READMEJP.txt
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@
RT_DLGINITを一部サポート。
コンボボックスとリストボックスの既定のスタイルが間違っていたのを修正。
コントロールのダイアログを修正・改良。
2018.XX.YY ver.4.6

2018.06.05 ver.4.6
ダイアログのフォントと寸法に関する間違いを修正。

/////////////////////////////////////////////////////
// 片山博文MZ (katahiromz) [A.N.T.]
Expand Down
19 changes: 17 additions & 2 deletions src/DialogRes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,14 @@ struct DialogRes
}

{
DWORD value = (m_style & ~DS_SETFONT);
DWORD value = m_style;
if ((value & DS_SHELLFONT) == DS_SHELLFONT)
;
else if ((value & DS_SHELLFONT) == DS_FIXEDSYS)
;
else if ((value & DS_SHELLFONT) == DS_SETFONT)
value &= ~DS_SETFONT;

MStringW str = m_db.DumpBitField(L"DIALOG", L"PARENT.STYLE", value);
if (value)
{
Expand Down Expand Up @@ -1096,7 +1103,15 @@ struct DialogRes

HDC hDC = CreateCompatibleDC(NULL);
HFONT hFont = NULL;
if (m_style & DS_SETFONT)
if ((m_style & DS_SHELLFONT) == DS_SHELLFONT)
{
hFont = HFONT(GetStockObject(SYSTEM_FONT));
}
else if ((m_style & DS_SHELLFONT) == DS_FIXEDSYS)
{
hFont = HFONT(GetStockObject(SYSTEM_FIXED_FONT));
}
else if (m_style & DS_SETFONT)
{
if (m_point_size == 0x7FFF)
{
Expand Down
52 changes: 48 additions & 4 deletions src/MDlgPropDlg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,37 @@ class MDlgPropDlg : public MDialogBase
return TRUE;
}

INT PointSizeFromStockFont(MString& strFont, INT nObject)
{
HFONT hFont = HFONT(GetStockObject(nObject));

LOGFONT lf;
GetObject(hFont, sizeof(lf), &lf);

strFont = lf.lfFaceName;

HDC hDC = CreateCompatibleDC(NULL);
SelectObject(hDC, hFont);

// lf.lfHeight --> nFontSize
INT nFontSize;
if (lf.lfHeight < 0)
{
lf.lfHeight = -lf.lfHeight;
}
else
{
TEXTMETRIC tm;
GetTextMetrics(hDC, &tm);
lf.lfHeight -= tm.tmInternalLeading;
}
nFontSize = MulDiv(lf.lfHeight, 72, GetDeviceCaps(hDC, LOGPIXELSY));

DeleteDC(hDC);

return nFontSize;
}

void OnOK(HWND hwnd)
{
BOOL bExtended = (::IsDlgButtonChecked(hwnd, chx1) == BST_CHECKED);
Expand Down Expand Up @@ -319,10 +350,23 @@ class MDlgPropDlg : public MDialogBase

MString strFont = GetDlgItemText(cmb4);
mstr_trim(strFont);
if (strFont.empty())
style &= ~DS_SETFONT;
else
style |= DS_SETFONT;

if ((style & DS_SHELLFONT) != DS_SHELLFONT)
{
if (strFont.empty())
style &= ~DS_SETFONT;
else
style |= DS_SETFONT;
}

if ((style & DS_SHELLFONT) == DS_SHELLFONT)
{
nFontSize = PointSizeFromStockFont(strFont, SYSTEM_FONT);
}
else if ((style & DS_SHELLFONT) == DS_FIXEDSYS)
{
nFontSize = PointSizeFromStockFont(strFont, SYSTEM_FIXED_FONT);
}

if (bExtended)
{
Expand Down

0 comments on commit 0f89454

Please sign in to comment.