2 * PROJECT: PAINT for ReactOS
4 * FILE: base/applications/paint/main.c
5 * PURPOSE: Initializing everything
6 * PROGRAMMERS: Benedikt Freisen
9 /* INCLUDES *********************************************************/
16 #include "definitions.h"
21 #include "globalvar.h"
27 #include "toolsettings.h"
28 #include "selection.h"
31 /* FUNCTIONS ********************************************************/
36 BITMAPINFO bitmapinfo
;
40 HBITMAP hBms
[HISTORYSIZE
];
44 BOOL imageSaved
= TRUE
;
54 int airBrushWidth
= 5;
65 /* initial palette colors; may be changed by the user during execution */
66 int palColors
[28] = { 0x000000, 0x464646, 0x787878, 0x300099, 0x241ced, 0x0078ff, 0x0ec2ff,
67 0x00f2ff, 0x1de6a8, 0x4cb122, 0xefb700, 0xf36d4d, 0x99362f, 0x98316f,
68 0xffffff, 0xdcdcdc, 0xb4b4b4, 0x3c5a9c, 0xb1a3ff, 0x7aaae5, 0x9ce4f5,
69 0xbdf9ff, 0xbcf9d3, 0x61bb9d, 0xead999, 0xd19a70, 0x8e6d54, 0xd5a5b5
72 /* foreground and background colors with initial value */
73 int fgColor
= 0x00000000;
74 int bgColor
= 0x00ffffff;
80 HWND hToolBoxContainer
;
83 CHOOSECOLOR choosecolor
;
99 HINSTANCE hProgInstance
;
102 TCHAR filepathname
[1000];
103 BOOL isAFile
= FALSE
;
109 BOOL showGrid
= FALSE
;
110 BOOL showMiniature
= FALSE
;
114 HWND hSizeboxLeftTop
;
115 HWND hSizeboxCenterTop
;
116 HWND hSizeboxRightTop
;
117 HWND hSizeboxLeftCenter
;
118 HWND hSizeboxRightCenter
;
119 HWND hSizeboxLeftBottom
;
120 HWND hSizeboxCenterBottom
;
121 HWND hSizeboxRightBottom
;
126 _tWinMain (HINSTANCE hThisInstance
, HINSTANCE hPrevInstance
, LPTSTR lpszArgument
, int nFunsterStil
)
128 HWND hwnd
; /* This is the handle for our window */
129 MSG messages
; /* Here messages to the application are saved */
131 WNDCLASSEX wclScroll
;
134 WNDCLASSEX wclSettings
;
135 WNDCLASSEX wclSelection
;
137 TCHAR progtitle
[1000];
141 HIMAGELIST hImageList
;
145 TCHAR tooltips
[16][30];
148 TCHAR sfnFilename
[1000];
149 TCHAR sfnFiletitle
[256];
150 TCHAR sfnFilter
[1000];
151 TCHAR ofnFilename
[1000];
152 TCHAR ofnFiletitle
[256];
153 TCHAR ofnFilter
[1000];
154 TCHAR miniaturetitle
[100];
155 int custColors
[16] = { 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff,
156 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff
159 hProgInstance
= hThisInstance
;
162 InitCommonControls();
164 /* initializing and registering the window class used for the main window */
165 wincl
.hInstance
= hThisInstance
;
166 wincl
.lpszClassName
= _T("WindowsApp");
167 wincl
.lpfnWndProc
= WindowProcedure
;
168 wincl
.style
= CS_DBLCLKS
;
169 wincl
.cbSize
= sizeof(WNDCLASSEX
);
170 wincl
.hIcon
= LoadIcon(NULL
, IDI_APPLICATION
);
171 wincl
.hIconSm
= LoadIcon(hThisInstance
, MAKEINTRESOURCE(500));
172 wincl
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
173 wincl
.lpszMenuName
= NULL
;
174 wincl
.cbClsExtra
= 0;
175 wincl
.cbWndExtra
= 0;
176 wincl
.hbrBackground
= GetSysColorBrush(COLOR_BTNFACE
);
177 RegisterClassEx (&wincl
);
179 /* initializing and registering the window class used for the scroll box */
180 wclScroll
.hInstance
= hThisInstance
;
181 wclScroll
.lpszClassName
= _T("Scrollbox");
182 wclScroll
.lpfnWndProc
= WindowProcedure
;
184 wclScroll
.cbSize
= sizeof(WNDCLASSEX
);
185 wclScroll
.hIcon
= NULL
;
186 wclScroll
.hIconSm
= NULL
;
187 wclScroll
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
188 wclScroll
.lpszMenuName
= NULL
;
189 wclScroll
.cbClsExtra
= 0;
190 wclScroll
.cbWndExtra
= 0;
191 wclScroll
.hbrBackground
= GetSysColorBrush(COLOR_APPWORKSPACE
);
192 RegisterClassEx (&wclScroll
);
194 /* initializing and registering the window class used for the palette window */
195 wclPal
.hInstance
= hThisInstance
;
196 wclPal
.lpszClassName
= _T("Palette");
197 wclPal
.lpfnWndProc
= PalWinProc
;
198 wclPal
.style
= CS_DBLCLKS
;
199 wclPal
.cbSize
= sizeof(WNDCLASSEX
);
201 wclPal
.hIconSm
= NULL
;
202 wclPal
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
203 wclPal
.lpszMenuName
= NULL
;
204 wclPal
.cbClsExtra
= 0;
205 wclPal
.cbWndExtra
= 0;
206 wclPal
.hbrBackground
= GetSysColorBrush(COLOR_BTNFACE
);
207 RegisterClassEx (&wclPal
);
209 /* initializing and registering the window class for the settings window */
210 wclSettings
.hInstance
= hThisInstance
;
211 wclSettings
.lpszClassName
= _T("ToolSettings");
212 wclSettings
.lpfnWndProc
= SettingsWinProc
;
213 wclSettings
.style
= CS_DBLCLKS
;
214 wclSettings
.cbSize
= sizeof(WNDCLASSEX
);
215 wclSettings
.hIcon
= NULL
;
216 wclSettings
.hIconSm
= NULL
;
217 wclSettings
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
218 wclSettings
.lpszMenuName
= NULL
;
219 wclSettings
.cbClsExtra
= 0;
220 wclSettings
.cbWndExtra
= 0;
221 wclSettings
.hbrBackground
= GetSysColorBrush(COLOR_BTNFACE
);
222 RegisterClassEx (&wclSettings
);
224 /* initializing and registering the window class for the selection frame */
225 wclSelection
.hInstance
= hThisInstance
;
226 wclSelection
.lpszClassName
= _T("Selection");
227 wclSelection
.lpfnWndProc
= SelectionWinProc
;
228 wclSelection
.style
= CS_DBLCLKS
;
229 wclSelection
.cbSize
= sizeof(WNDCLASSEX
);
230 wclSelection
.hIcon
= NULL
;
231 wclSelection
.hIconSm
= NULL
;
232 wclSelection
.hCursor
= LoadCursor(NULL
, IDC_SIZEALL
);
233 wclSelection
.lpszMenuName
= NULL
;
234 wclSelection
.cbClsExtra
= 0;
235 wclSelection
.cbWndExtra
= 0;
236 wclSelection
.hbrBackground
= NULL
;
237 RegisterClassEx (&wclSelection
);
239 /* initializing and registering the window class for the size boxes */
240 wclSettings
.hInstance
= hThisInstance
;
241 wclSettings
.lpszClassName
= _T("Sizebox");
242 wclSettings
.lpfnWndProc
= SizeboxWinProc
;
243 wclSettings
.style
= CS_DBLCLKS
;
244 wclSettings
.cbSize
= sizeof(WNDCLASSEX
);
245 wclSettings
.hIcon
= NULL
;
246 wclSettings
.hIconSm
= NULL
;
247 wclSettings
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
248 wclSettings
.lpszMenuName
= NULL
;
249 wclSettings
.cbClsExtra
= 0;
250 wclSettings
.cbWndExtra
= 0;
251 wclSettings
.hbrBackground
= GetSysColorBrush(COLOR_HIGHLIGHT
);
252 RegisterClassEx (&wclSettings
);
254 LoadString(hThisInstance
, IDS_DEFAULTFILENAME
, filename
, SIZEOF(filename
));
255 LoadString(hThisInstance
, IDS_WINDOWTITLE
, resstr
, SIZEOF(resstr
));
256 _stprintf(progtitle
, resstr
, filename
);
257 LoadString(hThisInstance
, IDS_MINIATURETITLE
, miniaturetitle
, SIZEOF(miniaturetitle
));
259 /* create main window */
261 CreateWindowEx(0, _T("WindowsApp"), progtitle
, WS_OVERLAPPEDWINDOW
, CW_USEDEFAULT
, CW_USEDEFAULT
, 544,
262 375, HWND_DESKTOP
, NULL
, hThisInstance
, NULL
);
266 CreateWindowEx(WS_EX_PALETTEWINDOW
, _T("WindowsApp"), miniaturetitle
,
267 WS_OVERLAPPED
| WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
, 180, 200, 120, 100, hwnd
,
268 NULL
, hThisInstance
, NULL
);
270 /* loading and setting the window menu from resource */
271 menu
= LoadMenu(hThisInstance
, MAKEINTRESOURCE(ID_MENU
));
273 haccel
= LoadAccelerators(hThisInstance
, MAKEINTRESOURCE(800));
275 /* preloading the draw transparent/nontransparent icons for later use */
277 LoadImage(hThisInstance
, MAKEINTRESOURCE(IDI_NONTRANSPARENT
), IMAGE_ICON
, 40, 30, LR_DEFAULTCOLOR
);
279 LoadImage(hThisInstance
, MAKEINTRESOURCE(IDI_TRANSPARENT
), IMAGE_ICON
, 40, 30, LR_DEFAULTCOLOR
);
281 hCurFill
= LoadIcon(hThisInstance
, MAKEINTRESOURCE(IDC_FILL
));
282 hCurColor
= LoadIcon(hThisInstance
, MAKEINTRESOURCE(IDC_COLOR
));
283 hCurZoom
= LoadIcon(hThisInstance
, MAKEINTRESOURCE(IDC_ZOOM
));
284 hCurPen
= LoadIcon(hThisInstance
, MAKEINTRESOURCE(IDC_PEN
));
285 hCurAirbrush
= LoadIcon(hThisInstance
, MAKEINTRESOURCE(IDC_AIRBRUSH
));
287 CreateWindowEx(0, _T("STATIC"), _T(""), WS_CHILD
| WS_VISIBLE
| SS_ETCHEDHORZ
, 0, 0, 5000, 2, hwnd
, NULL
,
288 hThisInstance
, NULL
);
291 CreateWindowEx(0, _T("WindowsApp"), _T(""), WS_CHILD
| WS_VISIBLE
, 2, 2, 52, 350, hwnd
, NULL
,
292 hThisInstance
, NULL
);
293 /* creating the 16 bitmap radio buttons and setting the bitmap */
297 * FIXME: Unintentionally there is a line above the tool bar.
298 * To prevent cropping of the buttons height has been increased from 200 to 205
301 CreateWindowEx(0, TOOLBARCLASSNAME
, NULL
,
302 WS_CHILD
| WS_VISIBLE
| CCS_NOPARENTALIGN
| CCS_VERT
| CCS_NORESIZE
| TBSTYLE_TOOLTIPS
,
303 1, 1, 50, 205, hToolBoxContainer
, NULL
, hThisInstance
, NULL
);
304 hImageList
= ImageList_Create(16, 16, ILC_COLOR24
| ILC_MASK
, 16, 0);
305 SendMessage(hToolbar
, TB_SETIMAGELIST
, 0, (LPARAM
) hImageList
);
306 tempBm
= LoadImage(hThisInstance
, MAKEINTRESOURCE(IDB_TOOLBARICONS
), IMAGE_BITMAP
, 256, 16, 0);
307 ImageList_AddMasked(hImageList
, tempBm
, 0xff00ff);
308 DeleteObject(tempBm
);
309 SendMessage(hToolbar
, TB_BUTTONSTRUCTSIZE
, sizeof(TBBUTTON
), 0);
311 for(i
= 0; i
< 16; i
++)
317 wrapnow
= TBSTATE_WRAP
;
319 LoadString(hThisInstance
, IDS_TOOLTIP1
+ i
, tooltips
[i
], 30);
320 ZeroMemory(&tbbutton
, sizeof(TBBUTTON
));
321 tbbutton
.iString
= (INT_PTR
) tooltips
[i
];
322 tbbutton
.fsStyle
= TBSTYLE_CHECKGROUP
;
323 tbbutton
.fsState
= TBSTATE_ENABLED
| wrapnow
;
324 tbbutton
.idCommand
= ID_FREESEL
+ i
;
325 tbbutton
.iBitmap
= i
;
326 SendMessage(hToolbar
, TB_ADDBUTTONS
, 1, (LPARAM
) &tbbutton
);
329 SendMessage(hToolbar
, TB_CHECKBUTTON
, ID_PEN
, MAKELONG(TRUE
, 0));
330 SendMessage(hToolbar
, TB_SETMAXTEXTROWS
, 0, 0);
331 SendMessage(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(25, 25));
333 /* creating the tool settings child window */
335 CreateWindowEx(0, _T("ToolSettings"), _T(""), WS_CHILD
| WS_VISIBLE
, 5, 208, 42, 140,
336 hToolBoxContainer
, NULL
, hThisInstance
, NULL
);
338 CreateWindowEx(0, TRACKBAR_CLASS
, _T(""), WS_CHILD
| TBS_VERT
| TBS_AUTOTICKS
, 1, 1, 40, 64,
339 hToolSettings
, NULL
, hThisInstance
, NULL
);
340 SendMessage(hTrackbarZoom
, TBM_SETRANGE
, (WPARAM
) TRUE
, (LPARAM
) MAKELONG(0, 6));
341 SendMessage(hTrackbarZoom
, TBM_SETPOS
, (WPARAM
) TRUE
, (LPARAM
) 3);
343 /* creating the palette child window */
345 CreateWindowEx(0, _T("Palette"), _T(""), WS_CHILD
| WS_VISIBLE
, 56, 9, 255, 32, hwnd
, NULL
,
346 hThisInstance
, NULL
);
348 /* creating the scroll box */
350 CreateWindowEx(WS_EX_CLIENTEDGE
, _T("Scrollbox"), _T(""),
351 WS_CHILD
| WS_GROUP
| WS_HSCROLL
| WS_VSCROLL
| WS_VISIBLE
, 56, 49, 472, 248, hwnd
,
352 NULL
, hThisInstance
, NULL
);
354 /* creating the status bar */
356 CreateWindowEx(0, STATUSCLASSNAME
, _T(""), SBARS_SIZEGRIP
| WS_CHILD
| WS_VISIBLE
, 0, 0, 0, 0, hwnd
,
357 NULL
, hThisInstance
, NULL
);
358 SendMessage(hStatusBar
, SB_SETMINHEIGHT
, 21, 0);
361 CreateWindowEx(0, _T("Scrollbox"), _T(""), WS_CHILD
| WS_VISIBLE
, 0, 0, 500, 500, hScrollbox
, NULL
,
362 hThisInstance
, NULL
);
364 /* create selection window (initially hidden) */
366 CreateWindowEx(WS_EX_TRANSPARENT
, _T("Selection"), _T(""), WS_CHILD
| BS_OWNERDRAW
, 350, 0, 100, 100,
367 hScrlClient
, NULL
, hThisInstance
, NULL
);
369 /* creating the window inside the scroll box, on which the image in hDrawingDC's bitmap is drawn */
371 CreateWindowEx(0, _T("Scrollbox"), _T(""), WS_CHILD
| WS_VISIBLE
, 3, 3, imgXRes
, imgYRes
, hScrlClient
,
372 NULL
, hThisInstance
, NULL
);
374 hDrawingDC
= CreateCompatibleDC(GetDC(hImageArea
));
375 hSelDC
= CreateCompatibleDC(GetDC(hImageArea
));
376 SelectObject(hDrawingDC
, CreatePen(PS_SOLID
, 0, fgColor
));
377 SelectObject(hDrawingDC
, CreateSolidBrush(bgColor
));
379 hBms
[0] = CreateDIBWithProperties(imgXRes
, imgYRes
);
380 SelectObject(hDrawingDC
, hBms
[0]);
381 Rectangle(hDrawingDC
, 0 - 1, 0 - 1, imgXRes
+ 1, imgYRes
+ 1);
383 if (lpszArgument
[0] != 0)
385 HBITMAP bmNew
= NULL
;
386 LoadDIBFromFile(&bmNew
, lpszArgument
, &fileTime
, &fileSize
, &fileHPPM
, &fileVPPM
);
392 insertReversible(bmNew
);
393 GetFullPathName(lpszArgument
, SIZEOF(filepathname
), filepathname
, &temp
);
394 _tcscpy(filename
, temp
);
395 LoadString(hProgInstance
, IDS_WINDOWTITLE
, resstr
, SIZEOF(resstr
));
396 _stprintf(tempstr
, resstr
, filename
);
397 SetWindowText(hMainWnd
, tempstr
);
403 /* initializing the CHOOSECOLOR structure for use with ChooseColor */
404 choosecolor
.lStructSize
= sizeof(CHOOSECOLOR
);
405 choosecolor
.hwndOwner
= hwnd
;
406 choosecolor
.hInstance
= NULL
;
407 choosecolor
.rgbResult
= 0x00ffffff;
408 choosecolor
.lpCustColors
= (COLORREF
*) &custColors
;
409 choosecolor
.Flags
= 0;
410 choosecolor
.lCustData
= 0;
411 choosecolor
.lpfnHook
= NULL
;
412 choosecolor
.lpTemplateName
= NULL
;
414 /* initializing the OPENFILENAME structure for use with GetOpenFileName and GetSaveFileName */
415 CopyMemory(ofnFilename
, filename
, sizeof(filename
));
416 LoadString(hThisInstance
, IDS_OPENFILTER
, ofnFilter
, SIZEOF(ofnFilter
));
417 for(c
= ofnFilter
; *c
; c
++)
420 ZeroMemory(&ofn
, sizeof(OPENFILENAME
));
421 ofn
.lStructSize
= sizeof(OPENFILENAME
);
422 ofn
.hwndOwner
= hwnd
;
423 ofn
.hInstance
= hThisInstance
;
424 ofn
.lpstrFilter
= ofnFilter
;
425 ofn
.lpstrFile
= ofnFilename
;
426 ofn
.nMaxFile
= SIZEOF(ofnFilename
);
427 ofn
.lpstrFileTitle
= ofnFiletitle
;
428 ofn
.nMaxFileTitle
= SIZEOF(ofnFiletitle
);
429 ofn
.Flags
= OFN_HIDEREADONLY
;
431 CopyMemory(sfnFilename
, filename
, sizeof(filename
));
432 LoadString(hThisInstance
, IDS_SAVEFILTER
, sfnFilter
, SIZEOF(sfnFilter
));
433 for(c
= sfnFilter
; *c
; c
++)
436 ZeroMemory(&sfn
, sizeof(OPENFILENAME
));
437 sfn
.lStructSize
= sizeof(OPENFILENAME
);
438 sfn
.hwndOwner
= hwnd
;
439 sfn
.hInstance
= hThisInstance
;
440 sfn
.lpstrFilter
= sfnFilter
;
441 sfn
.lpstrFile
= sfnFilename
;
442 sfn
.nMaxFile
= SIZEOF(sfnFilename
);
443 sfn
.lpstrFileTitle
= sfnFiletitle
;
444 sfn
.nMaxFileTitle
= SIZEOF(sfnFiletitle
);
445 sfn
.Flags
= OFN_OVERWRITEPROMPT
| OFN_HIDEREADONLY
;
447 /* creating the size boxes */
449 CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD
| WS_VISIBLE
, 0, 0, 3, 3, hScrlClient
, NULL
,
450 hThisInstance
, NULL
);
452 CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD
| WS_VISIBLE
, 0, 0, 3, 3, hScrlClient
, NULL
,
453 hThisInstance
, NULL
);
455 CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD
| WS_VISIBLE
, 0, 0, 3, 3, hScrlClient
, NULL
,
456 hThisInstance
, NULL
);
458 CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD
| WS_VISIBLE
, 0, 0, 3, 3, hScrlClient
, NULL
,
459 hThisInstance
, NULL
);
460 hSizeboxRightCenter
=
461 CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD
| WS_VISIBLE
, 0, 0, 3, 3, hScrlClient
, NULL
,
462 hThisInstance
, NULL
);
464 CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD
| WS_VISIBLE
, 0, 0, 3, 3, hScrlClient
, NULL
,
465 hThisInstance
, NULL
);
466 hSizeboxCenterBottom
=
467 CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD
| WS_VISIBLE
, 0, 0, 3, 3, hScrlClient
, NULL
,
468 hThisInstance
, NULL
);
469 hSizeboxRightBottom
=
470 CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD
| WS_VISIBLE
, 0, 0, 3, 3, hScrlClient
, NULL
,
471 hThisInstance
, NULL
);
472 /* placing the size boxes around the image */
473 SendMessage(hImageArea
, WM_SIZE
, 0, 0);
475 /* by moving the window, the things in WM_SIZE are done */
476 MoveWindow(hwnd
, 100, 100, 600, 450, TRUE
);
478 /* Make the window visible on the screen */
479 ShowWindow (hwnd
, nFunsterStil
);
481 /* Run the message loop. It will run until GetMessage() returns 0 */
482 while (GetMessage(&messages
, NULL
, 0, 0))
484 TranslateAccelerator(hwnd
, haccel
, &messages
);
486 /* Translate virtual-key messages into character messages */
487 TranslateMessage(&messages
);
488 /* Send message to WindowProcedure */
489 DispatchMessage(&messages
);
492 /* The program return-value is 0 - The value that PostQuitMessage() gave */
493 return messages
.wParam
;