home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / winbase / ipc / ddeml / client / clinit.c < prev    next >
C/C++ Source or Header  |  1997-10-05  |  7KB  |  159 lines

  1.  
  2. /******************************************************************************\
  3. *       This is a part of the Microsoft Source Code Samples.
  4. *       Copyright (C) 1993-1997 Microsoft Corporation.
  5. *       All rights reserved.
  6. *       This source code is only intended as a supplement to
  7. *       Microsoft Development Tools and/or WinHelp documentation.
  8. *       See these sources for detailed information regarding the
  9. *       Microsoft samples programs.
  10. \******************************************************************************/
  11.  
  12. /***************************************************************************
  13.  *                                                                         *
  14.  *  MODULE      : clinit.c                                                 *
  15.  *                                                                         *
  16.  *  PURPOSE     : Contains initialization code for Client                  *
  17.  *                                                                         *
  18.  ***************************************************************************/
  19.  
  20. #include "client.h"
  21.  
  22. TCHAR szFrame[] = TEXT("mpframe");   /* Class name for "frame" window */
  23. TCHAR szChild[] = TEXT("mpchild");   /* Class name for MDI window     */
  24. TCHAR szList[] =  TEXT("mplist");    /* Class name for MDI window     */
  25.  
  26. /****************************************************************************
  27.  *                                                                          *
  28.  *  FUNCTION   : InitializeApplication ()                                   *
  29.  *                                                                          *
  30.  *  PURPOSE    : Sets up the class data structures and does a one-time      *
  31.  *               initialization of the app by registering the window classes*
  32.  *               Also registers the Link clipboard format                   *
  33.  *                                                                          *
  34.  *  RETURNS    : TRUE  - If successful.                                     *
  35.  *               FALSE - otherwise.                                         *
  36.  *                                                                          *
  37.  ****************************************************************************/
  38.  
  39. BOOL  APIENTRY InitializeApplication()
  40. {
  41.     WNDCLASS    wc;
  42.  
  43.     fmtLink = RegisterClipboardFormat(TEXT("Link"));
  44.  
  45.     if (!fmtLink)
  46.         return FALSE;
  47.  
  48.     /* Register the frame class */
  49.     wc.style         = 0;
  50.     wc.lpfnWndProc   = FrameWndProc;
  51.     wc.cbClsExtra    = 0;
  52.     wc.cbWndExtra    = 0;
  53.     wc.hInstance     = hInst;
  54.     wc.hIcon         = LoadIcon(hInst,MAKEINTRESOURCE(IDCLIENT));
  55.     wc.hCursor       = LoadCursor(NULL,IDC_ARROW);
  56.     wc.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE+1);
  57.     wc.lpszMenuName  = MAKEINTRESOURCE(IDCLIENT);
  58.     wc.lpszClassName = szFrame;
  59.  
  60.     if (!RegisterClass (&wc) )
  61.         return FALSE;
  62.  
  63.     /* Register the MDI child class */
  64.     wc.lpfnWndProc   = MDIChildWndProc;
  65.     wc.hIcon         = LoadIcon(hInst,MAKEINTRESOURCE(IDCONV));
  66.     wc.lpszMenuName  = NULL;
  67.     wc.cbWndExtra    = CHILDCBWNDEXTRA;
  68.     wc.lpszClassName = szChild;
  69.  
  70.     if (!RegisterClass(&wc))
  71.         return FALSE;
  72.  
  73.     wc.hIcon         = LoadIcon(hInst, MAKEINTRESOURCE(IDLIST));
  74.     wc.lpszClassName = szList;
  75.  
  76.     if (!RegisterClass(&wc))
  77.         return FALSE;
  78.  
  79.     return TRUE;
  80.  
  81. }
  82.  
  83. /****************************************************************************
  84.  *                                                                          *
  85.  *  FUNCTION   : InitializeInstance ()                                      *
  86.  *                                                                          *
  87.  *  PURPOSE    : Performs a per-instance initialization of Client.          *
  88.  *               - Enlarges message queue to handle lots of DDE messages.   *
  89.  *               - Initializes DDEML for this app                           *
  90.  *               - Creates atoms for our custom formats                     *
  91.  *               - Creates the main frame window                            *
  92.  *               - Loads accelerator table                                  *
  93.  *               - Shows main frame window                                  *
  94.  *                                                                          *
  95.  *  RETURNS    : TRUE  - If initialization was successful.                  *
  96.  *               FALSE - otherwise.                                         *
  97.  *                                                                          *
  98.  ****************************************************************************/
  99. BOOL  APIENTRY InitializeInstance(
  100. DWORD nCmdShow)
  101. {
  102.     extern HWND  hwndMDIClient;
  103.     TCHAR         sz[80];
  104.     INT          i;
  105.  
  106.     if (DdeInitialize(&idInst, (PFNCALLBACK)MakeProcInstance(
  107.             (FARPROC)DdeCallback, hInst), APPCMD_CLIENTONLY, 0L))
  108.         return FALSE;
  109.  
  110.     CCFilter.iCodePage = CP_WINANSI;
  111.  
  112.     for (i = 0; i < CFORMATS; i++) {
  113.         if (aFormats[i].fmt == 0)
  114.             aFormats[i].fmt = RegisterClipboardFormat(aFormats[i].sz);
  115.     }
  116.     hszHuge = DdeCreateStringHandle(idInst, TEXT("Huge"), 0);
  117.  
  118.     /* Get the base window title */
  119.     LoadString(hInst, IDS_APPNAME, sz, sizeof(sz));
  120.  
  121.     /* Create the frame */
  122.     hwndFrame = CreateWindow (szFrame,
  123.                               sz,
  124.                               WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
  125.                               CW_USEDEFAULT,
  126.                               CW_USEDEFAULT,
  127.                               400,
  128.                               200,
  129.                               NULL,
  130.                               NULL,
  131.                               hInst,
  132.                               NULL);
  133.  
  134.     if (!hwndFrame || !hwndMDIClient)
  135.         return FALSE;
  136.  
  137.     /* Load main menu accelerators */
  138.     if (!(hAccel = LoadAccelerators (hInst, MAKEINTRESOURCE(IDCLIENT))))
  139.         return FALSE;
  140.  
  141.     /* Display the frame window */
  142.     ShowWindow (hwndFrame, nCmdShow);
  143.     UpdateWindow (hwndFrame);
  144.  
  145.     /*
  146.      * We set this hook up so that we can catch the MSGF_DDEMGR filter
  147.      * which is called when DDEML is in a modal loop during synchronous
  148.      * transaction processing.
  149.      */
  150.     lpMsgFilterProc = (FARPROC)MakeProcInstance((FARPROC)MyMsgFilterProc, hInst);
  151.     ghhk = SetWindowsHookEx(WH_MSGFILTER, (HOOKPROC)lpMsgFilterProc, NULL,
  152.             GetCurrentThreadId());
  153.  
  154.     return TRUE;
  155. }
  156.  
  157.  
  158.  
  159.