6 * Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
42 ////////////////////////////////////////////////////////////////////////////////
55 TCHAR szTitle
[MAX_LOADSTRING
];
56 TCHAR szFrameClass
[MAX_LOADSTRING
];
57 TCHAR szChildClass
[MAX_LOADSTRING
];
60 ////////////////////////////////////////////////////////////////////////////////
62 BOOL
InitInstance(HINSTANCE hInstance
, int nCmdShow
)
64 WNDCLASSEX wcFrame
= {
66 CS_HREDRAW
| CS_VREDRAW
/*style*/,
71 LoadIcon(hInstance
, MAKEINTRESOURCE(IDI_MDI_APP
)),
72 LoadCursor(0, IDC_ARROW
),
76 (HICON
)LoadImage(hInstance
, MAKEINTRESOURCE(IDI_MDI_APP
), IMAGE_ICON
,
77 GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), LR_SHARED
)
79 ATOM hFrameWndClass
= RegisterClassEx(&wcFrame
); // register frame window class
82 CS_CLASSDC
|CS_DBLCLKS
|CS_VREDRAW
,
88 LoadCursor(0, IDC_ARROW
),
93 ATOM hChildWndClass
= RegisterClass(&wcChild
); // register child windows class
95 WNDCLASSEX wcChild
= {
97 CS_HREDRAW
| CS_VREDRAW
/*style*/,
100 sizeof(HANDLE
)/*cbWndExtra*/,
102 LoadIcon(hInstance
, MAKEINTRESOURCE(IDI_MDI_APP
)),
103 LoadCursor(0, IDC_ARROW
),
107 (HICON
)LoadImage(hInstance
, MAKEINTRESOURCE(IDC_MDI_APP
), IMAGE_ICON
,
108 GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), LR_SHARED
)
111 ATOM hChildWndClass
= RegisterClassEx(&wcChild
); // register child windows class
114 HMENU hMenu
= LoadMenu(hInstance
, MAKEINTRESOURCE(IDC_MDI_APP
));
115 HMENU hMenuOptions
= GetSubMenu(hMenu
, ID_OPTIONS_MENU
);
116 HMENU hChildMenu
= LoadMenu(hInstance
, MAKEINTRESOURCE(IDC_MDI_APP_CHILD
));
118 INITCOMMONCONTROLSEX icc
= {
119 sizeof(INITCOMMONCONTROLSEX
),
126 // hMenuView = GetSubMenu(hMenuFrame, ID_VIEW_MENU);
127 hAccel
= LoadAccelerators(hInstance
, MAKEINTRESOURCE(IDC_MDI_APP
));
128 hFont
= CreateFont(-MulDiv(8,GetDeviceCaps(hdc
,LOGPIXELSY
),72), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _T("MS Sans Serif"));
131 hFrameWnd
= CreateWindowEx(0, (LPCTSTR
)(int)hFrameWndClass
, szTitle
,
132 // hFrameWnd = CreateWindow(szFrameClass, szTitle,
133 WS_OVERLAPPEDWINDOW
| WS_CLIPCHILDREN
,
134 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
135 NULL
/*hWndParent*/, hMenuFrame
, hInstance
, NULL
/*lpParam*/);
140 if (InitCommonControlsEx(&icc
))
143 TBBUTTON toolbarBtns
[] = {
144 {0, 0, 0, TBSTYLE_SEP
},
145 {0, ID_WINDOW_NEW_WINDOW
, TBSTATE_ENABLED
, TBSTYLE_BUTTON
},
146 {1, ID_WINDOW_CASCADE
, TBSTATE_ENABLED
, TBSTYLE_BUTTON
},
147 {2, ID_WINDOW_TILE_HORZ
, TBSTATE_ENABLED
, TBSTYLE_BUTTON
},
148 {3, ID_WINDOW_TILE_VERT
, TBSTATE_ENABLED
, TBSTYLE_BUTTON
},
149 {4, 2/*TODO: ID_...*/, TBSTATE_ENABLED
, TBSTYLE_BUTTON
},
150 {5, 2/*TODO: ID_...*/, TBSTATE_ENABLED
, TBSTYLE_BUTTON
},
153 hToolBar
= CreateToolbarEx(hFrameWnd
, WS_CHILD
|WS_VISIBLE
,
154 IDC_TOOLBAR
, 2, hInstance
, IDB_TOOLBAR
, toolbarBtns
,
155 sizeof(toolbarBtns
)/sizeof(TBBUTTON
), 16, 15, 16, 15, sizeof(TBBUTTON
));
156 CheckMenuItem(hMenuOptions
, ID_OPTIONS_TOOLBAR
, MF_BYCOMMAND
|MF_CHECKED
);
158 // Create the status bar
159 hStatusBar
= CreateStatusWindow(WS_VISIBLE
|WS_CHILD
|WS_CLIPSIBLINGS
|SBT_NOBORDERS
,
160 "", hFrameWnd
, IDC_STATUSBAR
);
163 CheckMenuItem(hMenuOptions
, ID_OPTIONS_STATUSBAR
, MF_BYCOMMAND
|MF_CHECKED
);
165 // Create the status bar panes
169 SendMessage(hStatusBar
, SB_SETPARTS
, 3, (long)nParts
);
171 CheckMenuItem(hMenuOptions
, ID_OPTIONS_TOOLBAR
, MF_BYCOMMAND
|MF_GRAYED
);
172 CheckMenuItem(hMenuOptions
, ID_OPTIONS_STATUSBAR
, MF_BYCOMMAND
|MF_GRAYED
);
175 ShowWindow(hFrameWnd
, nCmdShow
);
176 UpdateWindow(hFrameWnd
);
181 ////////////////////////////////////////////////////////////////////////////////
183 void UpdateStatusBar(void)
188 size
= sizeof(text
)/sizeof(TCHAR
);
189 GetUserName(text
, &size
);
190 SendMessage(hStatusBar
, SB_SETTEXT
, 1, (LPARAM
)text
);
191 size
= sizeof(text
)/sizeof(TCHAR
);
192 GetComputerName(text
, &size
);
193 SendMessage(hStatusBar
, SB_SETTEXT
, 0, (LPARAM
)text
);
197 static int g_foundPrevInstance
= 0;
199 // search for already running win[e]files
200 static BOOL CALLBACK
EnumWndProc(HWND hWnd
, LPARAM lParam
)
204 GetClassName(hWnd
, cls
, 128);
205 if (!lstrcmp(cls
, (LPCTSTR
)lParam
)) {
206 g_foundPrevInstance
++;
212 ////////////////////////////////////////////////////////////////////////////////
214 void ExitInstance(void)
216 DestroyMenu(hMenuFrame
);
220 int APIENTRY
WinMain(HINSTANCE hInstance
,
221 HINSTANCE hPrevInstance
,
229 // Initialize global strings
230 LoadString(hInstance
, IDS_APP_TITLE
, szTitle
, MAX_LOADSTRING
);
231 LoadString(hInstance
, IDC_MDI_APP
, szFrameClass
, MAX_LOADSTRING
);
232 LoadString(hInstance
, IDC_MDI_APP_CHILD
, szChildClass
, MAX_LOADSTRING
);
234 // Allow only one running instance
235 EnumWindows(EnumWndProc
, (LPARAM
)szFrameClass
);
236 if (g_foundPrevInstance
)
239 // Store instance handle in our global variable
242 // Perform application initialization:
243 if (!InitInstance(hInstance
, nCmdShow
)) {
246 // hAccel = LoadAccelerators(hInstance, (LPCTSTR)IDC_MDI_APP);
247 hMDIClient
= GetWindow(hFrameWnd
, GW_CHILD
);
249 // Main message loop:
250 while (GetMessage(&msg
, (HWND
)NULL
, 0, 0)) {
251 if (!TranslateMDISysAccel(hMDIClient
, &msg
) &&
252 !TranslateAccelerator(hFrameWnd
, hAccel
, &msg
)) {
253 TranslateMessage(&msg
);
254 DispatchMessage(&msg
);