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"
30 /* FUNCTIONS ********************************************************/
35 BITMAPINFO bitmapinfo
;
44 // global status variables
54 int airBrushWidth
= 5;
65 // global declarations and WinMain
68 // initial palette colors; may be changed by the user during execution
70 {0x000000, 0x464646, 0x787878, 0x300099, 0x241ced, 0x0078ff, 0x0ec2ff,
71 0x00f2ff, 0x1de6a8, 0x4cb122, 0xefb700, 0xf36d4d, 0x99362f, 0x98316f,
72 0xffffff, 0xdcdcdc, 0xb4b4b4, 0x3c5a9c, 0xb1a3ff, 0x7aaae5, 0x9ce4f5,
73 0xbdf9ff, 0xbcf9d3, 0x61bb9d, 0xead999, 0xd19a70, 0x8e6d54, 0xd5a5b5};
74 // foreground and background colors with initial value
75 int fgColor
= 0x00000000;
76 int bgColor
= 0x00ffffff;
77 // the current zoom in percent*10
83 CHOOSECOLOR choosecolor
;
99 HINSTANCE hProgInstance
;
102 TCHAR filepathname
[1000];
103 BOOL isAFile
= FALSE
;
105 BOOL showGrid
= FALSE
;
106 BOOL showMiniature
= FALSE
;
110 int WINAPI
_tWinMain (HINSTANCE hThisInstance
, HINSTANCE hPrevInstance
, LPTSTR lpszArgument
, int nFunsterStil
)
112 HWND hwnd
; /* This is the handle for our window */
113 MSG messages
; /* Here messages to the application are saved */
114 WNDCLASSEX wclScroll
;
117 WNDCLASSEX wclSettings
;
118 WNDCLASSEX wclSelection
;
119 TCHAR progtitle
[1000];
123 HIMAGELIST hImageList
;
127 TCHAR tooltips
[16][30];
129 TCHAR sfnFilename
[1000];
130 TCHAR sfnFiletitle
[256];
131 TCHAR sfnFilter
[1000];
132 TCHAR ofnFilename
[1000];
133 TCHAR ofnFiletitle
[256];
134 TCHAR ofnFilter
[1000];
135 TCHAR miniaturetitle
[100];
137 {0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff,
138 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff};
140 hProgInstance
= hThisInstance
;
143 InitCommonControls();
145 /* initializing and registering the window class used for the main window */
146 wincl
.hInstance
= hThisInstance
;
147 wincl
.lpszClassName
= _T("WindowsApp");
148 wincl
.lpfnWndProc
= WindowProcedure
;
149 wincl
.style
= CS_DBLCLKS
;
150 wincl
.cbSize
= sizeof (WNDCLASSEX
);
151 wincl
.hIcon
= LoadIcon (NULL
, IDI_APPLICATION
);
152 wincl
.hIconSm
= LoadIcon (hThisInstance
, MAKEINTRESOURCE(500));
153 wincl
.hCursor
= LoadCursor (NULL
, IDC_ARROW
);
154 wincl
.lpszMenuName
= NULL
;
155 wincl
.cbClsExtra
= 0;
156 wincl
.cbWndExtra
= 0;
157 wincl
.hbrBackground
= GetSysColorBrush(COLOR_BTNFACE
);
158 RegisterClassEx (&wincl
);
160 /* initializing and registering the window class used for the scroll box */
161 wclScroll
.hInstance
= hThisInstance
;
162 wclScroll
.lpszClassName
= _T("Scrollbox");
163 wclScroll
.lpfnWndProc
= WindowProcedure
;
165 wclScroll
.cbSize
= sizeof (WNDCLASSEX
);
166 wclScroll
.hIcon
= NULL
;
167 wclScroll
.hIconSm
= NULL
;
168 wclScroll
.hCursor
= LoadCursor (NULL
, IDC_ARROW
);
169 wclScroll
.lpszMenuName
= NULL
;
170 wclScroll
.cbClsExtra
= 0;
171 wclScroll
.cbWndExtra
= 0;
172 wclScroll
.hbrBackground
= GetSysColorBrush(COLOR_APPWORKSPACE
);
173 RegisterClassEx (&wclScroll
);
175 /* initializing and registering the window class used for the palette window */
176 wclPal
.hInstance
= hThisInstance
;
177 wclPal
.lpszClassName
= _T("Palette");
178 wclPal
.lpfnWndProc
= PalWinProc
;
179 wclPal
.style
= CS_DBLCLKS
;
180 wclPal
.cbSize
= sizeof (WNDCLASSEX
);
182 wclPal
.hIconSm
= NULL
;
183 wclPal
.hCursor
= LoadCursor (NULL
, IDC_ARROW
);
184 wclPal
.lpszMenuName
= NULL
;
185 wclPal
.cbClsExtra
= 0;
186 wclPal
.cbWndExtra
= 0;
187 wclPal
.hbrBackground
= GetSysColorBrush(COLOR_BTNFACE
);
188 RegisterClassEx (&wclPal
);
190 /* initializing and registering the window class for the settings window */
191 wclSettings
.hInstance
= hThisInstance
;
192 wclSettings
.lpszClassName
= _T("ToolSettings");
193 wclSettings
.lpfnWndProc
= SettingsWinProc
;
194 wclSettings
.style
= CS_DBLCLKS
;
195 wclSettings
.cbSize
= sizeof (WNDCLASSEX
);
196 wclSettings
.hIcon
= NULL
;
197 wclSettings
.hIconSm
= NULL
;
198 wclSettings
.hCursor
= LoadCursor (NULL
, IDC_ARROW
);
199 wclSettings
.lpszMenuName
= NULL
;
200 wclSettings
.cbClsExtra
= 0;
201 wclSettings
.cbWndExtra
= 0;
202 wclSettings
.hbrBackground
= GetSysColorBrush(COLOR_BTNFACE
);
203 RegisterClassEx (&wclSettings
);
205 /* initializing and registering the window class for the selection frame */
206 wclSelection
.hInstance
= hThisInstance
;
207 wclSelection
.lpszClassName
= _T("Selection");
208 wclSelection
.lpfnWndProc
= SelectionWinProc
;
209 wclSelection
.style
= CS_DBLCLKS
;
210 wclSelection
.cbSize
= sizeof (WNDCLASSEX
);
211 wclSelection
.hIcon
= NULL
;
212 wclSelection
.hIconSm
= NULL
;
213 wclSelection
.hCursor
= LoadCursor (NULL
, IDC_SIZEALL
);
214 wclSelection
.lpszMenuName
= NULL
;
215 wclSelection
.cbClsExtra
= 0;
216 wclSelection
.cbWndExtra
= 0;
217 wclSelection
.hbrBackground
= NULL
;//GetSysColorBrush(COLOR_BTNFACE);
218 RegisterClassEx (&wclSelection
);
220 LoadString(hThisInstance
, IDS_DEFAULTFILENAME
, filename
, SIZEOF(filename
));
221 LoadString(hThisInstance
, IDS_WINDOWTITLE
, resstr
, SIZEOF(resstr
));
222 _stprintf(progtitle
, resstr
, filename
);
223 LoadString(hThisInstance
, IDS_MINIATURETITLE
, miniaturetitle
, SIZEOF(miniaturetitle
));
225 /* create main window */
226 hwnd
= CreateWindowEx (0, _T("WindowsApp"), progtitle
, WS_OVERLAPPEDWINDOW
, CW_USEDEFAULT
, CW_USEDEFAULT
, 544, 375, HWND_DESKTOP
, NULL
, hThisInstance
, NULL
);
229 hwndMiniature
= CreateWindowEx(WS_EX_PALETTEWINDOW
, _T("WindowsApp"), miniaturetitle
, WS_OVERLAPPED
| WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
, 180, 200, 120, 100, hwnd
, NULL
, hThisInstance
, NULL
);
231 /* loading and setting the window menu from resource */
232 menu
= LoadMenu(hThisInstance
, MAKEINTRESOURCE(ID_MENU
));
234 haccel
= LoadAccelerators(hThisInstance
, MAKEINTRESOURCE(800));
236 /* preloading the draw transparent/nontransparent icons for later use */
237 hNontranspIcon
= LoadImage(hThisInstance
, MAKEINTRESOURCE(IDI_NONTRANSPARENT
), IMAGE_ICON
, 40, 30, LR_DEFAULTCOLOR
);
238 hTranspIcon
= LoadImage(hThisInstance
, MAKEINTRESOURCE(IDI_TRANSPARENT
), IMAGE_ICON
, 40, 30, LR_DEFAULTCOLOR
);
240 hCurFill
= LoadIcon(hThisInstance
, MAKEINTRESOURCE(IDC_FILL
));
241 hCurColor
= LoadIcon(hThisInstance
, MAKEINTRESOURCE(IDC_COLOR
));
242 hCurZoom
= LoadIcon(hThisInstance
, MAKEINTRESOURCE(IDC_ZOOM
));
243 hCurPen
= LoadIcon(hThisInstance
, MAKEINTRESOURCE(IDC_PEN
));
244 hCurAirbrush
= LoadIcon(hThisInstance
, MAKEINTRESOURCE(IDC_AIRBRUSH
));
246 CreateWindowEx (0, _T("STATIC"), _T(""), WS_CHILD
| WS_VISIBLE
| SS_ETCHEDHORZ
, 0, 0, 5000, 2, hwnd
, NULL
, hThisInstance
, NULL
);
248 /* creating the 16 bitmap radio buttons and setting the bitmap */
251 /* FIXME: Unintentionally there is a line above the tool bar. To prevent cropping of the buttons height has been increased from 200 to 205 */
252 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
);
253 hImageList
= ImageList_Create(16, 16, ILC_COLOR24
| ILC_MASK
, 16, 0);
254 SendMessage(hToolbar
, TB_SETIMAGELIST
, 0, (LPARAM
)hImageList
);
255 tempBm
= LoadImage(hThisInstance
, MAKEINTRESOURCE(IDB_TOOLBARICONS
), IMAGE_BITMAP
, 256, 16, 0);
256 ImageList_AddMasked(hImageList
, tempBm
, 0xff00ff);
257 DeleteObject(tempBm
);
258 SendMessage(hToolbar
, TB_BUTTONSTRUCTSIZE
, sizeof(TBBUTTON
), 0);
264 if (i
% 2 == 1) wrapnow
= TBSTATE_WRAP
;
265 LoadString(hThisInstance
, IDS_TOOLTIP1
+ i
, tooltips
[i
], 30);
266 ZeroMemory(&tbbutton
, sizeof(TBBUTTON
));
267 tbbutton
.iString
= (INT_PTR
)tooltips
[i
];
268 tbbutton
.fsStyle
= TBSTYLE_CHECKGROUP
;
269 tbbutton
.fsState
= TBSTATE_ENABLED
| wrapnow
;
270 tbbutton
.idCommand
= ID_FREESEL
+ i
;
271 tbbutton
.iBitmap
= i
;
272 SendMessage(hToolbar
, TB_ADDBUTTONS
, 1, (LPARAM
)&tbbutton
);
274 /* SendMessage(hToolbar, TB_SETROWS, MAKEWPARAM(8, FALSE), (LPARAM)NULL); */
275 SendMessage(hToolbar
, TB_CHECKBUTTON
, ID_PEN
, MAKELONG(TRUE
, 0));
276 SendMessage(hToolbar
, TB_SETMAXTEXTROWS
, 0, 0);
278 SendMessage(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(25, 25));
279 /* SendMessage(hToolbar, TB_AUTOSIZE, 0, 0); */
281 /* creating the tool settings child window */
282 hToolSettings
= CreateWindowEx(0, _T("ToolSettings"), _T(""), WS_CHILD
| WS_VISIBLE
, 7, 210, 42, 140, hwnd
, NULL
, hThisInstance
, NULL
);
284 /* creating the palette child window */
285 hPalWin
= CreateWindowEx(0, _T("Palette"), _T(""), WS_CHILD
| WS_VISIBLE
, 56, 9, 255, 32, hwnd
, NULL
, hThisInstance
, NULL
);
287 /* creating the scroll box */
288 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
);
290 /* creating the status bar */
291 hStatusBar
= CreateWindowEx (0, STATUSCLASSNAME
, _T(""), SBARS_SIZEGRIP
| WS_CHILD
| WS_VISIBLE
, 0, 0, 0, 0, hwnd
, NULL
, hThisInstance
, NULL
);
292 SendMessage(hStatusBar
, SB_SETMINHEIGHT
, 21, 0);
294 hScrlClient
= CreateWindowEx(0, _T("Scrollbox"), _T(""), WS_CHILD
| WS_VISIBLE
, 0, 0, 500, 500, hScrollbox
, NULL
, hThisInstance
, NULL
);
296 /* create selection window (initially hidden) */
297 hSelection
= CreateWindowEx(WS_EX_TRANSPARENT
, _T("Selection"), _T(""), WS_CHILD
| BS_OWNERDRAW
, 350, 0, 100, 100, hScrlClient
, NULL
, hThisInstance
, NULL
);
299 /* creating the window inside the scroll box, on which the image in hDrawingDC's bitmap is drawn */
300 hImageArea
= CreateWindowEx (0, _T("Scrollbox"), _T(""), WS_CHILD
| WS_VISIBLE
, 3, 3, imgXRes
, imgYRes
, hScrlClient
, NULL
, hThisInstance
, NULL
);
302 hDrawingDC
= CreateCompatibleDC(GetDC(hImageArea
));
303 hSelDC
= CreateCompatibleDC(GetDC(hImageArea
));
304 SelectObject(hDrawingDC
, CreatePen(PS_SOLID
, 0, fgColor
));
305 SelectObject(hDrawingDC
, CreateSolidBrush(bgColor
));
307 hBms
[0] = CreateDIBWithProperties(imgXRes
, imgYRes
);
308 SelectObject(hDrawingDC
, hBms
[0]);
309 Rectangle(hDrawingDC
, 0-1, 0-1, imgXRes
+1, imgYRes
+1);
311 /* initializing the CHOOSECOLOR structure for use with ChooseColor */
312 choosecolor
.lStructSize
= sizeof(CHOOSECOLOR
);
313 choosecolor
.hwndOwner
= hwnd
;
314 choosecolor
.hInstance
= NULL
;
315 choosecolor
.rgbResult
= 0x00ffffff;
316 choosecolor
.lpCustColors
= (COLORREF
*)&custColors
;
317 choosecolor
.Flags
= 0;
318 choosecolor
.lCustData
= 0;
319 choosecolor
.lpfnHook
= NULL
;
320 choosecolor
.lpTemplateName
= NULL
;
322 /* initializing the OPENFILENAME structure for use with GetOpenFileName and GetSaveFileName */
323 CopyMemory(ofnFilename
, filename
, sizeof(filename
));
324 LoadString(hThisInstance
, IDS_OPENFILTER
, ofnFilter
, SIZEOF(ofnFilter
));
325 for (c
= ofnFilter
; *c
; c
++) if (*c
== '\1') *c
= '\0';
326 ZeroMemory(&ofn
, sizeof(OPENFILENAME
));
327 ofn
.lStructSize
= sizeof (OPENFILENAME
);
328 ofn
.hwndOwner
= hwnd
;
329 ofn
.hInstance
= hThisInstance
;
330 ofn
.lpstrFilter
= ofnFilter
;
331 ofn
.lpstrFile
= ofnFilename
;
332 ofn
.nMaxFile
= SIZEOF(ofnFilename
);
333 ofn
.lpstrFileTitle
= ofnFiletitle
;
334 ofn
.nMaxFileTitle
= SIZEOF(ofnFiletitle
);
335 ofn
.Flags
= OFN_HIDEREADONLY
;
337 CopyMemory(sfnFilename
, filename
, sizeof(filename
));
338 LoadString(hThisInstance
, IDS_SAVEFILTER
, sfnFilter
, SIZEOF(sfnFilter
));
339 for (c
= sfnFilter
; *c
; c
++) if (*c
== '\1') *c
= '\0';
340 ZeroMemory(&sfn
, sizeof(OPENFILENAME
));
341 sfn
.lStructSize
= sizeof (OPENFILENAME
);
342 sfn
.hwndOwner
= hwnd
;
343 sfn
.hInstance
= hThisInstance
;
344 sfn
.lpstrFilter
= sfnFilter
;
345 sfn
.lpstrFile
= sfnFilename
;
346 sfn
.nMaxFile
= SIZEOF(sfnFilename
);
347 sfn
.lpstrFileTitle
= sfnFiletitle
;
348 sfn
.nMaxFileTitle
= SIZEOF(sfnFiletitle
);
349 sfn
.Flags
= OFN_OVERWRITEPROMPT
| OFN_HIDEREADONLY
;
352 /* by moving the window, the things in WM_SIZE are done */
353 MoveWindow(hwnd
, 100, 100, 600, 450, TRUE
);
355 /* Make the window visible on the screen */
356 ShowWindow (hwnd
, nFunsterStil
);
358 /* Run the message loop. It will run until GetMessage() returns 0 */
359 while (GetMessage (&messages
, NULL
, 0, 0))
361 TranslateAccelerator(hwnd
, haccel
, &messages
);
363 /* Translate virtual-key messages into character messages */
364 TranslateMessage(&messages
);
365 /* Send message to WindowProcedure */
366 DispatchMessage(&messages
);
369 /* The program return-value is 0 - The value that PostQuitMessage() gave */
370 return messages
.wParam
;