ReactOS  0.4.15-dev-5122-g72bdbdd
mdi.c File Reference
#include <windows.h>
#include <commctrl.h>
#include <string.h>
#include "resource.h"
Include dependency graph for mdi.c:

Go to the source code of this file.

Macros

#define IDC_MAIN_MDI   101
 
#define IDC_MAIN_TOOL   102
 
#define IDC_MAIN_STATUS   103
 
#define IDC_CHILD_EDIT   101
 
#define ID_MDI_FIRSTCHILD   50000
 

Functions

BOOL LoadTextFileToEdit (HWND hEdit, LPCTSTR pszFileName)
 
BOOL SaveTextFileFromEdit (HWND hEdit, LPCTSTR pszFileName)
 
void DoFileOpen (HWND hwnd)
 
void DoFileSave (HWND hwnd)
 
HWND CreateNewMDIChild (HWND hMDIClient)
 
LRESULT CALLBACK WndProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 
LRESULT CALLBACK MDIChildWndProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 
BOOL SetUpMDIChildWindowClass (HINSTANCE hInstance)
 
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
 

Variables

const char g_szClassName [] = "myWindowClass"
 
const char g_szChildClassName [] = "myMDIChildWindowClass"
 
HWND g_hMDIClient = NULL
 
HWND g_hMainWindow = NULL
 

Macro Definition Documentation

◆ ID_MDI_FIRSTCHILD

#define ID_MDI_FIRSTCHILD   50000

Definition at line 19 of file mdi.c.

◆ IDC_CHILD_EDIT

#define IDC_CHILD_EDIT   101

Definition at line 17 of file mdi.c.

◆ IDC_MAIN_MDI

#define IDC_MAIN_MDI   101

Definition at line 13 of file mdi.c.

◆ IDC_MAIN_STATUS

#define IDC_MAIN_STATUS   103

Definition at line 15 of file mdi.c.

◆ IDC_MAIN_TOOL

#define IDC_MAIN_TOOL   102

Definition at line 14 of file mdi.c.

Function Documentation

◆ CreateNewMDIChild()

HWND CreateNewMDIChild ( HWND  hMDIClient)

Definition at line 151 of file mdi.c.

