Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenmagnifier.c
Go to the documentation of this file.
00001 /* 00002 * PROJECT: ReactOS Magnify 00003 * LICENSE: GPL - See COPYING in the top level directory 00004 * FILE: base/applications/magnify/magnifier.c 00005 * PURPOSE: Magnification of parts of the screen. 00006 * COPYRIGHT: Copyright 2007 Marc Piulachs <marc.piulachs@codexchange.net> 00007 * 00008 */ 00009 00010 #include "magnifier.h" 00011 00012 const TCHAR szWindowClass[] = TEXT("MAGNIFIER"); 00013 00014 #define MAX_LOADSTRING 100 00015 00016 // Global Variables: 00017 HINSTANCE hInst; // current instance 00018 HWND hMainWnd; 00019 00020 TCHAR szTitle[MAX_LOADSTRING]; // The title bar text 00021 00022 #define REPAINT_SPEED 100 00023 00024 HWND hDesktopWindow = NULL; 00025 00026 //Current magnified area 00027 POINT cp; 00028 00029 //Last positions 00030 POINT pMouse; 00031 POINT pCaret; 00032 POINT pFocus; 00033 00034 // Forward declarations of functions included in this code module: 00035 ATOM MyRegisterClass(HINSTANCE hInstance); 00036 BOOL InitInstance(HINSTANCE, int); 00037 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); 00038 INT_PTR CALLBACK AboutProc(HWND, UINT, WPARAM, LPARAM); 00039 INT_PTR CALLBACK OptionsProc(HWND, UINT, WPARAM, LPARAM); 00040 INT_PTR CALLBACK WarningProc(HWND, UINT, WPARAM, LPARAM); 00041 00042 int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) 00043 { 00044 // TODO: Place code here. 00045 MSG msg; 00046 HACCEL hAccelTable; 00047 00048 UNREFERENCED_PARAMETER(hPrevInstance); 00049 UNREFERENCED_PARAMETER(lpCmdLine); 00050 00051 // Initialize global strings 00052 LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); 00053 MyRegisterClass(hInstance); 00054 00055 // Perform application initialization: 00056 if (!InitInstance (hInstance, nCmdShow)) 00057 { 00058 return FALSE; 00059 } 00060 00061 hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_MAGNIFIER)); 00062 00063 // Main message loop: 00064 while (GetMessage(&msg, NULL, 0, 0)) 00065 { 00066 if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) 00067 { 00068 TranslateMessage(&msg); 00069 DispatchMessage(&msg); 00070 } 00071 } 00072 00073 return (int) msg.wParam; 00074 } 00075 00076 00077 00078 /* 00079 * FUNCTION: MyRegisterClass() 00080 * 00081 * PURPOSE: Registers the window class. 00082 * 00083 * COMMENTS: 00084 * 00085 * This function and its usage are only necessary if you want this code 00086 * to be compatible with Win32 systems prior to the 'RegisterClassEx' 00087 * function that was added to Windows 95. It is important to call this function 00088 * so that the application will get 'well formed' small icons associated 00089 * with it. 00090 */ 00091 ATOM MyRegisterClass(HINSTANCE hInstance) 00092 { 00093 WNDCLASS wc; 00094 00095 wc.style = CS_HREDRAW | CS_VREDRAW; 00096 wc.lpfnWndProc = WndProc; 00097 wc.cbClsExtra = 0; 00098 wc.cbWndExtra = 0; 00099 wc.hInstance = hInstance; 00100 wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON)); 00101 wc.hCursor = LoadCursor(NULL, IDC_ARROW); 00102 wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); 00103 wc.lpszMenuName = MAKEINTRESOURCE(IDC_MAGNIFIER); 00104 wc.lpszClassName = szWindowClass; 00105 00106 return RegisterClass(&wc); 00107 } 00108 00109 /* 00110 * FUNCTION: InitInstance(HINSTANCE, int) 00111 * 00112 * PURPOSE: Saves instance handle and creates main window 00113 * 00114 * COMMENTS: 00115 * 00116 * In this function, we save the instance handle in a global variable and 00117 * create and display the main program window. 00118 */ 00119 BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) 00120 { 00121 hInst = hInstance; // Store instance handle in our global variable 00122 00123 // Create the Window 00124 hMainWnd = CreateWindowEx( 00125 WS_EX_TOPMOST, 00126 szWindowClass, 00127 szTitle, 00128 WS_OVERLAPPEDWINDOW, 00129 CW_USEDEFAULT, 00130 CW_USEDEFAULT, 00131 CW_USEDEFAULT, 00132 CW_USEDEFAULT, 00133 NULL, 00134 NULL, 00135 hInstance, 00136 NULL); 00137 00138 if (!hMainWnd) 00139 { 00140 return FALSE; 00141 } 00142 00143 ShowWindow(hMainWnd, (bStartMinimized) ? SW_MINIMIZE : nCmdShow); 00144 UpdateWindow(hMainWnd); 00145 00146 if (bShowWarning) 00147 { 00148 DialogBox (hInstance, MAKEINTRESOURCE(IDD_WARNINGDIALOG), hMainWnd, (DLGPROC)WarningProc); 00149 } 00150 00151 return TRUE; 00152 } 00153 00154 void Refresh () 00155 { 00156 if (!IsIconic(hMainWnd)) 00157 { 00158 // Invalidate the client area forcing a WM_PAINT message 00159 InvalidateRgn(hMainWnd, NULL, TRUE); 00160 } 00161 } 00162 00163 void Draw(HDC aDc) 00164 { 00165 HDC desktopHdc = NULL; 00166 HDC HdcStrech; 00167 HANDLE hOld; 00168 HBITMAP HbmpStrech; 00169 00170 RECT R; 00171 RECT appRect; 00172 DWORD rop = SRCCOPY; 00173 CURSORINFO cinfo; 00174 ICONINFO iinfo; 00175 00176 int Width, Height, AppWidth, AppHeight; 00177 LONG blitAreaWidth, blitAreaHeight, blitAreaX, blitAreaY; 00178 00179 desktopHdc = GetWindowDC (hDesktopWindow); 00180 00181 GetClientRect(hMainWnd, &appRect); 00182 GetWindowRect(hDesktopWindow, &R); 00183 00184 ZeroMemory(&cinfo, sizeof(CURSORINFO)); 00185 ZeroMemory(&iinfo, sizeof(ICONINFO)); 00186 cinfo.cbSize = sizeof(cinfo); 00187 GetCursorInfo(&cinfo); 00188 GetIconInfo(cinfo.hCursor, &iinfo); 00189 00190 /* Create a memory DC compatible with client area DC.*/ 00191 HdcStrech = CreateCompatibleDC(desktopHdc); 00192 00193 /* Create a bitmap compatible with the client area DC.*/ 00194 HbmpStrech = CreateCompatibleBitmap( 00195 desktopHdc, 00196 R.right, 00197 R.bottom); 00198 00199 /* Select our bitmap in memory DC and save the old one.*/ 00200 hOld = SelectObject (HdcStrech , HbmpStrech); 00201 00202 /* Paint the screen bitmap to our in memory DC */ 00203 BitBlt( 00204 HdcStrech, 00205 0, 00206 0, 00207 R.right, 00208 R.bottom, 00209 desktopHdc, 00210 0, 00211 0, 00212 SRCCOPY); 00213 00214 /* Draw the mouse pointer in the right position */ 00215 DrawIcon( 00216 HdcStrech , 00217 pMouse.x - iinfo.xHotspot, // - 10, 00218 pMouse.y - iinfo.yHotspot, // - 10, 00219 cinfo.hCursor); 00220 00221 Width = (R.right - R.left); 00222 Height = (R.bottom - R.top); 00223 00224 AppWidth = (appRect.right - appRect.left); 00225 AppHeight = (appRect.bottom - appRect.top); 00226 00227 blitAreaWidth = AppWidth / iZoom; 00228 blitAreaHeight = AppHeight / iZoom; 00229 00230 blitAreaX = (cp.x) - (blitAreaWidth /2); 00231 blitAreaY = (cp.y) - (blitAreaHeight /2); 00232 00233 if (blitAreaX < 0) 00234 { 00235 blitAreaX = 0; 00236 } 00237 00238 if (blitAreaY < 0) 00239 { 00240 blitAreaY = 0; 00241 } 00242 00243 if (blitAreaX > (Width - blitAreaWidth)) 00244 { 00245 blitAreaX = (Width - blitAreaWidth); 00246 } 00247 00248 if (blitAreaY > (Height - blitAreaHeight)) 00249 { 00250 blitAreaY = (Height - blitAreaHeight); 00251 } 00252 00253 if (bInvertColors) 00254 { 00255 rop = NOTSRCCOPY; 00256 } 00257 00258 /* Blast the stretched image from memory DC to window DC.*/ 00259 StretchBlt( 00260 aDc, 00261 0, 00262 0, 00263 AppWidth, 00264 AppHeight, 00265 HdcStrech, 00266 blitAreaX, 00267 blitAreaY, 00268 blitAreaWidth, 00269 blitAreaHeight, 00270 rop); 00271 00272 /* Cleanup.*/ 00273 if (iinfo.hbmMask) 00274 DeleteObject(iinfo.hbmMask); 00275 if (iinfo.hbmColor) 00276 DeleteObject(iinfo.hbmColor); 00277 SelectObject (HdcStrech, hOld); 00278 DeleteObject (HbmpStrech); 00279 DeleteDC (HdcStrech); 00280 ReleaseDC(hDesktopWindow, desktopHdc); 00281 } 00282 00283 /* 00284 * FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) 00285 * 00286 * PURPOSE: Processes messages for the main window. 00287 * 00288 * WM_COMMAND - process the application menu 00289 * WM_PAINT - Paint the main window 00290 * WM_DESTROY - post a quit message and return 00291 * 00292 */ 00293 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) 00294 { 00295 int wmId; 00296 00297 switch (message) 00298 { 00299 case WM_TIMER: 00300 { 00301 POINT pNewMouse; 00302 POINT pNewCaret; 00303 POINT pNewFocus; 00304 HWND hwnd1, hwnd2, hwnd3; 00305 DWORD a, b; 00306 RECT controlRect; 00307 00308 //Get current mouse position 00309 GetCursorPos (&pNewMouse); 00310 00311 //Get caret position 00312 hwnd1 = GetForegroundWindow (); 00313 a = GetWindowThreadProcessId(hwnd1, NULL); 00314 b = GetCurrentThreadId(); 00315 AttachThreadInput (a, b, TRUE); 00316 hwnd2 = GetFocus(); 00317 00318 GetCaretPos( &pNewCaret); 00319 ClientToScreen (hwnd2, (LPPOINT) &pNewCaret); 00320 AttachThreadInput (a, b, FALSE); 00321 00322 //Get current control focus 00323 hwnd3 = GetFocus (); 00324 GetWindowRect (hwnd3 , &controlRect); 00325 pNewFocus.x = controlRect.left; 00326 pNewFocus.y = controlRect.top; 00327 00328 //If mouse has moved .... 00329 if (((pMouse.x != pNewMouse.x) || (pMouse.y != pNewMouse.y)) && bFollowMouse) 00330 { 00331 //Update to new position 00332 pMouse = pNewMouse; 00333 cp = pNewMouse; 00334 Refresh(); 00335 } 00336 else if (((pCaret.x != pNewCaret.x) || (pCaret.y != pNewCaret.y)) && bFollowCaret) 00337 { 00338 //Update to new position 00339 pCaret = pNewCaret; 00340 cp = pNewCaret; 00341 Refresh(); 00342 } 00343 else if (((pFocus.x != pNewFocus.x) || (pFocus.y != pNewFocus.y)) && bFollowFocus) 00344 { 00345 //Update to new position 00346 pFocus = pNewFocus; 00347 cp = pNewFocus; 00348 Refresh(); 00349 } 00350 } 00351 break; 00352 case WM_COMMAND: 00353 wmId = LOWORD(wParam); 00354 // Parse the menu selections: 00355 switch (wmId) 00356 { 00357 case IDM_OPTIONS: 00358 DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOGOPTIONS), hWnd, (DLGPROC)OptionsProc); 00359 break; 00360 case IDM_ABOUT: 00361 DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, (DLGPROC)AboutProc); 00362 break; 00363 case IDM_EXIT: 00364 DestroyWindow(hWnd); 00365 break; 00366 default: 00367 return DefWindowProc(hWnd, message, wParam, lParam); 00368 } 00369 break; 00370 case WM_PAINT: 00371 { 00372 PAINTSTRUCT PaintStruct; 00373 HDC dc; 00374 dc = BeginPaint(hWnd, &PaintStruct); 00375 Draw(dc); 00376 EndPaint(hWnd, &PaintStruct); 00377 } 00378 break; 00379 case WM_ERASEBKGND: 00380 //handle WM_ERASEBKGND by simply returning non-zero because we did all the drawing in WM_PAINT. 00381 break; 00382 case WM_DESTROY: 00383 //Save settings to registry 00384 SaveSettings (); 00385 KillTimer (hWnd , 1); 00386 PostQuitMessage(0); 00387 break; 00388 case WM_CREATE: 00389 //Load settings from registry 00390 LoadSettings (); 00391 00392 //Get the desktop window 00393 hDesktopWindow = GetDesktopWindow(); 00394 00395 //Set the timer 00396 SetTimer (hWnd , 1, REPAINT_SPEED , NULL); 00397 break; 00398 default: 00399 return DefWindowProc(hWnd, message, wParam, lParam); 00400 } 00401 return 0; 00402 } 00403 00404 // Message handler for about box. 00405 INT_PTR CALLBACK AboutProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) 00406 { 00407 UNREFERENCED_PARAMETER(lParam); 00408 switch (message) 00409 { 00410 case WM_INITDIALOG: 00411 return (INT_PTR)TRUE; 00412 00413 case WM_COMMAND: 00414 if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) 00415 { 00416 EndDialog(hDlg, LOWORD(wParam)); 00417 return (INT_PTR)TRUE; 00418 } 00419 break; 00420 } 00421 return (INT_PTR)FALSE; 00422 } 00423 00424 // Message handler for options box. 00425 INT_PTR CALLBACK OptionsProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) 00426 { 00427 UNREFERENCED_PARAMETER(lParam); 00428 switch (message) 00429 { 00430 case WM_INITDIALOG: 00431 { 00432 //Add the zoom items.... 00433 SendDlgItemMessage(hDlg, IDC_ZOOM, CB_ADDSTRING, 0, (LPARAM)("1")); 00434 SendDlgItemMessage(hDlg, IDC_ZOOM, CB_ADDSTRING, 0, (LPARAM)("2")); 00435 SendDlgItemMessage(hDlg, IDC_ZOOM, CB_ADDSTRING, 0, (LPARAM)("3")); 00436 SendDlgItemMessage(hDlg, IDC_ZOOM, CB_ADDSTRING, 0, (LPARAM)("4")); 00437 SendDlgItemMessage(hDlg, IDC_ZOOM, CB_ADDSTRING, 0, (LPARAM)("5")); 00438 SendDlgItemMessage(hDlg, IDC_ZOOM, CB_ADDSTRING, 0, (LPARAM)("6")); 00439 SendDlgItemMessage(hDlg, IDC_ZOOM, CB_ADDSTRING, 0, (LPARAM)("7")); 00440 SendDlgItemMessage(hDlg, IDC_ZOOM, CB_ADDSTRING, 0, (LPARAM)("8")); 00441 00442 // 00443 SendDlgItemMessage(hDlg, IDC_ZOOM, CB_SETCURSEL, iZoom - 1, 0); 00444 00445 if (bFollowMouse) 00446 SendDlgItemMessage(hDlg,IDC_FOLLOWMOUSECHECK,BM_SETCHECK , wParam ,0); 00447 00448 if (bFollowFocus) 00449 SendDlgItemMessage(hDlg,IDC_FOLLOWKEYBOARDCHECK,BM_SETCHECK , wParam ,0); 00450 00451 if (bFollowCaret) 00452 SendDlgItemMessage(hDlg,IDC_FOLLOWTEXTEDITINGCHECK,BM_SETCHECK , wParam ,0); 00453 00454 if (bInvertColors) 00455 SendDlgItemMessage(hDlg,IDC_INVERTCOLORSCHECK,BM_SETCHECK , wParam ,0); 00456 00457 if (bStartMinimized) 00458 SendDlgItemMessage(hDlg,IDC_STARTMINIMIZEDCHECK,BM_SETCHECK , wParam ,0); 00459 00460 if (bShowMagnifier) 00461 SendDlgItemMessage(hDlg,IDC_SHOWMAGNIFIERCHECK,BM_SETCHECK , wParam ,0); 00462 00463 return (INT_PTR)TRUE; 00464 } 00465 case WM_COMMAND: 00466 switch(LOWORD(wParam)) 00467 { 00468 case IDOK: 00469 case IDCANCEL: 00470 EndDialog(hDlg, LOWORD(wParam)); 00471 return (INT_PTR)TRUE; 00472 00473 case IDC_BUTTON_HELP: 00474 /* unimplemented */ 00475 MessageBox(hDlg , TEXT("Magnifier help not available yet!") , TEXT("Help") , MB_OK); 00476 break; 00477 case IDC_ZOOM: 00478 if(HIWORD(wParam) == CBN_SELCHANGE) 00479 { 00480 HWND hCombo = GetDlgItem(hDlg,IDC_ZOOM); 00481 00482 /* Get index of current selection and the text of that selection. */ 00483 iZoom = SendMessage( hCombo, CB_GETCURSEL, (WPARAM) wParam, (LPARAM) lParam ) + 1; 00484 00485 //Update the magnigier UI 00486 Refresh (); 00487 } 00488 break; 00489 case IDC_INVERTCOLORSCHECK: 00490 bInvertColors = IsDlgButtonChecked (hDlg, IDC_INVERTCOLORSCHECK); 00491 Refresh (); 00492 break; 00493 case IDC_FOLLOWMOUSECHECK: 00494 bFollowMouse = IsDlgButtonChecked (hDlg, IDC_FOLLOWMOUSECHECK); 00495 break; 00496 case IDC_FOLLOWKEYBOARDCHECK: 00497 bFollowFocus = IsDlgButtonChecked (hDlg, IDC_FOLLOWKEYBOARDCHECK); 00498 break; 00499 case IDC_FOLLOWTEXTEDITINGCHECK: 00500 bFollowCaret = IsDlgButtonChecked (hDlg, IDC_FOLLOWTEXTEDITINGCHECK); 00501 break; 00502 case IDC_STARTMINIMIZEDCHECK: 00503 bStartMinimized = IsDlgButtonChecked (hDlg, IDC_STARTMINIMIZEDCHECK); 00504 break; 00505 case IDC_SHOWMAGNIFIER: 00506 bShowMagnifier = IsDlgButtonChecked (hDlg, IDC_SHOWMAGNIFIERCHECK); 00507 if (bShowMagnifier){ 00508 ShowWindow (hMainWnd , SW_SHOW); 00509 }else{ 00510 ShowWindow (hMainWnd , SW_HIDE); 00511 } 00512 break; 00513 } 00514 } 00515 return (INT_PTR)FALSE; 00516 } 00517 00518 // Message handler for warning box. 00519 INT_PTR CALLBACK WarningProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) 00520 { 00521 UNREFERENCED_PARAMETER(lParam); 00522 00523 switch (message) 00524 { 00525 case WM_INITDIALOG: 00526 return (INT_PTR)TRUE; 00527 case WM_COMMAND: 00528 switch(LOWORD(wParam)) 00529 { 00530 case IDC_SHOWWARNINGCHECK: 00531 bShowWarning = !IsDlgButtonChecked (hDlg, IDC_SHOWWARNINGCHECK); 00532 break; 00533 } 00534 if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) 00535 { 00536 EndDialog(hDlg, LOWORD(wParam)); 00537 return (INT_PTR)TRUE; 00538 } 00539 break; 00540 } 00541 return (INT_PTR)FALSE; 00542 } Generated on Sun May 27 2012 04:16:55 for ReactOS by
1.7.6.1
|