3 static const TCHAR szMainWndClass
[] = TEXT("WordPadMainWndClass");
5 #define ID_MDI_FIRSTCHILD 50000
6 #define ID_MDI_WINDOWMENU 5
9 static const MENU_HINT MainMenuHintTable
[] = {
11 {ID_BLANK
, IDS_HINT_BLANK
},
12 {ID_NEW
, IDS_HINT_NEW
},
13 {ID_OPEN
, IDS_HINT_OPEN
},
14 {ID_CLOSE
, IDS_HINT_CLOSE
},
15 {ID_CLOSEALL
, IDS_HINT_CLOSEALL
},
16 {ID_SAVE
, IDS_HINT_SAVE
},
17 {ID_SAVEAS
, IDS_HINT_SAVEAS
},
18 {ID_PRINT
, IDS_HINT_PRINT
},
19 {ID_PRINTPRE
, IDS_HINT_PRINTPRE
},
20 {ID_PAGESETUP
, IDS_HINT_PAGESETUP
},
21 {ID_EXIT
, IDS_HINT_EXIT
},
24 {ID_WINDOW_NEXT
, IDS_HINT_NEXT
},
25 {ID_WINDOW_CASCADE
, IDS_HINT_CASCADE
},
26 {ID_WINDOW_TILE_HORZ
, IDS_HINT_TILE_HORZ
},
27 {ID_WINDOW_TILE_VERT
, IDS_HINT_TILE_VERT
},
28 {ID_WINDOW_ARRANGE
, IDS_HINT_ARRANGE
}
31 static const MENU_HINT SystemMenuHintTable
[] = {
32 {SC_RESTORE
, IDS_HINT_SYS_RESTORE
},
33 {SC_MOVE
, IDS_HINT_SYS_MOVE
},
34 {SC_SIZE
, IDS_HINT_SYS_SIZE
},
35 {SC_MINIMIZE
, IDS_HINT_SYS_MINIMIZE
},
36 {SC_MAXIMIZE
, IDS_HINT_SYS_MAXIMIZE
},
37 {SC_CLOSE
, IDS_HINT_CLOSE
},
38 {SC_NEXTWINDOW
, IDS_HINT_NEXT
},
43 CreateToolbars(PMAIN_WND_INFO Info
)
49 MainWndResize(PVOID Context
,
56 PMAIN_WND_INFO Info
= (PMAIN_WND_INFO
)Context
;
58 /* Calculate the MDI client rectangle */
62 if (Info
->hStatus
!= NULL
)
64 GetWindowRect(Info
->hStatus
,
66 rcClient
.bottom
-= (rcStatus
.bottom
- rcStatus
.top
);
70 dwp
= BeginDeferWindowPos(2);
73 /* Update the MDI client */
74 if (Info
->hMdiClient
!= NULL
)
76 dwp
= DeferWindowPos(dwp
,
81 rcClient
.right
- rcClient
.left
,
82 rcClient
.bottom
- rcClient
.top
,
88 /* Update the status bar */
89 if (Info
->hStatus
!= NULL
)
91 dwp
= DeferWindowPos(dwp
,
95 cy
- (rcStatus
.bottom
- rcStatus
.top
),
97 rcStatus
.bottom
- rcStatus
.top
,
103 EndDeferWindowPos(dwp
);
108 InitMainWnd(PMAIN_WND_INFO Info
)
110 CLIENTCREATESTRUCT ccs
;
111 INT statwidths
[] = {110, -1};
113 /* FIXME - create controls and initialize the application */
115 /* create the status bar */
116 Info
->hStatus
= CreateWindowEx(0,
119 WS_VISIBLE
| WS_CHILD
| WS_CLIPSIBLINGS
| CCS_NOPARENTALIGN
| SBARS_SIZEGRIP
,
125 (HMENU
)IDC_STATUSBAR
,
129 if (Info
->hStatus
!= NULL
)
130 SendMessage(Info
->hStatus
,
132 sizeof(statwidths
)/sizeof(int),
135 /* create the MDI client window */
136 ccs
.hWindowMenu
= GetSubMenu(GetMenu(Info
->hSelf
),
138 ccs
.idFirstChild
= ID_MDI_FIRSTCHILD
;
139 Info
->hMdiClient
= CreateWindowEx(WS_EX_ACCEPTFILES
| WS_EX_CLIENTEDGE
,
142 WS_VISIBLE
| WS_CHILD
| WS_CLIPCHILDREN
| WS_CLIPSIBLINGS
| WS_VSCROLL
| WS_HSCROLL
,
152 CreateToolbars(Info
);
154 /* initialize file open/save structure */
155 FileInitialize(Info
->hSelf
);
159 MainWndCommand(PMAIN_WND_INFO Info
,
163 static TCHAR szFileName
[MAX_PATH
];
164 static TCHAR szDocumentName
[MAX_PATH
];
166 UNREFERENCED_PARAMETER(hControl
);
172 OPEN_EDIT_INFO OpenInfo
;
175 OpenInfo
.CreateNew
= TRUE
;
177 LoadAndFormatString(hInstance
,
179 &OpenInfo
.lpDocumentName
,
180 ++Info
->ImagesCreated
);
182 Ret
= DialogBox(hInstance
,
183 MAKEINTRESOURCE(IDD_NEWDOCSEL
),
188 OpenInfo
.DocType
= Ret
;
190 CreateEditWindow(Info
,
198 MessageBox(NULL
, _T("Bingo"), NULL
, 0);
203 OPEN_EDIT_INFO OpenInfo
;
205 if (DoOpenFile(Info
->hSelf
,
206 szFileName
, /* full file path */
207 szDocumentName
)) /* file name */
209 OpenInfo
.CreateNew
= FALSE
;
211 OpenInfo
.lpDocumentPath
= szFileName
;
212 OpenInfo
.lpDocumentName
= szDocumentName
;
214 CreateEditWindow(Info
,
222 SendMessage(Info
->hSelf
,
229 case ID_WINDOW_TILE_HORZ
:
230 SendMessage(Info
->hMdiClient
,
236 case ID_WINDOW_TILE_VERT
:
237 SendMessage(Info
->hMdiClient
,
243 case ID_WINDOW_CASCADE
:
244 SendMessage(Info
->hMdiClient
,
250 case ID_WINDOW_ARRANGE
:
251 SendMessage(Info
->hMdiClient
,
258 SendMessage(Info
->hMdiClient
,
267 MAKEINTRESOURCE(IDD_ABOUTBOX
),
275 DestroyMainWnd(PMAIN_WND_INFO Info
)
277 /* FIXME - cleanup allocated resources */
282 UpdateMainStatusBar(PMAIN_WND_INFO Info
)
284 if (Info
->hStatus
!= NULL
)
286 SendMessage(Info
->hStatus
,
288 (WPARAM
)Info
->InMenuLoop
,
294 MainWndMenuHint(PMAIN_WND_INFO Info
,
296 const MENU_HINT
*HintArray
,
301 const MENU_HINT
*LastHint
;
302 UINT HintId
= DefHintId
;
304 LastHint
= HintArray
+ HintsCount
;
305 while (HintArray
!= LastHint
)
307 if (HintArray
->CmdId
== CmdId
)
309 HintId
= HintArray
->HintId
;
316 StatusBarLoadString(Info
->hStatus
,
324 static LRESULT CALLBACK
325 MainWndProc(HWND hwnd
,
332 static RECT wndOldPos
;
334 /* Get the window context */
335 Info
= (PMAIN_WND_INFO
)GetWindowLongPtr(hwnd
,
337 if (Info
== NULL
&& uMsg
!= WM_CREATE
)
339 goto HandleDefaultMessage
;
346 Info
= (PMAIN_WND_INFO
)(((LPCREATESTRUCT
)lParam
)->lpCreateParams
);
348 /* Initialize the main window context */
351 SetWindowLongPtr(hwnd
,
357 /* Show the window */
360 /* get the windows position */
372 /* NOTE - do *not* forward this message to DefFrameProc! Otherwise the MDI client
373 will attempt to resize itself */
387 /* FIXME - handle other notifications */
396 goto HandleDefaultMessage
;
401 if (Info
->hStatus
!= NULL
)
403 if (!MainWndMenuHint(Info
,
406 sizeof(MainMenuHintTable
) / sizeof(MainMenuHintTable
[0]),
409 MainWndMenuHint(Info
,
412 sizeof(SystemMenuHintTable
) / sizeof(SystemMenuHintTable
[0]),
419 case WM_ENTERMENULOOP
:
421 Info
->InMenuLoop
= TRUE
;
422 UpdateMainStatusBar(Info
);
426 case WM_EXITMENULOOP
:
428 Info
->InMenuLoop
= FALSE
;
429 UpdateMainStatusBar(Info
);
442 goto HandleDefaultMessage
;
448 goto HandleDefaultMessage
;
454 goto HandleDefaultMessage
;
459 DestroyMainWnd(Info
);
461 /* FIXME: set the windows position in registry*/
464 HeapFree(ProcessHeap
,
467 SetWindowLongPtr(hwnd
,
471 /* Break the message queue loop */
478 HandleDefaultMessage
:
479 if (Info
!= NULL
&& Info
->hMdiClient
!= NULL
)
481 Ret
= DefFrameProc(hwnd
,
489 Ret
= DefWindowProc(hwnd
,
502 MainWndGetCurrentEditor(PMAIN_WND_INFO MainWnd
,
505 MDI_EDITOR_TYPE EditorType
;
507 if (MainWnd
->ActiveEditor
!= NULL
)
509 EditorType
= *((PMDI_EDITOR_TYPE
)MainWnd
->ActiveEditor
);
510 *Info
= MainWnd
->ActiveEditor
;
514 EditorType
= metUnknown
;
522 MainWndSwitchEditorContext(PMAIN_WND_INFO Info
,
526 PMDI_EDITOR_TYPE EditorType
;
528 /* FIXME - optimize light weight switching
529 when switching from and to an editor of same type */
531 if (hDeactivate
!= NULL
)
533 EditorType
= (PMDI_EDITOR_TYPE
)GetWindowLongPtr(hDeactivate
,
535 if (EditorType
!= NULL
)
540 SetEditorEnvironment((PEDIT_WND_INFO
)EditorType
,
548 Info
->ActiveEditor
= NULL
;
552 if (hActivate
!= NULL
)
554 EditorType
= (PMDI_EDITOR_TYPE
)GetWindowLongPtr(hActivate
,
556 if (EditorType
!= NULL
)
558 Info
->ActiveEditor
= EditorType
;
563 SetEditorEnvironment((PEDIT_WND_INFO
)EditorType
,
575 CreateMainWindow(LPCTSTR lpCaption
,
579 HWND hMainWnd
= NULL
;
581 Info
= (MAIN_WND_INFO
*) HeapAlloc(ProcessHeap
,
583 sizeof(MAIN_WND_INFO
));
587 sizeof(MAIN_WND_INFO
));
588 Info
->nCmdShow
= nCmdShow
;
590 /* FIXME - load the window position from the registry */
592 hMainWnd
= CreateWindowEx(WS_EX_WINDOWEDGE
,
595 WS_OVERLAPPEDWINDOW
| WS_CLIPCHILDREN
| WS_CLIPSIBLINGS
,
604 if (hMainWnd
== NULL
)
606 HeapFree(ProcessHeap
,
616 MainWndTranslateMDISysAccel(HWND hwnd
,
621 /* Get the window context */
622 Info
= (PMAIN_WND_INFO
)GetWindowLongPtr(hwnd
,
624 if (Info
!= NULL
&& Info
->hMdiClient
!= NULL
)
626 return TranslateMDISysAccel(Info
->hMdiClient
,
634 InitMainWindowImpl(VOID
)
638 wc
.cbSize
= sizeof(WNDCLASSEX
);
639 wc
.lpfnWndProc
= MainWndProc
;
640 wc
.hInstance
= hInstance
;
641 wc
.hIcon
= LoadIcon(hInstance
,
642 MAKEINTRESOURCE(IDI_ICON
));
643 wc
.hCursor
= LoadCursor(NULL
,
645 wc
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
646 wc
.lpszMenuName
= MAKEINTRESOURCE(IDR_MAINMENU
);
647 wc
.lpszClassName
= szMainWndClass
;
648 wc
.hIconSm
= (HICON
)LoadImage(hInstance
,
649 MAKEINTRESOURCE(IDI_ICON
),
655 return RegisterClassEx(&wc
) != (ATOM
)0;
659 UninitMainWindowImpl(VOID
)
661 UnregisterClass(szMainWndClass
,