152 {
154  HWND hChild;
155 
156  mcs.szTitle = "[Untitled]";
157  mcs.szClass = g_szChildClassName;
158  mcs.hOwner = GetModuleHandle(NULL);
159  mcs.x = mcs.cx = CW_USEDEFAULT;
160  mcs.y = mcs.cy = CW_USEDEFAULT;
161  mcs.style = MDIS_ALLCHILDSTYLES;
162 
164  if(!hChild)
165  {
166  MessageBox(hMDIClient, "MDI Child creation failed.", "Oh Oh...",
168  }
169  return hChild;
170 }
static HTREEITEM hChild
Definition: treeview.c:381
HANDLE HWND
Definition: compat.h:19
#define MB_ICONEXCLAMATION
Definition: winuser.h:779
const char g_szChildClassName[]
Definition: mdi.c:11
#define CW_USEDEFAULT
Definition: winuser.h:225
LONG_PTR LPARAM
Definition: windef.h:208
#define MDIS_ALLCHILDSTYLES
Definition: winuser.h:253
#define MessageBox
Definition: winuser.h:5812
#define GetModuleHandle
Definition: winbase.h:3688
#define NULL
Definition: types.h:112
#define MB_OK
Definition: winuser.h:784
#define WM_MDICREATE
Definition: winuser.h:1802
#define SendMessage
Definition: winuser.h:5833
static struct myctx * mcs
Definition: adnstest.c:53
HWND hMDIClient
Definition: main.c:49

Referenced by WndProc().

◆ DoFileOpen()

void DoFileOpen ( HWND  hwnd)

Definition at line 95 of file mdi.c.

96 {
98  char szFileName[MAX_PATH] = "";
99 
100  ZeroMemory(&ofn, sizeof(ofn));
101 
102  ofn.lStructSize = sizeof(ofn);
103  ofn.hwndOwner = hwnd;
104  ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
105  ofn.lpstrFile = szFileName;
108  ofn.lpstrDefExt = "txt";
109 
110  if(GetOpenFileName(&ofn))
111  {
113  if(LoadTextFileToEdit(hEdit, szFileName))
114  {
117 
118  SetWindowText(hwnd, szFileName);
119  }
120  }
121 }
#define IDC_MAIN_STATUS
Definition: mdi.c:15
#define OFN_FILEMUSTEXIST
Definition: commdlg.h:106
#define OFN_EXPLORER
Definition: commdlg.h:104
BOOL LoadTextFileToEdit(HWND hEdit, LPCTSTR pszFileName)
Definition: mdi.c:24
HWND g_hMainWindow
Definition: mdi.c:22
#define IDC_CHILD_EDIT
Definition: mdi.c:17
HWND hwndOwner
Definition: commdlg.h:330
OPENFILENAME ofn
Definition: main.cpp:37
#define ZeroMemory
Definition: winbase.h:1667
LPCSTR lpstrDefExt
Definition: commdlg.h:345
#define SendDlgItemMessage
Definition: winuser.h:5832
#define GetOpenFileName
Definition: commdlg.h:665
DWORD nMaxFile
Definition: commdlg.h:337
LONG_PTR LPARAM
Definition: windef.h:208
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define MAX_PATH
Definition: compat.h:34
DWORD lStructSize
Definition: commdlg.h:329
#define SB_SETTEXT
Definition: commctrl.h:1949
#define OFN_HIDEREADONLY
Definition: commdlg.h:107
static HWND hEdit
Definition: autocomplete.c:34
LPSTR lpstrFile
Definition: commdlg.h:336
#define SetWindowText
Definition: winuser.h:5847
LPCSTR lpstrFilter
Definition: commdlg.h:332
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4022
DWORD Flags
Definition: commdlg.h:342

Referenced by MDIChildWndProc(), and WndProc().

◆ DoFileSave()

void DoFileSave ( HWND  hwnd)

Definition at line 123 of file mdi.c.

124 {
126  char szFileName[MAX_PATH] = "";
127 
128  ZeroMemory(&ofn, sizeof(ofn));
129 
130  ofn.lStructSize = sizeof(ofn);
131  ofn.hwndOwner = hwnd;
132  ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
133  ofn.lpstrFile = szFileName;
135  ofn.lpstrDefExt = "txt";
137 
138  if(GetSaveFileName(&ofn))
139  {
141  if(SaveTextFileFromEdit(hEdit, szFileName))
142  {
145 
146  SetWindowText(hwnd, szFileName);
147  }
148  }
149 }
#define IDC_MAIN_STATUS
Definition: mdi.c:15
#define OFN_EXPLORER
Definition: commdlg.h:104
HWND g_hMainWindow
Definition: mdi.c:22
#define IDC_CHILD_EDIT
Definition: mdi.c:17
HWND hwndOwner
Definition: commdlg.h:330
OPENFILENAME ofn
Definition: main.cpp:37
#define ZeroMemory
Definition: winbase.h:1667
LPCSTR lpstrDefExt
Definition: commdlg.h:345
#define SendDlgItemMessage
Definition: winuser.h:5832
DWORD nMaxFile
Definition: commdlg.h:337
#define GetSaveFileName
Definition: commdlg.h:666
LONG_PTR LPARAM
Definition: windef.h:208
#define OFN_PATHMUSTEXIST
Definition: commdlg.h:117
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define MAX_PATH
Definition: compat.h:34
DWORD lStructSize
Definition: commdlg.h:329
BOOL SaveTextFileFromEdit(HWND hEdit, LPCTSTR pszFileName)
Definition: mdi.c:59
#define SB_SETTEXT
Definition: commctrl.h:1949
#define OFN_HIDEREADONLY
Definition: commdlg.h:107
static HWND hEdit
Definition: autocomplete.c:34
LPSTR lpstrFile
Definition: commdlg.h:336
#define OFN_OVERWRITEPROMPT
Definition: commdlg.h:116
#define SetWindowText
Definition: winuser.h:5847
LPCSTR lpstrFilter
Definition: commdlg.h:332
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4022
DWORD Flags
Definition: commdlg.h:342

Referenced by MDIChildWndProc().

◆ LoadTextFileToEdit()

BOOL LoadTextFileToEdit ( HWND  hEdit,
LPCTSTR  pszFileName 
)

Definition at line 24 of file mdi.c.

25 {
26  HANDLE hFile;
28 
30  OPEN_EXISTING, 0, NULL);
32  {
34 
36  if(dwFileSize != 0xFFFFFFFF)
37  {
38  LPSTR pszFileText;
39 
40  pszFileText = GlobalAlloc(GPTR, dwFileSize + 1);
41  if(pszFileText != NULL)
42  {
43  DWORD dwRead;
44 
45  if(ReadFile(hFile, pszFileText, dwFileSize, &dwRead, NULL))
46  {
47  pszFileText[dwFileSize] = 0; // Add null terminator
48  if(SetWindowText(hEdit, pszFileText))
49  bSuccess = TRUE; // It worked!
50  }
51  GlobalFree(pszFileText);
52  }
53  }
55  }
56  return bSuccess;
57 }
HGLOBAL NTAPI GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:368
#define CloseHandle
Definition: compat.h:598
#define GPTR
Definition: winbase.h:293
#define TRUE
Definition: types.h:120
DWORD dwFileSize
Definition: more.c:40
#define INVALID_HANDLE_VALUE
Definition: compat.h:590
char * LPSTR
Definition: xmlstorage.h:182
static BOOLEAN bSuccess
Definition: drive.cpp:430
#define FILE_SHARE_READ
Definition: compat.h:136
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
WORD WORD PSZ PSZ pszFileName
Definition: vdmdbg.h:41
#define OPEN_EXISTING
Definition: compat.h:634
unsigned long DWORD
Definition: ntddk_ex.h:95
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:331
static HWND hEdit
Definition: autocomplete.c:34
#define GENERIC_READ
Definition: compat.h:135
_In_ HANDLE hFile
Definition: mswsock.h:90
IN OUT PVCB OUT PDIRENT OUT PBCB IN BOOLEAN CreateFile
Definition: fatprocs.h:913
#define ReadFile(a, b, c, d, e)
Definition: compat.h:601
#define SetWindowText
Definition: winuser.h:5847
#define NULL
Definition: types.h:112

