home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 2001 January / VPR0101A.BIN / OLS / TAR32053 / tar32053.exe / SRC / DFLTWIN.C < prev    next >
C/C++ Source or Header  |  1999-05-23  |  6KB  |  209 lines

  1. /*
  2.     DfltWin.c
  3.     Tar32.DLLがデフォルトで用意する窓
  4. */
  5. /*#include <process.h>  for _beginthread() */
  6. #include "dfltwin.h"
  7.  
  8. #include "dllmain.h"
  9. #include "resource.h"
  10. #include "defconf.h"
  11. #include "tar32.h"
  12. #include "tarmsg.h"
  13. #include <windows.h>
  14. #include <winbase.h>
  15. extern HWND api_hwnd;
  16.  
  17. static volatile HWND dialog_hwnd;
  18. static volatile int button_cancel;
  19. static volatile HANDLE thread;
  20. static    DWORD thread_id;
  21. static volatile int CreateDialog_flag;
  22.  
  23.  
  24. static BOOL CALLBACK archiver_proc(HWND _hwnd,UINT _uMsg,UINT _nState,EXTRACTINGINFOEX *_pInfo)
  25. {
  26.     return 1;
  27. }
  28.  
  29. static BOOL CALLBACK dialog_func(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
  30. {
  31.     /*if(dialog_hwnd!=hwnd){
  32.         return DefWindowProc(hwnd,message,wParam,lParam);
  33.     }*/
  34.     switch(message){
  35.     /*case WM_PAINT:
  36.         return DefWindowProc(hwnd,message,wParam,lParam);
  37.     */
  38.     case WM_COMMAND:
  39.         switch(LOWORD(wParam)){
  40.         case IDCANCEL:
  41.             button_cancel=1;
  42.             return 1;
  43.             break;
  44.         }
  45.         return 0;
  46.         break;
  47.     case WM_INITDIALOG:
  48.         //MessageBox(NULL,"init dialog","tar32.dll",0);
  49.  
  50.         button_cancel=0;
  51.         dialog_hwnd = hwnd;
  52.         CreateDialog_flag=1;
  53.         return 1;
  54.         break;
  55.     case WM_DESTROY:
  56. //MessageBox(api_hwnd,"PostQuit(pre)","tar32.dll debug",0);
  57.         //PostQuitMessage(0);
  58.         
  59.         //DestroyWindow(hwnd);
  60.         //EndDialog(hwnd,0);
  61.         return 0;
  62. //MessageBox(api_hwnd,"PostQuit(post)","tar32.dll debug",0);
  63.         break;
  64.     default:
  65.         /* WM_ARCEXTRACT_UINTは定数でないので case部に書けない。。*/
  66.         if(message == WM_ARCEXTRACT_UINT){
  67.             int nMode=(int)wParam;
  68.             EXTRACTINGINFOEX  *pInfo = (EXTRACTINGINFOEX *)lParam;
  69.             char textstr[100];
  70.  
  71.             switch(nMode){
  72.             case ARCEXTRACT_BEGIN:/* それぞれの書庫内ファイルの処理開始 */
  73.             case ARCEXTRACT_INPROCESS:/* それぞれの書庫内ファイルを展開中 */
  74.                 SetDlgItemText(hwnd,IDC_EDIT_FILENAME,pInfo->exinfo.szSourceFileName);
  75.                 sprintf(textstr,"%8d / %8d",pInfo->exinfo.dwWriteSize,pInfo->exinfo.dwFileSize);
  76.                 SetDlgItemText(hwnd,IDC_EDIT_SIZE,textstr);
  77.                 if(button_cancel){
  78.                     if(MessageBox(NULL,"TAR32.DLLを中断しますか?\n"
  79.                             "(注:中断するとその後の動作が不安定になる場合があります)","TAR32.DLL",MB_OKCANCEL) == IDOK){
  80.                         ReplyMessage(1);
  81.                         return 0;
  82.                     }else{
  83.                         button_cancel=0;
  84.                     }
  85.                 }
  86.  
  87.                 //MessageBox(hwnd,"aaaa","tar32.dll",0);
  88.                 break;
  89.             case ARCEXTRACT_END:/*処理終了*/
  90.                 EndDialog(hwnd,0);
  91.                 /*DestroyWindow(hwnd);
  92.                 PostQuitMessage(0);*/
  93.                 
  94.                 //PostQuitMessage(0);
  95.             /*MessageBox(api_hwnd,"ARCEXTRACT_END(pre)","tar32.dll debug",0);
  96.                 PostMessage(hwnd,WM_DESTROY,0,0);
  97.             MessageBox(api_hwnd,"ARCEXTRACT_END(post)","tar32.dll debug",0);
  98.                 break;*/
  99.                 break;
  100.             case ARCEXTRACT_OPEN:/* 処理開始 */
  101.                 break;
  102.             case ARCEXTRACT_COPY:/*ワークファイルの書き戻し*/
  103.                 break;
  104.             }
  105.             return 1;
  106.         }else{
  107.             /* 真のデフォルト処理 */
  108.             //return DefWindowProc(hwnd,message,wParam,lParam);
  109.             return 0;
  110.         }
  111.         break;
  112.     }
  113.     return 1;
  114. }
  115. static DWORD WINAPI thread_func(LPVOID param)
  116. {
  117.     button_cancel=0;
  118.     if (DialogBox(application_instance,
  119.         MAKEINTRESOURCE(IDD_DIALOG_EXECUTING),
  120.         NULL,dialog_func) == -1){
  121.       MessageBox(NULL,"CreateDialog Failed!","TAR32.DLL",MB_ICONWARNING);
  122.     }
  123.     return 0;
  124.  
  125. #if 0
  126.     MSG msg;
  127.  
  128.     /*
  129.     MessageBox(NULL,"Start DialogBox","TAR32",0);
  130.     DialogBox(application_instance,MAKEINTRESOURCE(IDD_DIALOG_EXECUTING),api_hwnd,(DLGPROC)dialog_func);
  131.     MessageBox(NULL,"End DialogBox","TAR32",0);
  132.     */
  133.     button_cancel=0;
  134.     //dialog_hwnd = CreateDialog(application_instance,MAKEINTRESOURCE(IDD_DIALOG_EXECUTING),api_hwnd,(DLGPROC)dialog_func);
  135.     //dialog_hwnd = CreateDialog(NULL,MAKEINTRESOURCE(IDD_DIALOG_EXECUTING),api_hwnd,(DLGPROC)dialog_func);
  136.     dialog_hwnd = CreateDialog(application_instance,MAKEINTRESOURCE(IDD_DIALOG_EXECUTING),NULL,dialog_func);
  137.  
  138.     /* api_hwndを指定するとうまくいかない。。何故。。*/
  139.     //dialog_hwnd = CreateDialog(application_instance,MAKEINTRESOURCE(IDD_DIALOG_EXECUTING),api_hwnd,(DLGPROC)dialog_func);
  140.     
  141.     //CreateDialog_flag=1;
  142.     if(dialog_hwnd==NULL){
  143.         MessageBox(NULL,"CreateDialog Failed!","TAR32.DLL",MB_ICONWARNING);
  144.         return 0;
  145.     }
  146.  
  147.     ShowWindow(dialog_hwnd,SW_SHOW);
  148.     UpdateWindow(dialog_hwnd);
  149.     /*ShowWindow(api_hwnd,SW_SHOW);
  150.     UpdateWindow(api_hwnd);*/
  151.  
  152.     while(GetMessage(&msg,dialog_hwnd,0,0)){
  153.     //while(GetMessage(&msg,NULL,0,0)){
  154.         //if(!IsDialogMessage(dialog_hwnd,&msg)){
  155.             TranslateMessage(&msg);
  156.             DispatchMessage(&msg);
  157.         //}
  158.     }
  159.     //MessageBox(api_hwnd,"thread_func exitting...","tar32.dll debug",0);
  160. #endif
  161.     return 0;
  162. }
  163.  
  164. /* TAR32.DLLデフォルトウインドウ(ダイアログ)の作成 */
  165. /*        作成したウインドウのハンドルを返す */
  166. int DefaultWindowInit(HWND *_pHwnd,ARCHIVERPROC **_pProc)
  167. {
  168.  
  169.     //MessageBox(NULL,"Start DialogBox","TAR32",0);
  170.  
  171.     CreateDialog_flag=0;
  172.     /* CreateThreadでは標準Cランタイムライブラリ(memcpyなど)が使えないらしい。*/
  173.     //thread = CreateThread(NULL,0,thread_func,NULL,0,&thread_id);
  174.     thread = _beginthread(thread_func,0,NULL);
  175.     //thread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)thread_func,NULL,0,&thread_id);
  176.  
  177.     //SetThreadPriority(thread,THREAD_PRIORITY_HIGHEST);
  178.     //MessageBox(api_hwnd,"Post CreateThread","",0);
  179.     if(thread == NULL || thread == -1){
  180.         MessageBox(NULL,"Dialog thread execute failed!","TAR32.DLL",MB_ICONWARNING);
  181.     }
  182.     while(CreateDialog_flag==0){
  183.         Sleep(100);
  184.     }
  185.  
  186.     *_pHwnd=dialog_hwnd;
  187.     *_pProc=archiver_proc;
  188.     //return dialog_hwnd;
  189.     return 0;
  190. }
  191.  
  192. /* デフォルトウインドウが閉じるのを待つ */
  193. void WaitDefaultWindowEnd(void)
  194. {
  195.     /*
  196.     DWORD exitcode;
  197.     while(GetExitCodeThread(thread,&exitcode)!=0 && exitcode==STILL_ACTIVE){
  198.         Sleep(100);
  199.     }
  200.     */
  201.     /*HANDLE hthisthread;
  202.     hthisthread = GetCurrentThread();
  203.     SetThreadPriority(hthisthread,THREAD_PRIORITY_LOWEST);
  204.     while(WaitForSingleObject(thread, 100)==WAIT_TIMEOUT){
  205.         ;
  206.     }*/
  207.     WaitForSingleObject(thread, INFINITE);
  208. }
  209.