CLINIT.C
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:6k
源码类别:

Windows编程

开发平台:

Visual C++

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