Referenced by DoFileOpen().

◆ MDIChildWndProc()

LRESULT CALLBACK MDIChildWndProc ( HWND  hwnd,
UINT  msg,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 346 of file mdi.c.

347 {
348  switch(msg)
349  {
350  case WM_CREATE:
351  {
352  HFONT hfDefault;
353  HWND hEdit;
354 
355  // Create Edit Control
356 
357  hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "",
359  0, 0, 100, 100, hwnd, (HMENU)IDC_CHILD_EDIT, GetModuleHandle(NULL), NULL);
360  if(hEdit == NULL)
361  MessageBox(hwnd, "Could not create edit box.", "Error", MB_OK | MB_ICONERROR);
362 
363  hfDefault = GetStockObject(DEFAULT_GUI_FONT);
364  SendMessage(hEdit, WM_SETFONT, (WPARAM)hfDefault, MAKELPARAM(FALSE, 0));
365  }
366  break;
367  case WM_MDIACTIVATE:
368  {
369  HMENU hMenu, hFileMenu;
370  UINT EnableFlag;
371 
372  hMenu = GetMenu(g_hMainWindow);
373  if(hwnd == (HWND)lParam)
374  { //being activated, enable the menus
375  EnableFlag = MF_ENABLED;
376  }
377  else
378  { //being de-activated, gray the menus
379  EnableFlag = MF_GRAYED;
380  }
381 
382  EnableMenuItem(hMenu, 1, MF_BYPOSITION | EnableFlag);
383  EnableMenuItem(hMenu, 2, MF_BYPOSITION | EnableFlag);
384 
385  hFileMenu = GetSubMenu(hMenu, 0);
386  EnableMenuItem(hFileMenu, ID_FILE_SAVEAS, MF_BYCOMMAND | EnableFlag);
387 
388  EnableMenuItem(hFileMenu, ID_FILE_CLOSE, MF_BYCOMMAND | EnableFlag);
389  EnableMenuItem(hFileMenu, ID_FILE_CLOSEALL, MF_BYCOMMAND | EnableFlag);
390 
392  }
393  break;
394  case WM_COMMAND:
395  switch(LOWORD(wParam))
396  {
397  case ID_FILE_OPEN:
398  DoFileOpen(hwnd);
399  break;
400  case ID_FILE_SAVEAS:
401  DoFileSave(hwnd);
402  break;
403  case ID_EDIT_CUT:
405  break;
406  case ID_EDIT_COPY:
408  break;
409  case ID_EDIT_PASTE:
411  break;
412  }
413  break;
414  case WM_SIZE:
415  {
416  HWND hEdit;
417  RECT rcClient;
418 
419  // Calculate remaining height and size edit
420 
421  GetClientRect(hwnd, &rcClient);
422 
424  SetWindowPos(hEdit, NULL, 0, 0, rcClient.right, rcClient.bottom, SWP_NOZORDER);
425  }
426  return DefMDIChildProc(hwnd, msg, wParam, lParam);
427  default:
428  return DefMDIChildProc(hwnd, msg, wParam, lParam);
429 
430  }
431  return 0;
432 }
HGDIOBJ WINAPI GetStockObject(_In_ int)
HWND g_hMainWindow
Definition: mdi.c:22
BOOL WINAPI DrawMenuBar(_In_ HWND)
#define MF_BYCOMMAND
Definition: winuser.h:202
#define IDC_CHILD_EDIT
Definition: mdi.c:17
#define WM_CUT
Definition: winuser.h:1851
#define MAKELPARAM(l, h)
Definition: winuser.h:3998
#define ES_MULTILINE
Definition: pedump.c:667
#define ID_EDIT_COPY
Definition: resource.h:48
#define WM_PASTE
Definition: winuser.h:1853
#define ID_FILE_CLOSEALL
Definition: resource.h:13
#define ID_FILE_OPEN
Definition: resource.h:41
UINT_PTR WPARAM
Definition: windef.h:207
#define WS_CHILD
Definition: pedump.c:617
#define SendDlgItemMessage
Definition: winuser.h:5832
#define SWP_NOZORDER
Definition: winuser.h:1237
LONG right
Definition: windef.h:308
WPARAM wParam
Definition: combotst.c:138
BOOL WINAPI EnableMenuItem(_In_ HMENU, _In_ UINT, _In_ UINT)
#define FALSE
Definition: types.h:117
#define WM_COPY
Definition: winuser.h:1852
#define MF_BYPOSITION
Definition: winuser.h:203
#define CreateWindowEx
Definition: winuser.h:5745
#define DefMDIChildProc
Definition: ros2win.h:33
#define ES_AUTOVSCROLL
Definition: pedump.c:671
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define WM_SIZE
Definition: winuser.h:1601
#define MF_ENABLED
Definition: winuser.h:128
void DoFileSave(HWND hwnd)
Definition: mdi.c:123
#define ID_EDIT_CUT
Definition: wordpad.h:72
void DoFileOpen(HWND hwnd)
Definition: mdi.c:95
#define WS_HSCROLL
Definition: pedump.c:628
#define DEFAULT_GUI_FONT
Definition: wingdi.h:909
#define ID_FILE_SAVEAS
Definition: resource.h:43
#define MB_ICONERROR
Definition: winuser.h:781
static HWND hEdit
Definition: autocomplete.c:34
#define MessageBox
Definition: winuser.h:5812
HMENU WINAPI GetSubMenu(_In_ HMENU, _In_ int)
#define WM_COMMAND
Definition: winuser.h:1730
#define WM_MDIACTIVATE
Definition: winuser.h:1804
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
#define WS_EX_CLIENTEDGE
Definition: winuser.h:384
#define GetModuleHandle
Definition: winbase.h:3688
#define ID_FILE_CLOSE
Definition: resource.h:39
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
#define WS_VSCROLL
Definition: pedump.c:627
#define MB_OK
Definition: winuser.h:784
#define WM_SETFONT
Definition: winuser.h:1640
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
#define msg(x)
Definition: auth_time.c:54
#define SendMessage
Definition: winuser.h:5833
#define WM_CREATE
Definition: winuser.h:1598
#define ID_EDIT_PASTE
Definition: resource.h:49
LONG bottom
Definition: windef.h:309
BOOL WINAPI SetWindowPos(_In_ HWND, _In_opt_ HWND, _In_ int, _In_ int, _In_ int, _In_ int, _In_ UINT)
#define MF_GRAYED
Definition: winuser.h:129
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4022
#define WS_VISIBLE
Definition: pedump.c:620
HMENU WINAPI GetMenu(_In_ HWND)
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:60
LPARAM lParam
Definition: combotst.c:139
#define ES_AUTOHSCROLL
Definition: pedump.c:672
#define LOWORD(l)
Definition: pedump.c:82

