ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

fontview.c
Go to the documentation of this file.
00001 /*
00002  *  fontview
00003  *
00004  *  fontview.c
00005  *
00006  *  Copyright (C) 2007  Timo Kreuzer <timo <dot> kreuzer <at> reactos <dot> org>
00007  *
00008  *  This program is free software; you can redistribute it and/or modify
00009  *  it under the terms of the GNU General Public License as published by
00010  *  the Free Software Foundation; either version 2 of the License, or
00011  *  (at your option) any later version.
00012  *
00013  *  This program is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  *  GNU General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU General Public License along
00019  *  with this program; if not, write to the Free Software Foundation, Inc.,
00020  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00021  */
00022 
00023 #include "fontview.h"
00024 
00025 HINSTANCE g_hInstance;
00026 EXTLOGFONTW g_ExtLogFontW;
00027 
00028 static const WCHAR g_szFontViewClassName[] = L"FontViewWClass";
00029 
00030 /* Tye definition for the GetFontResourceInfo function */
00031 typedef BOOL (WINAPI *PGFRI)(LPCWSTR, DWORD *, LPVOID, DWORD);
00032 
00033 DWORD
00034 FormatString(
00035     DWORD dwFlags,
00036     HINSTANCE hInstance,
00037     DWORD dwStringId,
00038     DWORD dwLanguageId,
00039     LPWSTR lpBuffer,
00040     DWORD nSize,
00041     va_list* Arguments
00042 )
00043 {
00044     DWORD dwRet;
00045     int len;
00046     WCHAR Buffer[1000];
00047 
00048     len = LoadStringW(hInstance, dwStringId, (LPWSTR)Buffer, 1000);
00049 
00050     if (len)
00051     {
00052         dwFlags |= FORMAT_MESSAGE_FROM_STRING;
00053         dwFlags &= ~(FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_FROM_SYSTEM);
00054         dwRet = FormatMessageW(dwFlags, Buffer, 0, dwLanguageId, lpBuffer, nSize, Arguments);
00055         return dwRet;
00056     }
00057     return 0;
00058 }
00059 
00060 static void
00061 ErrorMsgBox(HWND hParent, DWORD dwCaptionID, DWORD dwMessageId, ...)
00062 {
00063     HLOCAL hMemCaption = NULL;
00064     HLOCAL hMemText = NULL;
00065     va_list args;
00066 
00067     va_start(args, dwMessageId);
00068     FormatString(FORMAT_MESSAGE_ALLOCATE_BUFFER,
00069                   NULL, dwMessageId, 0, (LPWSTR)&hMemText, 0, &args);
00070     va_end(args);
00071 
00072     FormatString(FORMAT_MESSAGE_ALLOCATE_BUFFER,
00073                   NULL, dwCaptionID, 0, (LPWSTR)&hMemCaption, 0, NULL);
00074 
00075     MessageBoxW(hParent, hMemText, hMemCaption, MB_ICONERROR);
00076 
00077     LocalFree(hMemCaption);
00078     LocalFree(hMemText);
00079 }
00080 
00081 int WINAPI
00082 WinMain (HINSTANCE hThisInstance,
00083          HINSTANCE hPrevInstance,
00084          LPSTR lpCmdLine,
00085          int nCmdShow)
00086 {
00087     int argc;
00088     WCHAR** argv;
00089     DWORD dwSize;
00090     HWND hMainWnd;
00091     MSG msg;
00092     WNDCLASSEXW wincl;
00093     HINSTANCE hDLL;
00094     PGFRI GetFontResourceInfoW;
00095 
00096     g_hInstance = hThisInstance;
00097 
00098     /* Get unicode command line */
00099     argv = CommandLineToArgvW(GetCommandLineW(), &argc);
00100     if (argc < 2)
00101     {
00102         ErrorMsgBox(0, IDS_ERROR, IDS_ERROR_BADCMD, argv[1]);
00103         return -1;
00104     }
00105 
00106     /* Try to add the font resource */
00107     if (!AddFontResourceW(argv[1]))
00108     {
00109         ErrorMsgBox(0, IDS_ERROR, IDS_ERROR_NOFONT, argv[1]);
00110         return -1;
00111     }
00112 
00113     /* Load the GetFontResourceInfo function from gdi32.dll */
00114     hDLL = LoadLibraryW(L"GDI32.DLL");
00115     GetFontResourceInfoW = (PGFRI)GetProcAddress(hDLL, "GetFontResourceInfoW");
00116 
00117     /* Get the font name */
00118     dwSize = sizeof(g_ExtLogFontW.elfFullName);
00119     if (!GetFontResourceInfoW(argv[1], &dwSize, g_ExtLogFontW.elfFullName, 1))
00120     {
00121         ErrorMsgBox(0, IDS_ERROR, IDS_ERROR_NOFONT, argv[1]);
00122         return -1;
00123     }
00124 
00125     dwSize = sizeof(LOGFONTW);
00126     if (!GetFontResourceInfoW(argv[1], &dwSize, &g_ExtLogFontW.elfLogFont, 2))
00127     {
00128         ErrorMsgBox(0, IDS_ERROR, IDS_ERROR_NOFONT, argv[1]);
00129         return -1;
00130     }
00131 
00132     if (!Display_InitClass(hThisInstance))
00133     {
00134         ErrorMsgBox(0, IDS_ERROR, IDS_ERROR_NOCLASS);
00135         return -1;
00136     }
00137 
00138     /* The main window class */
00139     wincl.cbSize = sizeof (WNDCLASSEXW);
00140     wincl.style = CS_DBLCLKS;
00141     wincl.lpfnWndProc = MainWndProc;
00142     wincl.cbClsExtra = 0;
00143     wincl.cbWndExtra = 0;
00144     wincl.hInstance = hThisInstance;
00145     wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
00146     wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
00147     wincl.hbrBackground = (HBRUSH)COLOR_BACKGROUND;
00148     wincl.lpszMenuName = NULL;
00149     wincl.lpszClassName = g_szFontViewClassName;
00150     wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
00151 
00152     /* Register the window class, and if it fails quit the program */
00153     if (!RegisterClassExW (&wincl))
00154     {
00155         ErrorMsgBox(0, IDS_ERROR, IDS_ERROR_NOCLASS);
00156         return 0;
00157     }
00158 
00159     /* The class is registered, let's create the main window */
00160     hMainWnd = CreateWindowExW(
00161                 0,                      /* Extended possibilites for variation */
00162                 g_szFontViewClassName,  /* Classname */
00163                 g_ExtLogFontW.elfFullName,/* Title Text */
00164                 WS_OVERLAPPEDWINDOW,    /* default window */
00165                 CW_USEDEFAULT,          /* Windows decides the position */
00166                 CW_USEDEFAULT,          /* where the window ends up on the screen */
00167                 544,                    /* The programs width */
00168                 375,                    /* and height in pixels */
00169                 HWND_DESKTOP,           /* The window is a child-window to desktop */
00170                 NULL,                   /* No menu */
00171                 hThisInstance,          /* Program Instance handler */
00172                 NULL                    /* No Window Creation data */
00173             );
00174     ShowWindow(hMainWnd, nCmdShow);
00175 
00176     /* Main message loop */
00177     while (GetMessage (&msg, NULL, 0, 0))
00178     {
00179         TranslateMessage(&msg);
00180         DispatchMessage(&msg);
00181     }
00182 
00183     RemoveFontResourceW(argv[1]);
00184 
00185     return msg.wParam;
00186 }
00187 
00188 static LRESULT
00189 MainWnd_OnCreate(HWND hwnd)
00190 {
00191     WCHAR szQuit[MAX_BUTTONNAME];
00192     WCHAR szPrint[MAX_BUTTONNAME];
00193     WCHAR szString[MAX_STRING];
00194     HWND hDisplay, hButtonQuit, hButtonPrint;
00195 
00196     /* create the display window */
00197     hDisplay = CreateWindowExW(
00198                 0,                      /* Extended style */
00199                 g_szFontDisplayClassName,   /* Classname */
00200                 L"",                /* Title text */
00201                 WS_CHILD | WS_VSCROLL,  /* Window style */
00202                 0,                      /* X-pos */
00203                 HEADER_SIZE,            /* Y-Pos */
00204                 550,                    /* Width */
00205                 370-HEADER_SIZE,        /* Height */
00206                 hwnd,                   /* Parent */
00207                 (HMENU)IDC_DISPLAY,     /* Identifier */
00208                 g_hInstance,            /* Program Instance handler */
00209                 NULL                    /* Window Creation data */
00210             );
00211 
00212     LoadStringW(g_hInstance, IDS_STRING, szString, MAX_STRING);
00213     SendMessage(hDisplay, FVM_SETSTRING, 0, (LPARAM)szString);
00214 
00215     /* Init the display window with the font name */
00216     SendMessage(hDisplay, FVM_SETTYPEFACE, 0, (LPARAM)&g_ExtLogFontW);
00217     ShowWindow(hDisplay, SW_SHOWNORMAL);
00218 
00219     /* Create the quit button */
00220     LoadStringW(g_hInstance, IDS_QUIT, szQuit, MAX_BUTTONNAME);
00221     hButtonQuit = CreateWindowExW(
00222                 0,                      /* Extended style */
00223                 L"button",              /* Classname */
00224                 szQuit,                 /* Title text */
00225                 WS_CHILD | WS_VISIBLE,  /* Window style */
00226                 BUTTON_POS_X,           /* X-pos */
00227                 BUTTON_POS_Y,           /* Y-Pos */
00228                 BUTTON_WIDTH,           /* Width */
00229                 BUTTON_HEIGHT,          /* Height */
00230                 hwnd,                   /* Parent */
00231                 (HMENU)IDC_QUIT,        /* Identifier */
00232                 g_hInstance,            /* Program Instance handler */
00233                 NULL                    /* Window Creation data */
00234             );
00235     SendMessage(hButtonQuit, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), (LPARAM)TRUE);
00236 
00237     /* Create the print button */
00238     LoadStringW(g_hInstance, IDS_PRINT, szPrint, MAX_BUTTONNAME);
00239     hButtonPrint = CreateWindowExW(
00240                 0,                      /* Extended style */
00241                 L"button",              /* Classname */
00242                 szPrint,                /* Title text */
00243                 WS_CHILD | WS_VISIBLE,  /* Window style */
00244                 450,                    /* X-pos */
00245                 BUTTON_POS_Y,           /* Y-Pos */
00246                 BUTTON_WIDTH,           /* Width */
00247                 BUTTON_HEIGHT,          /* Height */
00248                 hwnd,                   /* Parent */
00249                 (HMENU)IDC_PRINT,       /* Identifier */
00250                 g_hInstance,            /* Program Instance handler */
00251                 NULL                    /* Window Creation data */
00252             );
00253     SendMessage(hButtonPrint, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), (LPARAM)TRUE);
00254 
00255     return 0;
00256 }
00257 
00258 static LRESULT
00259 MainWnd_OnSize(HWND hwnd)
00260 {
00261     RECT rc;
00262 
00263     GetClientRect(hwnd, &rc);
00264     MoveWindow(GetDlgItem(hwnd, IDC_PRINT), rc.right - BUTTON_WIDTH - BUTTON_POS_X, BUTTON_POS_Y, BUTTON_WIDTH, BUTTON_HEIGHT, TRUE);
00265     MoveWindow(GetDlgItem(hwnd, IDC_DISPLAY), 0, HEADER_SIZE, rc.right, rc.bottom - HEADER_SIZE, TRUE);
00266 
00267     return 0;
00268 }
00269 
00270 static LRESULT
00271 MainWnd_OnPaint(HWND hwnd)
00272 {
00273     HDC hDC;
00274     PAINTSTRUCT ps;
00275     RECT rc;
00276 
00277     hDC = BeginPaint(hwnd, &ps);
00278     GetClientRect(hwnd, &rc);
00279     rc.top = HEADER_SIZE - 2;
00280     rc.bottom = HEADER_SIZE;
00281     FillRect(hDC, &rc, GetStockObject(GRAY_BRUSH));
00282     EndPaint(hwnd, &ps);
00283     return 0;
00284 }
00285 
00286 LRESULT CALLBACK
00287 MainWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
00288 {
00289     switch (message)
00290     {
00291         case WM_CREATE:
00292             return MainWnd_OnCreate(hwnd);
00293 
00294         case WM_PAINT:
00295             return MainWnd_OnPaint(hwnd);
00296 
00297         case WM_SIZE:
00298             return MainWnd_OnSize(hwnd);
00299 
00300         case WM_COMMAND:
00301             switch(LOWORD(wParam))
00302             {
00303                 case IDC_QUIT:
00304                     PostQuitMessage (0);    /* send a WM_QUIT to the message queue */
00305                     break;
00306 
00307                 case IDC_PRINT:
00308                     MessageBox(hwnd, TEXT("This function is unimplemented"), TEXT("Unimplemented"), MB_OK);
00309                     break;
00310             }
00311             break;
00312 
00313         case WM_DESTROY:
00314             PostQuitMessage (0);    /* send a WM_QUIT to the message queue */
00315             break;
00316 
00317         default:                    /* for messages that we don't deal with */
00318             return DefWindowProcW(hwnd, message, wParam, lParam);
00319     }
00320 
00321     return 0;
00322 }
00323 
00324 /* EOF */

Generated on Sun May 27 2012 04:16:36 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.