home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / conf_sdk / conf_sdk.exe / INIT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-24  |  7.9 KB  |  263 lines

  1. /* ----------------------------------------------------------------------
  2.  
  3.     CNFTEST sample for Microsoft ActiveX Conferencing
  4.  
  5.     Unpublished work.
  6.     Copyright (c) 1996, Microsoft Corporation
  7.     All rights reserved.
  8.  
  9.     MODULE: init.c
  10.  
  11.     PURPOSE: Performs application and instance specific initialization.
  12.  
  13.     COMMENTS:
  14.         This file initializes the application. It loads MSCONF.DLL
  15.         into memory and assign pointers to the APIs. It creates the 
  16.         Main window with menus and toolbars.  Once the application 
  17.         is initialized, it displays the window with the message 
  18.         "Application Initialized."  From this point the window is 
  19.         ready to take input from the user.  Selecting the menu items 
  20.         executes the API.
  21.  
  22.     FUNCTIONS:
  23.         VOID ReadPref(void)- Reads the current preferences
  24.         VOID WritePref(void)- Writes the current preference
  25.         VOID FCreateMsgWindow(void)- Creates the main message window
  26.         BOOL FInitInstance(int nCmdShow)- Initializes the window data 
  27.                 and register the window class 
  28.         BOOL FInitApp(LPSTR lpszCmd)-Initialize the application after 
  29.                 checking command line
  30. ---------------------------------------------------------------------- */
  31.  
  32. #include "main.h" //includes the necessary header files
  33.  
  34. static char _szAppTitle[] = "Microsoft Conferencing API Test Application";
  35.  
  36. // string constants (no change for international)
  37. static char _szAppClassName[] = "MSCONFTEST";
  38. static char _szAppName[] = "CnfTest";
  39. static char _szIniName[] = "CnfTest.ini";
  40.  
  41. // Section Names
  42. static char _szConfirm[]   = "Confirm";
  43. static char _szLogFlags[]  = "Log Flags";
  44. static char _szMainWnd[]   = "MainWnd";
  45. static char _szSbar[]      = "Show Status Bar";
  46. static char _szMsgFont[]   = "Message Font";
  47. static char _szDefName[]   = "Default Name";
  48. static char _szConferenceName[]   = "Conference Name";
  49. static char _szAddrType[]   = "Address Type";
  50. static char _szMediaType[]  = "Media Type";
  51. static char _szGuid[]       = "GUID";
  52. static char _szAppGuid[]    = "AppName";
  53. static char _szCmdGuid[]    = "CmdLine";
  54. static char _szDirGuid[]    = "CurrDir";
  55. static char _szGuidRemote[] = "GUID Remote";
  56. static char _szFileName[]   = "File Name";
  57.  
  58.  
  59. /* R E A D  P R E F */
  60. /*-------------------------------------------------------------------------
  61.     %%Function: ReadPref
  62.  
  63.     Reads the current preferences from the CnfTest.ini file.
  64.     Calls GetIniBool(), GetIniInt(), GetIniStr(), and GetIniHex(). 
  65. -------------------------------------------------------------------------*/
  66. VOID ReadPref(void)
  67. {
  68.     LPSTR lpsz;
  69.  
  70.     ClearStruct(&gPref);
  71.  
  72.     gPref.fConfirm    = GetIniBool(_szConfirm, fTrue);
  73.     gPref.fSbar       = GetIniBool(_szSbar, fTrue);
  74.     gPref.grfLog      = GetIniInt(_szLogFlags, LOG_ALWAYS);
  75.     gPref.iAddrType   = GetIniInt(_szAddrType, 0);
  76.     gPref.dwMediaType = GetIniInt(_szMediaType, CONF_MT_DATA);
  77.  
  78.     lpsz = GetIniStr(_szDefName, "user1");
  79.     lstrcpy(gPref.szDefName, lpsz);
  80.     FreePlpv(&lpsz);
  81.  
  82.     lpsz = GetIniStr(_szConferenceName, "Default");
  83.     lstrcpy(gPref.szConferenceName, lpsz);
  84.     FreePlpv(&lpsz);
  85.  
  86.     lpsz = GetIniStr(_szFileName, "c:\\autoexec.bat");
  87.     lstrcpy(gPref.szFileName, lpsz);
  88.     FreePlpv(&lpsz);
  89.  
  90.     GetIniHex(_szMainWnd, &gPref.wpMain, sizeof(WINDOWPLACEMENT));
  91.     GetIniHex(_szMsgFont, &gPref.lf, sizeof(LOGFONT));
  92.  
  93.     lpsz = GetIniStr(_szGuid, "1234567890123456789012345679012");
  94.     SzToGuid(lpsz, &gPref.guid);
  95.     FreePlpv(&lpsz);
  96.  
  97.     lpsz = GetIniStr(_szGuidRemote, "1234567890123456789012345679012");
  98.     SzToGuid(lpsz, &gPref.guidRemote);
  99.     FreePlpv(&lpsz);
  100.  
  101.     lpsz = GetIniStr(_szAppGuid, "appname.exe");
  102.     lstrcpy(gPref.szAppName, lpsz);
  103.     FreePlpv(&lpsz);
  104.  
  105.     lpsz = GetIniStr(_szCmdGuid, "parameter");
  106.     lstrcpy(gPref.szCmdLine, lpsz);
  107.     FreePlpv(&lpsz);
  108.  
  109.     lpsz = GetIniStr(_szDirGuid, "c:\\program files\\Meeting");
  110.     lstrcpy(gPref.szCurrDir, lpsz);
  111.     FreePlpv(&lpsz);
  112.  
  113.     lstrcpy(gPref.szData, "data");
  114. }
  115.  
  116.  
  117. /*  W R I T E  P R E F */
  118. /*-------------------------------------------------------------------------
  119.     %%Function: WritePref
  120.  
  121.     Write the current preferences
  122. -------------------------------------------------------------------------*/
  123. VOID WritePref(void)
  124. {
  125.     WriteIniBool(_szConfirm, gPref.fConfirm);
  126.     WriteIniBool(_szSbar, gPref.fSbar);
  127.     WriteIniInt(_szLogFlags, gPref.grfLog);
  128.     WriteIniStr(_szDefName, gPref.szDefName);
  129.     WriteIniStr(_szConferenceName, gPref.szConferenceName);
  130.     WriteIniInt(_szAddrType, gPref.iAddrType);
  131.     WriteIniInt(_szMediaType, gPref.dwMediaType);
  132.  
  133.     if (ghwndMain != NULL) 
  134.     {
  135.         gPref.wpMain.length = sizeof(WINDOWPLACEMENT);
  136.         GetWindowPlacement(ghwndMain, &gPref.wpMain);
  137.     }
  138.     WriteIniHex(_szMainWnd, &gPref.wpMain, sizeof(WINDOWPLACEMENT));
  139.  
  140.     WriteIniHex(_szMsgFont, &gPref.lf, sizeof(LOGFONT));
  141.     WriteIniStr(_szAppGuid, gPref.szAppName);
  142.     WriteIniStr(_szCmdGuid, gPref.szCmdLine);
  143.     WriteIniStr(_szDirGuid, gPref.szCurrDir);
  144.     WriteIniStr(_szFileName,gPref.szFileName);
  145.  
  146.  
  147.     {
  148.         CHAR sz[MAX_PATH];
  149.         GuidToSz(&gPref.guid, sz);
  150.         WriteIniStr(_szGuid, sz);
  151.         GuidToSz(&gPref.guidRemote, sz);
  152.         WriteIniStr(_szGuidRemote, sz);
  153.     }
  154. }
  155.  
  156.  
  157. /* F  C R E A T E  M S G  W I N D O W */
  158. /*----------------------------------------------------------------------------
  159.     %%Function: FCreateMsgWindow
  160.  
  161.     Create the main message window
  162.  
  163. ----------------------------------------------------------------------------*/
  164. BOOL FCreateMsgWindow(void)
  165. {
  166.     ghwndMsg = CreateWindow("LISTBOX", NULL,
  167.         WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_BORDER |
  168.         LBS_USETABSTOPS | LBS_NOINTEGRALHEIGHT | LBS_OWNERDRAWFIXED | LBS_HASSTRINGS ,
  169.         0, 0, 0, 0,
  170.         ghwndMain, (HMENU) IDW_MSG, ghInst, NULL);
  171.     if (ghwndMsg == NULL)
  172.         return fFalse;
  173.  
  174.     // set the font for the window
  175.     ghfontEntry = CreateFontIndirect(&gPref.lf);
  176.     if (ghfontEntry == hfontNil)
  177.         return fTrue;
  178.  
  179.     SendMessage(ghwndMsg, WM_SETFONT, (WPARAM) ghfontEntry, MAKELPARAM(fTrue, 0));
  180.  
  181.     return fTrue;
  182. }
  183.  
  184.  
  185. /*  F  I N I T  I N S T A N C E */
  186. /*-------------------------------------------------------------------------
  187.     %%Function: FInitInstance
  188.  
  189.     Initialize the window data and register the window class
  190. -------------------------------------------------------------------------*/
  191. BOOL FInitInstance(int nCmdShow)
  192. {
  193.     char  szTitle[MAX_PATH];
  194.     WNDCLASS  wc;
  195.  
  196.     Assert(ghInst != NULL);
  197.  
  198.     ghAccelTable = LoadAccelerators(ghInst, MAKEINTRESOURCE(ID_APPACCEL));
  199.  
  200.     LoadString(ghInst, IDS_APP_TITLE, szTitle, sizeof(szTitle));
  201.  
  202.     wc.style         = CS_HREDRAW | CS_VREDRAW;
  203.     wc.lpfnWndProc   = (WNDPROC)WndProc;
  204.     wc.cbClsExtra    = 0;
  205.     wc.cbWndExtra    = 0;
  206.     wc.hInstance     = ghInst;
  207.     wc.hIcon         = LoadIcon(ghInst, MAKEINTRESOURCE(ICO_APP));
  208.     wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  209.     wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
  210.     wc.lpszMenuName  = MAKEINTRESOURCE(IDM_APP);
  211.     wc.lpszClassName = _szAppClassName;
  212.  
  213.     // Register the window class and return FALSE if unsuccesful.
  214.     if (!RegisterClass(&wc))
  215.         return fFalse;
  216.  
  217.     // MAIN WINDOW
  218.     // Create a main window for this application instance.
  219.     ghwndMain = CreateWindow(_szAppClassName, szTitle, WS_OVERLAPPEDWINDOW,
  220.         CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
  221.         NULL, NULL, ghInst, NULL);
  222.     if (ghwndMain == NULL)
  223.         return fFalse;
  224.  
  225.     ghMenu = GetMenu(ghwndMain);
  226.  
  227.     if (!FCreateSbar() ||
  228.         !FCreateMsgWindow())
  229.         return fFalse;
  230.  
  231.     ShowHwnd(ghwndSbar, gPref.fSbar, IDM_VIEW_SBAR);
  232.  
  233.     if (gPref.wpMain.length != 0)
  234.         SetWindowPlacement(ghwndMain, &gPref.wpMain);
  235.  
  236.     ShowWindow(ghwndMain, nCmdShow);
  237.     UpdateWindow(ghwndMain);
  238.  
  239.     Log(LOG_ALWAYS, "Application Initialized");  // Successful and ready for input
  240.     return fTrue;
  241. }
  242.  
  243.  
  244. /*  F  I N I T  A P P */
  245. /*-------------------------------------------------------------------------
  246.     %%Function: FInitApp
  247.  
  248.     Initialize the application after checking command line, etc.
  249. -------------------------------------------------------------------------*/
  250. BOOL FInitApp(LPSTR lpszCmd)
  251. {
  252.     InitCommonControls();
  253.  
  254.     // Initialize stuff
  255.     ReadPref();
  256.  
  257.     ClearBytes( &grhConfNotify, sizeof(grhConfNotify));
  258.  
  259.     return fTrue;
  260. }
  261.  
  262.  
  263.