ReactOS  0.4.13-dev-52-g0efcfec
main.c
Go to the documentation of this file.
1 /*
2  * ReactOS Application
3  *
4  * main.c
5  *
6  * Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
7  *
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.
12  *
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.
17  *
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.
21  */
22 
23 #ifdef _MSC_VER
24 #include "stdafx.h"
25 #else
26 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
27 #include <windows.h>
28 #include <commctrl.h>
29 #include <stdlib.h>
30 #include <malloc.h>
31 #include <memory.h>
32 #include <tchar.h>
33 #include <process.h>
34 #include <stdio.h>
35 #endif
36 
37 #include "main.h"
38 #include "framewnd.h"
39 #include "childwnd.h"
40 
41 
43 // Global Variables:
44 //
45 
47 HACCEL hAccel;
54 
58 
59 
61 
63 {
64  WNDCLASSEX wcFrame = {
65  sizeof(WNDCLASSEX),
66  CS_HREDRAW | CS_VREDRAW/*style*/,
68  0/*cbClsExtra*/,
69  0/*cbWndExtra*/,
70  hInstance,
73  0/*hbrBackground*/,
74  0/*lpszMenuName*/,
78  };
79  ATOM hFrameWndClass = RegisterClassEx(&wcFrame); // register frame window class
80 #if 0
81  WNDCLASS wcChild = {
84  0/*cbClsExtra*/,
85  0/*cbWndExtra*/,
86  hInstance,
87  0/*hIcon*/,
89  0/*hbrBackground*/,
90  0/*lpszMenuName*/,
92  };
93  ATOM hChildWndClass = RegisterClass(&wcChild); // register child windows class
94 #else
95  // WNDCLASSEX wcChild = {
96  // sizeof(WNDCLASSEX),
97  // CS_HREDRAW | CS_VREDRAW/*style*/,
98  // ChildWndProc,
99  // 0/*cbClsExtra*/,
100  // sizeof(HANDLE)/*cbWndExtra*/,
101  // hInstance,
102  // LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MDI_APP)),
103  // LoadCursor(0, IDC_ARROW),
104  // 0/*hbrBackground*/,
105  // 0/*lpszMenuName*/,
106  // szChildClass,
107  // (HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDC_MDI_APP), IMAGE_ICON,
108  // GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED)
109  // };
110  // ATOM hChildWndClass = RegisterClassEx(&wcChild); // register child windows class
111 #endif
112 
114  HMENU hMenuOptions = GetSubMenu(hMenu, ID_OPTIONS_MENU);
115  // HMENU hChildMenu = LoadMenu(hInstance, MAKEINTRESOURCE(IDC_MDI_APP_CHILD));
116 
117  INITCOMMONCONTROLSEX icc = {
118  sizeof(INITCOMMONCONTROLSEX),
120  };
121 
122  HDC hdc = GetDC(0);
123 
124  hMenuFrame = hMenu;
125 // hMenuView = GetSubMenu(hMenuFrame, ID_VIEW_MENU);
127  hFont = CreateFont(-MulDiv(8,GetDeviceCaps(hdc,LOGPIXELSY),72), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _T("MS Sans Serif"));
128  ReleaseDC(0, hdc);
129 
130  hFrameWnd = CreateWindowEx(0, (LPCTSTR)(ULONG_PTR)hFrameWndClass, szTitle,
131 // hFrameWnd = CreateWindow(szFrameClass, szTitle,
134  NULL/*hWndParent*/, hMenuFrame, hInstance, NULL/*lpParam*/);
135  if (!hFrameWnd) {
136  return FALSE;
137  }
138 
139  if (InitCommonControlsEx(&icc))
140  {
141  int nParts[3];
142  TBBUTTON toolbarBtns[] = {
143  {0, 0, 0, TBSTYLE_SEP},
148  {4, 2/*TODO: ID_...*/, TBSTATE_ENABLED, TBSTYLE_BUTTON},
149  {5, 2/*TODO: ID_...*/, TBSTATE_ENABLED, TBSTYLE_BUTTON},
150  };
151 
153  IDC_TOOLBAR, 2, hInstance, IDB_TOOLBAR, toolbarBtns,
154  sizeof(toolbarBtns)/sizeof(TBBUTTON), 16, 15, 16, 15, sizeof(TBBUTTON));
156 
157  // Create the status bar
159  "", hFrameWnd, IDC_STATUSBAR);
160  if (!hStatusBar)
161  return FALSE;
163 
164  // Create the status bar panes
165  nParts[0] = 100;
166  nParts[1] = 210;
167  nParts[2] = 400;
169  } else {
172  }
173 
174  ShowWindow(hFrameWnd, nCmdShow);
176  UpdateStatusBar();
177  return TRUE;
178 }
179 
181 
182 void UpdateStatusBar(void)
183 {
184  TCHAR text[260];
185  DWORD size;
186 
187  size = sizeof(text)/sizeof(TCHAR);
188  GetUserName(text, &size);
190  size = sizeof(text)/sizeof(TCHAR);
193 }
194 
195 
196 static int g_foundPrevInstance = 0;
197 
198 // search for already running win[e]files
200 {
201  TCHAR cls[128];
202 
203  GetClassName(hWnd, cls, 128);
204  if (!lstrcmp(cls, (LPCTSTR)lParam)) {
206  return FALSE;
207  }
208  return TRUE;
209 }
210 
212 
213 void ExitInstance(void)
214 {
216 }
217 
218 
220  HINSTANCE hPrevInstance,
221  LPSTR lpCmdLine,
222  int nCmdShow)
223 {
224  MSG msg;
225 // HACCEL hAccel;
227 
228  // Initialize global strings
232 
233  // Allow only one running instance
236  return 1;
237 
238  // Store instance handle in our global variable
239  hInst = hInstance;
240 
241  // Perform application initialization:
242  if (!InitInstance(hInstance, nCmdShow)) {
243  return FALSE;
244  }
245 // hAccel = LoadAccelerators(hInstance, (LPCTSTR)IDC_MDI_APP);
247 
248  // Main message loop:
249  while (GetMessage(&msg, (HWND)NULL, 0, 0)) {
254  }
255  }
256  ExitInstance();
257  return msg.wParam;
258 }
#define WS_CLIPSIBLINGS
Definition: pedump.c:618
LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
Definition: childwnd.c:385
#define TranslateAccelerator
Definition: winuser.h:5726
#define MAKEINTRESOURCE
Definition: winuser.h:591
#define MAX_LOADSTRING
Definition: main.c:37
#define DispatchMessage
Definition: winuser.h:5631
BOOL WINAPI TranslateMessage(_In_ const MSG *)
static HICON
Definition: imagelist.c:84
#define TRUE
Definition: types.h:120
HWND hToolBar
Definition: main.c:52
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
#define LR_SHARED
Definition: winuser.h:1090
void ExitInstance(HINSTANCE hInstance)
Definition: main.c:164
#define IMAGE_ICON
Definition: winuser.h:212
#define IDC_STATUSBAR
Definition: resource.h:14
#define RegisterClassEx
Definition: winuser.h:5703
#define MF_BYCOMMAND
Definition: winuser.h:202
#define GW_CHILD
Definition: winuser.h:758
#define ID_OPTIONS_TOOLBAR
Definition: resource.h:40
HDC WINAPI GetDC(_In_opt_ HWND)
WORD ATOM
Definition: dimm.idl:113
#define GetUserName
Definition: winbase.h:3665
#define TBSTYLE_SEP
Definition: commctrl.h:954
const WCHAR * text
Definition: package.c:1827
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
#define IDC_MDI_APP
Definition: resource.h:16
static HDC
Definition: imagelist.c:92
#define GetComputerName
Definition: winbase.h:3614
#define CALLBACK
Definition: compat.h:27
WCHAR szTitle[MAX_LOADSTRING]
Definition: main.c:38
BOOL WINAPI UpdateWindow(_In_ HWND)
HWND hWnd
Definition: settings.c:17
#define CS_HREDRAW
Definition: winuser.h:648
#define SM_CYSMICON
Definition: winuser.h:1003
#define ID_WINDOW_TILE_VERT
Definition: resource.h:49
#define WS_CHILD
Definition: pedump.c:617
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
char * LPSTR
Definition: xmlstorage.h:182
#define WS_CLIPCHILDREN
Definition: pedump.c:619
HWND WINAPI CreateToolbarEx(HWND hwnd, DWORD style, UINT wID, INT nBitmaps, HINSTANCE hBMInst, UINT_PTR wBMID, LPCTBBUTTON lpButtons, INT iNumButtons, INT dxButton, INT dyButton, INT dxBitmap, INT dyBitmap, UINT uStructSize)
Definition: commctrl.c:929
struct tagINITCOMMONCONTROLSEX INITCOMMONCONTROLSEX
#define IDC_MDI_APP_CHILD
Definition: resource.h:17
void UpdateStatusBar(void)
Definition: main.c:182
uint32_t ULONG_PTR
Definition: typedefs.h:63
HINSTANCE hInst
Definition: main.c:29
#define LoadAccelerators
Definition: winuser.h:5676
HACCEL hAccel
Definition: main.c:47
unsigned int BOOL
Definition: ntddk_ex.h:94
#define CreateStatusWindow
Definition: commctrl.h:1905
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
#define ID_OPTIONS_MENU
Definition: resource.h:8
#define CreateWindowEx
Definition: winuser.h:5621
#define CW_USEDEFAULT
Definition: winuser.h:225
#define CreateFont
Definition: wingdi.h:4421
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
HWND hStatusBar
Definition: main.c:31
#define ID_WINDOW_CASCADE
Definition: resource.h:78
#define MF_CHECKED
Definition: winuser.h:132
#define CS_VREDRAW
Definition: winuser.h:653
char TCHAR
Definition: xmlstorage.h:189
#define ICC_BAR_CLASSES
Definition: commctrl.h:60
#define _T(x)
Definition: vfdio.h:22
WCHAR szFrameClass[MAX_LOADSTRING]
Definition: main.c:39
GLsizeiptr size
Definition: glext.h:5919
static int g_foundPrevInstance
Definition: main.c:196
BOOL WINAPI EnumWindows(_In_ WNDENUMPROC, _In_ LPARAM)
int WINAPI GetSystemMetrics(_In_ int)
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD WINAPI CheckMenuItem(_In_ HMENU, _In_ UINT, _In_ UINT)
#define IDC_TOOLBAR
Definition: wordpad.h:157
HINSTANCE hInstance
Definition: main.c:36
#define SM_CXSMICON
Definition: winuser.h:1002
#define ID_WINDOW_TILE_HORZ
Definition: resource.h:48
HWND WINAPI GetWindow(_In_ HWND, _In_ UINT)
HDC hdc
Definition: main.c:9
BOOL WINAPI InitCommonControlsEx(const INITCOMMONCONTROLSEX *lpInitCtrls)
Definition: commctrl.c:893
#define SB_SETTEXT
Definition: commctrl.h:1921
int WINAPI GetDeviceCaps(_In_opt_ HDC, _In_ int)
WCHAR szChildClass[MAX_LOADSTRING]
Definition: main.c:40
#define CS_DBLCLKS
Definition: winuser.h:646
HMENU WINAPI GetSubMenu(_In_ HMENU, _In_ int)
#define lstrcmp
Definition: winbase.h:3686
#define LoadCursor
Definition: winuser.h:5678
BOOL WINAPI DestroyMenu(_In_ HMENU)
#define CS_CLASSDC
Definition: winuser.h:645
#define GetClassName
Definition: winuser.h:5649
HWND hFrameWnd
Definition: main.c:30
HMENU hMenuFrame
Definition: main.c:32
#define LoadMenu
Definition: winuser.h:5683
LRESULT CALLBACK FrameWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
Definition: framewnd.c:1304
#define ID_OPTIONS_STATUSBAR
Definition: resource.h:41
#define IDS_APP_TITLE
Definition: resource.h:10
#define GetMessage
Definition: winuser.h:5656
#define SB_SETPARTS
Definition: commctrl.h:1926
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
#define msg(x)
Definition: auth_time.c:54
#define IDC_ARROW
Definition: winuser.h:682
static BOOL CALLBACK EnumWndProc(HWND hWnd, LPARAM lParam)
Definition: main.c:199
#define SendMessage
Definition: winuser.h:5709
#define TBSTATE_ENABLED
Definition: commctrl.h:946
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
Definition: main.c:56
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
#define LOGPIXELSY
Definition: wingdi.h:718
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR cmdline, int cmdshow)
Definition: main.c:8
#define IDB_TOOLBAR
Definition: wordpad.h:183
#define LoadImage
Definition: winuser.h:5681
#define RegisterClass
Definition: winuser.h:5702
WNDCLASSEXA WNDCLASSEX
Definition: winuser.h:5585
#define LoadIcon
Definition: winuser.h:5679
#define MF_GRAYED
Definition: winuser.h:129
#define ID_WINDOW_NEW_WINDOW
Definition: resource.h:44
#define WS_VISIBLE
Definition: pedump.c:620
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 SBT_NOBORDERS
Definition: commctrl.h:1943
#define MulDiv(x, y, z)
Definition: gdifloat.h:86
#define LoadString
Definition: winuser.h:5685
BOOL WINAPI TranslateMDISysAccel(_In_ HWND, _In_ LPMSG)
#define TBSTYLE_BUTTON
Definition: commctrl.h:953
#define APIENTRY
Definition: api.h:79
#define IDI_MDI_APP
Definition: resource.h:14
HWND hMDIClient
Definition: main.c:49
HFONT hFont
Definition: main.c:53