home *** CD-ROM | disk | FTP | other *** search
/ Hot Shareware 35 / hot35.iso / ficheros / LC / SEE4C10.ZIP / MFC_PGM.CPP < prev    next >
C/C++ Source or Header  |  1998-05-28  |  4KB  |  158 lines

  1. //
  2. //   mfc_pgm.cpp
  3. //
  4. //   MFC_PGM is intended as a simple example of the use of
  5. //   the Microsoft Foundation Class (MFC) library with the
  6. //   SMTP Email Engine for C/C++ (SEE4C)
  7. //
  8.  
  9. #include "stdafx.h"
  10. #include "resource.h"
  11.  
  12. #include "see.h"
  13. #include "mfc_pgm.h"
  14.  
  15. static CWnd * MainWndPtr;
  16.  
  17. // CMainWindow: constructor
  18.  
  19. CMainWindow::CMainWindow()
  20. {int Row;
  21.  CString s = "WSC Test";
  22.  LoadAccelTable( "MainAccelTable" );
  23.  Create( NULL, "MFC Example Program",
  24.       WS_OVERLAPPEDWINDOW, rectDefault, NULL, "MainMenu" );
  25.  for(Row=0;Row<NROWS;Row++) Buffer[Row].Empty;
  26.  TheRow = 0;
  27. }
  28.  
  29. // Display character on screen
  30.  
  31. void CMainWindow::DisplayChar(int nChar)
  32. {int Row;
  33.  // process the character
  34.  if(nChar==10) return;
  35.  if(nChar==13)
  36.    {if(TheRow<NROWS-1) TheRow++;
  37.     else
  38.       {// scroll page (TheRow==NROWS-1)
  39.        for(Row=0;Row<=NROWS-2;Row++) Buffer[Row] = Buffer[Row+1];
  40.        Buffer[NROWS-1].Empty();
  41.        TheRow = NROWS-1;
  42.       }
  43.    }
  44.  else
  45.    {// stuff character into display buffer
  46.     Buffer[TheRow] += (char)nChar;
  47.    }
  48. }
  49.  
  50. // Display string on screen
  51.  
  52. void CMainWindow::DisplayLine(CString Text)
  53. {
  54.  Buffer[TheRow] += Text;
  55.  DisplayChar(13);
  56.  Invalidate(TRUE);
  57. }
  58.  
  59. // CMainWindow message map
  60.  
  61. BEGIN_MESSAGE_MAP( CMainWindow, CFrameWnd )
  62.    //{{AFX_MSG_MAP( CMainWindow )
  63.    ON_WM_PAINT()
  64.    ON_COMMAND(ID_EXIT,    PgmExit)
  65.    ON_COMMAND(ID_SEND,    PgmSend)
  66.    //}}AFX_MSG_MAP
  67. END_MESSAGE_MAP()
  68.  
  69. CTheApp NEAR theApp;
  70.  
  71. // PgmExit: Exits application
  72.  
  73. void CMainWindow::PgmExit(void)
  74. {
  75.  PostQuitMessage(0);
  76. }
  77.  
  78. // display error message 
  79.  
  80. void CMainWindow::ShowError(int Code)
  81. {static char Buffer[65];
  82.  static char Temp[90];
  83.  seeErrorText(Code,(LPSTR)Buffer,65);
  84.  wsprintf((LPSTR)Temp,"SEE Error %d: %s\n", Code, (LPSTR)Buffer);
  85.  DisplayLine((LPSTR)Temp);
  86. }
  87.  
  88. // PgmSend : Send email
  89. void CMainWindow::PgmSend(void)
  90. {int Code;
  91.  
  92. /////////////////////////////////////////////////////////
  93. ////// IMPORTANT: edit these definitions before compiling 
  94. #define SMTP_HOST_NAME  "smtp_host_name"
  95. #define YOUR_EMAIL_ADDR "your_email_address"
  96. #define SEND_TO         "receipient's email address"
  97. ////// EXAMPLE //////////////////////////////////////////
  98. // #define SMTP_HOST_NAME  "mail.myisp.net"
  99. // #define YOUR_EMAIL_ADDR "<me@myisp.com>"
  100. // #define SEND_TO         "<mike@marshallsoft.com>"
  101. /////////////////////////////////////////////////////////
  102.  
  103.  // connect to SMTP server 
  104.  DisplayLine("Calling seeConnectTo()...");
  105.  Code = seeConnectTo(
  106.      (LPSTR)SMTP_HOST_NAME,                          // SMTP server 
  107.      (LPSTR)YOUR_EMAIL_ADDR,                         // return email address  
  108.      (LPSTR)NULL);                                   // Reply-To header   
  109.  if(Code<0) 
  110.    {ShowError(Code); 
  111.     return;
  112.    }
  113.  // send email 
  114.  DisplayLine("Calling seeSendEmail()...");
  115.  Code = seeSendEmail(
  116.      (LPSTR)"<msc@traveller.com>",                   // To list 
  117.      (LPSTR)NULL,                                    // CC list 
  118.      (LPSTR)NULL,                                    // BCC list 
  119.      (LPSTR)"Email from MFC_PGM",                    // subject 
  120.      (LPSTR)"This is a test.\r\n\r\n--Mike",         // message text 
  121.      (LPSTR)NULL);                                   // MIME attachment                 
  122.  if(Code<0) 
  123.    {ShowError(Code); 
  124.     return;
  125.    }
  126.  DisplayLine("Calling seeClose()...");
  127.  Code = seeClose();
  128.  Invalidate(TRUE);
  129. }
  130.  
  131. // OnPaint:
  132.  
  133. void CMainWindow::OnPaint()
  134. {int Row;
  135.  CPaintDC dc( this );
  136.  CRect rect;
  137.  GetClientRect( rect );
  138.  dc.SetTextAlign( TA_BASELINE | TA_LEFT );
  139.  dc.SetTextColor( ::GetSysColor( COLOR_WINDOWTEXT ) );
  140.  dc.SetBkMode(TRANSPARENT);
  141.  dc.SelectStockObject(ANSI_FIXED_FONT);
  142.  for(Row=0;Row<=TheRow;Row++)
  143.    {// display the row
  144.     dc.TextOut( 4, 16+(Row<<4), Buffer[Row], Buffer[Row].GetLength() );
  145.    }
  146. }
  147.  
  148. // InitInstance:
  149.  
  150. BOOL CTheApp::InitInstance()
  151. {SetDialogBkColor(); //hook gray dialogs
  152.  m_pMainWnd = new CMainWindow();
  153.  m_pMainWnd->ShowWindow( m_nCmdShow );
  154.  m_pMainWnd->UpdateWindow();
  155.  MainWndPtr = m_pMainWnd;
  156.  return TRUE;
  157. }
  158.