6 * Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
7 * Copyright (C) 2005 Martin Fuchs <martin-fuchs@gmx.net>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
32 extern void ExitInstance();
34 ////////////////////////////////////////////////////////////////////////////////
38 static int s_factor
= 2; // zoom factor
40 static POINT s_srcPos
= {0, 0}; // source rectangle position
41 static RECT s_lastSrc
= {-1,-1,-1,-1}; // last cursor position
43 BOOL s_dragging
= FALSE
;
52 ////////////////////////////////////////////////////////////////////////////////
54 // FUNCTION: SetZoom()
56 // PURPOSE: Change zoom level
59 static void SetZoom(HWND hWnd
, int factor
)
61 TCHAR buffer
[MAX_LOADSTRING
];
63 if (factor
>=MIN_ZOOM
&& factor
<=MAX_ZOOM
) {
66 SetScrollPos(hWnd
, SB_VERT
, s_factor
, TRUE
);
68 wsprintf(buffer
, TEXT("%s %dx"), szTitle
, s_factor
);
69 SetWindowText(hWnd
, buffer
);
74 ////////////////////////////////////////////////////////////////////////////////
76 // FUNCTION: _CmdWndProc(HWND, unsigned, WORD, LONG)
78 // PURPOSE: Processes WM_COMMAND messages for the main frame window.
82 static BOOL
_CmdWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
84 switch (LOWORD(wParam
)) {
85 // Parse the menu selections:
92 case ID_OPTIONS_REFRESH_RATE
:
98 InvalidateRect(hWnd
, NULL
, FALSE
);
108 ////////////////////////////////////////////////////////////////////////////////
110 // FUNCTION: FrameWndProc(HWND, unsigned, WORD, LONG)
112 // PURPOSE: Processes messages for the main window.
115 LRESULT CALLBACK
FrameWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
119 SetTimer(hWnd
, 0, 200, NULL
); // refresh display all 200 ms
120 SetScrollRange(hWnd
, SB_VERT
, 1, MAX_ZOOM
, FALSE
);
121 SetZoom(hWnd
, s_factor
);
125 if (!_CmdWndProc(hWnd
, message
, wParam
, lParam
)) {
126 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
136 BeginPaint(hWnd
, &ps
);
137 hdcMem
= GetDC(GetDesktopWindow());
139 GetClientRect(hWnd
, &clnt
);
140 size
.cx
= (clnt
.right
+ s_factor
-1) / s_factor
;
141 size
.cy
= (clnt
.bottom
+ s_factor
-1) / s_factor
;
143 StretchBlt(ps
.hdc
, 0, 0, size
.cx
*s_factor
, size
.cy
*s_factor
,
144 hdcMem
, s_srcPos
.x
, s_srcPos
.y
, size
.cx
, size
.cy
, SRCCOPY
);
146 ReleaseDC(GetDesktopWindow(), hdcMem
);
151 if (s_dragging
&& GetCapture()==hWnd
) {
154 int width
= GetSystemMetrics(SM_CXSCREEN
);
155 int height
= GetSystemMetrics(SM_CYSCREEN
);
157 GetCursorPos(&s_srcPos
);
159 GetClientRect(hWnd
, &clnt
);
161 s_srcPos
.x
-= clnt
.right
/ s_factor
/ 2;
162 s_srcPos
.y
-= clnt
.bottom
/ s_factor
/ 2;
166 else if (s_srcPos
.x
+clnt
.right
/s_factor
> width
)
167 s_srcPos
.x
= width
- clnt
.right
/s_factor
;
171 else if (s_srcPos
.y
+clnt
.bottom
/s_factor
> height
)
172 s_srcPos
.y
= height
- clnt
.bottom
/s_factor
;
174 if (memcmp(&rect
, &s_lastSrc
, sizeof(RECT
))) {
177 if (s_lastSrc
.bottom
!= -1)
178 DrawFocusRect(hdc
, &s_lastSrc
);
180 rect
.left
= s_srcPos
.x
- 1;
181 rect
.top
= s_srcPos
.y
- 1;
182 rect
.right
= rect
.left
+ clnt
.right
/s_factor
+ 2;
183 rect
.bottom
= rect
.top
+ clnt
.bottom
/s_factor
+ 2;
184 DrawFocusRect(hdc
, &rect
);
192 InvalidateRect(hWnd
, NULL
, FALSE
);
205 DrawFocusRect(hdc
, &s_lastSrc
);
208 s_lastSrc
.bottom
= -1;
219 SetZoom(hWnd
, s_factor
-1);
224 SetZoom(hWnd
, s_factor
+1);
236 return DefWindowProc(hWnd
, message
, wParam
, lParam
);