Annotation of mstools/samples/icon/icon.c, revision 1.1

1.1     ! root        1: /****************************************************************************
        !             2: 
        !             3:     PROGRAM: Icon.c
        !             4: 
        !             5:     PURPOSE: Demonstrates using an icon for the About box and minimize box
        !             6: 
        !             7:     FUNCTIONS:
        !             8: 
        !             9:        WinMain() - calls initialization function, processes message loop
        !            10:        InitApplication() - initializes window data and registers window
        !            11:        InitInstance() - saves instance handle and creates main window
        !            12:        MainWndProc() - processes messages
        !            13:        About() - processes messages for "About" dialog box
        !            14: 
        !            15: ****************************************************************************/
        !            16: 
        !            17: #include "windows.h"
        !            18: #include "icon.h"
        !            19: 
        !            20: HANDLE hInst;
        !            21: 
        !            22: 
        !            23: /****************************************************************************
        !            24: 
        !            25:     FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
        !            26: 
        !            27:     PURPOSE: calls initialization function, processes message loop
        !            28: 
        !            29: ****************************************************************************/
        !            30: 
        !            31: int APIENTRY WinMain(
        !            32:     HANDLE hInstance,
        !            33:     HANDLE hPrevInstance,
        !            34:     LPSTR lpCmdLine,
        !            35:     int nCmdShow
        !            36:     )
        !            37: {
        !            38:     MSG msg;
        !            39: 
        !            40:     UNREFERENCED_PARAMETER( lpCmdLine );
        !            41: 
        !            42:     if (!hPrevInstance)
        !            43:        if (!InitApplication(hInstance))
        !            44:            return (FALSE);
        !            45: 
        !            46:     if (!InitInstance(hInstance, nCmdShow))
        !            47:         return (FALSE);
        !            48: 
        !            49:     while (GetMessage(&msg, NULL, NULL, NULL)) {
        !            50:        TranslateMessage(&msg);
        !            51:        DispatchMessage(&msg);
        !            52:     }
        !            53:     return (msg.wParam);
        !            54: }
        !            55: 
        !            56: 
        !            57: /****************************************************************************
        !            58: 
        !            59:     FUNCTION: InitApplication(HANDLE)
        !            60: 
        !            61:     PURPOSE: Initializes window data and registers window class
        !            62: 
        !            63: ****************************************************************************/
        !            64: 
        !            65: BOOL InitApplication(HANDLE hInstance)
        !            66: {
        !            67:     WNDCLASS  wc;
        !            68: 
        !            69:     wc.style = NULL;
        !            70:     wc.lpfnWndProc = (WNDPROC) MainWndProc;
        !            71:     wc.cbClsExtra = 0;
        !            72:     wc.cbWndExtra = 0;
        !            73:     wc.hInstance = hInstance;
        !            74:     wc.hIcon = LoadIcon(hInstance, "MyIcon");           /* loads icon */
        !            75:     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
        !            76:     wc.hbrBackground = GetStockObject(WHITE_BRUSH); 
        !            77:     wc.lpszMenuName =  "IconMenu";
        !            78:     wc.lpszClassName = "IconWClass";
        !            79: 
        !            80:     return (RegisterClass(&wc));
        !            81: }
        !            82: 
        !            83: 
        !            84: /****************************************************************************
        !            85: 
        !            86:     FUNCTION:  InitInstance(HANDLE, int)
        !            87: 
        !            88:     PURPOSE:  Saves instance handle and creates main window
        !            89: 
        !            90: ****************************************************************************/
        !            91: 
        !            92: BOOL InitInstance(
        !            93:     HANDLE          hInstance,
        !            94:     INT             nCmdShow)
        !            95: {
        !            96:     HWND            hWnd;
        !            97: 
        !            98:     hInst = hInstance;
        !            99: 
        !           100:     hWnd = CreateWindow(
        !           101:         "IconWClass",
        !           102:         "Icon Sample Application",
        !           103:         WS_OVERLAPPEDWINDOW,
        !           104:         CW_USEDEFAULT,
        !           105:         CW_USEDEFAULT,
        !           106:         CW_USEDEFAULT,
        !           107:         CW_USEDEFAULT,
        !           108:         NULL,
        !           109:         NULL,
        !           110:         hInstance,
        !           111:         NULL
        !           112:     );
        !           113: 
        !           114:     if (!hWnd)
        !           115:         return (FALSE);
        !           116: 
        !           117:     ShowWindow(hWnd, nCmdShow);
        !           118:     UpdateWindow(hWnd);
        !           119:     return (TRUE);
        !           120: 
        !           121: }
        !           122: 
        !           123: /****************************************************************************
        !           124: 
        !           125:     FUNCTION: MainWndProc(HWND, unsigned, WORD, LONG)
        !           126: 
        !           127:     PURPOSE:  Processes messages
        !           128: 
        !           129:     MESSAGES:
        !           130: 
        !           131:        WM_COMMAND    - application menu (About dialog box)
        !           132:        WM_DESTROY    - destroy window
        !           133: 
        !           134: ****************************************************************************/
        !           135: 
        !           136: LONG APIENTRY MainWndProc(
        !           137:        HWND hWnd,
        !           138:        UINT message,
        !           139:        UINT wParam,
        !           140:        LONG lParam)
        !           141: {
        !           142:     FARPROC lpProcAbout;
        !           143: 
        !           144:     switch (message) {
        !           145:        case WM_COMMAND:
        !           146:            if (LOWORD(wParam) == IDM_ABOUT) {
        !           147:                lpProcAbout = MakeProcInstance((FARPROC)About, hInst);
        !           148: 
        !           149:                DialogBox(hInst,
        !           150:                    "AboutBox",
        !           151:                    hWnd,
        !           152:                    (WNDPROC)lpProcAbout);
        !           153: 
        !           154:                FreeProcInstance(lpProcAbout);
        !           155:                break;
        !           156:            }
        !           157:            else
        !           158:                return (DefWindowProc(hWnd, message, wParam, lParam));
        !           159: 
        !           160:        case WM_DESTROY:
        !           161:            PostQuitMessage(0);
        !           162:            break;
        !           163: 
        !           164:        default:
        !           165:            return (DefWindowProc(hWnd, message, wParam, lParam));
        !           166:     }
        !           167:     return (NULL);
        !           168: }
        !           169: 
        !           170: 
        !           171: /****************************************************************************
        !           172: 
        !           173:     FUNCTION: About(HWND, unsigned, WORD, LONG)
        !           174: 
        !           175:     PURPOSE:  Processes messages for "About" dialog box
        !           176: 
        !           177:     MESSAGES:
        !           178: 
        !           179:        WM_INITDIALOG - initialize dialog box
        !           180:        WM_COMMAND    - Input received
        !           181: 
        !           182: ****************************************************************************/
        !           183: 
        !           184: BOOL APIENTRY About(
        !           185:        HWND hDlg,
        !           186:        UINT message,
        !           187:        UINT wParam,
        !           188:        LONG lParam)
        !           189: {
        !           190:     switch (message) {
        !           191:        case WM_INITDIALOG:
        !           192:            return (TRUE);
        !           193: 
        !           194:        case WM_COMMAND:
        !           195:            if (LOWORD(wParam) == IDOK
        !           196:                || LOWORD(wParam) == IDCANCEL) {
        !           197:                EndDialog(hDlg, TRUE);
        !           198:                return (TRUE);
        !           199:            }
        !           200:            break;
        !           201:     }
        !           202:     return (FALSE);
        !           203:        UNREFERENCED_PARAMETER(lParam);
        !           204: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.