[DDK]: Merge 46183 from header-branch.
[reactos.git] / rosapps / templates / old_wordpad / editwnd.c
1 #include "precomp.h"
2
3 static const TCHAR szEditWndClass[] = TEXT("WordPadEditWndClass");
4
5
6 static BOOL
7 InitEditWnd(PEDIT_WND_INFO Info)
8 {
9 HANDLE hDLL;
10 HFONT hfDefault;
11
12 hDLL = LoadLibrary(_T("RICHED20.DLL"));
13 if (hDLL == NULL)
14 {
15 GetError(0);
16 return FALSE;
17 }
18
19 Info->hEdit = CreateWindowEx(0, //WS_EX_CLIENTEDGE,
20 RICHEDIT_CLASS,
21 NULL,
22 WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL |
23 ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL,
24 0,
25 0,
26 100,
27 100,
28 Info->hSelf,
29 NULL,
30 hInstance,
31 NULL);
32 if(Info->hEdit == NULL)
33 {
34 GetError(0);
35
36 return FALSE;
37 }
38
39 hfDefault = (HFONT) GetStockObject(DEFAULT_GUI_FONT);
40 SendMessage(Info->hEdit,
41 WM_SETFONT,
42 (WPARAM)hfDefault,
43 MAKELPARAM(FALSE, 0));
44
45 return TRUE;
46 }
47
48
49 static LRESULT CALLBACK
50 EditWndProc(HWND hwnd,
51 UINT uMsg,
52 WPARAM wParam,
53 LPARAM lParam)
54 {
55 PEDIT_WND_INFO Info;
56 LRESULT Ret = 0;
57
58 /* Get the window context */
59 Info = (PEDIT_WND_INFO)GetWindowLongPtr(hwnd,
60 GWLP_USERDATA);
61 if (Info == NULL && uMsg != WM_CREATE)
62 {
63 goto HandleDefaultMessage;
64 }
65
66 switch (uMsg)
67 {
68 case WM_CREATE:
69 {
70 Info = (PEDIT_WND_INFO)(((LPMDICREATESTRUCT)((LPCREATESTRUCT)lParam)->lpCreateParams)->lParam);
71 Info->hSelf = hwnd;
72
73 SetWindowLongPtr(hwnd,
74 GWLP_USERDATA,
75 (LONG_PTR)Info);
76
77 if (!InitEditWnd(Info))
78 {
79 Ret = (LRESULT)-1;
80 break;
81 }
82 break;
83 }
84
85 case WM_SIZE:
86 {
87 RECT rcClient;
88
89 if (GetClientRect(Info->hSelf,
90 &rcClient))
91 {
92 SetWindowPos(Info->hEdit,
93 NULL,
94 0,
95 0,
96 rcClient.right,
97 rcClient.bottom,
98 SWP_NOZORDER);
99 }
100 }
101
102 default:
103 HandleDefaultMessage:
104 Ret = DefMDIChildProc(hwnd,
105 uMsg,
106 wParam,
107 lParam);
108 break;
109 }
110
111 return Ret;
112
113 }
114
115
116 VOID
117 SetEditorEnvironment(PEDIT_WND_INFO Info,
118 BOOL Setup)
119 {
120 if (Setup)
121 {
122 /* FIXME - setup editor environment (e.g. show toolbars, enable menus etc) */
123 }
124 else
125 {
126 /* FIXME - cleanup editor environment (e.g. hide toolbars, disable menus etc) */
127 }
128 }
129
130
131 BOOL
132 CreateEditWindow(struct _MAIN_WND_INFO *MainWnd,
133 POPEN_EDIT_INFO OpenInfo)
134 {
135 PEDIT_WND_INFO Info;
136 HWND hWndEditor;
137
138 Info = (EDIT_WND_INFO*) HeapAlloc(ProcessHeap,
139 0,
140 sizeof(EDIT_WND_INFO));
141 if (Info != NULL)
142 {
143 ZeroMemory(Info,
144 sizeof(EDIT_WND_INFO));
145 Info->MainWnd = MainWnd;
146 Info->MdiEditorType = metImageEditor;
147 Info->OpenInfo = OpenInfo;
148
149 hWndEditor = CreateMDIWindow(szEditWndClass,
150 OpenInfo->lpDocumentName,
151 WS_MAXIMIZE,
152 CW_USEDEFAULT,
153 CW_USEDEFAULT,
154 CW_USEDEFAULT,
155 CW_USEDEFAULT,
156 MainWnd->hMdiClient,
157 hInstance,
158 (LPARAM)Info);
159
160 if (hWndEditor != NULL)
161 return TRUE;
162
163
164 HeapFree(ProcessHeap,
165 0,
166 Info);
167 }
168
169 return FALSE;
170 }
171
172 BOOL
173 InitEditWindowImpl(VOID)
174 {
175 WNDCLASSEX wc = {0};
176
177 wc.cbSize = sizeof(WNDCLASSEX);
178 wc.lpfnWndProc = EditWndProc;
179 wc.hInstance = hInstance;
180 wc.hIcon = LoadIcon(hInstance,
181 MAKEINTRESOURCE(IDI_ICON));
182 wc.hCursor = LoadCursor(NULL,
183 IDC_ARROW);
184 wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
185 wc.lpszMenuName = NULL;
186 wc.lpszClassName = szEditWndClass;
187 wc.hIconSm = (HICON)LoadImage(hInstance,
188 MAKEINTRESOURCE(IDI_ICON),
189 IMAGE_ICON,
190 16,
191 16,
192 LR_SHARED);
193
194 return RegisterClassEx(&wc) != (ATOM)0;
195 }
196
197 VOID
198 UninitEditWindowImpl(VOID)
199 {
200 UnregisterClass(szEditWndClass,
201 hInstance);
202 }