Referenced by SetUpMDIChildWindowClass().

◆ SaveTextFileFromEdit()

BOOL SaveTextFileFromEdit ( HWND  hEdit,
LPCTSTR  pszFileName 
)

Definition at line 59 of file mdi.c.

60 {
61  HANDLE hFile;
63 
67  {
68  DWORD dwTextLength;
69 
70  dwTextLength = GetWindowTextLength(hEdit);
71  // No need to bother if there's no text.
72  if(dwTextLength > 0)
73  {
74  LPSTR pszText;
75  DWORD dwBufferSize = dwTextLength + 1;
76 
77  pszText = GlobalAlloc(GPTR, dwBufferSize);
78  if(pszText != NULL)
79  {
80  if(GetWindowText(hEdit, pszText, dwBufferSize))
81  {
82  DWORD dwWritten;
83 
84  if(WriteFile(hFile, pszText, dwTextLength, &dwWritten, NULL))
85  bSuccess = TRUE;
86  }
87  GlobalFree(pszText);
88  }
89  }
91  }
92  return bSuccess;
93 }
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
HGLOBAL NTAPI GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:368
#define CloseHandle
Definition: compat.h:598
#define GPTR
Definition: winbase.h:293
#define TRUE
Definition: types.h:120
#define INVALID_HANDLE_VALUE
Definition: compat.h:590
char * LPSTR
Definition: xmlstorage.h:182
static BOOLEAN bSuccess
Definition: drive.cpp:430
#define GetWindowText
Definition: winuser.h:5788
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GENERIC_WRITE
Definition: nt_native.h:90
WORD WORD PSZ PSZ pszFileName
Definition: vdmdbg.h:41
unsigned long DWORD
Definition: ntddk_ex.h:95
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
static HWND hEdit
Definition: autocomplete.c:34
_In_ HANDLE hFile
Definition: mswsock.h:90
#define CREATE_ALWAYS
Definition: disk.h:72
IN OUT PVCB OUT PDIRENT OUT PBCB IN BOOLEAN CreateFile
Definition: fatprocs.h:913
#define NULL
Definition: types.h:112
#define GetWindowTextLength
Definition: winuser.h:5789

