-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmdi_handler.cc
More file actions
147 lines (127 loc) · 4.44 KB
/
mdi_handler.cc
File metadata and controls
147 lines (127 loc) · 4.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include "mdi_handler.h"
#include "libpicalc/libpicalc_dll.h"
#include "dialogs.h"
#include "globals.h"
#include "resource.h"
HWND g_hMDIClient = NULL;
BOOL LoadTextFileToEdit(HWND hEdit, LPCWSTR pszFileName) {
HANDLE hFile;
BOOLEAN bSuccess = FALSE;
hFile = CreateFile(pszFileName, GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, 0, NULL);
if (hFile != INVALID_HANDLE_VALUE) {
DWORD dwFileSize;
dwFileSize = GetFileSize(hFile, NULL);
if (dwFileSize != 0xFFFFFFFF) {
LPWSTR pszFileText;
pszFileText = (LPWSTR)GlobalAlloc(GPTR, dwFileSize + 1);
if (pszFileText != NULL) {
DWORD dwRead;
if (ReadFile(hFile, pszFileText, dwFileSize, &dwRead, NULL)) {
pszFileText[dwFileSize] = 0; // Add null terminator
if (SetWindowText(hEdit, pszFileText)) {
bSuccess = TRUE; // It worked!
}
}
GlobalFree(pszFileText);
}
}
CloseHandle(hFile);
}
return bSuccess;
}
void DoFileOpen(HWND hwnd) {
OPENFILENAME ofn;
WCHAR szFileName[MAX_PATH] = L"";
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFilter = L"Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
ofn.lpstrFile = szFileName;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
ofn.lpstrDefExt = L"txt";
if (GetOpenFileName(&ofn)) {
HWND hEdit = GetDlgItem(hwnd, IDC_CHILD_EDIT);
if (LoadTextFileToEdit(hEdit, szFileName)) {
SendDlgItemMessage(g_hMainWindow, IDC_MAIN_STATUS, SB_SETTEXT, 0,
(LPARAM)L"Opened...");
SendDlgItemMessage(g_hMainWindow, IDC_MAIN_STATUS, SB_SETTEXT, 1,
(LPARAM)szFileName);
SetWindowText(hwnd, szFileName);
}
}
}
HWND CreateNewMDIChild(HWND hMDIClient) {
MDICREATESTRUCT mcs;
HWND hChild = NULL;
mcs.szTitle = szEmptyFileName;
mcs.szClass = g_szChildClassName;
mcs.hOwner = GetModuleHandle(NULL);
mcs.x = mcs.cx = CW_USEDEFAULT;
mcs.y = mcs.cy = CW_USEDEFAULT;
mcs.style = MDIS_ALLCHILDSTYLES;
hChild = (HWND)SendMessage(hMDIClient, WM_MDICREATE, 0, (LONG_PTR)&mcs);
if (!hChild || hChild == NULL) {
MessageBox(hMDIClient, L"MDI Child creation failed.", L"Uh Oh...",
MB_ICONEXCLAMATION | MB_OK);
}
return hChild;
}
LRESULT CALLBACK MDIChildWndProc(HWND hWnd,
UINT msg,
WPARAM wParam,
LPARAM lParam) {
switch (msg) {
case WM_CREATE: {
HFONT hfDefault;
HWND hEdit = NULL;
HWND hDis = NULL;
// Create Edit Control
hEdit = CreateWindowExW(WS_EX_CLIENTEDGE, L"EDIT", L"",
WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL |
ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL,
0, 0, 100, 100, hWnd, (HMENU)IDC_CHILD_EDIT,
GetModuleHandle(NULL), NULL);
if (!hEdit || hEdit == NULL) {
MessageBoxW(hWnd, L"Could not create edit box.", L"Error",
MB_OK | MB_ICONERROR);
}
// Create regular control
hDis = CreateWindowExW(WS_EX_MDICHILD, L"MDICLIENT", L"hawk",
WS_CHILD | WS_VSCROLL,
0, 0, 100, 100, hWnd, NULL,
GetModuleHandle(NULL), NULL);
if (!hDis || hDis == NULL) {
MessageBoxW(hWnd, L"Could not create Pi box.", L"Error",
MB_OK | MB_ICONERROR);
}
hfDefault = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
SendMessage(hEdit, WM_SETFONT, (WPARAM)hfDefault, MAKELPARAM(FALSE, 0));
//SendMessage(hDis, WM_SETFONT, (WPARAM)hfDefault, MAKELPARAM(FALSE, 0));
} break;
case WM_MDIACTIVATE: {
} break;
case WM_COMMAND:
break;
case WM_SIZE: {
HWND hEdit;
RECT rcClient;
// Calculate remaining height and size edit
GetClientRect(hWnd, &rcClient);
hEdit = GetDlgItem(hWnd, IDC_CHILD_EDIT);
SetWindowPos(hEdit, HWND_TOP, 0, 0, rcClient.right, rcClient.bottom,
SWP_NOZORDER);
} break;
case WM_PAINT: {
// Actually paint the contents of our window finally
//PaintMDI(hWnd, g_hMDIClient);
} break;
case WM_MDIDESTROY:
DestroyWindow(hWnd);
break;
default:
return DefMDIChildProc(hWnd, msg, wParam, lParam);
}
return 0;
}