2 * PROJECT: PAINT for ReactOS
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 ********************************************************/
28 void selectTool(int tool
)
30 ShowWindow(hSelection
, SW_HIDE
);
32 pointSP
= 0; // resets the point-buffer of the polygon and bezier functions
33 SendMessage(hToolSettings
, WM_PAINT
, 0, 0);
35 ShowWindow(hTrackbarZoom
, SW_SHOW
);
37 ShowWindow(hTrackbarZoom
, SW_HIDE
);
40 void updateCanvasAndScrollbars()
42 ShowWindow(hSelection
, SW_HIDE
);
43 MoveWindow(hImageArea
, 3, 3, imgXRes
*zoom
/1000, imgYRes
*zoom
/1000, FALSE
);
44 InvalidateRect(hScrollbox
, NULL
, TRUE
);
45 InvalidateRect(hImageArea
, NULL
, FALSE
);
47 SetScrollPos(hScrollbox
, SB_HORZ
, 0, TRUE
);
48 SetScrollPos(hScrollbox
, SB_VERT
, 0, TRUE
);
51 void zoomTo(int newZoom
, int mouseX
, int mouseY
)
53 long clientRectScrollbox
[4];
54 long clientRectImageArea
[4];
55 GetClientRect(hScrollbox
, (LPRECT
)&clientRectScrollbox
);
56 GetClientRect(hImageArea
, (LPRECT
)&clientRectImageArea
);
58 w
= clientRectImageArea
[2] * clientRectScrollbox
[2] / (clientRectImageArea
[2] * newZoom
/ zoom
);
59 h
= clientRectImageArea
[3] * clientRectScrollbox
[3] / (clientRectImageArea
[3] * newZoom
/ zoom
);
60 x
= max(0, min(clientRectImageArea
[2] - w
, mouseX
- w
/ 2)) * newZoom
/ zoom
;
61 y
= max(0, min(clientRectImageArea
[3] - h
, mouseY
- h
/ 2)) * newZoom
/ zoom
;
65 ShowWindow(hSelection
, SW_HIDE
);
66 MoveWindow(hImageArea
, 3, 3, imgXRes
*zoom
/1000, imgYRes
*zoom
/1000, FALSE
);
67 InvalidateRect(hScrollbox
, NULL
, TRUE
);
68 InvalidateRect(hImageArea
, NULL
, FALSE
);
70 SendMessage(hScrollbox
, WM_HSCROLL
, SB_THUMBPOSITION
| (x
<< 16), 0);
71 SendMessage(hScrollbox
, WM_VSCROLL
, SB_THUMBPOSITION
| (y
<< 16), 0);
74 int tempZoom
= newZoom
;
78 tempZoom
= tempZoom
>>1;
80 SendMessage(hTrackbarZoom
, TBM_SETPOS
, (WPARAM
)TRUE
, (LPARAM
)tbPos
);
83 void drawZoomFrame(int mouseX
, int mouseY
)
85 long clientRectScrollbox
[4];
86 long clientRectImageArea
[4];
87 GetClientRect(hScrollbox
, (LPRECT
)&clientRectScrollbox
);
88 GetClientRect(hImageArea
, (LPRECT
)&clientRectImageArea
);
90 w
= clientRectImageArea
[2] * clientRectScrollbox
[2] / (clientRectImageArea
[2] * 2);
91 h
= clientRectImageArea
[3] * clientRectScrollbox
[3] / (clientRectImageArea
[3] * 2);
92 x
= max(0, min(clientRectImageArea
[2] - w
, mouseX
- w
/ 2));
93 y
= max(0, min(clientRectImageArea
[3] - h
, mouseY
- h
/ 2));
95 hdc
= GetDC(hImageArea
);
97 oldPen
= SelectObject(hdc
, CreatePen(PS_SOLID
, 0, 0));
100 logbrush
.lbStyle
= BS_HOLLOW
;
101 oldBrush
= SelectObject(hdc
, CreateBrushIndirect(&logbrush
));
103 rop
= SetROP2(hdc
, R2_NOT
);
104 Rectangle(hdc
, x
, y
, x
+ w
, y
+ h
);
106 DeleteObject(SelectObject(hdc
, oldBrush
));
107 DeleteObject(SelectObject(hdc
, oldPen
));
108 ReleaseDC(hImageArea
, hdc
);
114 LRESULT CALLBACK
WindowProcedure (HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
116 switch (message
) /* handle the messages */
119 PostQuitMessage (0); /* send a WM_QUIT to the message queue */
122 if (hwnd
==hwndMiniature
)
124 ShowWindow(hwndMiniature
, SW_HIDE
);
125 showMiniature
= FALSE
;
130 TCHAR programname
[20];
131 TCHAR saveprompttext
[100];
133 LoadString(hProgInstance
, IDS_PROGRAMNAME
, programname
, SIZEOF(programname
));
134 LoadString(hProgInstance
, IDS_SAVEPROMPTTEXT
, saveprompttext
, SIZEOF(saveprompttext
));
135 _stprintf(temptext
, saveprompttext
, filename
);
136 switch (MessageBox(hwnd
, temptext
, programname
, MB_YESNOCANCEL
| MB_ICONQUESTION
))
142 SendMessage(hwnd
, WM_COMMAND
, IDM_FILESAVEAS
, 0);
152 case WM_INITMENUPOPUP
:
158 EnableMenuItem(GetMenu(hMainWnd
), IDM_FILEASWALLPAPERPLANE
, MF_ENABLED
| MF_BYCOMMAND
);
159 EnableMenuItem(GetMenu(hMainWnd
), IDM_FILEASWALLPAPERCENTERED
, MF_ENABLED
| MF_BYCOMMAND
);
160 EnableMenuItem(GetMenu(hMainWnd
), IDM_FILEASWALLPAPERSTRETCHED
, MF_ENABLED
| MF_BYCOMMAND
);
164 EnableMenuItem(GetMenu(hMainWnd
), IDM_FILEASWALLPAPERPLANE
, MF_GRAYED
| MF_BYCOMMAND
);
165 EnableMenuItem(GetMenu(hMainWnd
), IDM_FILEASWALLPAPERCENTERED
, MF_GRAYED
| MF_BYCOMMAND
);
166 EnableMenuItem(GetMenu(hMainWnd
), IDM_FILEASWALLPAPERSTRETCHED
, MF_GRAYED
| MF_BYCOMMAND
);
171 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITUNDO
, MF_ENABLED
| MF_BYCOMMAND
);
173 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITUNDO
, MF_GRAYED
| MF_BYCOMMAND
);
175 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITREDO
, MF_ENABLED
| MF_BYCOMMAND
);
177 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITREDO
, MF_GRAYED
| MF_BYCOMMAND
);
178 if (IsWindowVisible(hSelection
))
180 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITCUT
, MF_ENABLED
| MF_BYCOMMAND
);
181 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITCOPY
, MF_ENABLED
| MF_BYCOMMAND
);
182 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITDELETESELECTION
, MF_ENABLED
| MF_BYCOMMAND
);
183 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITINVERTSELECTION
, MF_ENABLED
| MF_BYCOMMAND
);
184 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITCOPYTO
, MF_ENABLED
| MF_BYCOMMAND
);
188 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITCUT
, MF_GRAYED
| MF_BYCOMMAND
);
189 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITCOPY
, MF_GRAYED
| MF_BYCOMMAND
);
190 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITDELETESELECTION
, MF_GRAYED
| MF_BYCOMMAND
);
191 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITINVERTSELECTION
, MF_GRAYED
| MF_BYCOMMAND
);
192 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITCOPYTO
, MF_GRAYED
| MF_BYCOMMAND
);
194 OpenClipboard(hMainWnd
);
195 if (GetClipboardData(CF_BITMAP
)!=NULL
)
196 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITPASTE
, MF_ENABLED
| MF_BYCOMMAND
);
198 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITPASTE
, MF_GRAYED
| MF_BYCOMMAND
);
202 if (IsWindowVisible(hSelection
))
203 EnableMenuItem(GetMenu(hMainWnd
), IDM_IMAGECROP
, MF_ENABLED
| MF_BYCOMMAND
);
205 EnableMenuItem(GetMenu(hMainWnd
), IDM_IMAGECROP
, MF_GRAYED
| MF_BYCOMMAND
);
207 CheckMenuItem(GetMenu(hMainWnd
), IDM_IMAGEDRAWOPAQUE
, MF_CHECKED
| MF_BYCOMMAND
);
209 CheckMenuItem(GetMenu(hMainWnd
), IDM_IMAGEDRAWOPAQUE
, MF_UNCHECKED
| MF_BYCOMMAND
);
212 if (IsWindowVisible(hStatusBar
))
213 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWSTATUSBAR
, MF_CHECKED
| MF_BYCOMMAND
);
215 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWSTATUSBAR
, MF_UNCHECKED
| MF_BYCOMMAND
);
218 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWSHOWGRID
, MF_CHECKED
| MF_BYCOMMAND
);
220 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWSHOWGRID
, MF_UNCHECKED
| MF_BYCOMMAND
);
222 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWSHOWMINIATURE
, MF_CHECKED
| MF_BYCOMMAND
);
224 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWSHOWMINIATURE
, MF_UNCHECKED
| MF_BYCOMMAND
);
227 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM125
, MF_CHECKED
| MF_BYCOMMAND
);
229 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM125
, MF_UNCHECKED
| MF_BYCOMMAND
);
231 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM25
, MF_CHECKED
| MF_BYCOMMAND
);
233 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM25
, MF_UNCHECKED
| MF_BYCOMMAND
);
235 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM50
, MF_CHECKED
| MF_BYCOMMAND
);
237 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM50
, MF_UNCHECKED
| MF_BYCOMMAND
);
239 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM100
, MF_CHECKED
| MF_BYCOMMAND
);
241 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM100
, MF_UNCHECKED
| MF_BYCOMMAND
);
243 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM200
, MF_CHECKED
| MF_BYCOMMAND
);
245 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM200
, MF_UNCHECKED
| MF_BYCOMMAND
);
247 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM400
, MF_CHECKED
| MF_BYCOMMAND
);
249 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM400
, MF_UNCHECKED
| MF_BYCOMMAND
);
251 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM800
, MF_CHECKED
| MF_BYCOMMAND
);
253 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM800
, MF_UNCHECKED
| MF_BYCOMMAND
);
259 int test
[] = {LOWORD(lParam
)-260, LOWORD(lParam
)-140, LOWORD(lParam
)-20};
260 SendMessage(hStatusBar
, WM_SIZE
, wParam
, lParam
);
261 SendMessage(hStatusBar
, SB_SETPARTS
, 3, (int)&test
);
262 MoveWindow(hScrollbox
, 56, 49,LOWORD(lParam
)-56, HIWORD(lParam
)-72, TRUE
);
263 //InvalidateRect(hwnd, NULL, TRUE);
265 if (hwnd
==hImageArea
)
267 MoveWindow(hSizeboxLeftTop
,
270 MoveWindow(hSizeboxCenterTop
,
271 imgXRes
*zoom
/2000+3*3/4,
273 MoveWindow(hSizeboxRightTop
,
276 MoveWindow(hSizeboxLeftCenter
,
278 imgYRes
*zoom
/2000+3*3/4, 3, 3, TRUE
);
279 MoveWindow(hSizeboxRightCenter
,
281 imgYRes
*zoom
/2000+3*3/4, 3, 3, TRUE
);
282 MoveWindow(hSizeboxLeftBottom
,
284 imgYRes
*zoom
/1000+3, 3, 3, TRUE
);
285 MoveWindow(hSizeboxCenterBottom
,
286 imgXRes
*zoom
/2000+3*3/4,
287 imgYRes
*zoom
/1000+3, 3, 3, TRUE
);
288 MoveWindow(hSizeboxRightBottom
,
290 imgYRes
*zoom
/1000+3, 3, 3, TRUE
);
292 if ((hwnd
==hImageArea
)||(hwnd
==hScrollbox
))
294 long clientRectScrollbox
[4];
295 long clientRectImageArea
[4];
296 SCROLLINFO horzScroll
;
297 SCROLLINFO vertScroll
;
298 GetClientRect(hScrollbox
, (LPRECT
)&clientRectScrollbox
);
299 GetClientRect(hImageArea
, (LPRECT
)&clientRectImageArea
);
300 horzScroll
.cbSize
= sizeof(SCROLLINFO
);
301 horzScroll
.fMask
= SIF_PAGE
| SIF_RANGE
;
302 horzScroll
.nMax
= clientRectImageArea
[2]+6-1;
304 horzScroll
.nPage
= clientRectScrollbox
[2];
306 horzScroll
.nTrackPos
= 0;
307 SetScrollInfo(hScrollbox
, SB_HORZ
, &horzScroll
, TRUE
);
308 GetClientRect(hScrollbox
, (LPRECT
)clientRectScrollbox
);
309 vertScroll
.cbSize
= sizeof(SCROLLINFO
);
310 vertScroll
.fMask
= SIF_PAGE
| SIF_RANGE
;
311 vertScroll
.nMax
= clientRectImageArea
[3]+6-1;
313 vertScroll
.nPage
= clientRectScrollbox
[3];
315 vertScroll
.nTrackPos
= 0;
316 SetScrollInfo(hScrollbox
, SB_VERT
, &vertScroll
, TRUE
);
317 MoveWindow(hScrlClient
,
318 -GetScrollPos(hScrollbox
, SB_HORZ
), -GetScrollPos(hScrollbox
, SB_VERT
),
319 max(clientRectImageArea
[2]+6, clientRectScrollbox
[2]), max(clientRectImageArea
[3]+6, clientRectScrollbox
[3]), TRUE
);
323 if (hwnd
==hScrollbox
)
326 si
.cbSize
= sizeof(SCROLLINFO
);
328 GetScrollInfo(hScrollbox
, SB_HORZ
, &si
);
329 switch (LOWORD(wParam
))
332 case SB_THUMBPOSITION
:
333 si
.nPos
= HIWORD(wParam
);
348 SetScrollInfo(hScrollbox
, SB_HORZ
, &si
, TRUE
);
349 MoveWindow(hScrlClient
, -GetScrollPos(hScrollbox
, SB_HORZ
),
350 -GetScrollPos(hScrollbox
, SB_VERT
), imgXRes
*zoom
/1000+6, imgYRes
*zoom
/1000+6, TRUE
);
354 if (hwnd
==hScrollbox
)
357 si
.cbSize
= sizeof(SCROLLINFO
);
359 GetScrollInfo(hScrollbox
, SB_VERT
, &si
);
360 switch (LOWORD(wParam
))
363 case SB_THUMBPOSITION
:
364 si
.nPos
= HIWORD(wParam
);
379 SetScrollInfo(hScrollbox
, SB_VERT
, &si
, TRUE
);
380 MoveWindow(hScrlClient
, -GetScrollPos(hScrollbox
, SB_HORZ
),
381 -GetScrollPos(hScrollbox
, SB_VERT
), imgXRes
*zoom
/1000+6, imgYRes
*zoom
/1000+6, TRUE
);
384 case WM_GETMINMAXINFO
:
387 MINMAXINFO
*mm
= (LPMINMAXINFO
)lParam
;
388 (*mm
).ptMinTrackSize
.x
= 330;
389 (*mm
).ptMinTrackSize
.y
= 430;
393 DefWindowProc (hwnd
, message
, wParam
, lParam
);
394 if (hwnd
==hImageArea
)
396 HDC hdc
= GetDC(hImageArea
);
397 StretchBlt(hdc
, 0, 0, imgXRes
*zoom
/1000, imgYRes
*zoom
/1000, hDrawingDC
, 0, 0, imgXRes
, imgYRes
, SRCCOPY
);
398 if (showGrid
&& (zoom
>=4000))
400 HPEN oldPen
= SelectObject(hdc
, CreatePen(PS_SOLID
, 1, 0x00a0a0a0));
402 for (counter
= 0; counter
<= imgYRes
; counter
++)
404 MoveToEx(hdc
, 0, counter
*zoom
/1000, NULL
);
405 LineTo(hdc
, imgXRes
*zoom
/1000, counter
*zoom
/1000);
407 for (counter
= 0; counter
<= imgXRes
; counter
++)
409 MoveToEx(hdc
, counter
*zoom
/1000, 0, NULL
);
410 LineTo(hdc
, counter
*zoom
/1000, imgYRes
*zoom
/1000);
412 DeleteObject(SelectObject(hdc
, oldPen
));
414 ReleaseDC(hImageArea
, hdc
);
415 SendMessage(hSelection
, WM_PAINT
, 0, 0);
416 SendMessage(hwndMiniature
, WM_PAINT
, 0, 0);
418 if (hwnd
==hwndMiniature
)
422 GetClientRect(hwndMiniature
, (LPRECT
)&mclient
);
423 hdc
= GetDC(hwndMiniature
);
424 BitBlt(hdc
, -min(imgXRes
*GetScrollPos(hScrollbox
, SB_HORZ
)/10000, imgXRes
-mclient
[2]),
425 -min(imgYRes
*GetScrollPos(hScrollbox
, SB_VERT
)/10000, imgYRes
-mclient
[3]), imgXRes
, imgYRes
, hDrawingDC
, 0, 0, SRCCOPY
);
426 ReleaseDC(hwndMiniature
, hdc
);
430 // mouse events used for drawing
433 if (hwnd
==hImageArea
)
441 SetCursor(hCurColor
);
450 SetCursor(hCurAirbrush
);
453 SetCursor(LoadCursor(NULL
, IDC_CROSS
));
455 } else DefWindowProc(hwnd
, message
, wParam
, lParam
);
458 if (hwnd
==hImageArea
)
460 if ((!drawing
)||(activeTool
==5))
462 SetCapture(hImageArea
);
464 startPaintingL(hDrawingDC
, LOWORD(lParam
)*1000/zoom
, HIWORD(lParam
)*1000/zoom
, fgColor
, bgColor
);
467 SendMessage(hwnd
, WM_LBUTTONUP
, wParam
, lParam
);
470 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
471 if ((activeTool
==6)&&(zoom
<8000)) zoomTo(zoom
*2, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
475 if (hwnd
==hImageArea
)
477 if ((!drawing
)||(activeTool
==5))
479 SetCapture(hImageArea
);
481 startPaintingR(hDrawingDC
, LOWORD(lParam
)*1000/zoom
, HIWORD(lParam
)*1000/zoom
, fgColor
, bgColor
);
484 SendMessage(hwnd
, WM_RBUTTONUP
, wParam
, lParam
);
487 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
488 if ((activeTool
==6)&&(zoom
>125)) zoomTo(zoom
/2, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
492 if ((hwnd
==hImageArea
)&&drawing
)
496 endPaintingL(hDrawingDC
, LOWORD(lParam
)*1000/zoom
, HIWORD(lParam
)*1000/zoom
, fgColor
, bgColor
);
497 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
500 int tempColor
= GetPixel(hDrawingDC
, LOWORD(lParam
)*1000/zoom
, HIWORD(lParam
)*1000/zoom
);
501 if (tempColor
!=CLR_INVALID
) fgColor
= tempColor
;
502 SendMessage(hPalWin
, WM_PAINT
, 0, 0);
504 SendMessage(hStatusBar
, SB_SETTEXT
, 2, (LPARAM
)"");
508 if ((hwnd
==hImageArea
)&&drawing
)
512 endPaintingR(hDrawingDC
, LOWORD(lParam
)*1000/zoom
, HIWORD(lParam
)*1000/zoom
, fgColor
, bgColor
);
513 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
516 int tempColor
= GetPixel(hDrawingDC
, LOWORD(lParam
)*1000/zoom
, HIWORD(lParam
)*1000/zoom
);
517 if (tempColor
!=CLR_INVALID
) bgColor
= tempColor
;
518 SendMessage(hPalWin
, WM_PAINT
, 0, 0);
520 SendMessage(hStatusBar
, SB_SETTEXT
, 2, (LPARAM
)"");
524 if (hwnd
==hImageArea
)
526 if ((!drawing
)||(activeTool
<=9))
529 _stprintf(coordStr
, _T("%d, %d"), (short)LOWORD(lParam
)*1000/zoom
, (short)HIWORD(lParam
)*1000/zoom
);
530 SendMessage(hStatusBar
, SB_SETTEXT
, 1, (LPARAM
)coordStr
);
534 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
535 drawZoomFrame((short)LOWORD(lParam
), (short)HIWORD(lParam
));
539 tme
.cbSize
= sizeof(TRACKMOUSEEVENT
);
540 tme
.dwFlags
= TME_LEAVE
;
541 tme
.hwndTrack
= hImageArea
;
543 TrackMouseEvent(&tme
);
547 if ((wParam
&MK_LBUTTON
)!=0)
549 whilePaintingL(hDrawingDC
, (short)LOWORD(lParam
)*1000/zoom
, (short)HIWORD(lParam
)*1000/zoom
, fgColor
, bgColor
);
550 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
551 if ((activeTool
>=10)||(activeTool
==2))
554 _stprintf(sizeStr
, _T("%d x %d"), (short)LOWORD(lParam
)*1000/zoom
-startX
, (short)HIWORD(lParam
)*1000/zoom
-startY
);
555 SendMessage(hStatusBar
, SB_SETTEXT
, 2, (LPARAM
)sizeStr
);
558 if ((wParam
&MK_RBUTTON
)!=0)
560 whilePaintingR(hDrawingDC
, (short)LOWORD(lParam
)*1000/zoom
, (short)HIWORD(lParam
)*1000/zoom
, fgColor
, bgColor
);
561 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
565 _stprintf(sizeStr
, _T("%d x %d"), (short)LOWORD(lParam
)*1000/zoom
-startX
, (short)HIWORD(lParam
)*1000/zoom
-startY
);
566 SendMessage(hStatusBar
, SB_SETTEXT
, 2, (LPARAM
)sizeStr
);
574 SendMessage(hStatusBar
, SB_SETTEXT
, 1, (LPARAM
)_T(""));
576 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
580 // menu and button events
583 switch (LOWORD(wParam
))
587 HICON paintIcon
= LoadIcon(hProgInstance
, MAKEINTRESOURCE(IDI_APPICON
));
588 TCHAR infotitle
[100];
590 LoadString(hProgInstance
, IDS_INFOTITLE
, infotitle
, SIZEOF(infotitle
));
591 LoadString(hProgInstance
, IDS_INFOTEXT
, infotext
, SIZEOF(infotext
));
592 ShellAbout(hMainWnd
, infotitle
, infotext
, paintIcon
);
593 DeleteObject(paintIcon
);
596 case IDM_HELPHELPTOPICS
:
597 //HtmlHelp(hMainWnd, "help\\Paint.chm", 0, 0);
600 SendMessage(hwnd
, WM_CLOSE
, wParam
, lParam
);
603 Rectangle(hDrawingDC
, 0-1, 0-1, imgXRes
+1, imgYRes
+1);
604 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
607 if (GetOpenFileName(&ofn
)!=0)
609 HBITMAP bmNew
= NULL
;
610 LoadDIBFromFile(&bmNew
, ofn
.lpstrFile
, &fileTime
, &fileSize
, &fileHPPM
, &fileVPPM
);
615 insertReversible(bmNew
);
616 updateCanvasAndScrollbars();
617 CopyMemory(filename
, ofn
.lpstrFileTitle
, sizeof(filename
));
618 CopyMemory(filepathname
, ofn
.lpstrFileTitle
, sizeof(filepathname
));
619 LoadString(hProgInstance
, IDS_WINDOWTITLE
, resstr
, SIZEOF(resstr
));
620 _stprintf(tempstr
, resstr
, filename
);
621 SetWindowText(hMainWnd
, tempstr
);
630 SaveDIBToFile(hBms
[currInd
], filepathname
, hDrawingDC
, &fileTime
, &fileSize
, fileHPPM
, fileVPPM
);
634 SendMessage(hwnd
, WM_COMMAND
, IDM_FILESAVEAS
, 0);
637 if (GetSaveFileName(&sfn
)!=0)
641 SaveDIBToFile(hBms
[currInd
], sfn
.lpstrFile
, hDrawingDC
, &fileTime
, &fileSize
, fileHPPM
, fileVPPM
);
642 CopyMemory(filename
, sfn
.lpstrFileTitle
, sizeof(filename
));
643 CopyMemory(filepathname
, sfn
.lpstrFile
, sizeof(filepathname
));
644 LoadString(hProgInstance
, IDS_WINDOWTITLE
, resstr
, SIZEOF(resstr
));
645 _stprintf(tempstr
, resstr
, filename
);
646 SetWindowText(hMainWnd
, tempstr
);
651 case IDM_FILEASWALLPAPERPLANE
:
652 SetWallpaper(filepathname
, 1, 1);
654 case IDM_FILEASWALLPAPERCENTERED
:
655 SetWallpaper(filepathname
, 1, 0);
657 case IDM_FILEASWALLPAPERSTRETCHED
:
658 SetWallpaper(filepathname
, 2, 0);
662 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
666 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
669 OpenClipboard(hMainWnd
);
671 SetClipboardData(CF_BITMAP
, CopyImage(hSelBm
, IMAGE_BITMAP
, 0, 0, LR_COPYRETURNORG
));
675 OpenClipboard(hMainWnd
);
676 if (GetClipboardData(CF_BITMAP
)!=NULL
)
678 DeleteObject(SelectObject(hSelDC
, hSelBm
= CopyImage(GetClipboardData(CF_BITMAP
), IMAGE_BITMAP
, 0, 0, LR_COPYRETURNORG
)));
680 rectSel_src
[0] = rectSel_src
[1] = rectSel_src
[2] = rectSel_src
[3] = 0;
681 rectSel_dest
[0] = rectSel_dest
[1] = 0;
682 rectSel_dest
[2] = GetDIBWidth(hSelBm
);
683 rectSel_dest
[3] = GetDIBHeight(hSelBm
);
684 BitBlt(hDrawingDC
, rectSel_dest
[0], rectSel_dest
[1], rectSel_dest
[2], rectSel_dest
[3], hSelDC
, 0, 0, SRCCOPY
);
686 ShowWindow(hSelection
, SW_SHOW
);
690 case IDM_EDITDELETESELECTION
:
691 ShowWindow(hSelection
, SW_HIDE
);
693 case IDM_EDITSELECTALL
:
696 startPaintingL(hDrawingDC
, 0, 0, fgColor
, bgColor
);
697 whilePaintingL(hDrawingDC
, imgXRes
, imgYRes
, fgColor
, bgColor
);
698 endPaintingL(hDrawingDC
, imgXRes
, imgYRes
, fgColor
, bgColor
);
702 if (GetSaveFileName(&ofn
)!=0) SaveDIBToFile(hSelBm
, ofn
.lpstrFile
, hDrawingDC
, NULL
, NULL
, fileHPPM
, fileVPPM
);
704 case IDM_COLORSEDITPALETTE
:
705 if (ChooseColor(&choosecolor
))
707 fgColor
= choosecolor
.rgbResult
;
708 SendMessage(hPalWin
, WM_PAINT
, 0, 0);
711 case IDM_IMAGEINVERTCOLORS
:
715 SetRect(&tempRect
, 0, 0, imgXRes
, imgYRes
);
716 InvertRect(hDrawingDC
, &tempRect
);
717 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
720 case IDM_IMAGEDELETEIMAGE
:
722 Rect(hDrawingDC
, 0, 0, imgXRes
, imgYRes
, bgColor
, bgColor
, 0, TRUE
);
723 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
725 case IDM_IMAGEROTATEMIRROR
:
726 switch (mirrorRotateDlg())
730 StretchBlt(hDrawingDC
, imgXRes
-1, 0, -imgXRes
, imgYRes
, hDrawingDC
, 0, 0, imgXRes
, imgYRes
, SRCCOPY
);
731 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
735 StretchBlt(hDrawingDC
, 0, imgYRes
-1, imgXRes
, -imgYRes
, hDrawingDC
, 0, 0, imgXRes
, imgYRes
, SRCCOPY
);
736 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
740 StretchBlt(hDrawingDC
, imgXRes
-1, imgYRes
-1, -imgXRes
, -imgYRes
, hDrawingDC
, 0, 0, imgXRes
, imgYRes
, SRCCOPY
);
741 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
745 case IDM_IMAGEATTRIBUTES
:
747 int retVal
= attributesDlg();
748 if ((LOWORD(retVal
)!=0)&&(HIWORD(retVal
)!=0))
750 cropReversible(LOWORD(retVal
), HIWORD(retVal
), 0, 0);
751 updateCanvasAndScrollbars();
755 case IDM_IMAGECHANGESIZE
:
757 int retVal
= changeSizeDlg();
758 if ((LOWORD(retVal
)!=0)&&(HIWORD(retVal
)!=0))
760 insertReversible(CopyImage(hBms
[currInd
], IMAGE_BITMAP
, imgXRes
*LOWORD(retVal
)/100, imgYRes
*HIWORD(retVal
)/100, 0));
761 updateCanvasAndScrollbars();
765 case IDM_IMAGEDRAWOPAQUE
:
766 transpBg
= 1-transpBg
;
767 SendMessage(hToolSettings
, WM_PAINT
, 0, 0);
770 insertReversible(CopyImage(hSelBm
, IMAGE_BITMAP
, 0, 0, LR_COPYRETURNORG
));
771 updateCanvasAndScrollbars();
774 case IDM_VIEWSTATUSBAR
:
775 if (IsWindowVisible(hStatusBar
))
776 ShowWindow(hStatusBar
, SW_HIDE
);
778 ShowWindow(hStatusBar
, SW_SHOW
);
781 case IDM_VIEWSHOWGRID
:
782 showGrid
= !showGrid
;
784 case IDM_VIEWSHOWMINIATURE
:
785 showMiniature
= !showMiniature
;
787 ShowWindow(hwndMiniature
, SW_SHOW
);
789 ShowWindow(hwndMiniature
, SW_HIDE
);
792 case IDM_VIEWZOOM125
:
801 case IDM_VIEWZOOM100
:
804 case IDM_VIEWZOOM200
:
807 case IDM_VIEWZOOM400
:
810 case IDM_VIEWZOOM800
:
864 return DefWindowProc (hwnd
, message
, wParam
, lParam
);