2 * PROJECT: PAINT for ReactOS
4 * FILE: base/applications/paint/winproc.c
5 * PURPOSE: Window procedure of the main window and all children apart from
6 * hPalWin, hToolSettings and hSelection
7 * PROGRAMMERS: Benedikt Freisen
10 /* INCLUDES *********************************************************/
14 //#include <htmlhelp.h>
17 #include "definitions.h"
18 #include "globalvar.h"
26 /* FUNCTIONS ********************************************************/
31 ShowWindow(hSelection
, SW_HIDE
);
33 pointSP
= 0; // resets the point-buffer of the polygon and bezier functions
34 SendMessage(hToolSettings
, WM_PAINT
, 0, 0);
35 ShowWindow(hTrackbarZoom
, (tool
== 6) ? SW_SHOW
: SW_HIDE
);
39 updateCanvasAndScrollbars()
41 ShowWindow(hSelection
, SW_HIDE
);
42 MoveWindow(hImageArea
, 3, 3, imgXRes
* zoom
/ 1000, imgYRes
* zoom
/ 1000, FALSE
);
43 InvalidateRect(hScrollbox
, NULL
, TRUE
);
44 InvalidateRect(hImageArea
, NULL
, FALSE
);
46 SetScrollPos(hScrollbox
, SB_HORZ
, 0, TRUE
);
47 SetScrollPos(hScrollbox
, SB_VERT
, 0, TRUE
);
51 zoomTo(int newZoom
, int mouseX
, int mouseY
)
54 int tempZoom
= newZoom
;
56 long clientRectScrollbox
[4];
57 long clientRectImageArea
[4];
59 GetClientRect(hScrollbox
, (LPRECT
) &clientRectScrollbox
);
60 GetClientRect(hImageArea
, (LPRECT
) &clientRectImageArea
);
61 w
= clientRectImageArea
[2] * clientRectScrollbox
[2] / (clientRectImageArea
[2] * newZoom
/ zoom
);
62 h
= clientRectImageArea
[3] * clientRectScrollbox
[3] / (clientRectImageArea
[3] * newZoom
/ zoom
);
63 x
= max(0, min(clientRectImageArea
[2] - w
, mouseX
- w
/ 2)) * newZoom
/ zoom
;
64 y
= max(0, min(clientRectImageArea
[3] - h
, mouseY
- h
/ 2)) * newZoom
/ zoom
;
68 ShowWindow(hSelection
, SW_HIDE
);
69 MoveWindow(hImageArea
, 3, 3, imgXRes
* zoom
/ 1000, imgYRes
* zoom
/ 1000, FALSE
);
70 InvalidateRect(hScrollbox
, NULL
, TRUE
);
71 InvalidateRect(hImageArea
, NULL
, FALSE
);
73 SendMessage(hScrollbox
, WM_HSCROLL
, SB_THUMBPOSITION
| (x
<< 16), 0);
74 SendMessage(hScrollbox
, WM_VSCROLL
, SB_THUMBPOSITION
| (y
<< 16), 0);
76 while (tempZoom
> 125)
79 tempZoom
= tempZoom
>> 1;
81 SendMessage(hTrackbarZoom
, TBM_SETPOS
, (WPARAM
) TRUE
, (LPARAM
) tbPos
);
85 drawZoomFrame(int mouseX
, int mouseY
)
93 long clientRectScrollbox
[4];
94 long clientRectImageArea
[4];
96 GetClientRect(hScrollbox
, (LPRECT
) &clientRectScrollbox
);
97 GetClientRect(hImageArea
, (LPRECT
) &clientRectImageArea
);
98 w
= clientRectImageArea
[2] * clientRectScrollbox
[2] / (clientRectImageArea
[2] * 2);
99 h
= clientRectImageArea
[3] * clientRectScrollbox
[3] / (clientRectImageArea
[3] * 2);
100 x
= max(0, min(clientRectImageArea
[2] - w
, mouseX
- w
/ 2));
101 y
= max(0, min(clientRectImageArea
[3] - h
, mouseY
- h
/ 2));
103 hdc
= GetDC(hImageArea
);
104 oldPen
= SelectObject(hdc
, CreatePen(PS_SOLID
, 0, 0));
105 logbrush
.lbStyle
= BS_HOLLOW
;
106 oldBrush
= SelectObject(hdc
, CreateBrushIndirect(&logbrush
));
107 rop
= SetROP2(hdc
, R2_NOT
);
108 Rectangle(hdc
, x
, y
, x
+ w
, y
+ h
);
110 DeleteObject(SelectObject(hdc
, oldBrush
));
111 DeleteObject(SelectObject(hdc
, oldPen
));
112 ReleaseDC(hImageArea
, hdc
);
116 alignChildrenToMainWindow()
120 GetClientRect(hMainWnd
, &clientRect
);
122 if (IsWindowVisible(hToolBoxContainer
))
125 w
= clientRect
.right
- 56;
130 w
= clientRect
.right
;
132 if (IsWindowVisible(hPalWin
))
135 h
= clientRect
.bottom
- 49;
140 h
= clientRect
.bottom
- 3;
143 MoveWindow(hScrollbox
, x
, y
, w
, IsWindowVisible(hStatusBar
) ? h
- 23 : h
, TRUE
);
144 MoveWindow(hPalWin
, x
, 9, 255, 32, TRUE
);
150 WindowProcedure(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
152 switch (message
) /* handle the messages */
155 PostQuitMessage(0); /* send a WM_QUIT to the message queue */
159 if (hwnd
== hwndMiniature
)
161 ShowWindow(hwndMiniature
, SW_HIDE
);
162 showMiniature
= FALSE
;
167 TCHAR programname
[20];
168 TCHAR saveprompttext
[100];
170 LoadString(hProgInstance
, IDS_PROGRAMNAME
, programname
, SIZEOF(programname
));
171 LoadString(hProgInstance
, IDS_SAVEPROMPTTEXT
, saveprompttext
, SIZEOF(saveprompttext
));
172 _stprintf(temptext
, saveprompttext
, filename
);
173 switch (MessageBox(hwnd
, temptext
, programname
, MB_YESNOCANCEL
| MB_ICONQUESTION
))
179 SendMessage(hwnd
, WM_COMMAND
, IDM_FILESAVEAS
, 0);
190 case WM_INITMENUPOPUP
:
196 EnableMenuItem(GetMenu(hMainWnd
), IDM_FILEASWALLPAPERPLANE
,
197 MF_ENABLED
| MF_BYCOMMAND
);
198 EnableMenuItem(GetMenu(hMainWnd
), IDM_FILEASWALLPAPERCENTERED
,
199 MF_ENABLED
| MF_BYCOMMAND
);
200 EnableMenuItem(GetMenu(hMainWnd
), IDM_FILEASWALLPAPERSTRETCHED
,
201 MF_ENABLED
| MF_BYCOMMAND
);
205 EnableMenuItem(GetMenu(hMainWnd
), IDM_FILEASWALLPAPERPLANE
,
206 MF_GRAYED
| MF_BYCOMMAND
);
207 EnableMenuItem(GetMenu(hMainWnd
), IDM_FILEASWALLPAPERCENTERED
,
208 MF_GRAYED
| MF_BYCOMMAND
);
209 EnableMenuItem(GetMenu(hMainWnd
), IDM_FILEASWALLPAPERSTRETCHED
,
210 MF_GRAYED
| MF_BYCOMMAND
);
214 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITUNDO
,
215 (undoSteps
> 0) ? (MF_ENABLED
| MF_BYCOMMAND
) : (MF_GRAYED
| MF_BYCOMMAND
));
216 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITREDO
,
217 (redoSteps
> 0) ? (MF_ENABLED
| MF_BYCOMMAND
) : (MF_GRAYED
| MF_BYCOMMAND
));
218 if (IsWindowVisible(hSelection
))
220 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITCUT
, MF_ENABLED
| MF_BYCOMMAND
);
221 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITCOPY
, MF_ENABLED
| MF_BYCOMMAND
);
222 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITDELETESELECTION
, MF_ENABLED
| MF_BYCOMMAND
);
223 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITINVERTSELECTION
, MF_ENABLED
| MF_BYCOMMAND
);
224 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITCOPYTO
, MF_ENABLED
| MF_BYCOMMAND
);
228 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITCUT
, MF_GRAYED
| MF_BYCOMMAND
);
229 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITCOPY
, MF_GRAYED
| MF_BYCOMMAND
);
230 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITDELETESELECTION
, MF_GRAYED
| MF_BYCOMMAND
);
231 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITINVERTSELECTION
, MF_GRAYED
| MF_BYCOMMAND
);
232 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITCOPYTO
, MF_GRAYED
| MF_BYCOMMAND
);
234 OpenClipboard(hMainWnd
);
235 if (GetClipboardData(CF_BITMAP
) != NULL
)
236 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITPASTE
, MF_ENABLED
| MF_BYCOMMAND
);
238 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITPASTE
, MF_GRAYED
| MF_BYCOMMAND
);
242 if (IsWindowVisible(hSelection
))
243 EnableMenuItem(GetMenu(hMainWnd
), IDM_IMAGECROP
, MF_ENABLED
| MF_BYCOMMAND
);
245 EnableMenuItem(GetMenu(hMainWnd
), IDM_IMAGECROP
, MF_GRAYED
| MF_BYCOMMAND
);
246 CheckMenuItem(GetMenu(hMainWnd
), IDM_IMAGEDRAWOPAQUE
, (transpBg
== 0) ?
247 (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
250 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWTOOLBOX
,
251 IsWindowVisible(hToolBoxContainer
) ?
252 (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
253 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWCOLORPALETTE
,
254 IsWindowVisible(hPalWin
) ?
255 (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
256 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWSTATUSBAR
,
257 IsWindowVisible(hStatusBar
) ?
258 (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
260 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWSHOWGRID
,
261 showGrid
? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
262 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWSHOWMINIATURE
,
263 showMiniature
? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
265 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM125
,
266 (zoom
== 125) ? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
267 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM25
,
268 (zoom
== 250) ? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
269 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM50
,
270 (zoom
== 500) ? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
271 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM100
,
272 (zoom
== 1000) ? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
273 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM200
,
274 (zoom
== 2000) ? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
275 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM400
,
276 (zoom
== 4000) ? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
277 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM800
,
278 (zoom
== 8000) ? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
283 if (hwnd
== hMainWnd
)
285 int test
[] = { LOWORD(lParam
) - 260, LOWORD(lParam
) - 140, LOWORD(lParam
) - 20 };
286 SendMessage(hStatusBar
, WM_SIZE
, wParam
, lParam
);
287 SendMessage(hStatusBar
, SB_SETPARTS
, 3, (LPARAM
)&test
);
288 alignChildrenToMainWindow();
290 if (hwnd
== hImageArea
)
292 MoveWindow(hSizeboxLeftTop
,
295 MoveWindow(hSizeboxCenterTop
,
296 imgXRes
* zoom
/ 2000 + 3 * 3 / 4,
298 MoveWindow(hSizeboxRightTop
,
299 imgXRes
* zoom
/ 1000 + 3,
301 MoveWindow(hSizeboxLeftCenter
,
303 imgYRes
* zoom
/ 2000 + 3 * 3 / 4, 3, 3, TRUE
);
304 MoveWindow(hSizeboxRightCenter
,
305 imgXRes
* zoom
/ 1000 + 3,
306 imgYRes
* zoom
/ 2000 + 3 * 3 / 4, 3, 3, TRUE
);
307 MoveWindow(hSizeboxLeftBottom
,
309 imgYRes
* zoom
/ 1000 + 3, 3, 3, TRUE
);
310 MoveWindow(hSizeboxCenterBottom
,
311 imgXRes
* zoom
/ 2000 + 3 * 3 / 4,
312 imgYRes
* zoom
/ 1000 + 3, 3, 3, TRUE
);
313 MoveWindow(hSizeboxRightBottom
,
314 imgXRes
* zoom
/ 1000 + 3,
315 imgYRes
* zoom
/ 1000 + 3, 3, 3, TRUE
);
317 if ((hwnd
== hImageArea
) || (hwnd
== hScrollbox
))
319 long clientRectScrollbox
[4];
320 long clientRectImageArea
[4];
322 GetClientRect(hScrollbox
, (LPRECT
) &clientRectScrollbox
);
323 GetClientRect(hImageArea
, (LPRECT
) &clientRectImageArea
);
324 si
.cbSize
= sizeof(SCROLLINFO
);
325 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
326 si
.nMax
= clientRectImageArea
[2] + 6 - 1;
328 si
.nPage
= clientRectScrollbox
[2];
329 SetScrollInfo(hScrollbox
, SB_HORZ
, &si
, TRUE
);
330 GetClientRect(hScrollbox
, (LPRECT
) clientRectScrollbox
);
331 si
.nMax
= clientRectImageArea
[3] + 6 - 1;
332 si
.nPage
= clientRectScrollbox
[3];
333 SetScrollInfo(hScrollbox
, SB_VERT
, &si
, TRUE
);
334 MoveWindow(hScrlClient
,
335 -GetScrollPos(hScrollbox
, SB_HORZ
), -GetScrollPos(hScrollbox
, SB_VERT
),
336 max(clientRectImageArea
[2] + 6, clientRectScrollbox
[2]),
337 max(clientRectImageArea
[3] + 6, clientRectScrollbox
[3]), TRUE
);
342 if (hwnd
== hScrollbox
)
345 si
.cbSize
= sizeof(SCROLLINFO
);
347 GetScrollInfo(hScrollbox
, SB_HORZ
, &si
);
348 switch (LOWORD(wParam
))
351 case SB_THUMBPOSITION
:
352 si
.nPos
= HIWORD(wParam
);
367 SetScrollInfo(hScrollbox
, SB_HORZ
, &si
, TRUE
);
368 MoveWindow(hScrlClient
, -GetScrollPos(hScrollbox
, SB_HORZ
),
369 -GetScrollPos(hScrollbox
, SB_VERT
), imgXRes
* zoom
/ 1000 + 6,
370 imgYRes
* zoom
/ 1000 + 6, TRUE
);
375 if (hwnd
== hScrollbox
)
378 si
.cbSize
= sizeof(SCROLLINFO
);
380 GetScrollInfo(hScrollbox
, SB_VERT
, &si
);
381 switch (LOWORD(wParam
))
384 case SB_THUMBPOSITION
:
385 si
.nPos
= HIWORD(wParam
);
400 SetScrollInfo(hScrollbox
, SB_VERT
, &si
, TRUE
);
401 MoveWindow(hScrlClient
, -GetScrollPos(hScrollbox
, SB_HORZ
),
402 -GetScrollPos(hScrollbox
, SB_VERT
), imgXRes
* zoom
/ 1000 + 6,
403 imgYRes
* zoom
/ 1000 + 6, TRUE
);
407 case WM_GETMINMAXINFO
:
408 if (hwnd
== hMainWnd
)
410 MINMAXINFO
*mm
= (LPMINMAXINFO
) lParam
;
411 (*mm
).ptMinTrackSize
.x
= 330;
412 (*mm
).ptMinTrackSize
.y
= 430;
417 DefWindowProc(hwnd
, message
, wParam
, lParam
);
418 if (hwnd
== hImageArea
)
420 HDC hdc
= GetDC(hImageArea
);
421 StretchBlt(hdc
, 0, 0, imgXRes
* zoom
/ 1000, imgYRes
* zoom
/ 1000, hDrawingDC
, 0, 0, imgXRes
,
423 if (showGrid
&& (zoom
>= 4000))
425 HPEN oldPen
= SelectObject(hdc
, CreatePen(PS_SOLID
, 1, 0x00a0a0a0));
427 for(counter
= 0; counter
<= imgYRes
; counter
++)
429 MoveToEx(hdc
, 0, counter
* zoom
/ 1000, NULL
);
430 LineTo(hdc
, imgXRes
* zoom
/ 1000, counter
* zoom
/ 1000);
432 for(counter
= 0; counter
<= imgXRes
; counter
++)
434 MoveToEx(hdc
, counter
* zoom
/ 1000, 0, NULL
);
435 LineTo(hdc
, counter
* zoom
/ 1000, imgYRes
* zoom
/ 1000);
437 DeleteObject(SelectObject(hdc
, oldPen
));
439 ReleaseDC(hImageArea
, hdc
);
440 SendMessage(hSelection
, WM_PAINT
, 0, 0);
441 SendMessage(hwndMiniature
, WM_PAINT
, 0, 0);
443 else if (hwnd
== hwndMiniature
)
447 GetClientRect(hwndMiniature
, (LPRECT
) &mclient
);
448 hdc
= GetDC(hwndMiniature
);
449 BitBlt(hdc
, -min(imgXRes
* GetScrollPos(hScrollbox
, SB_HORZ
) / 10000, imgXRes
- mclient
[2]),
450 -min(imgYRes
* GetScrollPos(hScrollbox
, SB_VERT
) / 10000, imgYRes
- mclient
[3]),
451 imgXRes
, imgYRes
, hDrawingDC
, 0, 0, SRCCOPY
);
452 ReleaseDC(hwndMiniature
, hdc
);
456 // mouse events used for drawing
459 if (hwnd
== hImageArea
)
467 SetCursor(hCurColor
);
476 SetCursor(hCurAirbrush
);
479 SetCursor(LoadCursor(NULL
, IDC_CROSS
));
483 DefWindowProc(hwnd
, message
, wParam
, lParam
);
487 if (hwnd
== hImageArea
)
489 if ((!drawing
) || (activeTool
== 5))
491 SetCapture(hImageArea
);
493 startPaintingL(hDrawingDC
, LOWORD(lParam
) * 1000 / zoom
, HIWORD(lParam
) * 1000 / zoom
,
498 SendMessage(hwnd
, WM_LBUTTONUP
, wParam
, lParam
);
501 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
502 if ((activeTool
== 6) && (zoom
< 8000))
503 zoomTo(zoom
* 2, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
508 if (hwnd
== hImageArea
)
510 if ((!drawing
) || (activeTool
== 5))
512 SetCapture(hImageArea
);
514 startPaintingR(hDrawingDC
, LOWORD(lParam
) * 1000 / zoom
, HIWORD(lParam
) * 1000 / zoom
,
519 SendMessage(hwnd
, WM_RBUTTONUP
, wParam
, lParam
);
522 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
523 if ((activeTool
== 6) && (zoom
> 125))
524 zoomTo(zoom
/ 2, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
529 if ((hwnd
== hImageArea
) && drawing
)
533 endPaintingL(hDrawingDC
, LOWORD(lParam
) * 1000 / zoom
, HIWORD(lParam
) * 1000 / zoom
, fgColor
,
535 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
539 GetPixel(hDrawingDC
, LOWORD(lParam
) * 1000 / zoom
, HIWORD(lParam
) * 1000 / zoom
);
540 if (tempColor
!= CLR_INVALID
)
542 SendMessage(hPalWin
, WM_PAINT
, 0, 0);
544 SendMessage(hStatusBar
, SB_SETTEXT
, 2, (LPARAM
) "");
549 if ((hwnd
== hImageArea
) && drawing
)
553 endPaintingR(hDrawingDC
, LOWORD(lParam
) * 1000 / zoom
, HIWORD(lParam
) * 1000 / zoom
, fgColor
,
555 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
559 GetPixel(hDrawingDC
, LOWORD(lParam
) * 1000 / zoom
, HIWORD(lParam
) * 1000 / zoom
);
560 if (tempColor
!= CLR_INVALID
)
562 SendMessage(hPalWin
, WM_PAINT
, 0, 0);
564 SendMessage(hStatusBar
, SB_SETTEXT
, 2, (LPARAM
) "");
569 if (hwnd
== hImageArea
)
571 if ((!drawing
) || (activeTool
<= 9))
576 _stprintf(coordStr
, _T("%d, %d"), (short)LOWORD(lParam
) * 1000 / zoom
,
577 (short)HIWORD(lParam
) * 1000 / zoom
);
578 SendMessage(hStatusBar
, SB_SETTEXT
, 1, (LPARAM
) coordStr
);
582 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
583 drawZoomFrame((short)LOWORD(lParam
), (short)HIWORD(lParam
));
586 tme
.cbSize
= sizeof(TRACKMOUSEEVENT
);
587 tme
.dwFlags
= TME_LEAVE
;
588 tme
.hwndTrack
= hImageArea
;
590 TrackMouseEvent(&tme
);
594 if ((wParam
& MK_LBUTTON
) != 0)
596 whilePaintingL(hDrawingDC
, (short)LOWORD(lParam
) * 1000 / zoom
,
597 (short)HIWORD(lParam
) * 1000 / zoom
, fgColor
, bgColor
);
598 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
599 if ((activeTool
>= 10) || (activeTool
== 2))
602 _stprintf(sizeStr
, _T("%d x %d"), (short)LOWORD(lParam
) * 1000 / zoom
- startX
,
603 (short)HIWORD(lParam
) * 1000 / zoom
- startY
);
604 SendMessage(hStatusBar
, SB_SETTEXT
, 2, (LPARAM
) sizeStr
);
607 if ((wParam
& MK_RBUTTON
) != 0)
609 whilePaintingR(hDrawingDC
, (short)LOWORD(lParam
) * 1000 / zoom
,
610 (short)HIWORD(lParam
) * 1000 / zoom
, fgColor
, bgColor
);
611 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
612 if (activeTool
>= 10)
615 _stprintf(sizeStr
, _T("%d x %d"), (short)LOWORD(lParam
) * 1000 / zoom
- startX
,
616 (short)HIWORD(lParam
) * 1000 / zoom
- startY
);
617 SendMessage(hStatusBar
, SB_SETTEXT
, 2, (LPARAM
) sizeStr
);
625 SendMessage(hStatusBar
, SB_SETTEXT
, 1, (LPARAM
) _T(""));
627 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
630 // menu and button events
633 switch (LOWORD(wParam
))
637 HICON paintIcon
= LoadIcon(hProgInstance
, MAKEINTRESOURCE(IDI_APPICON
));
638 TCHAR infotitle
[100];
640 LoadString(hProgInstance
, IDS_INFOTITLE
, infotitle
, SIZEOF(infotitle
));
641 LoadString(hProgInstance
, IDS_INFOTEXT
, infotext
, SIZEOF(infotext
));
642 ShellAbout(hMainWnd
, infotitle
, infotext
, paintIcon
);
643 DeleteObject(paintIcon
);
646 case IDM_HELPHELPTOPICS
:
647 //HtmlHelp(hMainWnd, "help\\Paint.chm", 0, 0);
650 SendMessage(hwnd
, WM_CLOSE
, wParam
, lParam
);
653 Rectangle(hDrawingDC
, 0 - 1, 0 - 1, imgXRes
+ 1, imgYRes
+ 1);
654 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
657 if (GetOpenFileName(&ofn
) != 0)
659 HBITMAP bmNew
= NULL
;
660 LoadDIBFromFile(&bmNew
, ofn
.lpstrFile
, &fileTime
, &fileSize
, &fileHPPM
, &fileVPPM
);
665 insertReversible(bmNew
);
666 updateCanvasAndScrollbars();
667 CopyMemory(filename
, ofn
.lpstrFileTitle
, sizeof(filename
));
668 CopyMemory(filepathname
, ofn
.lpstrFileTitle
, sizeof(filepathname
));
669 LoadString(hProgInstance
, IDS_WINDOWTITLE
, resstr
, SIZEOF(resstr
));
670 _stprintf(tempstr
, resstr
, filename
);
671 SetWindowText(hMainWnd
, tempstr
);
680 SaveDIBToFile(hBms
[currInd
], filepathname
, hDrawingDC
, &fileTime
, &fileSize
, fileHPPM
,
685 SendMessage(hwnd
, WM_COMMAND
, IDM_FILESAVEAS
, 0);
688 if (GetSaveFileName(&sfn
) != 0)
692 SaveDIBToFile(hBms
[currInd
], sfn
.lpstrFile
, hDrawingDC
, &fileTime
, &fileSize
,
694 CopyMemory(filename
, sfn
.lpstrFileTitle
, sizeof(filename
));
695 CopyMemory(filepathname
, sfn
.lpstrFile
, sizeof(filepathname
));
696 LoadString(hProgInstance
, IDS_WINDOWTITLE
, resstr
, SIZEOF(resstr
));
697 _stprintf(tempstr
, resstr
, filename
);
698 SetWindowText(hMainWnd
, tempstr
);
703 case IDM_FILEASWALLPAPERPLANE
:
704 SetWallpaper(filepathname
, 1, 1);
706 case IDM_FILEASWALLPAPERCENTERED
:
707 SetWallpaper(filepathname
, 1, 0);
709 case IDM_FILEASWALLPAPERSTRETCHED
:
710 SetWallpaper(filepathname
, 2, 0);
714 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
718 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
721 OpenClipboard(hMainWnd
);
723 SetClipboardData(CF_BITMAP
, CopyImage(hSelBm
, IMAGE_BITMAP
, 0, 0, LR_COPYRETURNORG
));
727 OpenClipboard(hMainWnd
);
728 if (GetClipboardData(CF_BITMAP
) != NULL
)
730 DeleteObject(SelectObject(hSelDC
, hSelBm
= CopyImage(GetClipboardData(CF_BITMAP
),
734 rectSel_src
[0] = rectSel_src
[1] = rectSel_src
[2] = rectSel_src
[3] = 0;
735 rectSel_dest
[0] = rectSel_dest
[1] = 0;
736 rectSel_dest
[2] = GetDIBWidth(hSelBm
);
737 rectSel_dest
[3] = GetDIBHeight(hSelBm
);
738 BitBlt(hDrawingDC
, rectSel_dest
[0], rectSel_dest
[1], rectSel_dest
[2], rectSel_dest
[3],
739 hSelDC
, 0, 0, SRCCOPY
);
741 ShowWindow(hSelection
, SW_SHOW
);
745 case IDM_EDITDELETESELECTION
:
747 /* remove selection window and already painted content using undo(),
748 paint Rect for rectangular selections and nothing for freeform selections */
753 Rect(hDrawingDC
, rectSel_dest
[0], rectSel_dest
[1], rectSel_dest
[2] + rectSel_dest
[0],
754 rectSel_dest
[3] + rectSel_dest
[1], bgColor
, bgColor
, 0, TRUE
);
758 case IDM_EDITSELECTALL
:
761 startPaintingL(hDrawingDC
, 0, 0, fgColor
, bgColor
);
762 whilePaintingL(hDrawingDC
, imgXRes
, imgYRes
, fgColor
, bgColor
);
763 endPaintingL(hDrawingDC
, imgXRes
, imgYRes
, fgColor
, bgColor
);
767 if (GetSaveFileName(&ofn
) != 0)
768 SaveDIBToFile(hSelBm
, ofn
.lpstrFile
, hDrawingDC
, NULL
, NULL
, fileHPPM
, fileVPPM
);
770 case IDM_COLORSEDITPALETTE
:
771 if (ChooseColor(&choosecolor
))
773 fgColor
= choosecolor
.rgbResult
;
774 SendMessage(hPalWin
, WM_PAINT
, 0, 0);
777 case IDM_IMAGEINVERTCOLORS
:
781 SetRect(&tempRect
, 0, 0, imgXRes
, imgYRes
);
782 InvertRect(hDrawingDC
, &tempRect
);
783 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
786 case IDM_IMAGEDELETEIMAGE
:
788 Rect(hDrawingDC
, 0, 0, imgXRes
, imgYRes
, bgColor
, bgColor
, 0, TRUE
);
789 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
791 case IDM_IMAGEROTATEMIRROR
:
792 switch (mirrorRotateDlg())
796 StretchBlt(hDrawingDC
, imgXRes
- 1, 0, -imgXRes
, imgYRes
, hDrawingDC
, 0, 0,
797 imgXRes
, imgYRes
, SRCCOPY
);
798 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
802 StretchBlt(hDrawingDC
, 0, imgYRes
- 1, imgXRes
, -imgYRes
, hDrawingDC
, 0, 0,
803 imgXRes
, imgYRes
, SRCCOPY
);
804 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
808 StretchBlt(hDrawingDC
, imgXRes
- 1, imgYRes
- 1, -imgXRes
, -imgYRes
, hDrawingDC
,
809 0, 0, imgXRes
, imgYRes
, SRCCOPY
);
810 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
814 case IDM_IMAGEATTRIBUTES
:
816 int retVal
= attributesDlg();
817 if ((LOWORD(retVal
) != 0) && (HIWORD(retVal
) != 0))
819 cropReversible(LOWORD(retVal
), HIWORD(retVal
), 0, 0);
820 updateCanvasAndScrollbars();
824 case IDM_IMAGECHANGESIZE
:
826 int retVal
= changeSizeDlg();
827 if ((LOWORD(retVal
) != 0) && (HIWORD(retVal
) != 0))
829 insertReversible(CopyImage(hBms
[currInd
], IMAGE_BITMAP
,
830 imgXRes
* LOWORD(retVal
) / 100,
831 imgYRes
* HIWORD(retVal
) / 100, 0));
832 updateCanvasAndScrollbars();
836 case IDM_IMAGEDRAWOPAQUE
:
837 transpBg
= 1 - transpBg
;
838 SendMessage(hToolSettings
, WM_PAINT
, 0, 0);
841 insertReversible(CopyImage(hSelBm
, IMAGE_BITMAP
, 0, 0, LR_COPYRETURNORG
));
842 updateCanvasAndScrollbars();
845 case IDM_VIEWTOOLBOX
:
846 ShowWindow(hToolBoxContainer
, IsWindowVisible(hToolBoxContainer
) ? SW_HIDE
: SW_SHOW
);
847 alignChildrenToMainWindow();
849 case IDM_VIEWCOLORPALETTE
:
850 ShowWindow(hPalWin
, IsWindowVisible(hPalWin
) ? SW_HIDE
: SW_SHOW
);
851 alignChildrenToMainWindow();
853 case IDM_VIEWSTATUSBAR
:
854 ShowWindow(hStatusBar
, IsWindowVisible(hStatusBar
) ? SW_HIDE
: SW_SHOW
);
855 alignChildrenToMainWindow();
858 case IDM_VIEWSHOWGRID
:
859 showGrid
= !showGrid
;
861 case IDM_VIEWSHOWMINIATURE
:
862 showMiniature
= !showMiniature
;
863 ShowWindow(hwndMiniature
, showMiniature
? SW_SHOW
: SW_HIDE
);
866 case IDM_VIEWZOOM125
:
875 case IDM_VIEWZOOM100
:
878 case IDM_VIEWZOOM200
:
881 case IDM_VIEWZOOM400
:
884 case IDM_VIEWZOOM800
:
938 return DefWindowProc(hwnd
, message
, wParam
, lParam
);