Annotation of mstools/ole20/samples/spoly/winmain.cpp, revision 1.1

1.1     ! root        1: /*** 
        !             2: *winmain.cpp
        !             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 polygon
        !             9: *  server, spoly.exe.
        !            10: *
        !            11: *  This program is intended to demonstrate an implementation of the IDispatch
        !            12: *  interface. Spoly is a very simple app, that implements two simple objects,
        !            13: *  CPoly and CPoint and exposes their properties and methods for programatic
        !            14: *  and cross-process access via IDispatch.
        !            15: *
        !            16: *Implementation Notes:
        !            17: *
        !            18: *****************************************************************************/
        !            19: 
        !            20: #include <stdio.h>
        !            21: #include <string.h>
        !            22: 
        !            23: #include "spoly.h"
        !            24: #include "cpoint.h"
        !            25: #include "cpoly.h"
        !            26: 
        !            27: 
        !            28: extern int g_fExitOnLastRelease;
        !            29: 
        !            30: 
        !            31: HANDLE g_hinst = 0;
        !            32: 
        !            33: HWND g_hwndFrame = 0;
        !            34: HWND g_hwndClient = 0;
        !            35: 
        !            36: char g_szFrameWndClass[] = "FrameWClass";
        !            37: 
        !            38: CStatBar FAR* g_psb = NULL;
        !            39: 
        !            40: 
        !            41: BOOL InitApplication(HANDLE);
        !            42: BOOL InitInstance(HANDLE, int);
        !            43: 
        !            44: extern "C" int PASCAL WinMain(HANDLE, HANDLE, LPSTR, int);
        !            45: extern "C" long FAR PASCAL FrameWndProc(HWND, UINT, WPARAM, LPARAM);
        !            46: 
        !            47: 
        !            48: extern "C" int PASCAL
        !            49: WinMain(
        !            50:     HANDLE hinst,
        !            51:     HANDLE hPrevInstance,
        !            52:     LPSTR lpCmdLine,
        !            53:     int nCmdShow)
        !            54: {
        !            55:     MSG msg;
        !            56:     int retval;
        !            57:     HRESULT hresult;
        !            58: 
        !            59:     if(!hPrevInstance)
        !            60:       if(!InitApplication(hinst))
        !            61:        return FALSE;
        !            62: 
        !            63:     if((hresult = InitOle()) != NOERROR)
        !            64:       return FALSE;
        !            65: 
        !            66:     if(!InitInstance(hinst, nCmdShow)){
        !            67:       retval = FALSE;
        !            68:       goto LExit;
        !            69:     }
        !            70: 
        !            71:     if(STRSTR(lpCmdLine, "-Embedding"))
        !            72:       g_fExitOnLastRelease = TRUE;
        !            73: 
        !            74:     while(GetMessage(&msg, NULL, NULL, NULL)) {
        !            75:       TranslateMessage(&msg);
        !            76:       DispatchMessage(&msg);
        !            77:     }
        !            78: 
        !            79:     CPoly::PolyTerm();
        !            80: 
        !            81:     retval = msg.wParam;
        !            82: 
        !            83: LExit:;
        !            84:     UninitOle();
        !            85: 
        !            86:     return retval;
        !            87: }
        !            88: 
        !            89: 
        !            90: BOOL
        !            91: InitApplication(HANDLE hinst)
        !            92: {
        !            93:     WNDCLASS  wc;
        !            94: 
        !            95:     wc.style           = CS_HREDRAW | CS_VREDRAW;
        !            96:     wc.lpfnWndProc     = FrameWndProc;
        !            97:     wc.cbClsExtra      = 0;
        !            98:     wc.cbWndExtra      = 0;
        !            99:     wc.hInstance       = hinst;
        !           100:     wc.hIcon           = LoadIcon(hinst, "SPOLY");
        !           101:     wc.hCursor         = LoadCursor(NULL, IDC_ARROW);
        !           102:     wc.hbrBackground   = (HBRUSH) (COLOR_APPWORKSPACE+1);
        !           103:     wc.lpszMenuName    = "SPolyMenu";
        !           104:     wc.lpszClassName   = g_szFrameWndClass;
        !           105: 
        !           106:     if(!RegisterClass(&wc))
        !           107:       return FALSE;
        !           108: 
        !           109:     return TRUE;
        !           110: }
        !           111: 
        !           112: 
        !           113: BOOL
        !           114: InitInstance(HANDLE hinst, int nCmdShow)
        !           115: {
        !           116:     g_hinst = hinst;
        !           117: 
        !           118:     // Create a main frame window
        !           119:     //
        !           120:     g_hwndFrame = CreateWindow(
        !           121:       g_szFrameWndClass,
        !           122:       "IDispatch Polygon Server",
        !           123:       WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
        !           124:       CW_USEDEFAULT,
        !           125:       CW_USEDEFAULT,
        !           126:       CW_USEDEFAULT,
        !           127:       CW_USEDEFAULT,
        !           128:       NULL,
        !           129:       NULL,
        !           130:       hinst,
        !           131:       NULL);
        !           132:     if(!g_hwndFrame)
        !           133:       return FALSE;
        !           134: 
        !           135:     g_hwndClient = GetWindow(g_hwndFrame, GW_CHILD);
        !           136:     if(!g_hwndClient)
        !           137:       return FALSE;
        !           138: 
        !           139:     // create the status bar
        !           140:     //
        !           141:     g_psb = CStatBar::Create(g_hinst, g_hwndFrame);
        !           142:     if(!g_psb)
        !           143:       return FALSE;
        !           144: 
        !           145:     // initialize and show the status bar
        !           146:     //
        !           147:     g_psb->SetHeight(GetSystemMetrics(SM_CYCAPTION) - 1);
        !           148:     g_psb->SetFont(GetStockObject(SYSTEM_FONT));
        !           149:     g_psb->SetText("");
        !           150:     g_psb->Show();
        !           151: 
        !           152:     ShowWindow(g_hwndFrame, nCmdShow);
        !           153: 
        !           154:     UpdateWindow(g_hwndFrame);
        !           155: 
        !           156:     return TRUE;
        !           157: }
        !           158: 
        !           159: 
        !           160: void
        !           161: FrameWndOnCreate(HWND hwnd)
        !           162: {
        !           163:     CLIENTCREATESTRUCT ccs;
        !           164: 
        !           165:     ccs.hWindowMenu = NULL;
        !           166:     ccs.idFirstChild = IDM_FIRSTCHILD;
        !           167: 
        !           168:     g_hwndClient = CreateWindow(
        !           169:       "MDICLIENT",
        !           170:       0,
        !           171:       WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE,
        !           172:       0, 0, 0, 0,
        !           173:       hwnd,
        !           174:       (HMENU) 1,
        !           175:       g_hinst,
        !           176:       &ccs);
        !           177: }
        !           178: 
        !           179: 
        !           180: void
        !           181: FrameWndOnSize(HWND hwnd)
        !           182: {
        !           183:     RECT rc;
        !           184:     int height;
        !           185: 
        !           186:     // Get the client rectangle for the frame window
        !           187:     GetClientRect(hwnd, &rc);
        !           188: 
        !           189:     height = g_psb->GetHeight();
        !           190: 
        !           191:     // adjust the client win to make room for the status bar.
        !           192:     //
        !           193:     MoveWindow(
        !           194:       g_hwndClient,
        !           195:       rc.left,
        !           196:       rc.top,
        !           197:       rc.right - rc.left,
        !           198:       rc.bottom - rc.top - height,
        !           199:       TRUE);
        !           200: 
        !           201:     // move the status bar to the bottom of the newly positioned window.
        !           202:     //
        !           203:     g_psb->SetX(rc.left);
        !           204:     g_psb->SetY(rc.bottom - height),
        !           205:     g_psb->SetWidth(rc.right - rc.left);
        !           206:     g_psb->Move();
        !           207: }
        !           208: 
        !           209: 
        !           210: extern "C" long FAR PASCAL
        !           211: FrameWndProc(
        !           212:     HWND hwnd,
        !           213:     UINT message,
        !           214:     WPARAM wParam,
        !           215:     LPARAM lParam)
        !           216: {
        !           217:     switch(message){
        !           218:     case WM_COMMAND:
        !           219:       switch(wParam){
        !           220:       case IDM_DUMP:
        !           221:        CPoly::PolyDump();
        !           222:        return 0;
        !           223: 
        !           224:       case IDM_CLEAR:
        !           225:        InvalidateRect(g_hwndClient, NULL, TRUE);
        !           226:        return 0;
        !           227:       }
        !           228:       break;
        !           229: 
        !           230:     case WM_CREATE:
        !           231:       FrameWndOnCreate(hwnd);
        !           232:       break;
        !           233: 
        !           234:     case WM_SIZE:
        !           235:       FrameWndOnSize(hwnd);
        !           236:       return 1;
        !           237: 
        !           238:     case WM_PAINT:
        !           239:       CPoly::PolyDraw();
        !           240:       break;
        !           241: 
        !           242:     case WM_CLOSE:
        !           243:       DestroyWindow(hwnd);
        !           244:       return 0;
        !           245: 
        !           246:     case WM_DESTROY:
        !           247:       PostQuitMessage(0);
        !           248:       return 0;
        !           249:     }
        !           250:     return DefFrameProc(hwnd, g_hwndClient, message, wParam, lParam);
        !           251: }
        !           252: 

unix.superglobalmegacorp.com

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