4e238c53cc1f8f2fb064a524e3f162579749ebda
[reactos.git] / rosapps / devutils / zoomin / framewnd.c
1 /*
2 * ReactOS zoomin
3 *
4 * framewnd.c
5 *
6 * Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
7 * Copyright (C) 2005 Martin Fuchs <martin-fuchs@gmx.net>
8 *
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.
13 *
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.
18 *
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.
22 */
23
24 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
25 #include <windows.h>
26 #include <windowsx.h>
27 #include <tchar.h>
28
29 #include "main.h"
30 #include "framewnd.h"
31
32
33 ////////////////////////////////////////////////////////////////////////////////
34 // Global Variables:
35 //
36
37 static int s_factor = 2; // zoom factor
38
39 static POINT s_srcPos = {0, 0}; // zoom factor
40
41
42 ////////////////////////////////////////////////////////////////////////////////
43 // Local module support methods
44 //
45
46
47 ////////////////////////////////////////////////////////////////////////////////
48 //
49 // FUNCTION: _CmdWndProc(HWND, unsigned, WORD, LONG)
50 //
51 // PURPOSE: Processes WM_COMMAND messages for the main frame window.
52 //
53 //
54
55 static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
56 {
57 switch (LOWORD(wParam)) {
58 // Parse the menu selections:
59 case ID_EDIT_EXIT:
60 DestroyWindow(hWnd);
61 break;
62
63 case ID_EDIT_COPY:
64 case ID_EDIT_REFRESH:
65 case ID_OPTIONS_REFRESH_RATE:
66 case ID_HELP_ABOUT:
67 // TODO:
68 break;
69
70 default:
71 return FALSE;
72 }
73
74 return TRUE;
75 }
76
77 ////////////////////////////////////////////////////////////////////////////////
78 //
79 // FUNCTION: FrameWndProc(HWND, unsigned, WORD, LONG)
80 //
81 // PURPOSE: Processes messages for the main window.
82 //
83
84 LRESULT CALLBACK FrameWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
85 {
86 switch (message) {
87 case WM_CREATE:
88 SetTimer(hWnd, 0, 200, NULL); // refresh display all 200 ms
89 break;
90
91 case WM_COMMAND:
92 if (!_CmdWndProc(hWnd, message, wParam, lParam)) {
93 return DefWindowProc(hWnd, message, wParam, lParam);
94 }
95 break;
96
97 case WM_PAINT: {
98 PAINTSTRUCT ps;
99 HDC hdcMem;
100 RECT rect;
101 SIZE size;
102
103 BeginPaint(hWnd, &ps);
104 hdcMem = GetDC(GetDesktopWindow());
105
106 GetClientRect(hWnd, &rect);
107 size.cx = rect.right / s_factor;
108 size.cy = rect.bottom / s_factor;
109
110 StretchBlt(ps.hdc, 0, 0, size.cx*s_factor, size.cy*s_factor, hdcMem, s_srcPos.x, s_srcPos.y, size.cx, size.cy, SRCCOPY);
111
112 ReleaseDC(GetDesktopWindow(), hdcMem);
113 EndPaint(hWnd, &ps);
114 break;}
115
116 case WM_TIMER:
117 if (GetCapture() == hWnd) {
118 RECT rect;
119
120 int width = GetSystemMetrics(SM_CXSCREEN);
121 int height = GetSystemMetrics(SM_CYSCREEN);
122
123 GetClientRect(hWnd, &rect);
124
125 GetCursorPos(&s_srcPos);
126
127 s_srcPos.x -= rect.right / s_factor / 2;
128 s_srcPos.y -= rect.bottom / s_factor / 2;
129
130 if (s_srcPos.x < 0)
131 s_srcPos.x = 0;
132 else if (s_srcPos.x+rect.right/s_factor > width)
133 s_srcPos.x = width - rect.right/s_factor;
134
135 if (s_srcPos.y < 0)
136 s_srcPos.y = 0;
137 else if (s_srcPos.y+rect.bottom/s_factor > height)
138 s_srcPos.y = height - rect.bottom/s_factor;
139 }
140
141 InvalidateRect(hWnd, NULL, FALSE);
142 break;
143
144 case WM_LBUTTONDOWN:
145 SetCapture(hWnd);
146 break;
147
148 case WM_LBUTTONUP:
149 ReleaseCapture();
150 break;
151
152 case WM_DESTROY:
153 KillTimer(hWnd, 0);
154 PostQuitMessage(0);
155 break;
156
157 default:
158 return DefWindowProc(hWnd, message, wParam, lParam);
159 }
160
161 return 0;
162 }