2 * PROJECT: PAINT for ReactOS
4 * FILE: base/applications/mspaint_new/main.cpp
5 * PURPOSE: Initializing everything
6 * PROGRAMMERS: Benedikt Freisen
9 /* INCLUDES *********************************************************/
13 /* FUNCTIONS ********************************************************/
18 BITMAPINFO bitmapinfo
;
25 STRETCHSKEW stretchSkew
;
27 HBITMAP hBms
[HISTORYSIZE
];
31 BOOL imageSaved
= TRUE
;
36 ToolsModel toolsModel
;
45 LPTSTR textToolText
= NULL
;
46 int textToolTextMaxLen
= 0;
48 PaletteModel paletteModel
;
52 CHOOSECOLOR choosecolor
;
66 HINSTANCE hProgInstance
;
69 TCHAR filepathname
[1000];
76 BOOL showGrid
= FALSE
;
77 BOOL showMiniature
= FALSE
;
79 CMainWindow mainWindow
;
80 CMiniatureWindow miniature
;
81 CMainWindow toolBoxContainer
;
82 CToolSettingsWindow toolSettingsWindow
;
83 CPaletteWindow paletteWindow
;
84 CScrollboxWindow scrollboxWindow
;
85 CScrollboxWindow scrlClientWindow
;
86 CSelectionWindow selectionWindow
;
87 CImgAreaWindow imageArea
;
88 CSizeboxWindow sizeboxLeftTop
;
89 CSizeboxWindow sizeboxCenterTop
;
90 CSizeboxWindow sizeboxRightTop
;
91 CSizeboxWindow sizeboxLeftCenter
;
92 CSizeboxWindow sizeboxRightCenter
;
93 CSizeboxWindow sizeboxLeftBottom
;
94 CSizeboxWindow sizeboxCenterBottom
;
95 CSizeboxWindow sizeboxRightBottom
;
96 CTextEditWindow textEditWindow
;
101 _tWinMain (HINSTANCE hThisInstance
, HINSTANCE hPrevInstance
, LPTSTR lpszArgument
, int nFunsterStil
)
103 HWND hwnd
; /* This is the handle for our window */
104 MSG messages
; /* Here messages to the application are saved */
106 TCHAR progtitle
[1000];
110 HIMAGELIST hImageList
;
114 TCHAR tooltips
[16][30];
118 TCHAR sfnFilename
[1000];
119 TCHAR sfnFiletitle
[256];
120 TCHAR sfnFilter
[1000];
121 TCHAR ofnFilename
[1000];
122 TCHAR ofnFiletitle
[256];
123 TCHAR ofnFilter
[1000];
124 TCHAR miniaturetitle
[100];
125 static int custColors
[16] = { 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff,
126 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff
129 /* init font for text tool */
130 lfTextFont
.lfHeight
= 0;
131 lfTextFont
.lfWidth
= 0;
132 lfTextFont
.lfEscapement
= 0;
133 lfTextFont
.lfOrientation
= 0;
134 lfTextFont
.lfWeight
= FW_NORMAL
;
135 lfTextFont
.lfItalic
= FALSE
;
136 lfTextFont
.lfUnderline
= FALSE
;
137 lfTextFont
.lfStrikeOut
= FALSE
;
138 lfTextFont
.lfCharSet
= DEFAULT_CHARSET
;
139 lfTextFont
.lfOutPrecision
= OUT_DEFAULT_PRECIS
;
140 lfTextFont
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
141 lfTextFont
.lfQuality
= DEFAULT_QUALITY
;
142 lfTextFont
.lfPitchAndFamily
= DEFAULT_PITCH
| FF_DONTCARE
;
143 lstrcpy(lfTextFont
.lfFaceName
, _T(""));
144 hfontTextFont
= CreateFontIndirect(&lfTextFont
);
146 hProgInstance
= hThisInstance
;
148 /* initialize common controls library */
149 InitCommonControls();
151 LoadString(hThisInstance
, IDS_DEFAULTFILENAME
, filename
, SIZEOF(filename
));
152 LoadString(hThisInstance
, IDS_WINDOWTITLE
, resstr
, SIZEOF(resstr
));
153 _stprintf(progtitle
, resstr
, filename
);
154 LoadString(hThisInstance
, IDS_MINIATURETITLE
, miniaturetitle
, SIZEOF(miniaturetitle
));
156 /* create main window */
157 RECT mainWindowPos
= {0, 0, 544, 375}; // FIXME: use equivalent of CW_USEDEFAULT for position
158 hwnd
= mainWindow
.Create(HWND_DESKTOP
, mainWindowPos
, progtitle
, WS_OVERLAPPEDWINDOW
, 0, 0U, NULL
);
160 RECT miniaturePos
= {180, 200, 180 + 120, 200 + 100};
161 miniature
.Create(hwnd
, miniaturePos
, miniaturetitle
,
162 WS_OVERLAPPED
| WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
, WS_EX_PALETTEWINDOW
, 0U, NULL
);
164 /* loading and setting the window menu from resource */
165 menu
= LoadMenu(hThisInstance
, MAKEINTRESOURCE(ID_MENU
));
167 haccel
= LoadAccelerators(hThisInstance
, MAKEINTRESOURCE(800));
169 /* preloading the draw transparent/nontransparent icons for later use */
171 (HICON
) LoadImage(hThisInstance
, MAKEINTRESOURCE(IDI_NONTRANSPARENT
), IMAGE_ICON
, 40, 30, LR_DEFAULTCOLOR
);
173 (HICON
) LoadImage(hThisInstance
, MAKEINTRESOURCE(IDI_TRANSPARENT
), IMAGE_ICON
, 40, 30, LR_DEFAULTCOLOR
);
175 hCurFill
= LoadIcon(hThisInstance
, MAKEINTRESOURCE(IDC_FILL
));
176 hCurColor
= LoadIcon(hThisInstance
, MAKEINTRESOURCE(IDC_COLOR
));
177 hCurZoom
= LoadIcon(hThisInstance
, MAKEINTRESOURCE(IDC_ZOOM
));
178 hCurPen
= LoadIcon(hThisInstance
, MAKEINTRESOURCE(IDC_PEN
));
179 hCurAirbrush
= LoadIcon(hThisInstance
, MAKEINTRESOURCE(IDC_AIRBRUSH
));
181 CreateWindowEx(0, _T("STATIC"), _T(""), WS_CHILD
| WS_VISIBLE
| SS_ETCHEDHORZ
, 0, 0, 5000, 2, hwnd
, NULL
,
182 hThisInstance
, NULL
);
184 RECT toolBoxContainerPos
= {2, 2, 2 + 52, 2 + 350};
185 toolBoxContainer
.Create(hwnd
, toolBoxContainerPos
, _T(""), WS_CHILD
| WS_VISIBLE
, 0, 0U, NULL
);
186 /* creating the 16 bitmap radio buttons and setting the bitmap */
190 * FIXME: Unintentionally there is a line above the tool bar (hidden by y-offset).
191 * To prevent cropping of the buttons height has been increased from 200 to 205
194 CreateWindowEx(0, TOOLBARCLASSNAME
, NULL
,
195 WS_CHILD
| WS_VISIBLE
| CCS_NOPARENTALIGN
| CCS_VERT
| CCS_NORESIZE
| TBSTYLE_TOOLTIPS
,
196 1, -2, 50, 205, toolBoxContainer
.m_hWnd
, NULL
, hThisInstance
, NULL
);
197 hImageList
= ImageList_Create(16, 16, ILC_COLOR24
| ILC_MASK
, 16, 0);
198 SendMessage(hToolbar
, TB_SETIMAGELIST
, 0, (LPARAM
) hImageList
);
199 tempBm
= (HBITMAP
) LoadImage(hThisInstance
, MAKEINTRESOURCE(IDB_TOOLBARICONS
), IMAGE_BITMAP
, 256, 16, 0);
200 ImageList_AddMasked(hImageList
, tempBm
, 0xff00ff);
201 DeleteObject(tempBm
);
202 SendMessage(hToolbar
, TB_BUTTONSTRUCTSIZE
, sizeof(TBBUTTON
), 0);
204 for(i
= 0; i
< 16; i
++)
210 wrapnow
= TBSTATE_WRAP
;
212 LoadString(hThisInstance
, IDS_TOOLTIP1
+ i
, tooltips
[i
], 30);
213 ZeroMemory(&tbbutton
, sizeof(TBBUTTON
));
214 tbbutton
.iString
= (INT_PTR
) tooltips
[i
];
215 tbbutton
.fsStyle
= TBSTYLE_CHECKGROUP
;
216 tbbutton
.fsState
= TBSTATE_ENABLED
| wrapnow
;
217 tbbutton
.idCommand
= ID_FREESEL
+ i
;
218 tbbutton
.iBitmap
= i
;
219 SendMessage(hToolbar
, TB_ADDBUTTONS
, 1, (LPARAM
) &tbbutton
);
222 SendMessage(hToolbar
, TB_CHECKBUTTON
, ID_PEN
, MAKELONG(TRUE
, 0));
223 SendMessage(hToolbar
, TB_SETMAXTEXTROWS
, 0, 0);
224 SendMessage(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(25, 25));
226 /* creating the tool settings child window */
227 RECT toolSettingsWindowPos
= {5, 208, 5 + 42, 208 + 140};
228 toolSettingsWindow
.Create(toolBoxContainer
.m_hWnd
, toolSettingsWindowPos
, _T(""), WS_CHILD
| WS_VISIBLE
, 0, 0U, NULL
);
230 CreateWindowEx(0, TRACKBAR_CLASS
, _T(""), WS_CHILD
| TBS_VERT
| TBS_AUTOTICKS
, 1, 1, 40, 64,
231 toolSettingsWindow
.m_hWnd
, NULL
, hThisInstance
, NULL
);
232 SendMessage(hTrackbarZoom
, TBM_SETRANGE
, (WPARAM
) TRUE
, (LPARAM
) MAKELONG(0, 6));
233 SendMessage(hTrackbarZoom
, TBM_SETPOS
, (WPARAM
) TRUE
, (LPARAM
) 3);
235 /* creating the palette child window */
236 RECT paletteWindowPos
= {56, 9, 56 + 255, 9 + 32};
237 paletteWindow
.Create(hwnd
, paletteWindowPos
, _T(""), WS_CHILD
| WS_VISIBLE
, 0, 0U, NULL
);
239 /* creating the scroll box */
240 RECT scrollboxWindowPos
= {56, 49, 56 + 472, 49 + 248};
241 scrollboxWindow
.Create(hwnd
, scrollboxWindowPos
, _T(""),
242 WS_CHILD
| WS_GROUP
| WS_HSCROLL
| WS_VSCROLL
| WS_VISIBLE
, WS_EX_CLIENTEDGE
, 0U, NULL
);
244 /* creating the status bar */
246 CreateWindowEx(0, STATUSCLASSNAME
, _T(""), SBARS_SIZEGRIP
| WS_CHILD
| WS_VISIBLE
, 0, 0, 0, 0, hwnd
,
247 NULL
, hThisInstance
, NULL
);
248 SendMessage(hStatusBar
, SB_SETMINHEIGHT
, 21, 0);
250 RECT scrlClientWindowPos
= {0, 0, 0 + 500, 0 + 500};
251 scrlClientWindow
.Create(scrollboxWindow
.m_hWnd
, scrlClientWindowPos
, _T(""), WS_CHILD
| WS_VISIBLE
, 0, 0U, NULL
);
253 /* create selection window (initially hidden) */
254 RECT selectionWindowPos
= {350, 0, 350 + 100, 0 + 100};
255 selectionWindow
.Create(scrlClientWindow
.m_hWnd
, selectionWindowPos
, _T(""), WS_CHILD
| BS_OWNERDRAW
, 0, 0U, NULL
);
257 /* creating the window inside the scroll box, on which the image in hDrawingDC's bitmap is drawn */
258 RECT imageAreaPos
= {3, 3, 3 + imgXRes
, 3 + imgYRes
};
259 imageArea
.Create(scrlClientWindow
.m_hWnd
, imageAreaPos
, _T(""), WS_CHILD
| WS_VISIBLE
, 0, 0U, NULL
);
261 hDC
= imageArea
.GetDC();
262 hDrawingDC
= CreateCompatibleDC(hDC
);
263 hSelDC
= CreateCompatibleDC(hDC
);
264 imageArea
.ReleaseDC(hDC
);
265 SelectObject(hDrawingDC
, CreatePen(PS_SOLID
, 0, paletteModel
.GetFgColor()));
266 SelectObject(hDrawingDC
, CreateSolidBrush(paletteModel
.GetBgColor()));
268 hBms
[0] = CreateDIBWithProperties(imgXRes
, imgYRes
);
269 SelectObject(hDrawingDC
, hBms
[0]);
270 Rectangle(hDrawingDC
, 0 - 1, 0 - 1, imgXRes
+ 1, imgYRes
+ 1);
272 if (lpszArgument
[0] != 0)
274 HBITMAP bmNew
= NULL
;
275 LoadDIBFromFile(&bmNew
, lpszArgument
, &fileTime
, &fileSize
, &fileHPPM
, &fileVPPM
);
281 insertReversible(bmNew
);
282 GetFullPathName(lpszArgument
, SIZEOF(filepathname
), filepathname
, &temp
);
283 _tcscpy(filename
, temp
);
284 LoadString(hProgInstance
, IDS_WINDOWTITLE
, resstr
, SIZEOF(resstr
));
285 _stprintf(tempstr
, resstr
, filename
);
286 mainWindow
.SetWindowText(tempstr
);
296 /* initializing the CHOOSECOLOR structure for use with ChooseColor */
297 choosecolor
.lStructSize
= sizeof(CHOOSECOLOR
);
298 choosecolor
.hwndOwner
= hwnd
;
299 choosecolor
.hInstance
= NULL
;
300 choosecolor
.rgbResult
= 0x00ffffff;
301 choosecolor
.lpCustColors
= (COLORREF
*) &custColors
;
302 choosecolor
.Flags
= 0;
303 choosecolor
.lCustData
= 0;
304 choosecolor
.lpfnHook
= NULL
;
305 choosecolor
.lpTemplateName
= NULL
;
307 /* initializing the OPENFILENAME structure for use with GetOpenFileName and GetSaveFileName */
308 CopyMemory(ofnFilename
, filename
, sizeof(filename
));
309 LoadString(hThisInstance
, IDS_OPENFILTER
, ofnFilter
, SIZEOF(ofnFilter
));
310 for(c
= ofnFilter
; *c
; c
++)
313 ZeroMemory(&ofn
, sizeof(OPENFILENAME
));
314 ofn
.lStructSize
= sizeof(OPENFILENAME
);
315 ofn
.hwndOwner
= hwnd
;
316 ofn
.hInstance
= hThisInstance
;
317 ofn
.lpstrFilter
= ofnFilter
;
318 ofn
.lpstrFile
= ofnFilename
;
319 ofn
.nMaxFile
= SIZEOF(ofnFilename
);
320 ofn
.lpstrFileTitle
= ofnFiletitle
;
321 ofn
.nMaxFileTitle
= SIZEOF(ofnFiletitle
);
322 ofn
.Flags
= OFN_HIDEREADONLY
;
324 CopyMemory(sfnFilename
, filename
, sizeof(filename
));
325 LoadString(hThisInstance
, IDS_SAVEFILTER
, sfnFilter
, SIZEOF(sfnFilter
));
326 for(c
= sfnFilter
; *c
; c
++)
329 ZeroMemory(&sfn
, sizeof(OPENFILENAME
));
330 sfn
.lStructSize
= sizeof(OPENFILENAME
);
331 sfn
.hwndOwner
= hwnd
;
332 sfn
.hInstance
= hThisInstance
;
333 sfn
.lpstrFilter
= sfnFilter
;
334 sfn
.lpstrFile
= sfnFilename
;
335 sfn
.nMaxFile
= SIZEOF(sfnFilename
);
336 sfn
.lpstrFileTitle
= sfnFiletitle
;
337 sfn
.nMaxFileTitle
= SIZEOF(sfnFiletitle
);
338 sfn
.Flags
= OFN_OVERWRITEPROMPT
| OFN_HIDEREADONLY
;
340 /* creating the size boxes */
341 RECT sizeboxPos
= {0, 0, 0 + 3, 0 + 3};
342 sizeboxLeftTop
.Create(scrlClientWindow
.m_hWnd
, sizeboxPos
, _T(""), WS_CHILD
| WS_VISIBLE
, 0, 0U, NULL
);
343 sizeboxCenterTop
.Create(scrlClientWindow
.m_hWnd
, sizeboxPos
, _T(""), WS_CHILD
| WS_VISIBLE
, 0, 0U, NULL
);
344 sizeboxRightTop
.Create(scrlClientWindow
.m_hWnd
, sizeboxPos
, _T(""), WS_CHILD
| WS_VISIBLE
, 0, 0U, NULL
);
345 sizeboxLeftCenter
.Create(scrlClientWindow
.m_hWnd
, sizeboxPos
, _T(""), WS_CHILD
| WS_VISIBLE
, 0, 0U, NULL
);
346 sizeboxRightCenter
.Create(scrlClientWindow
.m_hWnd
, sizeboxPos
, _T(""), WS_CHILD
| WS_VISIBLE
, 0, 0U, NULL
);
347 sizeboxLeftBottom
.Create(scrlClientWindow
.m_hWnd
, sizeboxPos
, _T(""), WS_CHILD
| WS_VISIBLE
, 0, 0U, NULL
);
348 sizeboxCenterBottom
.Create(scrlClientWindow
.m_hWnd
, sizeboxPos
, _T(""), WS_CHILD
| WS_VISIBLE
, 0, 0U, NULL
);
349 sizeboxRightBottom
.Create(scrlClientWindow
.m_hWnd
, sizeboxPos
, _T(""), WS_CHILD
| WS_VISIBLE
, 0, 0U, NULL
);
350 /* placing the size boxes around the image */
351 imageArea
.SendMessage(WM_SIZE
, 0, 0);
353 /* by moving the window, the things in WM_SIZE are done */
354 MoveWindow(hwnd
, 100, 100, 600, 450, TRUE
);
356 /* creating the text editor window for the text tool */
357 RECT textEditWindowPos
= {300, 0, 300 + 300, 0 + 200};
358 textEditWindow
.Create(hwnd
, textEditWindowPos
, _T(""), WS_OVERLAPPEDWINDOW
, 0, 0U, NULL
);
359 /* creating the edit control within the editor window */
361 CreateWindowEx(WS_EX_CLIENTEDGE
, _T("EDIT"), _T(""),
362 WS_CHILD
| WS_VISIBLE
| WS_BORDER
| WS_HSCROLL
| WS_VSCROLL
| ES_MULTILINE
| ES_NOHIDESEL
| ES_AUTOHSCROLL
| ES_AUTOVSCROLL
,
363 0, 0, 100, 100, textEditWindow
.m_hWnd
, NULL
, hThisInstance
, NULL
);
365 /* Make the window visible on the screen */
366 ShowWindow (hwnd
, nFunsterStil
);
368 /* inform the system, that the main window accepts dropped files */
369 DragAcceptFiles(hwnd
, TRUE
);
371 /* Run the message loop. It will run until GetMessage() returns 0 */
372 while (GetMessage(&messages
, NULL
, 0, 0))
374 TranslateAccelerator(hwnd
, (HACCEL
) haccel
, &messages
);
376 /* Translate virtual-key messages into character messages */
377 TranslateMessage(&messages
);
378 /* Send message to WindowProcedure */
379 DispatchMessage(&messages
);
382 /* The program return-value is 0 - The value that PostQuitMessage() gave */
383 return messages
.wParam
;