home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1999 November / PCONLINE_11_99.ISO / filesbbs / OS2 / ACDCR032.ZIP / source / burndialogproc.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-08-08  |  7.3 KB  |  220 lines

  1. #include "audiofolder.hh"
  2. #include "audiofolderhelp.h"
  3.  
  4. #include <stdio.h>
  5.  
  6.  
  7. HMODULE queryModuleHandle(void);
  8. ULONG launchWriter(PSZ parameter, PSZ folderPath,HWND hwnd,PSZ wrapperExe);
  9. PSZ buildAudioWriteParam(CWAudioFolder* thisPtr, PSZ trackname);
  10. MRESULT EXPENTRY writeStatusDialogProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) ;
  11.  
  12. extern BOOL setupDone;
  13. extern BOOL bGrabberFirst;
  14. extern ATOM atomStartWrite;
  15.  
  16. extern char chrCDRecord[CCHMAXPATH];/* Path to cdrecord */
  17. extern char chrCDROptions[CCHMAXPATH];
  18. extern LONG lCDROptions;
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25. MRESULT EXPENTRY writeObjectProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  26. {
  27.   CWAudioFolder * thisPtr;
  28.   SHORT a;
  29.   SIZEL sizel;
  30.   ULONG ulFlags;
  31.   HWND hwndLB;
  32.   char text[CCHMAXPATH];
  33.   char parameter[CCHMAXPATH*2];
  34.   char folderName[CCHMAXPATH];
  35.   HWND hwndTemp;
  36.   ULONG ulSize;
  37.   ULONG rc;
  38.   char statusText[100];
  39.   ULONG ulDrive;
  40.     
  41.   switch (msg)
  42.     {
  43.     case WM_APPTERMINATENOTIFY:
  44.       /* The last track is written. The wrapper program has ended */
  45.       rc=MBID_YES;
  46.       if(LONGFROMMP(mp2)!=0) {
  47.         if(!WinLoadString(WinQueryAnchorBlock(hwnd),queryModuleHandle(),IDSTR_WRITEERRORTEXT,sizeof(text),text))
  48.           sprintf(text,"CDRecord/2 returned a Non-zero resultcode. The written track is probably corrupted. \
  49. Do you want to continue writing?");
  50.         if(!WinLoadString(WinQueryAnchorBlock(hwnd),queryModuleHandle(),IDSTR_WRITEERRORTITLE, sizeof(statusText),
  51.                           statusText))
  52.           sprintf(statusText,"CD writing error!");               
  53.         rc=WinMessageBox(  HWND_DESKTOP,    hwnd,   text,   statusText, 0UL, MB_YESNO | MB_ICONEXCLAMATION|MB_MOVEABLE );
  54.       }
  55.       thisPtr=(CWAudioFolder*) WinQueryWindowULong(hwnd,QWL_USER);
  56.       if(thisPtr && rc==MBID_YES) {
  57.         /* Continue writing */
  58.         hwndLB=thisPtr->hwndWriteLB;/* Get write track listbox hwnd */
  59.         if(thisPtr->cwQueryWriteEnabled() && WinIsWindow(WinQueryAnchorBlock(HWND_DESKTOP),hwndLB)) {
  60.           /* User hasn't canceled the write */ 
  61.           thisPtr->bWrite++;
  62.           if(thisPtr->bWrite < thisPtr->aWrite) {
  63.             /* Get first trackname */
  64.             if(!WinSendMsg(hwndLB,LM_QUERYITEMTEXT,MPFROM2SHORT((SHORT)thisPtr->bWrite,(SHORT)CCHMAXPATH),&text)) {
  65.               WinPostMsg(hwnd,WM_QUIT,(MPARAM)0,(MPARAM)0);
  66.               return 0;
  67.             }          
  68.             /* Get folder name */
  69.             ulSize=sizeof(folderName);
  70.             thisPtr->wpQueryRealName(folderName,&ulSize,TRUE);
  71.             
  72.             /*********** Build commandline ******************/
  73.             /* Build writer param line */
  74.             sprintf(parameter,"%s",buildAudioWriteParam(thisPtr,text));           
  75.             
  76.             /* Update status window */
  77.             sprintf(statusText,"Writing track %d of %d     ",thisPtr->bWrite+1,thisPtr->aWrite);
  78.             WinSetWindowText(WinWindowFromID(thisPtr->hwndWriteStatus,IDST_WRITESTATUS),statusText);
  79.             
  80.             /* Check for CD-Size here */
  81.             
  82.             launchWriter(parameter,folderName,hwnd,"cdr2lnch.exe");
  83.             /* end of writer start */                                 
  84.             
  85.             return (MRESULT)TRUE;
  86.           }/* if(thisPtr->bWrite < thisPtr->aWrite) */
  87.         }/* thisPtr->cwQueryGrabEnabled() */
  88.       }/* end of if(thisPtr) */
  89.       if(thisPtr) {
  90.         /* Destroy write status window */
  91.         WinDestroyWindow(thisPtr->hwndWriteStatus);
  92.         thisPtr->hwndWriteStatus=NULL;
  93.            
  94.         /* Enable windows in write dialog */
  95.         thisPtr->cwEnableWriteControls(TRUE);
  96.         
  97.         /* Enable windows in selection dialog */
  98.         thisPtr->cwEnableSelectControls(TRUE);
  99.       }
  100.       WinPostMsg(hwnd,WM_QUIT,(MPARAM)0,(MPARAM)0);
  101.       return 0;
  102.  
  103.     default:
  104.       if(msg == atomStartWrite) {
  105.         /* Start write message */
  106.         thisPtr=(CWAudioFolder*)PVOIDFROMMP(mp1);
  107.         WinSetWindowULong(hwnd,QWL_USER,(ULONG)thisPtr);/* Save object ptr */
  108.         if(!thisPtr) {
  109.           /* Error: quit */
  110.           WinPostMsg(hwnd,WM_QUIT,(MPARAM)0,(MPARAM)0);
  111.           return 0;
  112.         }   
  113.  
  114.         hwndLB=thisPtr->hwndWriteLB;         
  115.         if(!WinIsWindow(WinQueryAnchorBlock(HWND_DESKTOP),hwndLB)) {
  116.            WinPostMsg(hwnd,WM_QUIT,(MPARAM)0,(MPARAM)0);
  117.            return 0;
  118.         }
  119.      
  120.         /* Get num tracks to write */   
  121.         thisPtr->aWrite=(int)LONGFROMMR(WinSendMsg(hwndLB,LM_QUERYITEMCOUNT,0,0));
  122.         if(!thisPtr->aWrite) {/* We have no tracks */
  123.           WinPostMsg(hwnd,WM_QUIT,(MPARAM)0,(MPARAM)0);
  124.           return 0;
  125.         }           
  126.         thisPtr->bWrite=0;
  127.  
  128.         /* Get first trackname */
  129.         if(!WinSendMsg(hwndLB,LM_QUERYITEMTEXT,MPFROM2SHORT((SHORT)thisPtr->bWrite,(SHORT)CCHMAXPATH),&text)) {
  130.           WinPostMsg(hwnd,WM_QUIT,(MPARAM)0,(MPARAM)0);
  131.           return 0;
  132.         }
  133.         thisPtr->cwEnableWrite(TRUE);
  134.  
  135.         /* Get folder name */
  136.         ulSize=sizeof(folderName);
  137.         thisPtr->wpQueryRealName(folderName,&ulSize,TRUE);
  138.  
  139.         /*********** Build commandline ******************/
  140.         /* Build grabber param line */
  141.         sprintf(parameter,"%s",buildAudioWriteParam(thisPtr,text));           
  142.         
  143.         /*************** Start the writer here ****************/
  144.         /* Build status window */
  145.         thisPtr->hwndWriteStatus=WinLoadDlg(HWND_DESKTOP,HWND_DESKTOP,
  146.                                        writeStatusDialogProc,queryModuleHandle(),IDDLG_WRITESTATUS,thisPtr);            
  147.  
  148.         //  sprintf(text,"hwndWriteStatus=%x",thisPtr->hwndWriteStatus);
  149.         //  WinMessageBox(  HWND_DESKTOP,   hwnd,   text,   "Debug", 0UL,   MB_OK | MB_ICONEXCLAMATION|MB_MOVEABLE );
  150.  
  151.         sprintf(statusText,"Writing track %d of %d     ",thisPtr->bWrite+1,thisPtr->aWrite);
  152.         WinSetWindowText(WinWindowFromID(thisPtr->hwndWriteStatus,IDST_WRITESTATUS),statusText);
  153.                    
  154.         /* Check for CD-Size here */
  155.       
  156.         launchWriter(parameter,folderName,hwnd,"cdr2lnch.exe");
  157.         /* end of writer start */         
  158.         return 0;               
  159.       }
  160.       break;
  161.     }
  162.   return WinDefWindowProc( hwnd, msg, mp1, mp2);
  163. }
  164.  
  165.  
  166. /* This thread handles the writing */
  167. void _Optlink writeThreadFunc (void *arg)
  168. {
  169.   HWND hwndWrite;
  170.   HAB  hab;
  171.   HMQ  hmq;
  172.   QMSG qmsg;
  173.  
  174.   CWAudioFolder * thisPtr;
  175.  
  176.   thisPtr=(CWAudioFolder*)arg;
  177.   thisPtr->wpLockObject();
  178.     
  179.   hab=WinInitialize(0);
  180.   if(hab) {
  181.     hmq=WinCreateMsgQueue(hab,0);
  182.     if(hmq) {
  183.       hwndWrite=WinCreateWindow(HWND_OBJECT,WC_STATIC,"myWriteObj",0,0,0,0,0,NULL,HWND_BOTTOM,12345,NULL,NULL);
  184.       if(hwndWrite) {
  185.         WinSubclassWindow(hwndWrite,&writeObjectProc);
  186.         /* write window created. Start writing */             
  187.         WinPostMsg(hwndWrite,atomStartWrite,MPFROMP(thisPtr),0);
  188.         while(WinGetMsg(hab,&qmsg,(HWND)NULL,0,0))
  189.           WinDispatchMsg(hab,&qmsg);
  190.         WinDestroyWindow(hwndWrite);
  191.       }
  192.       WinDestroyMsgQueue(hmq);
  193.     }
  194.     WinTerminate(hab);
  195.   }
  196.   thisPtr->wpUnlockObject();
  197.   thisPtr->tidWrite=0;
  198.   WinPostMsg(WinQueryWindow(thisPtr->hwndWriteLB,QW_PARENT),WM_CLOSE,0,0);
  199.   thisPtr->hwndWriteLB=NULL;
  200.  
  201.   //DosBeep(100,2000);
  202. }
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.