Back to index

lightning-sunbird  0.9+nobinonly
main.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 //
00038 #include <windows.h>
00039 #include <windowsx.h>
00040 #include <string.h>
00041 #include <stdlib.h>
00042 #ifndef MAPI_OLE     // Because MSFT doesn't do this for us :-(
00043 #include <mapi.h>
00044 #endif
00045 
00046 #include "port.h"
00047 #include "resource.h"
00048 
00049 #ifndef WM_PAINTICON
00050 #define WM_PAINTICON              0x26
00051 #endif // WM_PAINTICON
00052 
00053 /* 
00054  * Forward Declarations...
00055  */
00056 BOOL      InitInstance(HINSTANCE hInstance, int nCmdShow);
00057 BOOL CALLBACK LOADDS MyDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam);
00058 extern void ProcessCommand(HWND hWnd, int id, HWND hCtl, UINT codeNotify);
00059 BOOL      OpenMAPI(void);
00060 void      CloseMAPI(void);
00061 
00062 /*  
00063  * Global variables
00064  */
00065 HINSTANCE   hInst;
00066 HWND      hWnd;    
00067 
00068 #ifdef WIN16
00069 HICON  hIconApp;
00070 #endif
00071 
00072 char NEAR szAppName[] = "Netscape QA Helper";
00073 char NEAR szShortAppName[] = "QAHelper";
00074 char szClassName[] = "Netscape_QAHelper_Class_Name";
00075 
00076 void
00077 AppCleanup(void)
00078 {
00079   extern void    DoMAPILogoff(HWND hWnd);
00080   static BOOL isDone = FALSE;
00081 
00082   if (isDone)
00083     return;
00084 
00085   extern LHANDLE    mapiSession;
00086 
00087   if (mapiSession != 0)
00088   {
00089     DoMAPILogoff(hWnd);
00090   }
00091 
00092   CloseMAPI();
00093   isDone = TRUE;
00094 }
00095 
00096 BOOL 
00097 InitInstance(HINSTANCE hInstance, int nCmdShow)
00098 {
00099   /* Create a main window for this application instance.  */
00100   hWnd = CreateDialog((HINSTANCE) hInstance, 
00101             MAKEINTRESOURCE(ID_DIALOG),
00102             (HWND) NULL, (DLGPROC) MyDlgProc);
00103   
00104   if (!hWnd)
00105     return FALSE;
00106   else
00107     return TRUE;
00108 }
00109 
00110 BOOL InitApp(void)
00111 {
00112 #ifndef WIN16
00113   WNDCLASS wc;
00114   wc.style         = 0; 
00115   wc.lpfnWndProc   = DefDlgProc; 
00116   wc.cbClsExtra    = 0; 
00117   wc.cbWndExtra    = DLGWINDOWEXTRA; 
00118   wc.hInstance     = hInst; 
00119   wc.hIcon         = LoadIcon(hInst, MAKEINTRESOURCE(ID_ICON_APP)); 
00120   wc.hCursor       = LoadCursor(0, IDC_ARROW); 
00121   wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
00122   wc.lpszMenuName  = NULL; 
00123   wc.lpszClassName = szClassName;
00124   
00125   if(!RegisterClass(&wc))
00126     return FALSE;
00127 
00128 #else                
00129   hIconApp = LoadIcon(hInst, MAKEINTRESOURCE(ID_ICON_APP));
00130 #endif
00131   
00132   return TRUE;
00133 } // end InitApp
00134 
00135 // Win Main 
00136 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
00137 {
00138   MSG     msg;
00139   
00140   hInst = hInstance;
00141   
00142   if (!InitApp()) 
00143   { 
00144     return FALSE;
00145   }
00146   
00147   if (!InitInstance(hInstance, nCmdShow)) 
00148   {    
00149     return FALSE;
00150   }
00151 
00152   if (!OpenMAPI()) 
00153   {    
00154     return FALSE;
00155   }
00156 
00157   ShowWindow(hWnd, SW_SHOW);
00158   
00159   // Start the application
00160   while ((GetMessage(&msg, (HWND) NULL, (UINT) NULL, (UINT) NULL)))
00161   {
00162     if(IsDialogMessage(hWnd, &msg))
00163       continue;
00164     
00165     TranslateMessage(&msg);
00166     DispatchMessage(&msg);
00167   }
00168 
00169   return(msg.wParam);
00170 }
00171 
00172 BOOL CALLBACK LOADDS 
00173 MyDlgProc(HWND hWndMain, UINT wMsg, WPARAM wParam, LPARAM lParam) 
00174 {
00175   switch (wMsg) 
00176   {
00177   case WM_INITDIALOG: 
00178     {
00179       hWnd = hWndMain;
00180            SetDlgItemText(hWnd, ID_EDIT_ROW, "0");
00181     }
00182     break;
00183     
00184   case WM_CLOSE:
00185     {
00186       DestroyWindow(hWnd);
00187       break;
00188     }
00189 
00190   case WM_DESTROY:
00191     {
00192       AppCleanup();
00193 
00194 #ifndef WIN16
00195       UnregisterClass(szClassName, hInst);
00196 #else              
00197       // Destroy the 16 bit windows icon
00198       if(hIconApp != 0)
00199         DestroyIcon(hIconApp);
00200 #endif
00201       
00202       PostQuitMessage(0);
00203       break;
00204     }
00205   case WM_COMMAND:
00206     HANDLE_WM_COMMAND(hWnd, wParam, lParam, ProcessCommand);
00207     break;
00208     
00209   case WM_QUERYDRAGICON:     
00210 #ifdef WIN16
00211     return (BOOL)hIconApp;
00212 #endif
00213     
00214   case WM_PAINTICON:
00215 #ifdef WIN16    
00216     SetClassWord(hWnd, GCW_HICON, 0);
00217     
00218     // fall trough
00219   case WM_PAINT: 
00220     {
00221       if(!IsIconic(hWnd))
00222         return FALSE;
00223       PAINTSTRUCT ps;
00224       HDC hDC = BeginPaint(hWnd, &ps);
00225       SetMapMode(hDC, MM_TEXT);
00226       DrawIcon(hDC, 2, 2, hIconApp);
00227       EndPaint(hWnd, &ps);
00228       break;
00229     } 
00230 #endif //WIN16
00231     break;    // RICHIE - if this is not here NT 3.51 Pukes!!!!  
00232 
00233   default:
00234     return FALSE;
00235   }
00236   
00237   //~~av  return (DefWindowProc(hWnd, wMsg, wParam, lParam));
00238   return TRUE;
00239 }