marge trunk 7174
@@ -373,3 +373,21 @@ | ||
373 | 373 | } |
374 | 374 | } |
375 | 375 | } |
376 | + | |
377 | +HFONT SetDlgFonts(HWND hDlg, const int nIDDlgItems[], int nIDDlgItemCount, | |
378 | + const char *UILanguageFile, PCHAR key) | |
379 | +{ | |
380 | + if (key == NULL) key = "DLG_TAHOMA_FONT"; | |
381 | + HFONT hPrevFont = (HFONT)SendMessage(hDlg, WM_GETFONT, 0, 0); | |
382 | + LOGFONT logfont; | |
383 | + GetObject(hPrevFont, sizeof(LOGFONT), &logfont); | |
384 | + HFONT hNewFont; | |
385 | + if (get_lang_font(key, hDlg, &logfont, &hNewFont, UILanguageFile)) { | |
386 | + for (int i = 0 ; i < nIDDlgItemCount ; i++) { | |
387 | + const int nIDDlgItem = nIDDlgItems[i]; | |
388 | + SendDlgItemMessage(hDlg, nIDDlgItem, WM_SETFONT, (WPARAM)hNewFont, MAKELPARAM(TRUE,0)); | |
389 | + } | |
390 | + } | |
391 | + return hNewFont; | |
392 | +} | |
393 | + |
@@ -49,6 +49,8 @@ | ||
49 | 49 | char *key; |
50 | 50 | } DlgTextInfo; |
51 | 51 | void SetDlgTexts(HWND hDlgWnd, const DlgTextInfo *infos, int infoCount, const char *UILanguageFile); |
52 | +HFONT SetDlgFonts(HWND hDlg, const int nIDDlgItems[], int nIDDlgItemCount, | |
53 | + const char *UILanguageFile, PCHAR key); | |
52 | 54 | |
53 | 55 | #ifdef __cplusplus |
54 | 56 | } |
@@ -56,26 +56,10 @@ | ||
56 | 56 | }; |
57 | 57 | |
58 | 58 | struct DrapDropDlgData { |
59 | - HFONT hPrevFont; | |
59 | + HFONT hNewFont; | |
60 | 60 | DrapDropDlgParam *Param; |
61 | 61 | }; |
62 | 62 | |
63 | -static HFONT SetDlgFonts(HWND hDlg, const int nIDDlgItems[], int nIDDlgItemCount, const char *UILanguageFile, PCHAR key) | |
64 | -{ | |
65 | - if (key == NULL) key = "DLG_TAHOMA_FONT"; | |
66 | - HFONT hPrevFont = (HFONT)SendMessage(hDlg, WM_GETFONT, 0, 0); | |
67 | - LOGFONT logfont; | |
68 | - GetObject(hPrevFont, sizeof(LOGFONT), &logfont); | |
69 | - HFONT hNewFont; | |
70 | - if (get_lang_font("DLG_TAHOMA_FONT", hDlg, &logfont, &hNewFont, UILanguageFile)) { | |
71 | - for (int i = 0 ; i < nIDDlgItemCount ; i++) { | |
72 | - const int nIDDlgItem = nIDDlgItems[i]; | |
73 | - SendDlgItemMessage(hDlg, nIDDlgItem, WM_SETFONT, (WPARAM)hNewFont, MAKELPARAM(TRUE,0)); | |
74 | - } | |
75 | - } | |
76 | - return hNewFont; | |
77 | -} | |
78 | - | |
79 | 63 | static LRESULT CALLBACK OnDragDropDlgProc(HWND hDlgWnd, UINT msg, WPARAM wp, LPARAM lp) |
80 | 64 | { |
81 | 65 | static const int FontIDs[] = { |
@@ -117,7 +101,7 @@ | ||
117 | 101 | SetWindowLongPtr(hDlgWnd, DWLP_USER, (LONG_PTR)DlgData); |
118 | 102 | DrapDropDlgParam *Param = (DrapDropDlgParam *)lp; |
119 | 103 | DlgData->Param = Param; |
120 | - DlgData->hPrevFont = SetDlgFonts(hDlgWnd, FontIDs, _countof(FontIDs), Param->UILanguageFile, NULL); | |
104 | + DlgData->hNewFont = SetDlgFonts(hDlgWnd, FontIDs, _countof(FontIDs), Param->UILanguageFile, NULL); | |
121 | 105 | SetDlgTexts(hDlgWnd, TextInfos, _countof(TextInfos), Param->UILanguageFile); |
122 | 106 | |
123 | 107 | // target file |
@@ -258,15 +242,18 @@ | ||
258 | 242 | DlgData->Param->DropType = DROP_TYPE_CANCEL; |
259 | 243 | } |
260 | 244 | if (wID == IDOK || wID == IDCANCEL) { |
261 | - if (DlgData->hPrevFont != NULL) { | |
262 | - DeleteObject(DlgData->hPrevFont); | |
263 | - } | |
264 | 245 | EndDialog(hDlgWnd, wID); |
265 | - free(DlgData); | |
266 | 246 | break; |
267 | 247 | } |
268 | 248 | return FALSE; |
269 | 249 | } |
250 | + case WM_NCDESTROY: | |
251 | + if (DlgData->hNewFont != NULL) { | |
252 | + DeleteObject(DlgData->hNewFont); | |
253 | + DlgData->hNewFont = NULL; | |
254 | + } | |
255 | + free(DlgData); | |
256 | + break; | |
270 | 257 | |
271 | 258 | default: |
272 | 259 | return FALSE; |
@@ -1,6 +1,6 @@ | ||
1 | -/* | |
1 | +/* | |
2 | 2 | * Copyright (C) 1994-1998 T. Teranishi |
3 | - * (C) 2007-2017 TeraTerm Project | |
3 | + * (C) 2007-2018 TeraTerm Project | |
4 | 4 | * All rights reserved. |
5 | 5 | * |
6 | 6 | * Redistribution and use in source and binary forms, with or without |
@@ -28,82 +28,102 @@ | ||
28 | 28 | */ |
29 | 29 | |
30 | 30 | /* TERATERM.EXE, print-abort dialog box */ |
31 | -#include "stdafx.h" | |
31 | +#include <windows.h> | |
32 | +#include <windowsx.h> | |
32 | 33 | #include "teraterm.h" |
33 | 34 | #include "tttypes.h" |
34 | 35 | #include "ttlib.h" |
36 | +#include "dlglib.h" | |
35 | 37 | #include "tt_res.h" |
36 | 38 | #include "prnabort.h" |
37 | 39 | |
38 | -#ifdef _DEBUG | |
39 | -#define new DEBUG_NEW | |
40 | -#undef THIS_FILE | |
41 | -static char THIS_FILE[] = __FILE__; | |
42 | -#endif | |
40 | +LRESULT CALLBACK CPrnAbortDlg::OnDlgProc(HWND hDlgWnd, UINT msg, WPARAM wp, LPARAM lp) | |
41 | +{ | |
42 | + static const DlgTextInfo TextInfos[] = { | |
43 | + { IDC_PRNABORT_PRINTING, "DLG_PRNABORT_PRINTING" }, | |
44 | + { IDCANCEL, "BTN_CANCEL" }, | |
45 | + }; | |
46 | + static const int FontIDs[] = { | |
47 | + IDC_PRNABORT_PRINTING, IDCANCEL | |
48 | + }; | |
43 | 49 | |
44 | -// CPrnAbortDlg dialog | |
45 | -BEGIN_MESSAGE_MAP(CPrnAbortDlg, CDialog) | |
46 | - //{{AFX_MSG_MAP(CPrnAbortDlg) | |
47 | - //}}AFX_MSG_MAP | |
48 | -END_MESSAGE_MAP() | |
50 | + CPrnAbortDlg *self = (CPrnAbortDlg *)GetWindowLongPtr(hDlgWnd, DWLP_USER); | |
49 | 51 | |
50 | -// CPrnAbortDlg message handler | |
51 | -BOOL CPrnAbortDlg::Create(CWnd* p_Parent, PBOOL AbortFlag, PTTSet pts) | |
52 | -{ | |
53 | - BOOL Ok; | |
54 | - HWND HParent; | |
55 | - LOGFONT logfont; | |
56 | - HFONT font; | |
52 | + switch (msg) { | |
53 | + case WM_INITDIALOG: | |
54 | + { | |
55 | + CPrnAbortDlg *self = (CPrnAbortDlg *)lp; | |
56 | + SetWindowLongPtr(hDlgWnd, DWLP_USER, (LONG_PTR)self); | |
57 | + SetDlgTexts(hDlgWnd, TextInfos, _countof(TextInfos), self->m_ts->UILanguageFile); | |
58 | + self->m_hNewFont = | |
59 | + SetDlgFonts(hDlgWnd, FontIDs, _countof(FontIDs), | |
60 | + self->m_ts->UILanguageFile, "DLG_SYSTEM_FONT"); | |
61 | + return TRUE; | |
62 | + } | |
57 | 63 | |
58 | - m_pParent = p_Parent; | |
59 | - if (p_Parent!=NULL) { | |
60 | - HParent = p_Parent->GetSafeHwnd(); | |
64 | + case WM_COMMAND: | |
65 | + { | |
66 | + WORD wID = GET_WM_COMMAND_ID(wp, lp); | |
67 | + const WORD wCMD = GET_WM_COMMAND_CMD(wp, lp); | |
68 | + if (wID == IDOK) { | |
69 | + self->DestroyWindow(); | |
70 | + } | |
71 | + if (wID == IDCANCEL) { | |
72 | + self->OnCancel(); | |
73 | + } | |
74 | + return FALSE; | |
61 | 75 | } |
62 | - else { | |
63 | - HParent = NULL; | |
76 | + case WM_NCDESTROY: | |
77 | + self->PostNcDestroy(); | |
78 | + return TRUE; | |
79 | + | |
80 | + default: | |
81 | + return FALSE; | |
64 | 82 | } |
65 | - Abort = AbortFlag; | |
66 | - Ok = (CDialog::Create(CPrnAbortDlg::IDD, m_pParent)); | |
67 | - if (Ok) { | |
68 | - ::EnableWindow(HParent,FALSE); | |
69 | - ::EnableWindow(GetSafeHwnd(),TRUE); | |
70 | - } | |
83 | + return TRUE; | |
84 | +} | |
71 | 85 | |
72 | - font = (HFONT)SendMessage(WM_GETFONT, 0, 0); | |
73 | - GetObject(font, sizeof(LOGFONT), &logfont); | |
74 | - if (get_lang_font("DLG_SYSTEM_FONT", GetSafeHwnd(), &logfont, &DlgFont, pts->UILanguageFile)) { | |
75 | - SendDlgItemMessage(IDC_PRNABORT_PRINTING, WM_SETFONT, (WPARAM)DlgFont, MAKELPARAM(TRUE,0)); | |
76 | - SendDlgItemMessage(IDCANCEL, WM_SETFONT, (WPARAM)DlgFont, MAKELPARAM(TRUE,0)); | |
86 | +BOOL CPrnAbortDlg::Create(HINSTANCE hInstance, HWND hParent, PBOOL AbortFlag, PTTSet pts) | |
87 | +{ | |
88 | + m_pAbort = AbortFlag; | |
89 | + m_hParentWnd = hParent; | |
90 | + m_ts = pts; | |
91 | + | |
92 | + HRSRC hResource = ::FindResource(hInstance, MAKEINTRESOURCE(IDD_PRNABORTDLG), RT_DIALOG); | |
93 | + HANDLE hDlgTemplate = ::LoadResource(hInstance, hResource); | |
94 | + DLGTEMPLATE *lpTemplate = (DLGTEMPLATE *)::LockResource(hDlgTemplate); | |
95 | + HWND hWnd = ::CreateDialogIndirectParam( | |
96 | + hInstance, lpTemplate, hParent, | |
97 | + (DLGPROC)OnDlgProc, (LPARAM)this); | |
98 | + if (hWnd == NULL) | |
99 | + { | |
100 | + return FALSE; | |
77 | 101 | } |
78 | 102 | |
79 | - return Ok; | |
103 | + m_hWnd = hWnd; | |
104 | + ::EnableWindow(hParent,FALSE); | |
105 | + ::ShowWindow(hWnd, SW_SHOW); | |
106 | + ::EnableWindow(m_hWnd,TRUE); | |
107 | + return TRUE; | |
80 | 108 | } |
81 | 109 | |
82 | 110 | void CPrnAbortDlg::OnCancel() |
83 | 111 | { |
84 | - *Abort = TRUE; | |
112 | + *m_pAbort = TRUE; | |
85 | 113 | DestroyWindow(); |
86 | 114 | } |
87 | 115 | |
88 | -BOOL CPrnAbortDlg::OnCommand(WPARAM wParam, LPARAM lParam) | |
89 | -{ | |
90 | - *Abort = TRUE; | |
91 | - DestroyWindow(); | |
92 | - | |
93 | - return CDialog::OnCommand(wParam, lParam); | |
94 | -} | |
95 | - | |
96 | 116 | void CPrnAbortDlg::PostNcDestroy() |
97 | 117 | { |
118 | + ::DeleteObject(m_hNewFont); | |
98 | 119 | delete this; |
99 | 120 | } |
100 | 121 | |
101 | 122 | BOOL CPrnAbortDlg::DestroyWindow() |
102 | 123 | { |
103 | - HWND HParent; | |
124 | + ::EnableWindow(m_hParentWnd,TRUE); | |
125 | + ::SetFocus(m_hParentWnd); | |
126 | + ::DestroyWindow(m_hWnd); | |
127 | + return TRUE; | |
128 | +} | |
104 | 129 | |
105 | - HParent = m_pParent->GetSafeHwnd(); | |
106 | - ::EnableWindow(HParent,TRUE); | |
107 | - ::SetFocus(HParent); | |
108 | - return CDialog::DestroyWindow(); | |
109 | -} |
@@ -1,6 +1,6 @@ | ||
1 | 1 | /* |
2 | 2 | * Copyright (C) 1994-1998 T. Teranishi |
3 | - * (C) 2007-2017 TeraTerm Project | |
3 | + * (C) 2007-2018 TeraTerm Project | |
4 | 4 | * All rights reserved. |
5 | 5 | * |
6 | 6 | * Redistribution and use in source and binary forms, with or without |
@@ -28,40 +28,25 @@ | ||
28 | 28 | */ |
29 | 29 | |
30 | 30 | /* TERATERM.EXE, print-abort dialog box */ |
31 | +#pragma once | |
31 | 32 | |
33 | +#include "tttypes.h" // for TTSet | |
34 | + | |
32 | 35 | // CPrnAbortDlg dialog |
33 | -class CPrnAbortDlg : public CDialog | |
36 | +class CPrnAbortDlg | |
34 | 37 | { |
35 | -#ifndef NO_I18N | |
36 | -private: | |
37 | - HFONT DlgFont; | |
38 | -#endif | |
39 | - | |
40 | 38 | public: |
41 | -#ifndef NO_I18N | |
42 | - BOOL Create(CWnd* p_Parent, PBOOL AbortFlag, PTTSet pts); | |
43 | -#else | |
44 | - BOOL Create(CWnd* p_Parent, PBOOL AbortFlag); | |
45 | -#endif | |
39 | + HWND m_hWnd; | |
40 | + HWND GetSafeHwnd() const {return m_hWnd;} | |
41 | + BOOL Create(HINSTANCE hInstance, HWND hParent, PBOOL AbortFlag, PTTSet pts); | |
42 | + BOOL DestroyWindow(); | |
43 | + HFONT m_hNewFont; | |
46 | 44 | |
47 | - //{{AFX_DATA(CPrnAbortDlg) | |
48 | - enum { IDD = IDD_PRNABORTDLG }; | |
49 | - //}}AFX_DATA | |
50 | - | |
51 | - //{{AFX_VIRTUAL(CPrnAbortDlg) | |
52 | - public: | |
53 | - virtual BOOL DestroyWindow(); | |
54 | - protected: | |
55 | - virtual void OnCancel( ); | |
56 | - virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam); | |
57 | - virtual void PostNcDestroy(); | |
58 | - //}}AFX_VIRTUAL | |
59 | - | |
60 | - protected: | |
61 | - CWnd* m_pParent; | |
62 | - BOOL *Abort; | |
63 | - | |
64 | - //{{AFX_MSG(CPrnAbortDlg) | |
65 | - //}}AFX_MSG | |
66 | - DECLARE_MESSAGE_MAP() | |
45 | +private: | |
46 | + void OnCancel(); | |
47 | + void PostNcDestroy(); | |
48 | + HWND m_hParentWnd; | |
49 | + BOOL *m_pAbort; | |
50 | + TTTSet *m_ts; | |
51 | + static LRESULT CALLBACK OnDlgProc(HWND hDlgWnd, UINT msg, WPARAM wp, LPARAM lp); | |
67 | 52 | }; |
@@ -129,7 +129,6 @@ | ||
129 | 129 | DOCINFO Doc; |
130 | 130 | char DocName[50]; |
131 | 131 | CWnd* pParent; |
132 | - char uimsg[MAX_UIMSG]; | |
133 | 132 | |
134 | 133 | Printing = FALSE; |
135 | 134 | PrintAbortFlag = FALSE; |
@@ -144,16 +143,9 @@ | ||
144 | 143 | else { |
145 | 144 | pParent = (CWnd*)pTEKWin; |
146 | 145 | } |
147 | - PrnAbortDlg->Create(pParent,&PrintAbortFlag,&ts); | |
146 | + PrnAbortDlg->Create(hInst, pParent->GetSafeHwnd(),&PrintAbortFlag,&ts); | |
148 | 147 | HPrnAbortDlg = PrnAbortDlg->GetSafeHwnd(); |
149 | 148 | |
150 | - GetDlgItemText(HPrnAbortDlg, IDC_PRNABORT_PRINTING, uimsg, sizeof(uimsg)); | |
151 | - get_lang_msg("DLG_PRNABORT_PRINTING", ts.UIMsg, sizeof(ts.UIMsg), uimsg, ts.UILanguageFile); | |
152 | - SetDlgItemText(HPrnAbortDlg, IDC_PRNABORT_PRINTING, ts.UIMsg); | |
153 | - GetDlgItemText(HPrnAbortDlg, IDCANCEL, uimsg, sizeof(uimsg)); | |
154 | - get_lang_msg("BTN_CANCEL", ts.UIMsg, sizeof(ts.UIMsg), uimsg, ts.UILanguageFile); | |
155 | - SetDlgItemText(HPrnAbortDlg, IDCANCEL, ts.UIMsg); | |
156 | - | |
157 | 149 | SetAbortProc(PrintDC,PrnAbortProc); |
158 | 150 | |
159 | 151 | Doc.cbSize = sizeof(DOCINFO); |
@@ -595,7 +587,7 @@ | ||
595 | 587 | else { |
596 | 588 | pParent = (CWnd*)pTEKWin; |
597 | 589 | } |
598 | - PrnAbortDlg->Create(pParent,&PrintAbortFlag,&ts); | |
590 | + PrnAbortDlg->Create(hInst, pParent->GetSafeHwnd(),&PrintAbortFlag,&ts); | |
599 | 591 | HPrnAbortDlg = PrnAbortDlg->GetSafeHwnd(); |
600 | 592 | |
601 | 593 | HPrnFile = _lopen(PrnFName,OF_READ); |