home *** CD-ROM | disk | FTP | other *** search
/ Prima Shareware 3 / DuCom_Prima-Shareware-3_cd1.bin / PROGRAMO / C / CKTBL / SAMPLES / MFCDEMO / MFCDEMO.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-07  |  6.9 KB  |  272 lines

  1. // mfcdemo.cpp : Defines the class behaviors for the application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "mfcdemo.h"
  6.  
  7. #include "mainfrm.h"
  8. #include "mfcdedoc.h"
  9. #include "mfcdevw.h"
  10.  
  11. #include "ctl3d.h"   
  12. #include "cktbl.h"
  13.        
  14.        
  15. #ifdef _DEBUG
  16. #undef THIS_FILE
  17. static char BASED_CODE THIS_FILE[] = __FILE__;
  18. #endif
  19.  
  20. /////////////////////////////////////////////////////////////////////////////
  21. // CMfcdemoApp
  22.  
  23. BEGIN_MESSAGE_MAP(CMfcdemoApp, CWinApp)
  24.     //{{AFX_MSG_MAP(CMfcdemoApp)
  25.     ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  26.         // NOTE - the ClassWizard will add and remove mapping macros here.
  27.         //    DO NOT EDIT what you see in these blocks of generated code!
  28.     //}}AFX_MSG_MAP
  29.     // Standard file based document commands
  30.     ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  31.     ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  32.     // Standard print setup command
  33.     ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
  34. END_MESSAGE_MAP()
  35.  
  36. /////////////////////////////////////////////////////////////////////////////
  37. // CMfcdemoApp construction
  38.  
  39. CMfcdemoApp::CMfcdemoApp()
  40. {
  41.     // TODO: add construction code here,
  42.     // Place all significant initialization in InitInstance
  43. }
  44.  
  45. /////////////////////////////////////////////////////////////////////////////
  46. // The one and only CMfcdemoApp object
  47.  
  48. CMfcdemoApp NEAR theApp;
  49.        
  50.              
  51. /////////////////////////////////////////////////////////////////////////////
  52. // CAboutDlg dialog used for App About
  53.  
  54. class CAboutDlg : public CDialog
  55. {
  56. public:
  57.     CAboutDlg();
  58.  
  59. // Dialog Data
  60.     //{{AFX_DATA(CAboutDlg)
  61.     enum { IDD = IDD_ABOUTBOX };
  62.     //}}AFX_DATA  
  63.     
  64.     CBitmap     mastercard;
  65.     CBitmap     visa;
  66.     CBitmap        eurocard;
  67.     CBitmap        amex; 
  68.     BOOL        splashMode; 
  69.     
  70.     void SplashMode() { splashMode=1; }
  71.  
  72. // Implementation
  73. protected:
  74.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  75.     //{{AFX_MSG(CAboutDlg)
  76.     afx_msg void OnPaint();
  77.     afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
  78.     afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
  79.     afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
  80.     //}}AFX_MSG
  81.     DECLARE_MESSAGE_MAP()
  82. };
  83.  
  84. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  85. {
  86.     //{{AFX_DATA_INIT(CAboutDlg)
  87.     //}}AFX_DATA_INIT   
  88.     splashMode = 0;
  89. }
  90.  
  91. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  92. {
  93.     CDialog::DoDataExchange(pDX);
  94.     //{{AFX_DATA_MAP(CAboutDlg)
  95.     //}}AFX_DATA_MAP
  96. }
  97.  
  98. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  99.     //{{AFX_MSG_MAP(CAboutDlg)
  100.     ON_WM_PAINT()
  101.     ON_WM_CREATE()
  102.     ON_WM_LBUTTONDOWN()
  103.     ON_WM_RBUTTONDOWN()
  104.     //}}AFX_MSG_MAP
  105. END_MESSAGE_MAP()
  106.                 
  107.  
  108. /////////////////////////////////////////////////////////////////////////////
  109. // CMfcdemoApp initialization
  110.  
  111. BOOL CMfcdemoApp::InitInstance()
  112. {
  113.     // Standard initialization
  114.     // If you are not using these features and wish to reduce the size
  115.     //  of your final executable, you should remove from the following
  116.     //  the specific initialization routines you do not need.
  117.     
  118.     Ctl3dRegister(AfxGetInstanceHandle());
  119.     Ctl3dAutoSubclass(AfxGetInstanceHandle());
  120.        
  121.  
  122. #ifdef CKTBL_LIBRARY
  123.     CKTBLInitLib(m_hInstance);
  124. #endif    
  125.         
  126.     SetDialogBkColor();        // Set dialog background color to gray
  127.     LoadStdProfileSettings();  // Load standard INI file options (including MRU)
  128.  
  129.     // Register the application's document templates.  Document templates
  130.     //  serve as the connection between documents, frame windows and views.
  131.  
  132.     CMultiDocTemplate* pDocTemplate;
  133.     pDocTemplate = new CMultiDocTemplate(
  134.         IDR_MFCDEMTYPE,
  135.         RUNTIME_CLASS(CMfcdemoDoc),
  136.         RUNTIME_CLASS(CMDIChildWnd),        // standard MDI child frame
  137.         RUNTIME_CLASS(CMfcdemoView));
  138.     AddDocTemplate(pDocTemplate);
  139.  
  140.     // create main MDI Frame window
  141.     CMainFrame* pMainFrame = new CMainFrame;
  142.     if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
  143.         return FALSE;
  144.     m_pMainWnd = pMainFrame;
  145.  
  146.     // create a new (empty) document
  147.     OnFileNew();
  148.  
  149.     if (m_lpCmdLine[0] != '\0')
  150.     {
  151.         // TODO: add command line processing here
  152.     }
  153.  
  154.     // The main window has been initialized, so show and update it.
  155.     pMainFrame->ShowWindow(m_nCmdShow);
  156.     pMainFrame->UpdateWindow();
  157.                           
  158.     // add modal splash dialog (will close with a mouseclick)
  159.                               
  160.     CAboutDlg aboutDialog;
  161.     aboutDialog.SplashMode();
  162.     aboutDialog.DoModal();
  163.  
  164.     return TRUE;
  165. }
  166.              
  167.              
  168. int CMfcdemoApp::ExitInstance()
  169. {                                
  170.  
  171. #ifdef CKTBL_LIBRARY
  172.     CKTBLExitLib();
  173. #endif
  174.  
  175.    Ctl3dUnregister(AfxGetInstanceHandle());
  176.    return CWinApp::ExitInstance();
  177. }                
  178.                 
  179.                 
  180. // App command to run the dialog
  181. void CMfcdemoApp::OnAppAbout()
  182. {
  183.     CAboutDlg aboutDlg;
  184.     aboutDlg.DoModal();
  185. }
  186.  
  187. /////////////////////////////////////////////////////////////////////////////
  188. // CMfcdemoApp commands
  189.   
  190.                     
  191. void CAboutDlg::OnPaint()
  192. {
  193.     CPaintDC     dc(this); // device context for painting     
  194.     CBitmap     *oldbm, *bm; 
  195.     CDC            dcComp; 
  196.     CBitmap     *cards[4];
  197.     const         ncards = 4; 
  198.     CRect        rect,bmRect;    
  199.     BITMAP        bmInfo;
  200.     CBrush         *oldBrush, hollowBrush;
  201.     int            x,y,card;
  202.  
  203.     // CK: Paint the creditcard logos
  204.     
  205.     // TODO: Add your message handler code here
  206.     // Do not call CDialog::OnPaint() for painting messages
  207.     
  208.     cards[0] = &eurocard;
  209.     cards[1] = &mastercard;
  210.     cards[2] = &visa;
  211.     cards[3] = &amex;
  212.   
  213.     // create Compatible DC for bitmaps
  214.     
  215.     dcComp.CreateCompatibleDC( &dc );           
  216.     oldbm = dcComp.SelectObject( cards[0] );
  217.     
  218.     // get rectangle for cards
  219.                       
  220.     GetClientRect(&rect); 
  221.  
  222.     hollowBrush.CreateStockObject( HOLLOW_BRUSH );     
  223.     oldBrush = dc.SelectObject( &hollowBrush );
  224.            
  225.     x = rect.left + 10;  
  226.               
  227.     for( card=0; card<ncards; card++ ) {
  228.         bm = cards[card];     
  229.         bm->GetObject( sizeof(bmInfo), &bmInfo );
  230.         y = rect.bottom - (bmInfo.bmHeight + 15);
  231.         bmRect.SetRect( x-1,y-1, x+bmInfo.bmWidth+1, y+bmInfo.bmHeight+1 );
  232.         dc.Rectangle( &bmRect );
  233.         dcComp.SelectObject( bm );
  234.         dc.BitBlt( x,y,bmInfo.bmWidth, bmInfo.bmHeight, &dcComp, 0,0, SRCCOPY ); 
  235.         x += bmInfo.bmWidth + 10;
  236.     }
  237.     
  238.     dcComp.SelectObject( oldbm );
  239.     dc.SelectObject( oldBrush );
  240. }
  241.  
  242. int CAboutDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
  243. {                   
  244.     if (CDialog::OnCreate(lpCreateStruct) == -1)
  245.         return -1;
  246.     
  247.     // TODO: Add your specialized creation code here
  248.     
  249.     mastercard.LoadBitmap( IDB_MASTERCARD );
  250.     visa.LoadBitmap( IDB_VISA );
  251.     eurocard.LoadBitmap( IDB_EUROCARD );
  252.     amex.LoadBitmap( IDB_AMEX );
  253.     
  254.     return 0;
  255. }
  256.  
  257. void CAboutDlg::OnLButtonDown(UINT nFlags, CPoint point)
  258. {
  259.     // TODO: Add your message handler code here and/or call default
  260.     
  261.     CDialog::OnLButtonDown(nFlags, point);
  262.     if(splashMode) PostMessage(WM_CLOSE,0,0);
  263. }
  264.  
  265. void CAboutDlg::OnRButtonDown(UINT nFlags, CPoint point)
  266. {
  267.     // TODO: Add your message handler code here and/or call default
  268.     
  269.     CDialog::OnRButtonDown(nFlags, point);
  270.     if(splashMode) PostMessage(WM_CLOSE,0,0);
  271. }
  272.