home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 2003 November / VPR0311.ISO / OLS / TAR32223 / tar32223.lzh / tar32_2 / src / dlg.cpp < prev    next >
C/C++ Source or Header  |  2003-01-17  |  3KB  |  130 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. #if 0
  83.             // move to SendArcMessage() by tsuneo at 2001.11.20
  84.             extern HWND g_hwndOwnerWindow;
  85.             extern ARCHIVERPROC *g_pArcProc;
  86.             if(g_hwndOwnerWindow){
  87.                 LRESULT wndret = ::SendMessage(g_hwndOwnerWindow,mes,wParam,lParam);
  88.                 if(wndret != 0){
  89.                     pDlg->m_cancel = true;
  90.                 }
  91.             }
  92.             if(g_pArcProc){
  93.                 BOOL ProcRet = (*g_pArcProc)(g_hwndOwnerWindow, mes, wParam, pExtractingInfoEx);
  94.                 if(!ProcRet){
  95.                     pDlg->m_cancel = true;
  96.                 }
  97.             }
  98. #endif
  99.             if(pDlg->m_cancel){
  100.                 ReplyMessage(1);
  101.                 return 1;
  102.             }else{
  103.                 return 0;
  104.             }
  105.         }
  106.     }
  107.     return 0;
  108. }
  109.  
  110. void CTar32StatusDialog::Destroy()
  111. {
  112.     if(m_hThread == NULL){return;}
  113.     int ret;
  114.  
  115.     // WM_DESTROYの変わりにDestroyWindowを呼び出さないといけない。
  116.     //ret = SendMessage(m_hWnd, WM_DESTROY, 0, 0);
  117.     // しかしDestroyWindowは別スレッドからは送れない...
  118.     //ret = DestroyWindow(m_hWnd);
  119.     ret = SendMessage(m_hWnd, WM_CLOSE, 0, 0);    // 2000/03/03 by tsuneo
  120.     DWORD code;
  121.     // WaitForSingleObject() must call when m_hThread is alive.
  122.     //ret = WaitForSingleObject(m_hThread,INFINITE);
  123.     while(GetExitCodeThread(m_hThread,&code) && (code == STILL_ACTIVE)){
  124.         Sleep(1);
  125.     }
  126.     //ret = WaitForSingleObject(m_hThread,INFINITE);
  127.     m_hWnd = NULL;
  128.     m_hThread = NULL;
  129. }
  130.