home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 2001 June / VPR0106A.BIN / OLS / TAR32212 / tar32212.lzh / tar32_2 / src / dlg.cpp < prev    next >
C/C++ Source or Header  |  2000-12-25  |  3KB  |  127 lines

  1. #include "dlg.h"
  2. #include "tar32res.h"
  3. #include "tar32api.h" // EXTRACTINGINFOEX
  4. #include <winuser.h>
  5. #include <process.h>
  6.  
  7. CTar32StatusDialog::CTar32StatusDialog()
  8. {
  9.     m_cancel = false;
  10.     m_hWnd = NULL;
  11.     m_hThread = NULL;
  12. }
  13. CTar32StatusDialog::~CTar32StatusDialog()
  14. {
  15.     Destroy();
  16. }
  17. HWND CTar32StatusDialog::Create(HWND hParent)
  18. {
  19.     m_hParentWnd = hParent;
  20.     HANDLE  hThread = (HANDLE)_beginthread(ThreadFunc,0,this);
  21.     m_hThread = hThread;
  22.     while(m_hWnd == NULL){
  23.         Sleep(1);    // XXX busy wait....mmm
  24.     }
  25.     return m_hWnd;
  26. }
  27.  
  28. /*static*/ /*DWORD*/ void _cdecl CTar32StatusDialog::ThreadFunc(LPVOID param)
  29. {
  30.     CTar32StatusDialog *pDlg = (CTar32StatusDialog *)param;
  31.     extern HINSTANCE dll_instance;
  32.     HWND hWnd = CreateDialogParam(dll_instance, MAKEINTRESOURCE(IDD_DIALOG_STATUS),pDlg->m_hParentWnd, (DLGPROC)WindowFunc, (long)pDlg); // どんぞ:(DLGPROC)を追加
  33.     //HWND hWnd = CreateDialogParam(dll_instance, MAKEINTRESOURCE(IDD_DIALOG_STATUS),NULL, WindowFunc, (long)pDlg);
  34.     int ret;
  35.     ret = ShowWindow(hWnd, SW_SHOW);
  36.     ret = UpdateWindow(hWnd);
  37.     pDlg->m_hWnd = hWnd;
  38.  
  39.     {
  40.         MSG msg;
  41.         while(GetMessage(&msg, 0, 0, 0)){
  42.             if(hWnd==NULL || !IsDialogMessage(hWnd,&msg)){
  43.                 TranslateMessage(&msg);
  44.                 DispatchMessage(&msg);
  45.             }
  46.         }
  47.     }
  48.     Sleep(0);
  49.     //return 0;
  50. }
  51. /*static*/ BOOL CALLBACK CTar32StatusDialog::WindowFunc(HWND hWnd, UINT mes, WPARAM wParam, LPARAM lParam)
  52. {
  53.     extern UINT wm_arcextract;
  54.     CTar32StatusDialog *pDlg = (CTar32StatusDialog*)GetWindowLong(hWnd, GWL_USERDATA);
  55.     switch(mes){
  56.     case WM_INITDIALOG:
  57.         SetWindowLong(hWnd,GWL_USERDATA,lParam);
  58.         return 1;
  59.     case WM_DESTROY:
  60.         return 0;
  61. //        EndDialog(hWnd,0);
  62. //        return 0;
  63. //        PostQuitMessage(0);
  64. //        return 1;
  65.     case WM_CLOSE:
  66.         DestroyWindow(hWnd);
  67.         return 1;
  68.     case WM_COMMAND:
  69.         switch(LOWORD(wParam)){
  70.         case IDCANCEL:
  71.             if(pDlg)pDlg->m_cancel = true;
  72.             return 1;
  73.             break;    
  74.         }
  75.         break;
  76.     default:
  77.         if(mes == wm_arcextract){
  78.             EXTRACTINGINFOEX *pExtractingInfoEx = (EXTRACTINGINFOEX*)lParam;
  79.             ::SetDlgItemText(hWnd, IDC_FILENAME, pExtractingInfoEx->exinfo.szDestFileName);
  80.             ::SetDlgItemInt(hWnd, IDC_FILESIZE, pExtractingInfoEx->exinfo.dwWriteSize ,FALSE);
  81.  
  82.             extern HWND g_hwndOwnerWindow;
  83.             extern ARCHIVERPROC *g_pArcProc;
  84.             if(g_hwndOwnerWindow){
  85.                 LRESULT wndret = ::SendMessage(g_hwndOwnerWindow,mes,wParam,lParam);
  86.                 if(wndret != 0){
  87.                     pDlg->m_cancel = true;
  88.                 }
  89.             }
  90.             if(g_pArcProc){
  91.                 BOOL ProcRet = (*g_pArcProc)(g_hwndOwnerWindow, mes, wParam, pExtractingInfoEx);
  92.                 if(!ProcRet){
  93.                     pDlg->m_cancel = true;
  94.                 }
  95.             }
  96.             if(pDlg->m_cancel){
  97.                 ReplyMessage(1);
  98.                 return 1;
  99.             }else{
  100.                 return 0;
  101.             }
  102.         }
  103.     }
  104.     return 0;
  105. }
  106.  
  107. void CTar32StatusDialog::Destroy()
  108. {
  109.     if(m_hThread == NULL){return;}
  110.     int ret;
  111.  
  112.     // WM_DESTROYの変わりにDestroyWindowを呼び出さないといけない。
  113.     //ret = SendMessage(m_hWnd, WM_DESTROY, 0, 0);
  114.     // しかしDestroyWindowは別スレッドからは送れない...
  115.     //ret = DestroyWindow(m_hWnd);
  116.     ret = SendMessage(m_hWnd, WM_CLOSE, 0, 0);    // 2000/03/03 by tsuneo
  117.     DWORD code;
  118.     // WaitForSingleObject() must call when m_hThread is alive.
  119.     //ret = WaitForSingleObject(m_hThread,INFINITE);
  120.     while(GetExitCodeThread(m_hThread,&code) == STILL_ACTIVE){
  121.         Sleep(1);
  122.     }
  123.     //ret = WaitForSingleObject(m_hThread,INFINITE);
  124.     m_hWnd = NULL;
  125.     m_hThread = NULL;
  126. }
  127.