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
);
118 WindowProcedure(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
120 switch (message
) /* handle the messages */
123 PostQuitMessage(0); /* send a WM_QUIT to the message queue */
127 if (hwnd
== hwndMiniature
)
129 ShowWindow(hwndMiniature
, SW_HIDE
);
130 showMiniature
= FALSE
;
135 TCHAR programname
[20];
136 TCHAR saveprompttext
[100];
138 LoadString(hProgInstance
, IDS_PROGRAMNAME
, programname
, SIZEOF(programname
));
139 LoadString(hProgInstance
, IDS_SAVEPROMPTTEXT
, saveprompttext
, SIZEOF(saveprompttext
));
140 _stprintf(temptext
, saveprompttext
, filename
);
141 switch (MessageBox(hwnd
, temptext
, programname
, MB_YESNOCANCEL
| MB_ICONQUESTION
))
147 SendMessage(hwnd
, WM_COMMAND
, IDM_FILESAVEAS
, 0);
158 case WM_INITMENUPOPUP
:
164 EnableMenuItem(GetMenu(hMainWnd
), IDM_FILEASWALLPAPERPLANE
,
165 MF_ENABLED
| MF_BYCOMMAND
);
166 EnableMenuItem(GetMenu(hMainWnd
), IDM_FILEASWALLPAPERCENTERED
,
167 MF_ENABLED
| MF_BYCOMMAND
);
168 EnableMenuItem(GetMenu(hMainWnd
), IDM_FILEASWALLPAPERSTRETCHED
,
169 MF_ENABLED
| MF_BYCOMMAND
);
173 EnableMenuItem(GetMenu(hMainWnd
), IDM_FILEASWALLPAPERPLANE
,
174 MF_GRAYED
| MF_BYCOMMAND
);
175 EnableMenuItem(GetMenu(hMainWnd
), IDM_FILEASWALLPAPERCENTERED
,
176 MF_GRAYED
| MF_BYCOMMAND
);
177 EnableMenuItem(GetMenu(hMainWnd
), IDM_FILEASWALLPAPERSTRETCHED
,
178 MF_GRAYED
| MF_BYCOMMAND
);
183 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITUNDO
, MF_ENABLED
| MF_BYCOMMAND
);
185 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITUNDO
, MF_GRAYED
| MF_BYCOMMAND
);
187 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITREDO
, MF_ENABLED
| MF_BYCOMMAND
);
189 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITREDO
, MF_GRAYED
| MF_BYCOMMAND
);
190 if (IsWindowVisible(hSelection
))
192 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITCUT
, MF_ENABLED
| MF_BYCOMMAND
);
193 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITCOPY
, MF_ENABLED
| MF_BYCOMMAND
);
194 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITDELETESELECTION
, MF_ENABLED
| MF_BYCOMMAND
);
195 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITINVERTSELECTION
, MF_ENABLED
| MF_BYCOMMAND
);
196 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITCOPYTO
, MF_ENABLED
| MF_BYCOMMAND
);
200 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITCUT
, MF_GRAYED
| MF_BYCOMMAND
);
201 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITCOPY
, MF_GRAYED
| MF_BYCOMMAND
);
202 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITDELETESELECTION
, MF_GRAYED
| MF_BYCOMMAND
);
203 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITINVERTSELECTION
, MF_GRAYED
| MF_BYCOMMAND
);
204 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITCOPYTO
, MF_GRAYED
| MF_BYCOMMAND
);
206 OpenClipboard(hMainWnd
);
207 if (GetClipboardData(CF_BITMAP
) != NULL
)
208 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITPASTE
, MF_ENABLED
| MF_BYCOMMAND
);
210 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITPASTE
, MF_GRAYED
| MF_BYCOMMAND
);
214 if (IsWindowVisible(hSelection
))
215 EnableMenuItem(GetMenu(hMainWnd
), IDM_IMAGECROP
, MF_ENABLED
| MF_BYCOMMAND
);
217 EnableMenuItem(GetMenu(hMainWnd
), IDM_IMAGECROP
, MF_GRAYED
| MF_BYCOMMAND
);
218 CheckMenuItem(GetMenu(hMainWnd
), IDM_IMAGEDRAWOPAQUE
, (transpBg
== 0) ?
219 (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
222 if (IsWindowVisible(hStatusBar
))
223 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWSTATUSBAR
, MF_CHECKED
| MF_BYCOMMAND
);
225 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWSTATUSBAR
, MF_UNCHECKED
| MF_BYCOMMAND
);
227 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWSHOWGRID
,
228 showGrid
? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
229 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWSHOWMINIATURE
,
230 showMiniature
? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
232 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM125
,
233 (zoom
== 125) ? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
234 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM25
,
235 (zoom
== 250) ? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
236 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM50
,
237 (zoom
== 500) ? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
238 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM100
,
239 (zoom
== 1000) ? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
240 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM200
,
241 (zoom
== 2000) ? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
242 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM400
,
243 (zoom
== 4000) ? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
244 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM800
,
245 (zoom
== 8000) ? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
250 if (hwnd
== hMainWnd
)
252 int test
[] = { LOWORD(lParam
) - 260, LOWORD(lParam
) - 140, LOWORD(lParam
) - 20 };
253 SendMessage(hStatusBar
, WM_SIZE
, wParam
, lParam
);
254 SendMessage(hStatusBar
, SB_SETPARTS
, 3, (int)&test
);
255 MoveWindow(hScrollbox
, 56, 49, LOWORD(lParam
) - 56, HIWORD(lParam
) - 72, TRUE
);
256 //InvalidateRect(hwnd, NULL, TRUE);
258 if (hwnd
== hImageArea
)
260 MoveWindow(hSizeboxLeftTop
,
263 MoveWindow(hSizeboxCenterTop
,
264 imgXRes
* zoom
/ 2000 + 3 * 3 / 4,
266 MoveWindow(hSizeboxRightTop
,
267 imgXRes
* zoom
/ 1000 + 3,
269 MoveWindow(hSizeboxLeftCenter
,
271 imgYRes
* zoom
/ 2000 + 3 * 3 / 4, 3, 3, TRUE
);
272 MoveWindow(hSizeboxRightCenter
,
273 imgXRes
* zoom
/ 1000 + 3,
274 imgYRes
* zoom
/ 2000 + 3 * 3 / 4, 3, 3, TRUE
);
275 MoveWindow(hSizeboxLeftBottom
,
277 imgYRes
* zoom
/ 1000 + 3, 3, 3, TRUE
);
278 MoveWindow(hSizeboxCenterBottom
,
279 imgXRes
* zoom
/ 2000 + 3 * 3 / 4,
280 imgYRes
* zoom
/ 1000 + 3, 3, 3, TRUE
);
281 MoveWindow(hSizeboxRightBottom
,
282 imgXRes
* zoom
/ 1000 + 3,
283 imgYRes
* zoom
/ 1000 + 3, 3, 3, TRUE
);
285 if ((hwnd
== hImageArea
) || (hwnd
== hScrollbox
))
287 long clientRectScrollbox
[4];
288 long clientRectImageArea
[4];
290 GetClientRect(hScrollbox
, (LPRECT
) &clientRectScrollbox
);
291 GetClientRect(hImageArea
, (LPRECT
) &clientRectImageArea
);
292 si
.cbSize
= sizeof(SCROLLINFO
);
293 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
294 si
.nMax
= clientRectImageArea
[2] + 6 - 1;
296 si
.nPage
= clientRectScrollbox
[2];
297 SetScrollInfo(hScrollbox
, SB_HORZ
, &si
, TRUE
);
298 GetClientRect(hScrollbox
, (LPRECT
) clientRectScrollbox
);
299 si
.nMax
= clientRectImageArea
[3] + 6 - 1;
300 si
.nPage
= clientRectScrollbox
[3];
301 SetScrollInfo(hScrollbox
, SB_VERT
, &si
, TRUE
);
302 MoveWindow(hScrlClient
,
303 -GetScrollPos(hScrollbox
, SB_HORZ
), -GetScrollPos(hScrollbox
, SB_VERT
),
304 max(clientRectImageArea
[2] + 6, clientRectScrollbox
[2]),
305 max(clientRectImageArea
[3] + 6, clientRectScrollbox
[3]), TRUE
);
310 if (hwnd
== hScrollbox
)
313 si
.cbSize
= sizeof(SCROLLINFO
);
315 GetScrollInfo(hScrollbox
, SB_HORZ
, &si
);
316 switch (LOWORD(wParam
))
319 case SB_THUMBPOSITION
:
320 si
.nPos
= HIWORD(wParam
);
335 SetScrollInfo(hScrollbox
, SB_HORZ
, &si
, TRUE
);
336 MoveWindow(hScrlClient
, -GetScrollPos(hScrollbox
, SB_HORZ
),
337 -GetScrollPos(hScrollbox
, SB_VERT
), imgXRes
* zoom
/ 1000 + 6,
338 imgYRes
* zoom
/ 1000 + 6, TRUE
);
343 if (hwnd
== hScrollbox
)
346 si
.cbSize
= sizeof(SCROLLINFO
);
348 GetScrollInfo(hScrollbox
, SB_VERT
, &si
);
349 switch (LOWORD(wParam
))
352 case SB_THUMBPOSITION
:
353 si
.nPos
= HIWORD(wParam
);
368 SetScrollInfo(hScrollbox
, SB_VERT
, &si
, TRUE
);
369 MoveWindow(hScrlClient
, -GetScrollPos(hScrollbox
, SB_HORZ
),
370 -GetScrollPos(hScrollbox
, SB_VERT
), imgXRes
* zoom
/ 1000 + 6,
371 imgYRes
* zoom
/ 1000 + 6, TRUE
);
375 case WM_GETMINMAXINFO
:
376 if (hwnd
== hMainWnd
)
378 MINMAXINFO
*mm
= (LPMINMAXINFO
) lParam
;
379 (*mm
).ptMinTrackSize
.x
= 330;
380 (*mm
).ptMinTrackSize
.y
= 430;
385 DefWindowProc(hwnd
, message
, wParam
, lParam
);
386 if (hwnd
== hImageArea
)
388 HDC hdc
= GetDC(hImageArea
);
389 StretchBlt(hdc
, 0, 0, imgXRes
* zoom
/ 1000, imgYRes
* zoom
/ 1000, hDrawingDC
, 0, 0, imgXRes
,
391 if (showGrid
&& (zoom
>= 4000))
393 HPEN oldPen
= SelectObject(hdc
, CreatePen(PS_SOLID
, 1, 0x00a0a0a0));
395 for(counter
= 0; counter
<= imgYRes
; counter
++)
397 MoveToEx(hdc
, 0, counter
* zoom
/ 1000, NULL
);
398 LineTo(hdc
, imgXRes
* zoom
/ 1000, counter
* zoom
/ 1000);
400 for(counter
= 0; counter
<= imgXRes
; counter
++)
402 MoveToEx(hdc
, counter
* zoom
/ 1000, 0, NULL
);
403 LineTo(hdc
, counter
* zoom
/ 1000, imgYRes
* zoom
/ 1000);
405 DeleteObject(SelectObject(hdc
, oldPen
));
407 ReleaseDC(hImageArea
, hdc
);
408 SendMessage(hSelection
, WM_PAINT
, 0, 0);
409 SendMessage(hwndMiniature
, WM_PAINT
, 0, 0);
411 else if (hwnd
== hwndMiniature
)
415 GetClientRect(hwndMiniature
, (LPRECT
) &mclient
);
416 hdc
= GetDC(hwndMiniature
);
417 BitBlt(hdc
, -min(imgXRes
* GetScrollPos(hScrollbox
, SB_HORZ
) / 10000, imgXRes
- mclient
[2]),
418 -min(imgYRes
* GetScrollPos(hScrollbox
, SB_VERT
) / 10000, imgYRes
- mclient
[3]),
419 imgXRes
, imgYRes
, hDrawingDC
, 0, 0, SRCCOPY
);
420 ReleaseDC(hwndMiniature
, hdc
);
424 // mouse events used for drawing
427 if (hwnd
== hImageArea
)
435 SetCursor(hCurColor
);
444 SetCursor(hCurAirbrush
);
447 SetCursor(LoadCursor(NULL
, IDC_CROSS
));
451 DefWindowProc(hwnd
, message
, wParam
, lParam
);
455 if (hwnd
== hImageArea
)
457 if ((!drawing
) || (activeTool
== 5))
459 SetCapture(hImageArea
);
461 startPaintingL(hDrawingDC
, LOWORD(lParam
) * 1000 / zoom
, HIWORD(lParam
) * 1000 / zoom
,
466 SendMessage(hwnd
, WM_LBUTTONUP
, wParam
, lParam
);
469 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
470 if ((activeTool
== 6) && (zoom
< 8000))
471 zoomTo(zoom
* 2, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
476 if (hwnd
== hImageArea
)
478 if ((!drawing
) || (activeTool
== 5))
480 SetCapture(hImageArea
);
482 startPaintingR(hDrawingDC
, LOWORD(lParam
) * 1000 / zoom
, HIWORD(lParam
) * 1000 / zoom
,
487 SendMessage(hwnd
, WM_RBUTTONUP
, wParam
, lParam
);
490 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
491 if ((activeTool
== 6) && (zoom
> 125))
492 zoomTo(zoom
/ 2, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
497 if ((hwnd
== hImageArea
) && drawing
)
501 endPaintingL(hDrawingDC
, LOWORD(lParam
) * 1000 / zoom
, HIWORD(lParam
) * 1000 / zoom
, fgColor
,
503 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
507 GetPixel(hDrawingDC
, LOWORD(lParam
) * 1000 / zoom
, HIWORD(lParam
) * 1000 / zoom
);
508 if (tempColor
!= CLR_INVALID
)
510 SendMessage(hPalWin
, WM_PAINT
, 0, 0);
512 SendMessage(hStatusBar
, SB_SETTEXT
, 2, (LPARAM
) "");
517 if ((hwnd
== hImageArea
) && drawing
)
521 endPaintingR(hDrawingDC
, LOWORD(lParam
) * 1000 / zoom
, HIWORD(lParam
) * 1000 / zoom
, fgColor
,
523 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
527 GetPixel(hDrawingDC
, LOWORD(lParam
) * 1000 / zoom
, HIWORD(lParam
) * 1000 / zoom
);
528 if (tempColor
!= CLR_INVALID
)
530 SendMessage(hPalWin
, WM_PAINT
, 0, 0);
532 SendMessage(hStatusBar
, SB_SETTEXT
, 2, (LPARAM
) "");
537 if (hwnd
== hImageArea
)
539 if ((!drawing
) || (activeTool
<= 9))
544 _stprintf(coordStr
, _T("%d, %d"), (short)LOWORD(lParam
) * 1000 / zoom
,
545 (short)HIWORD(lParam
) * 1000 / zoom
);
546 SendMessage(hStatusBar
, SB_SETTEXT
, 1, (LPARAM
) coordStr
);
550 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
551 drawZoomFrame((short)LOWORD(lParam
), (short)HIWORD(lParam
));
554 tme
.cbSize
= sizeof(TRACKMOUSEEVENT
);
555 tme
.dwFlags
= TME_LEAVE
;
556 tme
.hwndTrack
= hImageArea
;
558 TrackMouseEvent(&tme
);
562 if ((wParam
& MK_LBUTTON
) != 0)
564 whilePaintingL(hDrawingDC
, (short)LOWORD(lParam
) * 1000 / zoom
,
565 (short)HIWORD(lParam
) * 1000 / zoom
, fgColor
, bgColor
);
566 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
567 if ((activeTool
>= 10) || (activeTool
== 2))
570 _stprintf(sizeStr
, _T("%d x %d"), (short)LOWORD(lParam
) * 1000 / zoom
- startX
,
571 (short)HIWORD(lParam
) * 1000 / zoom
- startY
);
572 SendMessage(hStatusBar
, SB_SETTEXT
, 2, (LPARAM
) sizeStr
);
575 if ((wParam
& MK_RBUTTON
) != 0)
577 whilePaintingR(hDrawingDC
, (short)LOWORD(lParam
) * 1000 / zoom
,
578 (short)HIWORD(lParam
) * 1000 / zoom
, fgColor
, bgColor
);
579 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
580 if (activeTool
>= 10)
583 _stprintf(sizeStr
, _T("%d x %d"), (short)LOWORD(lParam
) * 1000 / zoom
- startX
,
584 (short)HIWORD(lParam
) * 1000 / zoom
- startY
);
585 SendMessage(hStatusBar
, SB_SETTEXT
, 2, (LPARAM
) sizeStr
);
593 SendMessage(hStatusBar
, SB_SETTEXT
, 1, (LPARAM
) _T(""));
595 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
598 // menu and button events
601 switch (LOWORD(wParam
))
605 HICON paintIcon
= LoadIcon(hProgInstance
, MAKEINTRESOURCE(IDI_APPICON
));
606 TCHAR infotitle
[100];
608 LoadString(hProgInstance
, IDS_INFOTITLE
, infotitle
, SIZEOF(infotitle
));
609 LoadString(hProgInstance
, IDS_INFOTEXT
, infotext
, SIZEOF(infotext
));
610 ShellAbout(hMainWnd
, infotitle
, infotext
, paintIcon
);
611 DeleteObject(paintIcon
);
614 case IDM_HELPHELPTOPICS
:
615 //HtmlHelp(hMainWnd, "help\\Paint.chm", 0, 0);
618 SendMessage(hwnd
, WM_CLOSE
, wParam
, lParam
);
621 Rectangle(hDrawingDC
, 0 - 1, 0 - 1, imgXRes
+ 1, imgYRes
+ 1);
622 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
625 if (GetOpenFileName(&ofn
) != 0)
627 HBITMAP bmNew
= NULL
;
628 LoadDIBFromFile(&bmNew
, ofn
.lpstrFile
, &fileTime
, &fileSize
, &fileHPPM
, &fileVPPM
);
633 insertReversible(bmNew
);
634 updateCanvasAndScrollbars();
635 CopyMemory(filename
, ofn
.lpstrFileTitle
, sizeof(filename
));
636 CopyMemory(filepathname
, ofn
.lpstrFileTitle
, sizeof(filepathname
));
637 LoadString(hProgInstance
, IDS_WINDOWTITLE
, resstr
, SIZEOF(resstr
));
638 _stprintf(tempstr
, resstr
, filename
);
639 SetWindowText(hMainWnd
, tempstr
);
648 SaveDIBToFile(hBms
[currInd
], filepathname
, hDrawingDC
, &fileTime
, &fileSize
, fileHPPM
,
653 SendMessage(hwnd
, WM_COMMAND
, IDM_FILESAVEAS
, 0);
656 if (GetSaveFileName(&sfn
) != 0)
660 SaveDIBToFile(hBms
[currInd
], sfn
.lpstrFile
, hDrawingDC
, &fileTime
, &fileSize
,
662 CopyMemory(filename
, sfn
.lpstrFileTitle
, sizeof(filename
));
663 CopyMemory(filepathname
, sfn
.lpstrFile
, sizeof(filepathname
));
664 LoadString(hProgInstance
, IDS_WINDOWTITLE
, resstr
, SIZEOF(resstr
));
665 _stprintf(tempstr
, resstr
, filename
);
666 SetWindowText(hMainWnd
, tempstr
);
671 case IDM_FILEASWALLPAPERPLANE
:
672 SetWallpaper(filepathname
, 1, 1);
674 case IDM_FILEASWALLPAPERCENTERED
:
675 SetWallpaper(filepathname
, 1, 0);
677 case IDM_FILEASWALLPAPERSTRETCHED
:
678 SetWallpaper(filepathname
, 2, 0);
682 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
686 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
689 OpenClipboard(hMainWnd
);
691 SetClipboardData(CF_BITMAP
, CopyImage(hSelBm
, IMAGE_BITMAP
, 0, 0, LR_COPYRETURNORG
));
695 OpenClipboard(hMainWnd
);
696 if (GetClipboardData(CF_BITMAP
) != NULL
)
698 DeleteObject(SelectObject(hSelDC
, hSelBm
= CopyImage(GetClipboardData(CF_BITMAP
),
702 rectSel_src
[0] = rectSel_src
[1] = rectSel_src
[2] = rectSel_src
[3] = 0;
703 rectSel_dest
[0] = rectSel_dest
[1] = 0;
704 rectSel_dest
[2] = GetDIBWidth(hSelBm
);
705 rectSel_dest
[3] = GetDIBHeight(hSelBm
);
706 BitBlt(hDrawingDC
, rectSel_dest
[0], rectSel_dest
[1], rectSel_dest
[2], rectSel_dest
[3],
707 hSelDC
, 0, 0, SRCCOPY
);
709 ShowWindow(hSelection
, SW_SHOW
);
713 case IDM_EDITDELETESELECTION
:
714 ShowWindow(hSelection
, SW_HIDE
);
716 case IDM_EDITSELECTALL
:
719 startPaintingL(hDrawingDC
, 0, 0, fgColor
, bgColor
);
720 whilePaintingL(hDrawingDC
, imgXRes
, imgYRes
, fgColor
, bgColor
);
721 endPaintingL(hDrawingDC
, imgXRes
, imgYRes
, fgColor
, bgColor
);
725 if (GetSaveFileName(&ofn
) != 0)
726 SaveDIBToFile(hSelBm
, ofn
.lpstrFile
, hDrawingDC
, NULL
, NULL
, fileHPPM
, fileVPPM
);
728 case IDM_COLORSEDITPALETTE
:
729 if (ChooseColor(&choosecolor
))
731 fgColor
= choosecolor
.rgbResult
;
732 SendMessage(hPalWin
, WM_PAINT
, 0, 0);
735 case IDM_IMAGEINVERTCOLORS
:
739 SetRect(&tempRect
, 0, 0, imgXRes
, imgYRes
);
740 InvertRect(hDrawingDC
, &tempRect
);
741 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
744 case IDM_IMAGEDELETEIMAGE
:
746 Rect(hDrawingDC
, 0, 0, imgXRes
, imgYRes
, bgColor
, bgColor
, 0, TRUE
);
747 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
749 case IDM_IMAGEROTATEMIRROR
:
750 switch (mirrorRotateDlg())
754 StretchBlt(hDrawingDC
, imgXRes
- 1, 0, -imgXRes
, imgYRes
, hDrawingDC
, 0, 0,
755 imgXRes
, imgYRes
, SRCCOPY
);
756 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
760 StretchBlt(hDrawingDC
, 0, imgYRes
- 1, imgXRes
, -imgYRes
, hDrawingDC
, 0, 0,
761 imgXRes
, imgYRes
, SRCCOPY
);
762 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
766 StretchBlt(hDrawingDC
, imgXRes
- 1, imgYRes
- 1, -imgXRes
, -imgYRes
, hDrawingDC
,
767 0, 0, imgXRes
, imgYRes
, SRCCOPY
);
768 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
772 case IDM_IMAGEATTRIBUTES
:
774 int retVal
= attributesDlg();
775 if ((LOWORD(retVal
) != 0) && (HIWORD(retVal
) != 0))
777 cropReversible(LOWORD(retVal
), HIWORD(retVal
), 0, 0);
778 updateCanvasAndScrollbars();
782 case IDM_IMAGECHANGESIZE
:
784 int retVal
= changeSizeDlg();
785 if ((LOWORD(retVal
) != 0) && (HIWORD(retVal
) != 0))
787 insertReversible(CopyImage(hBms
[currInd
], IMAGE_BITMAP
,
788 imgXRes
* LOWORD(retVal
) / 100,
789 imgYRes
* HIWORD(retVal
) / 100, 0));
790 updateCanvasAndScrollbars();
794 case IDM_IMAGEDRAWOPAQUE
:
795 transpBg
= 1 - transpBg
;
796 SendMessage(hToolSettings
, WM_PAINT
, 0, 0);
799 insertReversible(CopyImage(hSelBm
, IMAGE_BITMAP
, 0, 0, LR_COPYRETURNORG
));
800 updateCanvasAndScrollbars();
803 case IDM_VIEWSTATUSBAR
:
804 ShowWindow(hStatusBar
, IsWindowVisible(hStatusBar
) ? SW_HIDE
: SW_SHOW
);
807 case IDM_VIEWSHOWGRID
:
808 showGrid
= !showGrid
;
810 case IDM_VIEWSHOWMINIATURE
:
811 showMiniature
= !showMiniature
;
812 ShowWindow(hwndMiniature
, showMiniature
? SW_SHOW
: SW_HIDE
);
815 case IDM_VIEWZOOM125
:
824 case IDM_VIEWZOOM100
:
827 case IDM_VIEWZOOM200
:
830 case IDM_VIEWZOOM400
:
833 case IDM_VIEWZOOM800
:
887 return DefWindowProc(hwnd
, message
, wParam
, lParam
);