2 * PROJECT: PAINT for ReactOS
4 * FILE: base/applications/paint/main.c
5 * PURPOSE: Initializing everything
6 * PROGRAMMERS: Benedikt Freisen
9 /* INCLUDES *********************************************************/
13 /* FUNCTIONS ********************************************************/
18 BITMAPINFO bitmapinfo
;
22 HBITMAP hBms
[HISTORYSIZE
];
26 BOOL imageSaved
= TRUE
;
35 int activeTool
= TOOL_PEN
;
36 int airBrushWidth
= 5;
47 /* initial palette colors; may be changed by the user during execution */
48 int palColors
[28] = { 0x000000, 0x464646, 0x787878, 0x300099, 0x241ced, 0x0078ff, 0x0ec2ff,
49 0x00f2ff, 0x1de6a8, 0x4cb122, 0xefb700, 0xf36d4d, 0x99362f, 0x98316f,
50 0xffffff, 0xdcdcdc, 0xb4b4b4, 0x3c5a9c, 0xb1a3ff, 0x7aaae5, 0x9ce4f5,
51 0xbdf9ff, 0xbcf9d3, 0x61bb9d, 0xead999, 0xd19a70, 0x8e6d54, 0xd5a5b5
54 /* foreground and background colors with initial value */
55 int fgColor
= 0x00000000;
56 int bgColor
= 0x00ffffff;
62 HWND hToolBoxContainer
;
65 CHOOSECOLOR choosecolor
;
81 HINSTANCE hProgInstance
;
84 TCHAR filepathname
[1000];
91 BOOL showGrid
= FALSE
;
92 BOOL showMiniature
= FALSE
;
97 HWND hSizeboxCenterTop
;
98 HWND hSizeboxRightTop
;
99 HWND hSizeboxLeftCenter
;
100 HWND hSizeboxRightCenter
;
101 HWND hSizeboxLeftBottom
;
102 HWND hSizeboxCenterBottom
;
103 HWND hSizeboxRightBottom
;
108 _tWinMain (HINSTANCE hThisInstance
, HINSTANCE hPrevInstance
, LPTSTR lpszArgument
, int nFunsterStil
)
110 HWND hwnd
; /* This is the handle for our window */
111 MSG messages
; /* Here messages to the application are saved */
113 WNDCLASSEX wclScroll
;
116 WNDCLASSEX wclSettings
;
117 WNDCLASSEX wclSelection
;
119 TCHAR progtitle
[1000];
123 HIMAGELIST hImageList
;
127 TCHAR tooltips
[16][30];
131 TCHAR sfnFilename
[1000];
132 TCHAR sfnFiletitle
[256];
133 TCHAR sfnFilter
[1000];
134 TCHAR ofnFilename
[1000];
135 TCHAR ofnFiletitle
[256];
136 TCHAR ofnFilter
[1000];
137 TCHAR miniaturetitle
[100];
138 static int custColors
[16] = { 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff,
139 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff
142 hProgInstance
= hThisInstance
;
145 InitCommonControls();
147 /* initializing and registering the window class used for the main window */
148 wincl
.hInstance
= hThisInstance
;
149 wincl
.lpszClassName
= _T("WindowsApp");
150 wincl
.lpfnWndProc
= WindowProcedure
;
151 wincl
.style
= CS_DBLCLKS
;
152 wincl
.cbSize
= sizeof(WNDCLASSEX
);
153 wincl
.hIcon
= LoadIcon(hThisInstance
, MAKEINTRESOURCE(IDI_APPICON
));
154 wincl
.hIconSm
= LoadIcon(hThisInstance
, MAKEINTRESOURCE(IDI_APPICON
));
155 wincl
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
156 wincl
.lpszMenuName
= NULL
;
157 wincl
.cbClsExtra
= 0;
158 wincl
.cbWndExtra
= 0;
159 wincl
.hbrBackground
= GetSysColorBrush(COLOR_BTNFACE
);
160 RegisterClassEx (&wincl
);
162 /* initializing and registering the window class used for the scroll box */
163 wclScroll
.hInstance
= hThisInstance
;
164 wclScroll
.lpszClassName
= _T("Scrollbox");
165 wclScroll
.lpfnWndProc
= WindowProcedure
;
167 wclScroll
.cbSize
= sizeof(WNDCLASSEX
);
168 wclScroll
.hIcon
= NULL
;
169 wclScroll
.hIconSm
= NULL
;
170 wclScroll
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
171 wclScroll
.lpszMenuName
= NULL
;
172 wclScroll
.cbClsExtra
= 0;
173 wclScroll
.cbWndExtra
= 0;
174 wclScroll
.hbrBackground
= GetSysColorBrush(COLOR_APPWORKSPACE
);
175 RegisterClassEx (&wclScroll
);
177 /* initializing and registering the window class used for the palette window */
178 wclPal
.hInstance
= hThisInstance
;
179 wclPal
.lpszClassName
= _T("Palette");
180 wclPal
.lpfnWndProc
= PalWinProc
;
181 wclPal
.style
= CS_DBLCLKS
;
182 wclPal
.cbSize
= sizeof(WNDCLASSEX
);
184 wclPal
.hIconSm
= NULL
;
185 wclPal
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
186 wclPal
.lpszMenuName
= NULL
;
187 wclPal
.cbClsExtra
= 0;
188 wclPal
.cbWndExtra
= 0;
189 wclPal
.hbrBackground
= GetSysColorBrush(COLOR_BTNFACE
);
190 RegisterClassEx (&wclPal
);
192 /* initializing and registering the window class for the settings window */
193 wclSettings
.hInstance
= hThisInstance
;
194 wclSettings
.lpszClassName
= _T("ToolSettings");
195 wclSettings
.lpfnWndProc
= SettingsWinProc
;
196 wclSettings
.style
= CS_DBLCLKS
;
197 wclSettings
.cbSize
= sizeof(WNDCLASSEX
);
198 wclSettings
.hIcon
= NULL
;
199 wclSettings
.hIconSm
= NULL
;
200 wclSettings
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
201 wclSettings
.lpszMenuName
= NULL
;
202 wclSettings
.cbClsExtra
= 0;
203 wclSettings
.cbWndExtra
= 0;
204 wclSettings
.hbrBackground
= GetSysColorBrush(COLOR_BTNFACE
);
205 RegisterClassEx (&wclSettings
);
207 /* initializing and registering the window class for the selection frame */
208 wclSelection
.hInstance
= hThisInstance
;
209 wclSelection
.lpszClassName
= _T("Selection");
210 wclSelection
.lpfnWndProc
= SelectionWinProc
;
211 wclSelection
.style
= CS_DBLCLKS
;
212 wclSelection
.cbSize
= sizeof(WNDCLASSEX
);
213 wclSelection
.hIcon
= NULL
;
214 wclSelection
.hIconSm
= NULL
;
215 wclSelection
.hCursor
= LoadCursor(NULL
, IDC_SIZEALL
);
216 wclSelection
.lpszMenuName
= NULL
;
217 wclSelection
.cbClsExtra
= 0;
218 wclSelection
.cbWndExtra
= 0;
219 wclSelection
.hbrBackground
= NULL
;
220 RegisterClassEx (&wclSelection
);
222 /* initializing and registering the window class for the size boxes */
223 wclSettings
.hInstance
= hThisInstance
;
224 wclSettings
.lpszClassName
= _T("Sizebox");
225 wclSettings
.lpfnWndProc
= SizeboxWinProc
;
226 wclSettings
.style
= CS_DBLCLKS
;
227 wclSettings
.cbSize
= sizeof(WNDCLASSEX
);
228 wclSettings
.hIcon
= NULL
;
229 wclSettings
.hIconSm
= NULL
;
230 wclSettings
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
231 wclSettings
.lpszMenuName
= NULL
;
232 wclSettings
.cbClsExtra
= 0;
233 wclSettings
.cbWndExtra
= 0;
234 wclSettings
.hbrBackground
= GetSysColorBrush(COLOR_HIGHLIGHT
);
235 RegisterClassEx (&wclSettings
);
237 LoadString(hThisInstance
, IDS_DEFAULTFILENAME
, filename
, SIZEOF(filename
));
238 LoadString(hThisInstance
, IDS_WINDOWTITLE
, resstr
, SIZEOF(resstr
));
239 _stprintf(progtitle
, resstr
, filename
);
240 LoadString(hThisInstance
, IDS_MINIATURETITLE
, miniaturetitle
, SIZEOF(miniaturetitle
));
242 /* create main window */
244 CreateWindowEx(0, _T("WindowsApp"), progtitle
, WS_OVERLAPPEDWINDOW
, CW_USEDEFAULT
, CW_USEDEFAULT
, 544,
245 375, HWND_DESKTOP
, NULL
, hThisInstance
, NULL
);
249 CreateWindowEx(WS_EX_PALETTEWINDOW
, _T("WindowsApp"), miniaturetitle
,
250 WS_OVERLAPPED
| WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
, 180, 200, 120, 100, hwnd
,
251 NULL
, hThisInstance
, NULL
);
253 /* loading and setting the window menu from resource */
254 menu
= LoadMenu(hThisInstance
, MAKEINTRESOURCE(ID_MENU
));
256 haccel
= LoadAccelerators(hThisInstance
, MAKEINTRESOURCE(800));
258 /* preloading the draw transparent/nontransparent icons for later use */
260 LoadImage(hThisInstance
, MAKEINTRESOURCE(IDI_NONTRANSPARENT
), IMAGE_ICON
, 40, 30, LR_DEFAULTCOLOR
);
262 LoadImage(hThisInstance
, MAKEINTRESOURCE(IDI_TRANSPARENT
), IMAGE_ICON
, 40, 30, LR_DEFAULTCOLOR
);
264 hCurFill
= LoadIcon(hThisInstance
, MAKEINTRESOURCE(IDC_FILL
));
265 hCurColor
= LoadIcon(hThisInstance
, MAKEINTRESOURCE(IDC_COLOR
));
266 hCurZoom
= LoadIcon(hThisInstance
, MAKEINTRESOURCE(IDC_ZOOM
));
267 hCurPen
= LoadIcon(hThisInstance
, MAKEINTRESOURCE(IDC_PEN
));
268 hCurAirbrush
= LoadIcon(hThisInstance
, MAKEINTRESOURCE(IDC_AIRBRUSH
));
270 CreateWindowEx(0, _T("STATIC"), _T(""), WS_CHILD
| WS_VISIBLE
| SS_ETCHEDHORZ
, 0, 0, 5000, 2, hwnd
, NULL
,
271 hThisInstance
, NULL
);
274 CreateWindowEx(0, _T("WindowsApp"), _T(""), WS_CHILD
| WS_VISIBLE
, 2, 2, 52, 350, hwnd
, NULL
,
275 hThisInstance
, NULL
);
276 /* creating the 16 bitmap radio buttons and setting the bitmap */
280 * FIXME: Unintentionally there is a line above the tool bar.
281 * To prevent cropping of the buttons height has been increased from 200 to 205
284 CreateWindowEx(0, TOOLBARCLASSNAME
, NULL
,
285 WS_CHILD
| WS_VISIBLE
| CCS_NOPARENTALIGN
| CCS_VERT
| CCS_NORESIZE
| TBSTYLE_TOOLTIPS
,
286 1, 1, 50, 205, hToolBoxContainer
, NULL
, hThisInstance
, NULL
);
287 hImageList
= ImageList_Create(16, 16, ILC_COLOR24
| ILC_MASK
, 16, 0);
288 SendMessage(hToolbar
, TB_SETIMAGELIST
, 0, (LPARAM
) hImageList
);
289 tempBm
= LoadImage(hThisInstance
, MAKEINTRESOURCE(IDB_TOOLBARICONS
), IMAGE_BITMAP
, 256, 16, 0);
290 ImageList_AddMasked(hImageList
, tempBm
, 0xff00ff);
291 DeleteObject(tempBm
);
292 SendMessage(hToolbar
, TB_BUTTONSTRUCTSIZE
, sizeof(TBBUTTON
), 0);
294 for(i
= 0; i
< 16; i
++)
300 wrapnow
= TBSTATE_WRAP
;
302 LoadString(hThisInstance
, IDS_TOOLTIP1
+ i
, tooltips
[i
], 30);
303 ZeroMemory(&tbbutton
, sizeof(TBBUTTON
));
304 tbbutton
.iString
= (INT_PTR
) tooltips
[i
];
305 tbbutton
.fsStyle
= TBSTYLE_CHECKGROUP
;
306 tbbutton
.fsState
= TBSTATE_ENABLED
| wrapnow
;
307 tbbutton
.idCommand
= ID_FREESEL
+ i
;
308 tbbutton
.iBitmap
= i
;
309 SendMessage(hToolbar
, TB_ADDBUTTONS
, 1, (LPARAM
) &tbbutton
);
312 SendMessage(hToolbar
, TB_CHECKBUTTON
, ID_PEN
, MAKELONG(TRUE
, 0));
313 SendMessage(hToolbar
, TB_SETMAXTEXTROWS
, 0, 0);
314 SendMessage(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(25, 25));
316 /* creating the tool settings child window */
318 CreateWindowEx(0, _T("ToolSettings"), _T(""), WS_CHILD
| WS_VISIBLE
, 5, 208, 42, 140,
319 hToolBoxContainer
, NULL
, hThisInstance
, NULL
);
321 CreateWindowEx(0, TRACKBAR_CLASS
, _T(""), WS_CHILD
| TBS_VERT
| TBS_AUTOTICKS
, 1, 1, 40, 64,
322 hToolSettings
, NULL
, hThisInstance
, NULL
);
323 SendMessage(hTrackbarZoom
, TBM_SETRANGE
, (WPARAM
) TRUE
, (LPARAM
) MAKELONG(0, 6));
324 SendMessage(hTrackbarZoom
, TBM_SETPOS
, (WPARAM
) TRUE
, (LPARAM
) 3);
326 /* creating the palette child window */
328 CreateWindowEx(0, _T("Palette"), _T(""), WS_CHILD
| WS_VISIBLE
, 56, 9, 255, 32, hwnd
, NULL
,
329 hThisInstance
, NULL
);
331 /* creating the scroll box */
333 CreateWindowEx(WS_EX_CLIENTEDGE
, _T("Scrollbox"), _T(""),
334 WS_CHILD
| WS_GROUP
| WS_HSCROLL
| WS_VSCROLL
| WS_VISIBLE
, 56, 49, 472, 248, hwnd
,
335 NULL
, hThisInstance
, NULL
);
337 /* creating the status bar */
339 CreateWindowEx(0, STATUSCLASSNAME
, _T(""), SBARS_SIZEGRIP
| WS_CHILD
| WS_VISIBLE
, 0, 0, 0, 0, hwnd
,
340 NULL
, hThisInstance
, NULL
);
341 SendMessage(hStatusBar
, SB_SETMINHEIGHT
, 21, 0);
344 CreateWindowEx(0, _T("Scrollbox"), _T(""), WS_CHILD
| WS_VISIBLE
, 0, 0, 500, 500, hScrollbox
, NULL
,
345 hThisInstance
, NULL
);
347 /* create selection window (initially hidden) */
349 CreateWindowEx(WS_EX_TRANSPARENT
, _T("Selection"), _T(""), WS_CHILD
| BS_OWNERDRAW
, 350, 0, 100, 100,
350 hScrlClient
, NULL
, hThisInstance
, NULL
);
352 /* creating the window inside the scroll box, on which the image in hDrawingDC's bitmap is drawn */
354 CreateWindowEx(0, _T("Scrollbox"), _T(""), WS_CHILD
| WS_VISIBLE
, 3, 3, imgXRes
, imgYRes
, hScrlClient
,
355 NULL
, hThisInstance
, NULL
);
357 hDC
= GetDC(hImageArea
);
358 hDrawingDC
= CreateCompatibleDC(hDC
);
359 hSelDC
= CreateCompatibleDC(hDC
);
360 ReleaseDC(hImageArea
, hDC
);
361 SelectObject(hDrawingDC
, CreatePen(PS_SOLID
, 0, fgColor
));
362 SelectObject(hDrawingDC
, CreateSolidBrush(bgColor
));
364 hBms
[0] = CreateDIBWithProperties(imgXRes
, imgYRes
);
365 SelectObject(hDrawingDC
, hBms
[0]);
366 Rectangle(hDrawingDC
, 0 - 1, 0 - 1, imgXRes
+ 1, imgYRes
+ 1);
368 if (lpszArgument
[0] != 0)
370 HBITMAP bmNew
= NULL
;
371 LoadDIBFromFile(&bmNew
, lpszArgument
, &fileTime
, &fileSize
, &fileHPPM
, &fileVPPM
);
377 insertReversible(bmNew
);
378 GetFullPathName(lpszArgument
, SIZEOF(filepathname
), filepathname
, &temp
);
379 _tcscpy(filename
, temp
);
380 LoadString(hProgInstance
, IDS_WINDOWTITLE
, resstr
, SIZEOF(resstr
));
381 _stprintf(tempstr
, resstr
, filename
);
382 SetWindowText(hMainWnd
, tempstr
);
388 /* initializing the CHOOSECOLOR structure for use with ChooseColor */
389 choosecolor
.lStructSize
= sizeof(CHOOSECOLOR
);
390 choosecolor
.hwndOwner
= hwnd
;
391 choosecolor
.hInstance
= NULL
;
392 choosecolor
.rgbResult
= 0x00ffffff;
393 choosecolor
.lpCustColors
= (COLORREF
*) &custColors
;
394 choosecolor
.Flags
= 0;
395 choosecolor
.lCustData
= 0;
396 choosecolor
.lpfnHook
= NULL
;
397 choosecolor
.lpTemplateName
= NULL
;
399 /* initializing the OPENFILENAME structure for use with GetOpenFileName and GetSaveFileName */
400 CopyMemory(ofnFilename
, filename
, sizeof(filename
));
401 LoadString(hThisInstance
, IDS_OPENFILTER
, ofnFilter
, SIZEOF(ofnFilter
));
402 for(c
= ofnFilter
; *c
; c
++)
405 ZeroMemory(&ofn
, sizeof(OPENFILENAME
));
406 ofn
.lStructSize
= sizeof(OPENFILENAME
);
407 ofn
.hwndOwner
= hwnd
;
408 ofn
.hInstance
= hThisInstance
;
409 ofn
.lpstrFilter
= ofnFilter
;
410 ofn
.lpstrFile
= ofnFilename
;
411 ofn
.nMaxFile
= SIZEOF(ofnFilename
);
412 ofn
.lpstrFileTitle
= ofnFiletitle
;
413 ofn
.nMaxFileTitle
= SIZEOF(ofnFiletitle
);
414 ofn
.Flags
= OFN_HIDEREADONLY
;
416 CopyMemory(sfnFilename
, filename
, sizeof(filename
));
417 LoadString(hThisInstance
, IDS_SAVEFILTER
, sfnFilter
, SIZEOF(sfnFilter
));
418 for(c
= sfnFilter
; *c
; c
++)
421 ZeroMemory(&sfn
, sizeof(OPENFILENAME
));
422 sfn
.lStructSize
= sizeof(OPENFILENAME
);
423 sfn
.hwndOwner
= hwnd
;
424 sfn
.hInstance
= hThisInstance
;
425 sfn
.lpstrFilter
= sfnFilter
;
426 sfn
.lpstrFile
= sfnFilename
;
427 sfn
.nMaxFile
= SIZEOF(sfnFilename
);
428 sfn
.lpstrFileTitle
= sfnFiletitle
;
429 sfn
.nMaxFileTitle
= SIZEOF(sfnFiletitle
);
430 sfn
.Flags
= OFN_OVERWRITEPROMPT
| OFN_HIDEREADONLY
;
432 /* creating the size boxes */
434 CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD
| WS_VISIBLE
, 0, 0, 3, 3, hScrlClient
, NULL
,
435 hThisInstance
, NULL
);
437 CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD
| WS_VISIBLE
, 0, 0, 3, 3, hScrlClient
, NULL
,
438 hThisInstance
, NULL
);
440 CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD
| WS_VISIBLE
, 0, 0, 3, 3, hScrlClient
, NULL
,
441 hThisInstance
, NULL
);
443 CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD
| WS_VISIBLE
, 0, 0, 3, 3, hScrlClient
, NULL
,
444 hThisInstance
, NULL
);
445 hSizeboxRightCenter
=
446 CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD
| WS_VISIBLE
, 0, 0, 3, 3, hScrlClient
, NULL
,
447 hThisInstance
, NULL
);
449 CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD
| WS_VISIBLE
, 0, 0, 3, 3, hScrlClient
, NULL
,
450 hThisInstance
, NULL
);
451 hSizeboxCenterBottom
=
452 CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD
| WS_VISIBLE
, 0, 0, 3, 3, hScrlClient
, NULL
,
453 hThisInstance
, NULL
);
454 hSizeboxRightBottom
=
455 CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD
| WS_VISIBLE
, 0, 0, 3, 3, hScrlClient
, NULL
,
456 hThisInstance
, NULL
);
457 /* placing the size boxes around the image */
458 SendMessage(hImageArea
, WM_SIZE
, 0, 0);
460 /* by moving the window, the things in WM_SIZE are done */
461 MoveWindow(hwnd
, 100, 100, 600, 450, TRUE
);
463 /* Make the window visible on the screen */
464 ShowWindow (hwnd
, nFunsterStil
);
466 /* Run the message loop. It will run until GetMessage() returns 0 */
467 while (GetMessage(&messages
, NULL
, 0, 0))
469 TranslateAccelerator(hwnd
, haccel
, &messages
);
471 /* Translate virtual-key messages into character messages */
472 TranslateMessage(&messages
);
473 /* Send message to WindowProcedure */
474 DispatchMessage(&messages
);
477 /* The program return-value is 0 - The value that PostQuitMessage() gave */
478 return messages
.wParam
;