Annotation of mstools/ole20/samples/dispdemo/dispdemo.cpp, revision 1.1

1.1     ! root        1: /*** 
        !             2: *dispdemo.c - IDespatch demo/sample client application.
        !             3: *
        !             4: *  Copyright (C) 1992, Microsoft Corporation.  All Rights Reserved.
        !             5: *  Information Contained Herein Is Proprietary and Confidential.
        !             6: *
        !             7: *Purpose:
        !             8: *  This module is the main entry point for the sample IDispatch client,
        !             9: *  dispdemo.exe.
        !            10: *
        !            11: *  This program is intended to demonstrate a client invoking methods
        !            12: *  and referencing properties on a remote object via the IDispatch
        !            13: *  interface.
        !            14: *
        !            15: *  The bulk of the sample can be found in the file crempoly.cpp, which
        !            16: *  implements CRemPoly, the remote polygon class.
        !            17: *
        !            18: *Implementation Notes:
        !            19: *
        !            20: *****************************************************************************/
        !            21: 
        !            22: #include <windows.h>
        !            23: #include <ole2.h>
        !            24: #include <dispatch.h>
        !            25: 
        !            26: #include "dispdemo.h"
        !            27: 
        !            28: 
        !            29: BOOL InitApplication(HANDLE);
        !            30: BOOL InitInstance(HANDLE, int);
        !            31: BOOL FAR PASCAL About(HWND, unsigned, WORD, LONG);
        !            32: 
        !            33: STDAPI_(BOOL) InitOle(void);
        !            34: STDAPI_(void) UninitOle(void);
        !            35: 
        !            36: extern "C" {
        !            37: int PASCAL WinMain(HANDLE, HANDLE, LPSTR, int);
        !            38: LRESULT FAR PASCAL MainWndProc(HWND, UINT, WPARAM, LPARAM);
        !            39: }
        !            40: 
        !            41: HANDLE g_hInst;
        !            42: 
        !            43: BOOL g_fTrace = FALSE;
        !            44: 
        !            45: char g_szDispDemoWClass[] = "DispDemoWClass";
        !            46: 
        !            47: extern "C" int PASCAL
        !            48: WinMain(
        !            49:     HANDLE hinst,
        !            50:     HANDLE hPrevInstance,
        !            51:     LPSTR lpCmdLine,
        !            52:     int nCmdShow)
        !            53: {
        !            54:     MSG msg;
        !            55: 
        !            56: 
        !            57:     (lpCmdLine); // UNUSED
        !            58: 
        !            59:     if(!hPrevInstance)
        !            60:       if(!InitApplication(hinst))
        !            61:        return FALSE;
        !            62: 
        !            63:     if(!InitOle())
        !            64:       return FALSE;
        !            65: 
        !            66:     if(!InitInstance(hinst, nCmdShow))
        !            67:       return FALSE;
        !            68: 
        !            69:     while(GetMessage(&msg, NULL, 0, 0)) {
        !            70:       TranslateMessage(&msg);
        !            71:       DispatchMessage(&msg);
        !            72:     }
        !            73: 
        !            74:     UninitOle();
        !            75: 
        !            76:     return msg.wParam;
        !            77: }
        !            78: 
        !            79: 
        !            80: BOOL
        !            81: InitApplication(HANDLE hinst)
        !            82: {
        !            83:     WNDCLASS  wc;
        !            84: 
        !            85:     wc.style           = NULL;
        !            86:     wc.lpfnWndProc     = MainWndProc;
        !            87:     wc.cbClsExtra      = 0;
        !            88:     wc.cbWndExtra      = 0;
        !            89:     wc.hInstance       = hinst;
        !            90:     wc.hIcon           = LoadIcon(hinst, "DISPDEMO");
        !            91:     wc.hCursor         = LoadCursor(NULL, IDC_ARROW);
        !            92:     wc.hbrBackground   = GetStockObject(WHITE_BRUSH); 
        !            93:     wc.lpszMenuName    = "DispDemoMenu";
        !            94:     wc.lpszClassName   = g_szDispDemoWClass;
        !            95:     if(!RegisterClass(&wc))
        !            96:       return FALSE;
        !            97: 
        !            98:     return TRUE;
        !            99: }
        !           100: 
        !           101: 
        !           102: BOOL
        !           103: InitInstance(HANDLE hinst, int nCmdShow)
        !           104: {
        !           105:     HWND hWnd;
        !           106: 
        !           107:     g_hInst = hinst;
        !           108: 
        !           109:     hWnd = CreateWindow(
        !           110:       g_szDispDemoWClass,
        !           111:       "IDispatch Demo App",
        !           112:       WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX,
        !           113:       CW_USEDEFAULT, CW_USEDEFAULT, 300, 100,
        !           114:       NULL, NULL, hinst, NULL);
        !           115: 
        !           116:     if(!hWnd)
        !           117:       return FALSE;
        !           118: 
        !           119:     ShowWindow(hWnd, nCmdShow);
        !           120:     UpdateWindow(hWnd);
        !           121: 
        !           122:     return TRUE;
        !           123: }
        !           124: 
        !           125: 
        !           126: BOOL FAR PASCAL
        !           127: About(HWND hDlg, unsigned message, WORD wParam, LONG lParam)
        !           128: {
        !           129:     switch(message){
        !           130:     case WM_INITDIALOG:
        !           131:       return TRUE;
        !           132: 
        !           133:     case WM_COMMAND:
        !           134:       switch(wParam){
        !           135:       case IDOK:
        !           136:       case IDCANCEL:
        !           137:        EndDialog(hDlg, TRUE);
        !           138:        return TRUE;
        !           139:       }
        !           140:       break;
        !           141:     }
        !           142:     return FALSE;
        !           143: }
        !           144: 
        !           145: 
        !           146: extern "C" LRESULT FAR PASCAL
        !           147: MainWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
        !           148: {
        !           149:     HMENU hmenu;
        !           150: static FARPROC pfnAbout;
        !           151: 
        !           152:     switch(message){
        !           153:     case WM_COMMAND:
        !           154:       switch(wParam){
        !           155:       case IDM_TRACE:
        !           156:        /* enable/disable trace */
        !           157:        g_fTrace = (g_fTrace) ? FALSE : TRUE;
        !           158:        hmenu = GetMenu(hwnd);
        !           159:        CheckMenuItem(hmenu, IDM_TRACE, g_fTrace ? MF_CHECKED : MF_UNCHECKED);
        !           160:        return 0;
        !           161: 
        !           162:       case IDM_POLY:
        !           163:        DoPoly(CLSID_CPoly);
        !           164:        return 0;
        !           165: 
        !           166:       case IDM_POLY2:
        !           167:        DoPoly(CLSID_CPoly2);
        !           168:        return 0;
        !           169: 
        !           170:       case IDM_ABOUT:
        !           171:        pfnAbout = (FARPROC)MakeProcInstance((FARPROC)About, g_hInst);
        !           172:        DialogBox(g_hInst, "AboutBox", hwnd, pfnAbout);
        !           173:        FreeProcInstance(pfnAbout);
        !           174:        return 0;
        !           175:       }
        !           176:       break;
        !           177: 
        !           178:     case WM_CLOSE:
        !           179:       DestroyWindow(hwnd);
        !           180:       return 0;
        !           181: 
        !           182:     case WM_DESTROY:
        !           183:       PostQuitMessage(0);
        !           184:       return 0;
        !           185:     }
        !           186:     return DefWindowProc(hwnd, message, wParam, lParam);
        !           187: }
        !           188: 
        !           189: 
        !           190: STDAPI_(BOOL)
        !           191: InitOle(void)
        !           192: {
        !           193:     if(OleInitialize(NULL) != 0)
        !           194:       return FALSE;
        !           195: 
        !           196:     return TRUE;
        !           197: }
        !           198: 
        !           199: 
        !           200: STDAPI_(void)
        !           201: UninitOle()
        !           202: {
        !           203:     OleUninitialize();
        !           204: }

unix.superglobalmegacorp.com

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