home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 11 / CDACTUAL11.iso / cdactual / demobin / share / W95 / FRACCOMP / FRACCDLG.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-26  |  8.4 KB  |  341 lines

  1. // FracCdlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "FracCompress.h"
  6. #include "FracCdlg.h"
  7. #include "frac.h"
  8.  
  9. #ifdef _DEBUG
  10. #undef THIS_FILE
  11. static char BASED_CODE THIS_FILE[] = __FILE__;
  12. #endif
  13.  
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CAboutDlg dialog used for App About
  16.  
  17. class CAboutDlg : public CDialog
  18. {
  19. public:
  20.     CAboutDlg();
  21.  
  22. // Dialog Data
  23.     //{{AFX_DATA(CAboutDlg)
  24.     enum { IDD = IDD_ABOUTBOX };
  25.     CBitmapButton m_picture;
  26.     //}}AFX_DATA
  27.  
  28. // Implementation
  29. protected:
  30.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  31.     //{{AFX_MSG(CAboutDlg)
  32.     virtual BOOL OnInitDialog();
  33.     //}}AFX_MSG
  34.     DECLARE_MESSAGE_MAP()
  35. };
  36.  
  37. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  38. {
  39.     //{{AFX_DATA_INIT(CAboutDlg)
  40.     //}}AFX_DATA_INIT
  41. }
  42.  
  43. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  44. {
  45.     CDialog::DoDataExchange(pDX);
  46.     //{{AFX_DATA_MAP(CAboutDlg)
  47.     DDX_Control(pDX, IDC_PIC, m_picture);
  48.     //}}AFX_DATA_MAP
  49. }
  50.  
  51. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  52.     //{{AFX_MSG_MAP(CAboutDlg)
  53.         // No message handlers
  54.     //}}AFX_MSG_MAP
  55. END_MESSAGE_MAP()
  56.  
  57. /////////////////////////////////////////////////////////////////////////////
  58. // CAboutDlg message handlers
  59.  
  60. BOOL CAboutDlg::OnInitDialog()
  61. {
  62.     CDialog::OnInitDialog();
  63.     CenterWindow();
  64.  
  65.     // TODO: Add extra about dlg initialization here
  66.     m_picture.LoadBitmaps("IDB_NBALL");
  67.     m_picture.SizeToContent();
  68.  
  69.     return TRUE;  // return TRUE  unless you set the focus to a control
  70. }
  71.  
  72. /////////////////////////////////////////////////////////////////////////////
  73. // CFracCompressDlg dialog
  74.  
  75. CFracCompressDlg::CFracCompressDlg(CWnd* pParent /*=NULL*/)
  76.     : CDialog(CFracCompressDlg::IDD, pParent)
  77. {
  78.     //{{AFX_DATA_INIT(CFracCompressDlg)
  79.     m_fileIn = _T("");
  80.     m_fileOut = _T("");
  81.     //}}AFX_DATA_INIT
  82.     // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  83.     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  84.     m_Compress = FALSE;
  85.     m_Done = FALSE;
  86.  
  87. }
  88.  
  89. void CFracCompressDlg::DoDataExchange(CDataExchange* pDX)
  90. {
  91.     CDialog::DoDataExchange(pDX);
  92.     //{{AFX_DATA_MAP(CFracCompressDlg)
  93.     DDX_Control(pDX, IDC_OFN, m_of);
  94.     DDX_Control(pDX, IDC_IFN, m_if);
  95.     DDX_Control(pDX, IDOK, m_okbutton);
  96.     DDX_Text(pDX, IDC_IFNSTRING, m_fileIn);
  97.     DDX_Text(pDX, IDC_OFNSTRING, m_fileOut);
  98.     //}}AFX_DATA_MAP
  99. }
  100.  
  101. BEGIN_MESSAGE_MAP(CFracCompressDlg, CDialog)
  102.     //{{AFX_MSG_MAP(CFracCompressDlg)
  103.     ON_WM_SYSCOMMAND()
  104.     ON_WM_PAINT()
  105.     ON_WM_QUERYDRAGICON()
  106.     ON_BN_CLICKED(IDC_OFN, OnOfn)
  107.     ON_BN_CLICKED(IDC_IFN, OnIfn)
  108.     ON_BN_CLICKED(IDC_DECOMPRESS, OnDecompress)
  109.     ON_BN_CLICKED(IDC_COMPRESS, OnCompress)
  110.     ON_BN_CLICKED(IDC_OPTIONS, OnOptions)
  111.     //}}AFX_MSG_MAP
  112. END_MESSAGE_MAP()
  113.  
  114. /////////////////////////////////////////////////////////////////////////////
  115. // CFracCompressDlg message handlers
  116.  
  117. BOOL CFracCompressDlg::OnInitDialog()
  118. {
  119.     CDialog::OnInitDialog();
  120.     CenterWindow();
  121.     m_Compress = TRUE;
  122.     m_if.LoadBitmaps("IDB_DOWNUP","IDB_DOWND");
  123.     m_if.SizeToContent( );
  124.     m_of.LoadBitmaps("IDB_DOWNUP","IDB_DOWND");
  125.     m_of.SizeToContent( );
  126.     CheckRadioButton(IDC_COMPRESS,IDC_DECOMPRESS,IDC_COMPRESS);
  127.     CString LpRegister = AfxRegisterWndClass(CS_CLASSDC,0,CreateSolidBrush(RGB(255,255,255)),0);    
  128.     m_viewer.CreateEx(WM_PARENTNOTIFY,LpRegister,"Processing...",WS_CAPTION|WS_POPUPWINDOW,0,0,256,256,GetSafeHwnd(),0);    
  129.     m_viewer.CenterWindow();
  130.     // Add "About..." menu item to system menu.
  131.  
  132.     // IDM_ABOUTBOX must be in the system command range.
  133.     ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  134.     ASSERT(IDM_ABOUTBOX < 0xF000);
  135.  
  136.     CMenu* pSysMenu = GetSystemMenu(FALSE);
  137.     CString strAboutMenu;
  138.     strAboutMenu.LoadString(IDS_ABOUTBOX);
  139.     if (!strAboutMenu.IsEmpty())
  140.     {
  141.         pSysMenu->AppendMenu(MF_SEPARATOR);
  142.         pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  143.     }
  144.     
  145.     // TODO: Add extra initialization here
  146.     
  147.     return TRUE;  // return TRUE  unless you set the focus to a control
  148. }
  149.  
  150. void CFracCompressDlg::OnSysCommand(UINT nID, LPARAM lParam)
  151. {
  152.     if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  153.     {
  154.         CAboutDlg dlgAbout;
  155.         dlgAbout.DoModal();
  156.     }
  157.     else
  158.     {
  159.         CDialog::OnSysCommand(nID, lParam);
  160.     }
  161. }
  162.  
  163. // If you add a minimize button to your dialog, you will need the code below
  164. //  to draw the icon.  For MFC applications using the document/view model,
  165. //  this is automatically done for you by the framework.
  166.  
  167. void CFracCompressDlg::OnPaint() 
  168. {
  169.     if (IsIconic())
  170.     {
  171.         CPaintDC dc(this); // device context for painting
  172.  
  173.         SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  174.  
  175.         // Center icon in client rectangle
  176.         int cxIcon = GetSystemMetrics(SM_CXICON);
  177.         int cyIcon = GetSystemMetrics(SM_CYICON);
  178.         CRect rect;
  179.         GetClientRect(&rect);
  180.         int x = (rect.Width() - cxIcon + 1) / 2;
  181.         int y = (rect.Height() - cyIcon + 1) / 2;
  182.  
  183.         // Draw the icon
  184.         dc.DrawIcon(x, y, m_hIcon);
  185.     }
  186.     else
  187.     {
  188.         CDialog::OnPaint();
  189.     }
  190. }
  191.  
  192. // The system calls this to obtain the cursor to display while the user drags
  193. //  the minimized window.
  194. HCURSOR CFracCompressDlg::OnQueryDragIcon()
  195. {
  196.     return (HCURSOR) m_hIcon;
  197. }
  198.  
  199.  
  200. void CFracCompressDlg::OnOfn() 
  201. {
  202.     // TODO: Add your control notification handler code here
  203.     if(m_Done)
  204.         return;
  205.     CFileDialog *fileDialog;
  206.     if(m_Compress)
  207.         fileDialog = new CFileDialog(FALSE,"FIC","*.*",OFN_HIDEREADONLY,
  208.         "FIC Files (*.FIC)|*.FIC|Trans File (*.TRN)|*.TRN|All Files (*.*)|*.*||");
  209.     else
  210.         fileDialog = new CFileDialog(FALSE,"DAT","*.*",OFN_HIDEREADONLY,
  211.         "Raw Files (*.DAT)|*.DAT|All Files (*.*)|*.*||");
  212.     
  213.  
  214.     if(fileDialog->DoModal() == IDOK)
  215.     {
  216.         m_fileOut = fileDialog->GetPathName();
  217.         UpdateData(FALSE);
  218.     }
  219.     delete fileDialog;
  220.     
  221.  
  222. }
  223.  
  224. void CFracCompressDlg::OnIfn() 
  225. {
  226.     // TODO: Add your control notification handler code here
  227.     if(m_Done)
  228.         return;
  229.     CFileDialog *fileDialog;
  230.     if(m_Compress)
  231.         fileDialog = new CFileDialog(TRUE,"DAT","*.*",OFN_HIDEREADONLY,
  232.         "Raw Files (*.DAT)|*.DAT|All Files (*.*)|*.*||");
  233.     else
  234.          fileDialog = new CFileDialog(TRUE,"FIC","*.*",OFN_HIDEREADONLY,
  235.         "FIC Files (*.FIC)|*.FIC|Trans File (*.TRN)|*.TRN|All Files (*.*)|*.*||");
  236.  
  237.     if(fileDialog->DoModal() == IDOK) 
  238.     { 
  239.         m_fileIn = fileDialog->GetPathName();
  240.         UpdateData(FALSE);
  241.     }
  242.     delete fileDialog;
  243.  
  244. }
  245.  
  246.  
  247.  
  248. void CFracCompressDlg::OnOK() 
  249. {
  250.     // TODO: Add extra validation here
  251.     if(m_Done)
  252.     {
  253.         CDialog::OnOK();
  254.         return;
  255.     }
  256.     UpdateData(TRUE);
  257.     CFracComp *FracComp = new CFracComp(GetSafeHwnd(),IDC_STATUS);
  258.     FracComp->SetFileName(m_fileIn,m_fileOut);
  259.     if(m_Compress) 
  260.         if(coption.m_change)
  261.         {
  262.             if(coption.m_display)
  263.             {
  264.                 FracComp->Compress(m_viewer.GetSafeHwnd(),coption.m_tol,coption.m_height,coption.m_width,coption.m_rd,
  265.                 coption.m_rd2,coption.m_dpss,atoi(coption.m_step),coption.m_slb,coption.m_ofb,coption.m_msl,coption.m_dsm,coption.m_pos,
  266.                 coption.m_24dc,coption.m_3dc);    
  267.                 m_viewer.SaveDC(FracComp->HandleDC());
  268.             }
  269.             else
  270.                 FracComp->Compress(NULL,coption.m_tol,coption.m_height,coption.m_width,coption.m_rd,
  271.                 coption.m_rd2,coption.m_dpss,atoi(coption.m_step),coption.m_slb,coption.m_ofb,coption.m_msl,coption.m_dsm,coption.m_pos,
  272.                 coption.m_24dc,coption.m_3dc);
  273.         }
  274.         else
  275.         {
  276.             FracComp->Compress(m_viewer.GetSafeHwnd()); 
  277.             m_viewer.SaveDC(FracComp->HandleDC());
  278.         }
  279.     else
  280.         {
  281.             if(doption.m_change)
  282.             {
  283.                 if(doption.m_display) 
  284.                 {
  285.                 
  286.                     FracComp->Decompress(m_viewer.GetSafeHwnd(),doption.m_sc,doption.m_nit,
  287.                         doption.m_post,doption.m_msl,doption.m_sb,doption.m_ofs,doption.m_out);
  288.                     m_viewer.SaveDC(FracComp->HandleDC());
  289.                 }
  290.                 else
  291.                     FracComp->Decompress(NULL,doption.m_sc,doption.m_nit,doption.m_post,
  292.                         doption.m_msl,doption.m_sb,doption.m_ofs,doption.m_out);
  293.             }
  294.             else
  295.             {
  296.         
  297.                 FracComp->Decompress(m_viewer.GetSafeHwnd());
  298.                 m_viewer.SaveDC(FracComp->HandleDC());
  299.             }
  300.  
  301.  
  302.  
  303.         }
  304.         delete FracComp;
  305.         m_Done = TRUE;
  306.         m_okbutton.SetWindowText("Close");
  307.     
  308. }
  309.  
  310. void CFracCompressDlg::OnDecompress() 
  311. {
  312.     // TODO: Add your control notification handler code here
  313.     if(m_Done)
  314.         return;
  315.     m_Compress = FALSE;    
  316.     CheckRadioButton(IDC_COMPRESS,IDC_DECOMPRESS,IDC_DECOMPRESS);
  317.  
  318. }
  319.  
  320. void CFracCompressDlg::OnCompress() 
  321. {
  322.     // TODO: Add your control notification handler code here
  323.     if(m_Done)
  324.         return;
  325.     m_Compress = TRUE;
  326.     CheckRadioButton(IDC_COMPRESS,IDC_DECOMPRESS,IDC_COMPRESS);
  327.  
  328. }
  329.  
  330. void CFracCompressDlg::OnOptions() 
  331. {
  332.     // TODO: Add your control notification handler code here
  333.     if(m_Done)
  334.         return;
  335.     if(m_Compress)
  336.         coption.DoModal();
  337.     else
  338.         doption.DoModal();
  339.  
  340. }
  341.