Skip to content
Newer
Older
100644 155 lines (139 sloc) 3.37 KB
e668eb3 @koron import latest 1.3.7
koron authored Aug 22, 2011
1 /* vi:set ts=8 sts=4 sw=4 tw=0: */
2 /*
3 * EdCmdDlg.cpp - Editor command setting dialog
4 *
5 * Last Change: 13:46:56 11-Mar-2001.
6 * Written by: Muraoka Taro <koron@tka.att.ne.jp>
7 *
8 * Copy right (C) 2000 KoRoN
9 */
10 #define WIN32_LEAN_AND_MEAN
11 #include "EdCmdDlg.h"
12 #include "winapiex.h"
13
14 EditorCommandDialog::EditorCommandDialog()
15 {
16 m_hWnd = 0;
17 }
18
19 EditorCommandDialog::~EditorCommandDialog()
20 {
21 }
22
23 int
24 EditorCommandDialog::doModal(HWND hwndParent)
25 {
26 return DialogBoxParam(GetModuleHandle(NULL),
27 MAKEINTRESOURCE(IDD_EDITORCMD), hwndParent, (DLGPROC)dlgProc,
28 (LPARAM)this);
29 }
30
31 LRESULT
32 EditorCommandDialog::onInitDialog(HWND hwndCtrl)
33 {
34 CRegKey regEditCmd;
35
36 if (regEditCmd.Create(HKEY_CURRENT_USER, REGKEY_BASE) == ERROR_SUCCESS)
37 {
38 DWORD dwBufSize;
39 char *pszFmt;
40
41 for (int loop = 0; loop < 2; ++loop)
42 {
43 if (regEditCmd.QueryValue((LPTSTR)0, REGKEY_EDITCMD, &dwBufSize)
44 == ERROR_SUCCESS)
45 {
46 char *pszFmt = new char[dwBufSize];
47 regEditCmd.QueryValue(pszFmt, REGKEY_EDITCMD, &dwBufSize);
48 SetDlgItemText(m_hWnd, IDC_EXECMD_FORMAT, pszFmt);
49 delete[] pszFmt;
50 break;
51 }
52 else if (!loop)
53 {
54 pszFmt = DEFAUTL_REG_EDITCMD;
55 regEditCmd.SetValue(pszFmt, REGKEY_EDITCMD);
56 }
57 }
58 regEditCmd.Close();
59 }
60 else
61 _RPT0(_CRT_ASSERT, "EditorCommandDialog::Cannot create registy\r\n");
62
63 char buf[1024];
64 LoadString(GetModuleHandle(NULL), IDS_SPECIAL_CHAR, buf, 1024);
65 SetDlgItemText(m_hWnd, IDC_SPECIAL_CHAR, buf);
66
67 SetFocus(m_hWnd);
68
69 return TRUE;
70 }
71
72 LRESULT
73 EditorCommandDialog::onCommand(WORD wNotifyCode, WORD wID, HWND hwndCtrl)
74 {
75 switch (wID)
76 {
77 case IDC_EXE_BROWSE:
78 {
79 char filename[MAX_PATH];
80 OPENFILENAME ofn;
81
82 Init_OPENFILENAME(&ofn);
83 filename[0] = '\0';
84 ofn.hwndOwner = m_hWnd;
85 ofn.lpstrFilter = "Program to edit {*.exe}\0*.exe\0\0";
86 ofn.lpstrFile = filename;
87 ofn.lpstrDefExt = "exe";
88 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
89 if (GetOpenFileName(&ofn))
90 SendMessage(GetDlgItem(m_hWnd, IDC_EXECMD_FORMAT),
91 WM_SETTEXT, 0, (LPARAM)filename);
92 }
93 break;
94 case IDOK:
95 {
96 int len = SendMessage(GetDlgItem(m_hWnd, IDC_EXECMD_FORMAT),
97 WM_GETTEXTLENGTH, 0, 0) + 1;
98 char *pszFmt = new char[len];
99
100 if (pszFmt)
101 {
102 if (!GetDlgItemText(m_hWnd, IDC_EXECMD_FORMAT,
103 pszFmt, len))
104 _RPT1(_CRT_WARN, "Cannot get format\r\n", len);
105 else
106 {
107 _RPT1(_CRT_WARN, "format=%s\r\n", pszFmt);
108 CRegKey regEditCmd;
109 if (regEditCmd.Create(HKEY_CURRENT_USER, REGKEY_BASE)
110 == ERROR_SUCCESS)
111 {
112 regEditCmd.SetValue(pszFmt, REGKEY_EDITCMD);
113 regEditCmd.Close();
114 }
115 else
116 _RPT0(_CRT_ASSERT, "Cannot create registy key\r\n");
117 }
118 delete[] pszFmt;
119 }
120 }
121 case IDCANCEL:
122 EndDialog(m_hWnd, 0);
123 return TRUE;
124 }
125 return FALSE;
126 }
127
128 LRESULT CALLBACK
129 EditorCommandDialog::dlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,
130 LPARAM lParam)
131 {
132 EditorCommandDialog* p_ecd = (EditorCommandDialog*)GetWindowLong(hDlg,
133 GWL_USERDATA);
134
135 if (!p_ecd)
136 {
137 if (uMsg == WM_INITDIALOG)
138 {
139 SetWindowLong(hDlg, GWL_USERDATA, lParam);
140 p_ecd = (EditorCommandDialog*)lParam;
141 p_ecd->m_hWnd = hDlg;
142 return p_ecd->onInitDialog((HWND)wParam);
143 }
144 return FALSE;
145 }
146
147 switch (uMsg)
148 {
149 case WM_COMMAND:
150 return p_ecd->onCommand(HIWORD(wParam), LOWORD(wParam),
151 (HWND)lParam);
152 }
153 return FALSE;
154 }
Something went wrong with that request. Please try again.