2 * PROJECT: PAINT for ReactOS
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
;
46 // global status variables
56 int airBrushWidth
= 5;
67 // global declarations and WinMain
70 // initial palette colors; may be changed by the user during execution
72 {0x000000, 0x464646, 0x787878, 0x300099, 0x241ced, 0x0078ff, 0x0ec2ff,
73 0x00f2ff, 0x1de6a8, 0x4cb122, 0xefb700, 0xf36d4d, 0x99362f, 0x98316f,
74 0xffffff, 0xdcdcdc, 0xb4b4b4, 0x3c5a9c, 0xb1a3ff, 0x7aaae5, 0x9ce4f5,
75 0xbdf9ff, 0xbcf9d3, 0x61bb9d, 0xead999, 0xd19a70, 0x8e6d54, 0xd5a5b5};
76 // foreground and background colors with initial value
77 int fgColor
= 0x00000000;
78 int bgColor
= 0x00ffffff;
79 // the current zoom in percent*10
85 CHOOSECOLOR choosecolor
;
101 HINSTANCE hProgInstance
;
104 TCHAR filepathname
[1000];
105 BOOL isAFile
= FALSE
;
107 BOOL showGrid
= FALSE
;
108 BOOL showMiniature
= FALSE
;
112 HWND hSizeboxLeftTop
;
113 HWND hSizeboxCenterTop
;
114 HWND hSizeboxRightTop
;
115 HWND hSizeboxLeftCenter
;
116 HWND hSizeboxRightCenter
;
117 HWND hSizeboxLeftBottom
;
118 HWND hSizeboxCenterBottom
;
119 HWND hSizeboxRightBottom
;
123 int WINAPI
_tWinMain (HINSTANCE hThisInstance
, HINSTANCE hPrevInstance
, LPTSTR lpszArgument
, int nFunsterStil
)
125 HWND hwnd
; /* This is the handle for our window */
126 MSG messages
; /* Here messages to the application are saved */
127 WNDCLASSEX wclScroll
;
130 WNDCLASSEX wclSettings
;
131 WNDCLASSEX wclSelection
;
132 TCHAR progtitle
[1000];
136 HIMAGELIST hImageList
;
140 TCHAR tooltips
[16][30];
142 TCHAR sfnFilename
[1000];
143 TCHAR sfnFiletitle
[256];
144 TCHAR sfnFilter
[1000];
145 TCHAR ofnFilename
[1000];
146 TCHAR ofnFiletitle
[256];
147 TCHAR ofnFilter
[1000];
148 TCHAR miniaturetitle
[100];
150 {0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff,
151 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff};
153 hProgInstance
= hThisInstance
;
156 InitCommonControls();
158 /* initializing and registering the window class used for the main window */
159 wincl
.hInstance
= hThisInstance
;
160 wincl
.lpszClassName
= _T("WindowsApp");
161 wincl
.lpfnWndProc
= WindowProcedure
;
162 wincl
.style
= CS_DBLCLKS
;
163 wincl
.cbSize
= sizeof (WNDCLASSEX
);
164 wincl
.hIcon
= LoadIcon (NULL
, IDI_APPLICATION
);
165 wincl
.hIconSm
= LoadIcon (hThisInstance
, MAKEINTRESOURCE(500));
166 wincl
.hCursor
= LoadCursor (NULL
, IDC_ARROW
);
167 wincl
.lpszMenuName
= NULL
;
168 wincl
.cbClsExtra
= 0;
169 wincl
.cbWndExtra
= 0;
170 wincl
.hbrBackground
= GetSysColorBrush(COLOR_BTNFACE
);
171 RegisterClassEx (&wincl
);
173 /* initializing and registering the window class used for the scroll box */
174 wclScroll
.hInstance
= hThisInstance
;
175 wclScroll
.lpszClassName
= _T("Scrollbox");
176 wclScroll
.lpfnWndProc
= WindowProcedure
;
178 wclScroll
.cbSize
= sizeof (WNDCLASSEX
);
179 wclScroll
.hIcon
= NULL
;
180 wclScroll
.hIconSm
= NULL
;
181 wclScroll
.hCursor
= LoadCursor (NULL
, IDC_ARROW
);
182 wclScroll
.lpszMenuName
= NULL
;
183 wclScroll
.cbClsExtra
= 0;
184 wclScroll
.cbWndExtra
= 0;
185 wclScroll
.hbrBackground
= GetSysColorBrush(COLOR_APPWORKSPACE
);
186 RegisterClassEx (&wclScroll
);
188 /* initializing and registering the window class used for the palette window */
189 wclPal
.hInstance
= hThisInstance
;
190 wclPal
.lpszClassName
= _T("Palette");
191 wclPal
.lpfnWndProc
= PalWinProc
;
192 wclPal
.style
= CS_DBLCLKS
;
193 wclPal
.cbSize
= sizeof (WNDCLASSEX
);
195 wclPal
.hIconSm
= NULL
;
196 wclPal
.hCursor
= LoadCursor (NULL
, IDC_ARROW
);
197 wclPal
.lpszMenuName
= NULL
;
198 wclPal
.cbClsExtra
= 0;
199 wclPal
.cbWndExtra
= 0;
200 wclPal
.hbrBackground
= GetSysColorBrush(COLOR_BTNFACE
);
201 RegisterClassEx (&wclPal
);
203 /* initializing and registering the window class for the settings window */
204 wclSettings
.hInstance
= hThisInstance
;
205 wclSettings
.lpszClassName
= _T("ToolSettings");
206 wclSettings
.lpfnWndProc
= SettingsWinProc
;
207 wclSettings
.style
= CS_DBLCLKS
;
208 wclSettings
.cbSize
= sizeof (WNDCLASSEX
);
209 wclSettings
.hIcon
= NULL
;
210 wclSettings
.hIconSm
= NULL
;
211 wclSettings
.hCursor
= LoadCursor (NULL
, IDC_ARROW
);
212 wclSettings
.lpszMenuName
= NULL
;
213 wclSettings
.cbClsExtra
= 0;
214 wclSettings
.cbWndExtra
= 0;
215 wclSettings
.hbrBackground
= GetSysColorBrush(COLOR_BTNFACE
);
216 RegisterClassEx (&wclSettings
);
218 /* initializing and registering the window class for the selection frame */
219 wclSelection
.hInstance
= hThisInstance
;
220 wclSelection
.lpszClassName
= _T("Selection");
221 wclSelection
.lpfnWndProc
= SelectionWinProc
;
222 wclSelection
.style
= CS_DBLCLKS
;
223 wclSelection
.cbSize
= sizeof (WNDCLASSEX
);
224 wclSelection
.hIcon
= NULL
;
225 wclSelection
.hIconSm
= NULL
;
226 wclSelection
.hCursor
= LoadCursor (NULL
, IDC_SIZEALL
);
227 wclSelection
.lpszMenuName
= NULL
;
228 wclSelection
.cbClsExtra
= 0;
229 wclSelection
.cbWndExtra
= 0;
230 wclSelection
.hbrBackground
= NULL
;//GetSysColorBrush(COLOR_BTNFACE);
231 RegisterClassEx (&wclSelection
);
233 /* initializing and registering the window class for the size boxes */
234 wclSettings
.hInstance
= hThisInstance
;
235 wclSettings
.lpszClassName
= _T("Sizebox");
236 wclSettings
.lpfnWndProc
= SizeboxWinProc
;
237 wclSettings
.style
= CS_DBLCLKS
;
238 wclSettings
.cbSize
= sizeof (WNDCLASSEX
);
239 wclSettings
.hIcon
= NULL
;
240 wclSettings
.hIconSm
= NULL
;
241 wclSettings
.hCursor
= LoadCursor (NULL
, IDC_ARROW
);
242 wclSettings
.lpszMenuName
= NULL
;
243 wclSettings
.cbClsExtra
= 0;
244 wclSettings
.cbWndExtra
= 0;
245 wclSettings
.hbrBackground
= GetSysColorBrush(COLOR_HIGHLIGHT
);
246 RegisterClassEx (&wclSettings
);
248 LoadString(hThisInstance
, IDS_DEFAULTFILENAME
, filename
, SIZEOF(filename
));
249 LoadString(hThisInstance
, IDS_WINDOWTITLE
, resstr
, SIZEOF(resstr
));
250 _stprintf(progtitle
, resstr
, filename
);
251 LoadString(hThisInstance
, IDS_MINIATURETITLE
, miniaturetitle
, SIZEOF(miniaturetitle
));
253 /* create main window */
254 hwnd
= CreateWindowEx (0, _T("WindowsApp"), progtitle
, WS_OVERLAPPEDWINDOW
, CW_USEDEFAULT
, CW_USEDEFAULT
, 544, 375, HWND_DESKTOP
, NULL
, hThisInstance
, NULL
);
257 hwndMiniature
= CreateWindowEx(WS_EX_PALETTEWINDOW
, _T("WindowsApp"), miniaturetitle
, WS_OVERLAPPED
| WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
, 180, 200, 120, 100, hwnd
, NULL
, hThisInstance
, NULL
);
259 /* loading and setting the window menu from resource */
260 menu
= LoadMenu(hThisInstance
, MAKEINTRESOURCE(ID_MENU
));
262 haccel
= LoadAccelerators(hThisInstance
, MAKEINTRESOURCE(800));
264 /* preloading the draw transparent/nontransparent icons for later use */
265 hNontranspIcon
= LoadImage(hThisInstance
, MAKEINTRESOURCE(IDI_NONTRANSPARENT
), IMAGE_ICON
, 40, 30, LR_DEFAULTCOLOR
);
266 hTranspIcon
= LoadImage(hThisInstance
, MAKEINTRESOURCE(IDI_TRANSPARENT
), IMAGE_ICON
, 40, 30, LR_DEFAULTCOLOR
);
268 hCurFill
= LoadIcon(hThisInstance
, MAKEINTRESOURCE(IDC_FILL
));
269 hCurColor
= LoadIcon(hThisInstance
, MAKEINTRESOURCE(IDC_COLOR
));
270 hCurZoom
= LoadIcon(hThisInstance
, MAKEINTRESOURCE(IDC_ZOOM
));
271 hCurPen
= LoadIcon(hThisInstance
, MAKEINTRESOURCE(IDC_PEN
));
272 hCurAirbrush
= LoadIcon(hThisInstance
, MAKEINTRESOURCE(IDC_AIRBRUSH
));
274 CreateWindowEx (0, _T("STATIC"), _T(""), WS_CHILD
| WS_VISIBLE
| SS_ETCHEDHORZ
, 0, 0, 5000, 2, hwnd
, NULL
, hThisInstance
, NULL
);
276 /* creating the 16 bitmap radio buttons and setting the bitmap */
279 /* FIXME: Unintentionally there is a line above the tool bar. To prevent cropping of the buttons height has been increased from 200 to 205 */
280 hToolbar
= CreateWindowEx(0, TOOLBARCLASSNAME
, NULL
, WS_CHILD
| WS_VISIBLE
| CCS_NOPARENTALIGN
| CCS_VERT
| CCS_NORESIZE
| TBSTYLE_TOOLTIPS
, 3, 3, 50, 205, hwnd
, NULL
, hThisInstance
, NULL
);
281 hImageList
= ImageList_Create(16, 16, ILC_COLOR24
| ILC_MASK
, 16, 0);
282 SendMessage(hToolbar
, TB_SETIMAGELIST
, 0, (LPARAM
)hImageList
);
283 tempBm
= LoadImage(hThisInstance
, MAKEINTRESOURCE(IDB_TOOLBARICONS
), IMAGE_BITMAP
, 256, 16, 0);
284 ImageList_AddMasked(hImageList
, tempBm
, 0xff00ff);
285 DeleteObject(tempBm
);
286 SendMessage(hToolbar
, TB_BUTTONSTRUCTSIZE
, sizeof(TBBUTTON
), 0);
292 if (i
% 2 == 1) wrapnow
= TBSTATE_WRAP
;
293 LoadString(hThisInstance
, IDS_TOOLTIP1
+ i
, tooltips
[i
], 30);
294 ZeroMemory(&tbbutton
, sizeof(TBBUTTON
));
295 tbbutton
.iString
= (INT_PTR
)tooltips
[i
];
296 tbbutton
.fsStyle
= TBSTYLE_CHECKGROUP
;
297 tbbutton
.fsState
= TBSTATE_ENABLED
| wrapnow
;
298 tbbutton
.idCommand
= ID_FREESEL
+ i
;
299 tbbutton
.iBitmap
= i
;
300 SendMessage(hToolbar
, TB_ADDBUTTONS
, 1, (LPARAM
)&tbbutton
);
302 /* SendMessage(hToolbar, TB_SETROWS, MAKEWPARAM(8, FALSE), (LPARAM)NULL); */
303 SendMessage(hToolbar
, TB_CHECKBUTTON
, ID_PEN
, MAKELONG(TRUE
, 0));
304 SendMessage(hToolbar
, TB_SETMAXTEXTROWS
, 0, 0);
306 SendMessage(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(25, 25));
307 /* SendMessage(hToolbar, TB_AUTOSIZE, 0, 0); */
309 /* creating the tool settings child window */
310 hToolSettings
= CreateWindowEx(0, _T("ToolSettings"), _T(""), WS_CHILD
| WS_VISIBLE
, 7, 210, 42, 140, hwnd
, NULL
, hThisInstance
, NULL
);
311 hTrackbarZoom
= CreateWindowEx(0, TRACKBAR_CLASS
, _T(""), WS_CHILD
| TBS_VERT
| TBS_AUTOTICKS
, 1, 1, 40, 64, hToolSettings
, NULL
, hThisInstance
, NULL
);
312 SendMessage(hTrackbarZoom
, TBM_SETRANGE
, (WPARAM
)TRUE
, (LPARAM
)MAKELONG(0, 6));
313 SendMessage(hTrackbarZoom
, TBM_SETPOS
, (WPARAM
)TRUE
, (LPARAM
)3);
315 /* creating the palette child window */
316 hPalWin
= CreateWindowEx(0, _T("Palette"), _T(""), WS_CHILD
| WS_VISIBLE
, 56, 9, 255, 32, hwnd
, NULL
, hThisInstance
, NULL
);
318 /* creating the scroll box */
319 hScrollbox
= CreateWindowEx (WS_EX_CLIENTEDGE
, _T("Scrollbox"), _T(""), WS_CHILD
| WS_GROUP
| WS_HSCROLL
| WS_VSCROLL
| WS_VISIBLE
, 56, 49, 472, 248, hwnd
, NULL
, hThisInstance
, NULL
);
321 /* creating the status bar */
322 hStatusBar
= CreateWindowEx (0, STATUSCLASSNAME
, _T(""), SBARS_SIZEGRIP
| WS_CHILD
| WS_VISIBLE
, 0, 0, 0, 0, hwnd
, NULL
, hThisInstance
, NULL
);
323 SendMessage(hStatusBar
, SB_SETMINHEIGHT
, 21, 0);
325 hScrlClient
= CreateWindowEx(0, _T("Scrollbox"), _T(""), WS_CHILD
| WS_VISIBLE
, 0, 0, 500, 500, hScrollbox
, NULL
, hThisInstance
, NULL
);
327 /* create selection window (initially hidden) */
328 hSelection
= CreateWindowEx(WS_EX_TRANSPARENT
, _T("Selection"), _T(""), WS_CHILD
| BS_OWNERDRAW
, 350, 0, 100, 100, hScrlClient
, NULL
, hThisInstance
, NULL
);
330 /* creating the window inside the scroll box, on which the image in hDrawingDC's bitmap is drawn */
331 hImageArea
= CreateWindowEx (0, _T("Scrollbox"), _T(""), WS_CHILD
| WS_VISIBLE
, 3, 3, imgXRes
, imgYRes
, hScrlClient
, NULL
, hThisInstance
, NULL
);
333 hDrawingDC
= CreateCompatibleDC(GetDC(hImageArea
));
334 hSelDC
= CreateCompatibleDC(GetDC(hImageArea
));
335 SelectObject(hDrawingDC
, CreatePen(PS_SOLID
, 0, fgColor
));
336 SelectObject(hDrawingDC
, CreateSolidBrush(bgColor
));
338 hBms
[0] = CreateDIBWithProperties(imgXRes
, imgYRes
);
339 SelectObject(hDrawingDC
, hBms
[0]);
340 Rectangle(hDrawingDC
, 0-1, 0-1, imgXRes
+1, imgYRes
+1);
342 /* initializing the CHOOSECOLOR structure for use with ChooseColor */
343 choosecolor
.lStructSize
= sizeof(CHOOSECOLOR
);
344 choosecolor
.hwndOwner
= hwnd
;
345 choosecolor
.hInstance
= NULL
;
346 choosecolor
.rgbResult
= 0x00ffffff;
347 choosecolor
.lpCustColors
= (COLORREF
*)&custColors
;
348 choosecolor
.Flags
= 0;
349 choosecolor
.lCustData
= 0;
350 choosecolor
.lpfnHook
= NULL
;
351 choosecolor
.lpTemplateName
= NULL
;
353 /* initializing the OPENFILENAME structure for use with GetOpenFileName and GetSaveFileName */
354 CopyMemory(ofnFilename
, filename
, sizeof(filename
));
355 LoadString(hThisInstance
, IDS_OPENFILTER
, ofnFilter
, SIZEOF(ofnFilter
));
356 for (c
= ofnFilter
; *c
; c
++) if (*c
== '\1') *c
= '\0';
357 ZeroMemory(&ofn
, sizeof(OPENFILENAME
));
358 ofn
.lStructSize
= sizeof (OPENFILENAME
);
359 ofn
.hwndOwner
= hwnd
;
360 ofn
.hInstance
= hThisInstance
;
361 ofn
.lpstrFilter
= ofnFilter
;
362 ofn
.lpstrFile
= ofnFilename
;
363 ofn
.nMaxFile
= SIZEOF(ofnFilename
);
364 ofn
.lpstrFileTitle
= ofnFiletitle
;
365 ofn
.nMaxFileTitle
= SIZEOF(ofnFiletitle
);
366 ofn
.Flags
= OFN_HIDEREADONLY
;
368 CopyMemory(sfnFilename
, filename
, sizeof(filename
));
369 LoadString(hThisInstance
, IDS_SAVEFILTER
, sfnFilter
, SIZEOF(sfnFilter
));
370 for (c
= sfnFilter
; *c
; c
++) if (*c
== '\1') *c
= '\0';
371 ZeroMemory(&sfn
, sizeof(OPENFILENAME
));
372 sfn
.lStructSize
= sizeof (OPENFILENAME
);
373 sfn
.hwndOwner
= hwnd
;
374 sfn
.hInstance
= hThisInstance
;
375 sfn
.lpstrFilter
= sfnFilter
;
376 sfn
.lpstrFile
= sfnFilename
;
377 sfn
.nMaxFile
= SIZEOF(sfnFilename
);
378 sfn
.lpstrFileTitle
= sfnFiletitle
;
379 sfn
.nMaxFileTitle
= SIZEOF(sfnFiletitle
);
380 sfn
.Flags
= OFN_OVERWRITEPROMPT
| OFN_HIDEREADONLY
;
382 hSizeboxLeftTop
= CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD
| WS_VISIBLE
, 0, 0, 3, 3, hScrlClient
, NULL
, hThisInstance
, NULL
);
383 hSizeboxCenterTop
= CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD
| WS_VISIBLE
, 0, 0, 3, 3, hScrlClient
, NULL
, hThisInstance
, NULL
);
384 hSizeboxRightTop
= CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD
| WS_VISIBLE
, 0, 0, 3, 3, hScrlClient
, NULL
, hThisInstance
, NULL
);
385 hSizeboxLeftCenter
= CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD
| WS_VISIBLE
, 0, 0, 3, 3, hScrlClient
, NULL
, hThisInstance
, NULL
);
386 hSizeboxRightCenter
= CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD
| WS_VISIBLE
, 0, 0, 3, 3, hScrlClient
, NULL
, hThisInstance
, NULL
);
387 hSizeboxLeftBottom
= CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD
| WS_VISIBLE
, 0, 0, 3, 3, hScrlClient
, NULL
, hThisInstance
, NULL
);
388 hSizeboxCenterBottom
= CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD
| WS_VISIBLE
, 0, 0, 3, 3, hScrlClient
, NULL
, hThisInstance
, NULL
);
389 hSizeboxRightBottom
= CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD
| WS_VISIBLE
, 0, 0, 3, 3, hScrlClient
, NULL
, hThisInstance
, NULL
);
390 SendMessage(hImageArea
, WM_SIZE
, 0, 0);
392 /* by moving the window, the things in WM_SIZE are done */
393 MoveWindow(hwnd
, 100, 100, 600, 450, TRUE
);
395 /* Make the window visible on the screen */
396 ShowWindow (hwnd
, nFunsterStil
);
398 /* Run the message loop. It will run until GetMessage() returns 0 */
399 while (GetMessage (&messages
, NULL
, 0, 0))
401 TranslateAccelerator(hwnd
, haccel
, &messages
);
403 /* Translate virtual-key messages into character messages */
404 TranslateMessage(&messages
);
405 /* Send message to WindowProcedure */
406 DispatchMessage(&messages
);
409 /* The program return-value is 0 - The value that PostQuitMessage() gave */
410 return messages
.wParam
;