2 * PROJECT: PAINT for ReactOS
4 * FILE: base/applications/mspaint/main.cpp
5 * PURPOSE: Initializing everything
6 * PROGRAMMERS: Benedikt Freisen
9 /* INCLUDES *********************************************************/
13 /* FUNCTIONS ********************************************************/
18 STRETCHSKEW stretchSkew
;
23 ToolsModel toolsModel
;
25 SelectionModel selectionModel
;
30 LPTSTR textToolText
= NULL
;
31 int textToolTextMaxLen
= 0;
33 PaletteModel paletteModel
;
35 RegistrySettings registrySettings
;
37 ImageModel imageModel
;
38 BOOL askBeforeEnlarging
= FALSE
; // TODO: initialize from registry
41 CHOOSECOLOR choosecolor
;
55 HINSTANCE hProgInstance
;
58 TCHAR filepathname
[1000];
65 BOOL showGrid
= FALSE
;
66 BOOL showMiniature
= FALSE
;
68 CMainWindow mainWindow
;
69 CFullscreenWindow fullscreenWindow
;
70 CMiniatureWindow miniature
;
71 CToolBox toolBoxContainer
;
72 CToolSettingsWindow toolSettingsWindow
;
73 CPaletteWindow paletteWindow
;
74 CScrollboxWindow scrollboxWindow
;
75 CScrollboxWindow scrlClientWindow
;
76 CSelectionWindow selectionWindow
;
77 CImgAreaWindow imageArea
;
78 CSizeboxWindow sizeboxLeftTop
;
79 CSizeboxWindow sizeboxCenterTop
;
80 CSizeboxWindow sizeboxRightTop
;
81 CSizeboxWindow sizeboxLeftCenter
;
82 CSizeboxWindow sizeboxRightCenter
;
83 CSizeboxWindow sizeboxLeftBottom
;
84 CSizeboxWindow sizeboxCenterBottom
;
85 CSizeboxWindow sizeboxRightBottom
;
86 CTextEditWindow textEditWindow
;
91 _tWinMain (HINSTANCE hThisInstance
, HINSTANCE hPrevInstance
, LPTSTR lpszArgument
, int nFunsterStil
)
93 HWND hwnd
; /* This is the handle for our window */
94 MSG messages
; /* Here messages to the application are saved */
96 TCHAR progtitle
[1000];
102 TCHAR sfnFilename
[1000];
103 TCHAR sfnFiletitle
[256];
104 TCHAR sfnFilter
[1000];
105 TCHAR ofnFilename
[1000];
106 TCHAR ofnFiletitle
[256];
107 TCHAR ofnFilter
[1000];
108 TCHAR miniaturetitle
[100];
109 static int custColors
[16] = { 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff,
110 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff
113 /* init font for text tool */
114 lfTextFont
.lfHeight
= 0;
115 lfTextFont
.lfWidth
= 0;
116 lfTextFont
.lfEscapement
= 0;
117 lfTextFont
.lfOrientation
= 0;
118 lfTextFont
.lfWeight
= FW_NORMAL
;
119 lfTextFont
.lfItalic
= FALSE
;
120 lfTextFont
.lfUnderline
= FALSE
;
121 lfTextFont
.lfStrikeOut
= FALSE
;
122 lfTextFont
.lfCharSet
= DEFAULT_CHARSET
;
123 lfTextFont
.lfOutPrecision
= OUT_DEFAULT_PRECIS
;
124 lfTextFont
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
125 lfTextFont
.lfQuality
= DEFAULT_QUALITY
;
126 lfTextFont
.lfPitchAndFamily
= DEFAULT_PITCH
| FF_DONTCARE
;
127 lstrcpy(lfTextFont
.lfFaceName
, _T(""));
128 hfontTextFont
= CreateFontIndirect(&lfTextFont
);
130 hProgInstance
= hThisInstance
;
132 /* initialize common controls library */
133 InitCommonControls();
135 LoadString(hThisInstance
, IDS_DEFAULTFILENAME
, filename
, SIZEOF(filename
));
136 LoadString(hThisInstance
, IDS_WINDOWTITLE
, resstr
, SIZEOF(resstr
));
137 _stprintf(progtitle
, resstr
, filename
);
138 LoadString(hThisInstance
, IDS_MINIATURETITLE
, miniaturetitle
, SIZEOF(miniaturetitle
));
140 /* load settings from registry */
141 registrySettings
.Load();
142 showMiniature
= registrySettings
.ShowThumbnail
;
143 imageModel
.Crop(registrySettings
.BMPWidth
, registrySettings
.BMPHeight
);
145 /* create main window */
146 RECT mainWindowPos
= {0, 0, 544, 375}; // FIXME: use equivalent of CW_USEDEFAULT for position
147 hwnd
= mainWindow
.Create(HWND_DESKTOP
, mainWindowPos
, progtitle
, WS_OVERLAPPEDWINDOW
);
149 RECT fullscreenWindowPos
= {0, 0, 100, 100};
150 fullscreenWindow
.Create(HWND_DESKTOP
, fullscreenWindowPos
, NULL
, WS_POPUPWINDOW
| WS_MAXIMIZE
);
152 RECT miniaturePos
= {(LONG
) registrySettings
.ThumbXPos
, (LONG
) registrySettings
.ThumbYPos
,
153 (LONG
) registrySettings
.ThumbXPos
+ (LONG
) registrySettings
.ThumbWidth
,
154 (LONG
) registrySettings
.ThumbYPos
+ (LONG
) registrySettings
.ThumbHeight
};
155 miniature
.Create(hwnd
, miniaturePos
, miniaturetitle
,
156 WS_OVERLAPPED
| WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
, WS_EX_PALETTEWINDOW
);
157 miniature
.ShowWindow(showMiniature
? SW_SHOW
: SW_HIDE
);
159 /* loading and setting the window menu from resource */
160 menu
= LoadMenu(hThisInstance
, MAKEINTRESOURCE(ID_MENU
));
162 haccel
= LoadAccelerators(hThisInstance
, MAKEINTRESOURCE(800));
164 /* preloading the draw transparent/nontransparent icons for later use */
166 (HICON
) LoadImage(hThisInstance
, MAKEINTRESOURCE(IDI_NONTRANSPARENT
), IMAGE_ICON
, 40, 30, LR_DEFAULTCOLOR
);
168 (HICON
) LoadImage(hThisInstance
, MAKEINTRESOURCE(IDI_TRANSPARENT
), IMAGE_ICON
, 40, 30, LR_DEFAULTCOLOR
);
170 hCurFill
= LoadIcon(hThisInstance
, MAKEINTRESOURCE(IDC_FILL
));
171 hCurColor
= LoadIcon(hThisInstance
, MAKEINTRESOURCE(IDC_COLOR
));
172 hCurZoom
= LoadIcon(hThisInstance
, MAKEINTRESOURCE(IDC_ZOOM
));
173 hCurPen
= LoadIcon(hThisInstance
, MAKEINTRESOURCE(IDC_PEN
));
174 hCurAirbrush
= LoadIcon(hThisInstance
, MAKEINTRESOURCE(IDC_AIRBRUSH
));
176 CreateWindowEx(0, _T("STATIC"), NULL
, WS_CHILD
| WS_VISIBLE
| SS_ETCHEDHORZ
, 0, 0, 5000, 2, hwnd
, NULL
,
177 hThisInstance
, NULL
);
179 RECT toolBoxContainerPos
= {2, 2, 2 + 52, 2 + 350};
180 toolBoxContainer
.Create(hwnd
, toolBoxContainerPos
, NULL
, WS_CHILD
| WS_VISIBLE
);
181 /* creating the tool settings child window */
182 RECT toolSettingsWindowPos
= {5, 208, 5 + 42, 208 + 140};
183 toolSettingsWindow
.Create(toolBoxContainer
.m_hWnd
, toolSettingsWindowPos
, NULL
, WS_CHILD
| WS_VISIBLE
);
185 /* creating the palette child window */
186 RECT paletteWindowPos
= {56, 9, 56 + 255, 9 + 32};
187 paletteWindow
.Create(hwnd
, paletteWindowPos
, NULL
, WS_CHILD
| WS_VISIBLE
);
189 /* creating the scroll box */
190 RECT scrollboxWindowPos
= {56, 49, 56 + 472, 49 + 248};
191 scrollboxWindow
.Create(hwnd
, scrollboxWindowPos
, NULL
,
192 WS_CHILD
| WS_GROUP
| WS_HSCROLL
| WS_VSCROLL
| WS_VISIBLE
, WS_EX_CLIENTEDGE
);
194 /* creating the status bar */
196 CreateWindowEx(0, STATUSCLASSNAME
, NULL
, SBARS_SIZEGRIP
| WS_CHILD
| WS_VISIBLE
, 0, 0, 0, 0, hwnd
,
197 NULL
, hThisInstance
, NULL
);
198 SendMessage(hStatusBar
, SB_SETMINHEIGHT
, 21, 0);
200 RECT scrlClientWindowPos
= {0, 0, 0 + 500, 0 + 500};
201 scrlClientWindow
.Create(scrollboxWindow
.m_hWnd
, scrlClientWindowPos
, NULL
, WS_CHILD
| WS_VISIBLE
);
203 /* create selection window (initially hidden) */
204 RECT selectionWindowPos
= {350, 0, 350 + 100, 0 + 100};
205 selectionWindow
.Create(scrlClientWindow
.m_hWnd
, selectionWindowPos
, NULL
, WS_CHILD
| BS_OWNERDRAW
);
207 /* creating the window inside the scroll box, on which the image in hDrawingDC's bitmap is drawn */
208 RECT imageAreaPos
= {3, 3, 3 + imageModel
.GetWidth(), 3 + imageModel
.GetHeight()};
209 imageArea
.Create(scrlClientWindow
.m_hWnd
, imageAreaPos
, NULL
, WS_CHILD
| WS_VISIBLE
);
211 if (lpszArgument
[0] != 0)
213 HBITMAP bmNew
= NULL
;
214 LoadDIBFromFile(&bmNew
, lpszArgument
, &fileTime
, &fileSize
, &fileHPPM
, &fileVPPM
);
220 imageModel
.Insert(bmNew
);
221 GetFullPathName(lpszArgument
, SIZEOF(filepathname
), filepathname
, &temp
);
222 _tcscpy(filename
, temp
);
223 LoadString(hProgInstance
, IDS_WINDOWTITLE
, resstr
, SIZEOF(resstr
));
224 _stprintf(tempstr
, resstr
, filename
);
225 mainWindow
.SetWindowText(tempstr
);
226 imageModel
.ClearHistory();
235 /* initializing the CHOOSECOLOR structure for use with ChooseColor */
236 choosecolor
.lStructSize
= sizeof(CHOOSECOLOR
);
237 choosecolor
.hwndOwner
= hwnd
;
238 choosecolor
.hInstance
= NULL
;
239 choosecolor
.rgbResult
= 0x00ffffff;
240 choosecolor
.lpCustColors
= (COLORREF
*) &custColors
;
241 choosecolor
.Flags
= 0;
242 choosecolor
.lCustData
= 0;
243 choosecolor
.lpfnHook
= NULL
;
244 choosecolor
.lpTemplateName
= NULL
;
246 /* initializing the OPENFILENAME structure for use with GetOpenFileName and GetSaveFileName */
247 CopyMemory(ofnFilename
, filename
, sizeof(filename
));
248 LoadString(hThisInstance
, IDS_OPENFILTER
, ofnFilter
, SIZEOF(ofnFilter
));
249 for(c
= ofnFilter
; *c
; c
++)
252 ZeroMemory(&ofn
, sizeof(OPENFILENAME
));
253 ofn
.lStructSize
= sizeof(OPENFILENAME
);
254 ofn
.hwndOwner
= hwnd
;
255 ofn
.hInstance
= hThisInstance
;
256 ofn
.lpstrFilter
= ofnFilter
;
257 ofn
.lpstrFile
= ofnFilename
;
258 ofn
.nMaxFile
= SIZEOF(ofnFilename
);
259 ofn
.lpstrFileTitle
= ofnFiletitle
;
260 ofn
.nMaxFileTitle
= SIZEOF(ofnFiletitle
);
261 ofn
.Flags
= OFN_HIDEREADONLY
;
263 CopyMemory(sfnFilename
, filename
, sizeof(filename
));
264 LoadString(hThisInstance
, IDS_SAVEFILTER
, sfnFilter
, SIZEOF(sfnFilter
));
265 for(c
= sfnFilter
; *c
; c
++)
268 ZeroMemory(&sfn
, sizeof(OPENFILENAME
));
269 sfn
.lStructSize
= sizeof(OPENFILENAME
);
270 sfn
.hwndOwner
= hwnd
;
271 sfn
.hInstance
= hThisInstance
;
272 sfn
.lpstrFilter
= sfnFilter
;
273 sfn
.lpstrFile
= sfnFilename
;
274 sfn
.nMaxFile
= SIZEOF(sfnFilename
);
275 sfn
.lpstrFileTitle
= sfnFiletitle
;
276 sfn
.nMaxFileTitle
= SIZEOF(sfnFiletitle
);
277 sfn
.Flags
= OFN_OVERWRITEPROMPT
| OFN_HIDEREADONLY
;
279 /* creating the size boxes */
280 RECT sizeboxPos
= {0, 0, 0 + 3, 0 + 3};
281 sizeboxLeftTop
.Create(scrlClientWindow
.m_hWnd
, sizeboxPos
, NULL
, WS_CHILD
| WS_VISIBLE
);
282 sizeboxCenterTop
.Create(scrlClientWindow
.m_hWnd
, sizeboxPos
, NULL
, WS_CHILD
| WS_VISIBLE
);
283 sizeboxRightTop
.Create(scrlClientWindow
.m_hWnd
, sizeboxPos
, NULL
, WS_CHILD
| WS_VISIBLE
);
284 sizeboxLeftCenter
.Create(scrlClientWindow
.m_hWnd
, sizeboxPos
, NULL
, WS_CHILD
| WS_VISIBLE
);
285 sizeboxRightCenter
.Create(scrlClientWindow
.m_hWnd
, sizeboxPos
, NULL
, WS_CHILD
| WS_VISIBLE
);
286 sizeboxLeftBottom
.Create(scrlClientWindow
.m_hWnd
, sizeboxPos
, NULL
, WS_CHILD
| WS_VISIBLE
);
287 sizeboxCenterBottom
.Create(scrlClientWindow
.m_hWnd
, sizeboxPos
, NULL
, WS_CHILD
| WS_VISIBLE
);
288 sizeboxRightBottom
.Create(scrlClientWindow
.m_hWnd
, sizeboxPos
, NULL
, WS_CHILD
| WS_VISIBLE
);
289 /* placing the size boxes around the image */
290 imageArea
.SendMessage(WM_SIZE
, 0, 0);
292 /* by moving the window, the things in WM_SIZE are done */
293 mainWindow
.SetWindowPlacement(&(registrySettings
.WindowPlacement
));
295 /* creating the text editor window for the text tool */
296 RECT textEditWindowPos
= {300, 0, 300 + 300, 0 + 200};
297 textEditWindow
.Create(hwnd
, textEditWindowPos
, NULL
, WS_OVERLAPPEDWINDOW
);
299 /* Make the window visible on the screen */
300 ShowWindow (hwnd
, nFunsterStil
);
302 /* inform the system, that the main window accepts dropped files */
303 DragAcceptFiles(hwnd
, TRUE
);
305 /* Run the message loop. It will run until GetMessage() returns 0 */
306 while (GetMessage(&messages
, NULL
, 0, 0))
308 TranslateAccelerator(hwnd
, (HACCEL
) haccel
, &messages
);
310 /* Translate virtual-key messages into character messages */
311 TranslateMessage(&messages
);
312 /* Send message to WindowProcedure */
313 DispatchMessage(&messages
);
316 /* write back settings to registry */
317 registrySettings
.ShowThumbnail
= showMiniature
;
318 registrySettings
.BMPWidth
= imageModel
.GetWidth();
319 registrySettings
.BMPHeight
= imageModel
.GetHeight();
320 registrySettings
.Store();
322 /* The program return-value is 0 - The value that PostQuitMessage() gave */
323 return messages
.wParam
;