Referenced by DoFileSave().

◆ SetUpMDIChildWindowClass()

BOOL SetUpMDIChildWindowClass ( HINSTANCE  hInstance)

Definition at line 434 of file mdi.c.

435 {
436  WNDCLASSEX wc;
437 
438  wc.cbSize = sizeof(WNDCLASSEX);
439  wc.style = CS_HREDRAW | CS_VREDRAW;
441  wc.cbClsExtra = 0;
442  wc.cbWndExtra = 0;
443  wc.hInstance = hInstance;
446  wc.hbrBackground = (HBRUSH)(COLOR_3DFACE+1);
447  wc.lpszMenuName = NULL;
450 
451  if(!RegisterClassEx(&wc))
452  {
453  MessageBox(0, "Could Not Register Child Window", "Oh Oh...",
455  return FALSE;
456  }
457  else
458  return TRUE;
459 }
UINT style
Definition: winuser.h:3192
LPCSTR lpszMenuName
Definition: winuser.h:3200
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
#define RegisterClassEx
Definition: winuser.h:5827
HCURSOR hCursor
Definition: winuser.h:3198
WNDPROC lpfnWndProc
Definition: winuser.h:3193
LPCSTR lpszClassName
Definition: winuser.h:3201
#define TRUE
Definition: types.h:120
#define CS_HREDRAW
Definition: winuser.h:648
#define IDI_APPLICATION
Definition: winuser.h:699
HICON hIconSm
Definition: winuser.h:3202
#define MB_ICONEXCLAMATION
Definition: winuser.h:779
const char g_szChildClassName[]
Definition: mdi.c:11
LRESULT CALLBACK MDIChildWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: mdi.c:346
HINSTANCE hInstance
Definition: charmap.c:20
#define COLOR_3DFACE
Definition: winuser.h:923
#define FALSE
Definition: types.h:117
HINSTANCE hInstance
Definition: winuser.h:3196
UINT cbSize
Definition: winuser.h:3191
HBRUSH hbrBackground
Definition: winuser.h:3199
#define CS_VREDRAW
Definition: winuser.h:653
int cbWndExtra
Definition: winuser.h:3195
HICON hIcon
Definition: winuser.h:3197
#define MessageBox
Definition: winuser.h:5812
#define LoadCursor
Definition: winuser.h:5802
int cbClsExtra
Definition: winuser.h:3194
#define NULL
Definition: types.h:112
#define MB_OK
Definition: winuser.h:784
#define IDC_ARROW
Definition: winuser.h:682
WNDCLASSEXA WNDCLASSEX
Definition: winuser.h:5709
#define LoadIcon
Definition: winuser.h:5803

Referenced by WinMain().

◆ WinMain()

int WINAPI WinMain ( HINSTANCE  hInstance,
HINSTANCE  hPrevInstance,
LPSTR  lpCmdLine,
int  nCmdShow 
)

Definition at line 462 of file mdi.c.

464 {
465  WNDCLASSEX wc;
466  HWND hwnd;
467  MSG Msg;
468 
470 
471  wc.cbSize = sizeof(WNDCLASSEX);
472  wc.style = 0;
473  wc.lpfnWndProc = WndProc;
474  wc.cbClsExtra = 0;
475  wc.cbWndExtra = 0;
476  wc.hInstance = hInstance;
479  wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
483 
484  if(!RegisterClassEx(&wc))
485  {
486  MessageBox(NULL, "Window Registration Failed!", "Error!",
488  return 0;
489  }
490 
492  return 0;
493 
495  0,
497  "MDI Test Application",
499  CW_USEDEFAULT, CW_USEDEFAULT, 480, 320,
500  NULL, NULL, hInstance, NULL);
501 
502  if(hwnd == NULL)
503  {
504  MessageBox(NULL, "Window Creation Failed!", "Error!",
506  return 0;
507  }
508 
510 
511  ShowWindow(hwnd, nCmdShow);
513 
514  while(GetMessage(&Msg, NULL, 0, 0) > 0)
515  {
517  {
520  }
521  }
522  return Msg.wParam;
523 }
HWND g_hMainWindow
Definition: mdi.c:22
UINT style
Definition: winuser.h:3192
#define MAKEINTRESOURCE
Definition: winuser.h:591
#define IDR_MAINMENU
Definition: resource.h:40
#define DispatchMessage
Definition: winuser.h:5755
BOOL WINAPI TranslateMessage(_In_ const MSG *)
LPCSTR lpszMenuName
Definition: winuser.h:3200
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
#define RegisterClassEx
Definition: winuser.h:5827
HCURSOR hCursor
Definition: winuser.h:3198
WNDPROC lpfnWndProc
Definition: winuser.h:3193
LPCSTR lpszClassName
Definition: winuser.h:3201
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
struct @1591 Msg[]
BOOL WINAPI UpdateWindow(_In_ HWND)
#define IDI_APPLICATION
Definition: winuser.h:699
BOOL WINAPI TranslateMDISysAccel(HWND hwndClient, LPMSG msg)
Definition: mdi.c:1763
HICON hIconSm
Definition: winuser.h:3202
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define WS_CLIPCHILDREN
Definition: pedump.c:619
#define COLOR_WINDOW
Definition: winuser.h:912
#define MB_ICONEXCLAMATION
Definition: winuser.h:779
HINSTANCE hInstance
Definition: charmap.c:20
HINSTANCE hInstance
Definition: winuser.h:3196
#define CreateWindowEx
Definition: winuser.h:5745
#define CW_USEDEFAULT
Definition: winuser.h:225
UINT cbSize
Definition: winuser.h:3191
HBRUSH hbrBackground
Definition: winuser.h:3199
BOOL SetUpMDIChildWindowClass(HINSTANCE hInstance)
Definition: mdi.c:434
int cbWndExtra
Definition: winuser.h:3195
HICON hIcon
Definition: winuser.h:3197
#define MessageBox
Definition: winuser.h:5812
const char g_szClassName[]
Definition: mdi.c:10
#define LoadCursor
Definition: winuser.h:5802
int cbClsExtra
Definition: winuser.h:3194
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: mdi.c:172
#define NULL
Definition: types.h:112
#define MB_OK
Definition: winuser.h:784
HWND g_hMDIClient
Definition: mdi.c:21
#define GetMessage
Definition: winuser.h:5780
#define IDC_ARROW
Definition: winuser.h:682
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
VOID WINAPI InitCommonControls(void)
Definition: commctrl.c:863
WNDCLASSEXA WNDCLASSEX
Definition: winuser.h:5709
#define LoadIcon
Definition: winuser.h:5803
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4022

◆ WndProc()

LRESULT CALLBACK WndProc ( HWND  hwnd,
UINT  msg,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 172 of file mdi.c.

173 {
174  switch(msg)
175  {
176  case WM_CREATE:
177  {
178  HWND hTool;
179  TBBUTTON tbb[3];
180  TBADDBITMAP tbab;
181 
182  HWND hStatus;
183  int statwidths[] = {100, -1};
184 
185  CLIENTCREATESTRUCT ccs;
186 
187  // Create MDI Client
188 
189  // Find window menu where children will be listed
190  ccs.hWindowMenu = GetSubMenu(GetMenu(hwnd), 2);
192 
197 
198  if(g_hMDIClient == NULL)
199  MessageBox(hwnd, "Could not create MDI client.", "Error", MB_OK | MB_ICONERROR);
200 
201  // Create Toolbar
202 
203  hTool = CreateWindowEx(0, TOOLBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0,
205  if(hTool == NULL)
206  MessageBox(hwnd, "Could not create tool bar.", "Error", MB_OK | MB_ICONERROR);
207 
208  // Send the TB_BUTTONSTRUCTSIZE message, which is required for
209  // backward compatibility.
210  SendMessage(hTool, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
211 
212  tbab.hInst = HINST_COMMCTRL;
213  tbab.nID = IDB_STD_SMALL_COLOR;
214  SendMessage(hTool, TB_ADDBITMAP, 0, (LPARAM)&tbab);
215 
216  ZeroMemory(tbb, sizeof(tbb));
217  tbb[0].iBitmap = STD_FILENEW;
218  tbb[0].fsState = TBSTATE_ENABLED;
219  tbb[0].fsStyle = TBSTYLE_BUTTON;
220  tbb[0].idCommand = ID_FILE_NEW;
221 
222  tbb[1].iBitmap = STD_FILEOPEN;
223  tbb[1].fsState = TBSTATE_ENABLED;
224  tbb[1].fsStyle = TBSTYLE_BUTTON;
225  tbb[1].idCommand = ID_FILE_OPEN;
226 
227  tbb[2].iBitmap = STD_FILESAVE;
228  tbb[2].fsState = TBSTATE_ENABLED;
229  tbb[2].fsStyle = TBSTYLE_BUTTON;
230  tbb[2].idCommand = ID_FILE_SAVEAS;
231 
232  SendMessage(hTool, TB_ADDBUTTONS, sizeof(tbb)/sizeof(TBBUTTON), (LPARAM)&tbb);
233 
234  // Create Status bar
235 
237  WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP, 0, 0, 0, 0,
239 
240  SendMessage(hStatus, SB_SETPARTS, sizeof(statwidths)/sizeof(int), (LPARAM)statwidths);
241  SendMessage(hStatus, SB_SETTEXT, 0, (LPARAM)"Hi there :)");
242  }
243  break;
244  case WM_SIZE:
245  {
246  HWND hTool;
247  RECT rcTool;
248  int iToolHeight;
249 
250  HWND hStatus;
251  RECT rcStatus;
252  int iStatusHeight;
253 
254  HWND hMDI;
255  int iMDIHeight;
256  RECT rcClient;
257 
258  // Size toolbar and get height
259 
260  hTool = GetDlgItem(hwnd, IDC_MAIN_TOOL);
261  SendMessage(hTool, TB_AUTOSIZE, 0, 0);
262 
263  GetWindowRect(hTool, &rcTool);
264  iToolHeight = rcTool.bottom - rcTool.top;
265 
266  // Size status bar and get height
267 
269  SendMessage(hStatus, WM_SIZE, 0, 0);
270 
271  GetWindowRect(hStatus, &rcStatus);
272  iStatusHeight = rcStatus.bottom - rcStatus.top;
273 
274  // Calculate remaining height and size edit
275 
276  GetClientRect(hwnd, &rcClient);
277 
278  iMDIHeight = rcClient.bottom - iToolHeight - iStatusHeight;
279 
280  hMDI = GetDlgItem(hwnd, IDC_MAIN_MDI);
281  SetWindowPos(hMDI, NULL, 0, iToolHeight, rcClient.right, iMDIHeight, SWP_NOZORDER);
282  }
283  break;
284  case WM_CLOSE:
286  break;
287  case WM_DESTROY:
288  PostQuitMessage(0);
289  break;
290  case WM_COMMAND:
291  switch(LOWORD(wParam))
292  {
293  case ID_FILE_EXIT:
294  PostMessage(hwnd, WM_CLOSE, 0, 0);
295  break;
296  case ID_FILE_NEW:
298  break;
299  case ID_FILE_OPEN:
300  {
302  if(hChild)
303  {
305  }
306  }
307  break;
308  case ID_FILE_CLOSE:
309  {
311  if(hChild)
312  {
313  SendMessage(hChild, WM_CLOSE, 0, 0);
314  }
315  }
316  break;
317  case ID_WINDOW_TILE:
319  break;
320  case ID_WINDOW_CASCADE:
322  break;
323  default:
324  {
326  {
328  }
329  else
330  {
332  if(hChild)
333  {
335  }
336  }
337  }
338  }
339  break;
340  default:
342  }
343  return 0;
344 }
#define IDC_MAIN_STATUS
Definition: mdi.c:15
#define TB_BUTTONSTRUCTSIZE
Definition: commctrl.h:1134
static HTREEITEM hChild
Definition: treeview.c:381
#define WM_MDICASCADE
Definition: winuser.h:1809
LONG top
Definition: windef.h:307
HANDLE HWND
Definition: compat.h:19
#define IDB_STD_SMALL_COLOR
Definition: commctrl.h:1064
#define ZeroMemory
Definition: winbase.h:1667
#define ID_FILE_OPEN
Definition: resource.h:41
UINT_PTR WPARAM
Definition: windef.h:207
#define STD_FILENEW
Definition: commctrl.h:1077
HINSTANCE hInst
Definition: commctrl.h:1059
#define WS_CHILD
Definition: pedump.c:617
#define SWP_NOZORDER
Definition: winuser.h:1237
BYTE fsStyle
Definition: commctrl.h:952
#define WS_CLIPCHILDREN
Definition: pedump.c:619
LONG right
Definition: windef.h:308
#define STATUSCLASSNAME
Definition: commctrl.h:1939
BOOL WINAPI DestroyWindow(_In_ HWND)
WPARAM wParam
Definition: combotst.c:138
#define DefFrameProc
Definition: ros2win.h:32
SERVICE_STATUS_HANDLE hStatus
Definition: w32time.c:14
#define TB_AUTOSIZE
Definition: commctrl.h:1137
#define ID_FILE_EXIT
Definition: resource.h:46
#define ID_WINDOW_TILE
Definition: resource.h:80
#define CreateWindowEx
Definition: winuser.h:5745
#define CW_USEDEFAULT
Definition: winuser.h:225
#define TOOLBARCLASSNAME
Definition: commctrl.h:946
LONG_PTR LPARAM
Definition: windef.h:208
#define WM_DESTROY
Definition: winuser.h:1599
int iBitmap
Definition: commctrl.h:949
#define ID_FILE_NEW
Definition: resource.h:40
#define PostMessage
Definition: winuser.h:5822
#define ID_WINDOW_CASCADE
Definition: resource.h:79
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define SBARS_SIZEGRIP
Definition: commctrl.h:1923
#define WM_SIZE
Definition: winuser.h:1601
#define IDC_MAIN_MDI
Definition: mdi.c:13
#define WM_CLOSE
Definition: winuser.h:1611
void DoFileOpen(HWND hwnd)
Definition: mdi.c:95
#define WS_HSCROLL
Definition: pedump.c:628
#define TB_ADDBITMAP
Definition: commctrl.h:1056
#define IDC_MAIN_TOOL
Definition: mdi.c:14
#define ID_FILE_SAVEAS
Definition: resource.h:43
#define WM_MDIGETACTIVE
Definition: winuser.h:1811
#define ID_MDI_FIRSTCHILD
Definition: mdi.c:19
#define SB_SETTEXT
Definition: commctrl.h:1949
int idCommand
Definition: commctrl.h:950
#define MB_ICONERROR
Definition: winuser.h:781
#define TB_ADDBUTTONS
Definition: commctrl.h:1271
#define MessageBox
Definition: winuser.h:5812
HMENU WINAPI GetSubMenu(_In_ HMENU, _In_ int)
#define WM_COMMAND
Definition: winuser.h:1730
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
#define WS_EX_CLIENTEDGE
Definition: winuser.h:384
#define GetModuleHandle
Definition: winbase.h:3688
#define ID_FILE_CLOSE
Definition: resource.h:39
#define NULL
Definition: types.h:112
#define WS_VSCROLL
Definition: pedump.c:627
#define MB_OK
Definition: winuser.h:784
HWND g_hMDIClient
Definition: mdi.c:21
#define SB_SETPARTS
Definition: commctrl.h:1954
#define HINST_COMMCTRL
Definition: commctrl.h:1063
#define msg(x)
Definition: auth_time.c:54
#define SendMessage
Definition: winuser.h:5833
#define TBSTATE_ENABLED
Definition: commctrl.h:974
#define WM_CREATE
Definition: winuser.h:1598
HWND CreateNewMDIChild(HWND hMDIClient)
Definition: mdi.c:151
#define STD_FILESAVE
Definition: commctrl.h:1079
LONG bottom
Definition: windef.h:309
BOOL WINAPI GetWindowRect(_In_ HWND, _Out_ LPRECT)
BOOL WINAPI SetWindowPos(_In_ HWND, _In_opt_ HWND, _In_ int, _In_ int, _In_ int, _In_ int, _In_ UINT)
BYTE fsState
Definition: commctrl.h:951
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4022
#define STD_FILEOPEN
Definition: commctrl.h:1078
#define WS_VISIBLE
Definition: pedump.c:620
HMENU WINAPI GetMenu(_In_ HWND)
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:60
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
#define TBSTYLE_BUTTON
Definition: commctrl.h:981
#define WM_MDITILE
Definition: winuser.h:1808
UINT_PTR nID
Definition: commctrl.h:1060

Referenced by WinMain().

Variable Documentation

◆ g_hMainWindow

HWND g_hMainWindow = NULL

Definition at line 22 of file mdi.c.

Referenced by DoFileOpen(), DoFileSave(), MDIChildWndProc(), and WinMain().

◆ g_hMDIClient

HWND g_hMDIClient = NULL

Definition at line 21 of file mdi.c.

Referenced by WinMain(), and WndProc().

◆ g_szChildClassName

const char g_szChildClassName[] = "myMDIChildWindowClass"

Definition at line 11 of file mdi.c.

Referenced by CreateNewMDIChild(), and SetUpMDIChildWindowClass().

◆ g_szClassName

const char g_szClassName[] = "myWindowClass"

Definition at line 10 of file mdi.c.

Referenced by WinMain().