Fontti

Torak 01.05.02 00:00

Hyvin pieni fontin valinta demo.

 Tekstiversio  Arvo: 2 (4 ääntä)  Äänestä: +  -
/* Pieni fontti demo. Napsauta ikkunaa ja valitse yleisestä
   dialogista haluamasi fontin ominaisuudet. */

#include <windows.h>

LRESULT CALLBACK
WndProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PSTR szCmdLine, int iCmdShow)
{
        static TCHAR szAppName[] = TEXT ("Fontti");
        HWND        hwnd;
        MSG               msg;
        WNDCLASS        wc;

        wc.style         = CS_HREDRAW | CS_VREDRAW;
        wc.lpfnWndProc   = WndProc;
        wc.cbClsExtra    = 0;
        wc.cbWndExtra    = 0;
        wc.hInstance     = hInstance;
        wc.hIcon         = LoadIcon (NULL, IDI_APPLICATION);
        wc.hCursor       = LoadCursor (NULL, IDC_ARROW);
        wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
        wc.lpszMenuName  = szAppName;
        wc.lpszClassName = szAppName;
        if (!RegisterClass (&wc))
          return 0;

        hwnd = CreateWindow (szAppName, szAppName, WS_OVERLAPPEDWINDOW,
                200, 200, 200, 200, NULL, NULL, hInstance, NULL);
        if(hwnd == NULL) return 0;

        ShowWindow (hwnd, iCmdShow);
        UpdateWindow (hwnd);
        while (GetMessage (&msg, NULL, 0, 0))
        {
                TranslateMessage (&msg);
                DispatchMessage (&msg);
        }
        return msg.wParam;
}

LRESULT CALLBACK
WndProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
        static CHOOSEFONT       cf;
        static LOGFONT          lf;
        HDC                     hdc;
        PAINTSTRUCT             ps;
        RECT                rect;

        switch (msg)
        {
                case WM_CREATE:
                        GetObject (GetStockObject (SYSTEM_FONT), sizeof (lf), &lf);
                        cf.lStructSize    = sizeof (CHOOSEFONT) ;
                        cf.hwndOwner      = hwnd ;
                        cf.hDC            = NULL ;
                        cf.lpLogFont      = &lf ;
                        cf.iPointSize     = 0 ;
                        cf.Flags          = CF_INITTOLOGFONTSTRUCT |
                                CF_SCREENFONTS | CF_EFFECTS ;
                cf.rgbColors      = 0 ;
                        cf.lCustData      = 0 ;
                        cf.lpfnHook       = NULL ;
                        cf.lpTemplateName = NULL ;
                        cf.hInstance      = NULL ;
                        cf.lpszStyle      = NULL ;
                        cf.nFontType      = 0 ;
                        cf.nSizeMin       = 0 ;
                        cf.nSizeMax       = 0 ;
                break;

                case WM_LBUTTONDOWN:
                        ChooseFont(&cf);
                        InvalidateRgn(hwnd, NULL, FALSE);
                break;

                case WM_PAINT:
                        hdc = BeginPaint (hwnd, &ps);
                        SelectObject (hdc, CreateFontIndirect (&lf));
                        SetTextColor (hdc, cf.rgbColors) ;
                        GetClientRect (hwnd, &rect) ;
                        DrawText (hdc, TEXT ("Fontti demo"), -1, &rect,
                DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;
                EndPaint (hwnd, &ps);
        break;

        case WM_DESTROY:
                PostQuitMessage (0) ;
        break;
     }
     return DefWindowProc (hwnd, msg, wParam, lParam) ;
}
 

Akheron 19:42 22.2.05 
Heh. Hauskaa, miten suhteellinen käsite "pieni" voi olla kun kyse on Windowsista :)