Advertisement
Guest User

giulio8

a guest
Sep 24th, 2009
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 17.20 KB | None | 0 0
  1. // Avi PostEdit - Annotation Re-capture
  2. // Initial drafted code developed by giulio8  - 22/6/2009
  3.  
  4. // Play an AVI using the MSvfw32.lib
  5. // in the case of Dev-C++ link with libmsvfw32.a via
  6. // Project>>Project Options>>Parameters>>Add Lib>>libmsvfw32.a
  7.  
  8.  
  9.  
  10. #include <cstdio>
  11. #include <fstream>
  12. using namespace std;
  13.  
  14. #include <windows.h>
  15.  
  16.  
  17. #include <vfw.h>
  18.  
  19.  
  20.  
  21. #include "avi_utils.h"
  22.  
  23.  
  24. #include <shlwapi.h>
  25. //Nota: perch questo codice funzioni va linkato anche con shlwapi.lib; in VC++ si pu ottenere tale effetto anche con un #pragma non standard
  26. #ifdef _MSC_VER
  27. #pragma comment(lib,"shlwapi.lib")
  28. #endif
  29. //...
  30.  
  31.  
  32. #define ID_MCIFrame 0
  33. #define ID_MENU1 9001
  34. #define ID_MENU2 9002
  35. #define ID_MENU3 9003
  36. #define ID_MENU4 9004
  37. #define ID_MENU5 9005
  38. #define ID_MENU6 9006
  39. #define ID_MENU7 9007
  40.  
  41. static HINSTANCE BCX_hInstance;
  42. static int     BCX_ScaleX;
  43. static int     BCX_ScaleY;
  44. static char    BCX_ClassName[2048];
  45. static HANDLE  ghInst;
  46. static HWND    Form1;
  47. static HWND    MCIFrame;
  48. static HMENU   MainMenu;
  49. static HMENU   FileMenu;
  50. static OPENFILENAME OpenFileName;
  51. static char    szFile[2048];
  52. static char    szFileTitle[2048];
  53. static char    szFileBmp[2048];
  54. static char    szFileTitleBmp[2048];
  55. static char    szFileBmpC[2048];
  56. static char    szFileTitleBmpC[2048];
  57.  
  58. #define Show(Window)  RedrawWindow(Window,0,0,0);ShowWindow(Window,SW_SHOW);
  59.  
  60. HWND    BCX_Form(char*,int=0,int=0,int=250,int=150,int=0,int=0);
  61. void    BCX_Set_Form_Color (HWND,COLORREF);
  62. void    Center (HWND,HWND=0,HWND=0);
  63. char*   BCX_TmpStr(size_t);
  64. char*   str (double);
  65. char*   curdir (void);
  66.  
  67. void    FormLoad (void);
  68. LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
  69. int     InitOpenFileName (void);
  70. int     PopFileOpenDlg (HWND, char *, char *);
  71. BOOL    AddMenu (HWND);
  72.  
  73. LONG lFrame_start;
  74. LONG lFrame_end;
  75.  
  76. // standard Windows Graphical User Interface main
  77. int WINAPI WinMain(HINSTANCE hInst,HINSTANCE hPrev,LPSTR CmdLine,int CmdShow)
  78. {
  79.  WNDCLASS Wc;
  80.  MSG      Msg;
  81.  // *****************************
  82.  strcpy(BCX_ClassName,"ApiEdit");
  83.  // ************************************
  84.  // Scale Dialog Units To Screen Units
  85.  // ************************************
  86.  RECT rc          =  {0,0,4,8};
  87.  MapDialogRect       (NULL,&rc);
  88.  BCX_ScaleX       =  rc.right/2;
  89.  BCX_ScaleY       =  rc.bottom/4;
  90.  BCX_hInstance    =  hInst;
  91.  // ******************************************************
  92.  Wc.style         =  CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  93.  Wc.lpfnWndProc   =  WndProc;
  94.  Wc.cbClsExtra    =  0;
  95.  Wc.cbWndExtra    =  0;
  96.  Wc.hInstance     =  hInst;
  97.  Wc.hIcon         =  LoadIcon(NULL,IDI_WINLOGO);
  98.  Wc.hCursor       =  LoadCursor(NULL,IDC_ARROW);
  99.  Wc.hbrBackground =  (HBRUSH)(COLOR_BTNFACE+1);
  100.  Wc.lpszMenuName  =  NULL;
  101.  Wc.lpszClassName =  BCX_ClassName;
  102.  RegisterClass(&Wc);
  103.  
  104.  FormLoad();
  105.  // event message loop
  106.  while(GetMessage(&Msg,NULL,0,0))
  107.  {
  108.     HWND hActiveWindow = GetActiveWindow();
  109.     if (!IsWindow(hActiveWindow) || !IsDialogMessage(hActiveWindow,&Msg))
  110.       {
  111.         TranslateMessage(&Msg);
  112.         DispatchMessage(&Msg);
  113.       }
  114.  }
  115.  return Msg.wParam;
  116. }
  117.  
  118.  
  119. // circular storage, hold the memory leaks to a minimum
  120. char *BCX_TmpStr (size_t Bites)
  121. {
  122.   static int   StrCnt;
  123.   static char *StrFunc[2048];
  124.   StrCnt=(StrCnt + 1) & 2047;
  125.   if(StrFunc[StrCnt]) free (StrFunc[StrCnt]);
  126.   return StrFunc[StrCnt]=(char*)calloc(Bites+128,sizeof(char));
  127. }
  128.  
  129.  
  130. char *str (double d)
  131. {
  132.   register char *strtmp = BCX_TmpStr(16);
  133.   sprintf(strtmp,"% .15G",d);
  134.   return strtmp;
  135. }
  136.  
  137.  
  138. char *curdir (void)
  139. {
  140.   register char *strtmp = BCX_TmpStr(2048);
  141.   GetCurrentDirectory (1024,strtmp);
  142.   return strtmp;
  143. }
  144.  
  145.  
  146. // center the window form on the screen, optional, for looks
  147. void Center (HWND hwnd, HWND Xhwnd, HWND Yhwnd)
  148. {
  149.   RECT rect, rectP;
  150.   int  x, y, width, height;
  151.   int  screenwidth, screenheight;
  152.   if(Xhwnd==0)
  153.     {
  154.       RECT  DesktopArea;
  155.       RECT  rc;
  156.       SystemParametersInfo(SPI_GETWORKAREA,0,&DesktopArea,0);
  157.       GetWindowRect(hwnd,&rc);
  158.       SetWindowPos(hwnd,HWND_TOP,
  159.         ((DesktopArea.right-DesktopArea.left)-(rc.right-rc.left))/2+
  160.           DesktopArea.left,((DesktopArea.bottom-DesktopArea.top)-
  161.          (rc.bottom-rc.top))/2 + DesktopArea.top,0,0,SWP_NOSIZE);
  162.       return;
  163.     }
  164.   GetWindowRect (hwnd,&rect);
  165.   GetWindowRect (Xhwnd,&rectP);
  166.   width = rect.right-rect.left;
  167.   x = ((rectP.right-rectP.left)-width)/2 + rectP.left;
  168.   if (Yhwnd==NULL)
  169.   {
  170.       height = rect.bottom-rect.top;
  171.       y = ((rectP.bottom-rectP.top)-height)/2 + rectP.top;
  172.   }
  173.   else
  174.   {
  175.       GetWindowRect(Yhwnd,&rectP);
  176.       height = rect.bottom-rect.top;
  177.       y = ((rectP.bottom-rectP.top)-height)/2+rectP.top;
  178.   }
  179.   screenwidth = GetSystemMetrics(SM_CXSCREEN);
  180.   screenheight = GetSystemMetrics(SM_CYSCREEN);
  181.   if ((x<0))
  182.     x=0;
  183.   if ((y<0))
  184.     y=0;
  185.   if ((x+width>screenwidth))  
  186.     x = screenwidth-width;
  187.   if ((y+height>screenheight))
  188.     y = screenheight-height;
  189.   MoveWindow (hwnd, x, y, width, height, FALSE);
  190. }
  191.  
  192.  
  193. // create the windows form
  194. HWND BCX_Form(char *Caption, int X, int Y, int W, int H, int Style, int Exstyle)
  195. {
  196.    HWND  A;
  197.    // assigne default style if none given
  198.    if (!Style)
  199.    {
  200.         Style= WS_MINIMIZEBOX  |
  201.         WS_SIZEBOX      |
  202.         WS_CAPTION      |
  203.         WS_MAXIMIZEBOX  |
  204.         WS_POPUP        |
  205.         WS_SYSMENU;
  206.    }
  207.    A = CreateWindowEx(Exstyle,BCX_ClassName,Caption,
  208.    Style,
  209.    X*BCX_ScaleX,
  210.    Y*BCX_ScaleY,
  211.    (4+W)*BCX_ScaleX,
  212.    (12+H)*BCX_ScaleY,
  213.    NULL,(HMENU)NULL,BCX_hInstance,NULL);
  214.    SendMessage(A,(UINT)WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),
  215.      (LPARAM)MAKELPARAM(FALSE,0));
  216.    return A;
  217. }
  218.  
  219.  
  220. // color, why not
  221. void BCX_Set_Form_Color (HWND hWnd, COLORREF Kolor)
  222. {
  223.   HBRUSH hbr=CreateSolidBrush(Kolor);
  224.   DeleteObject((HBRUSH)SetClassLong(hWnd,GCL_HBRBACKGROUND,(DWORD)hbr));
  225.   InvalidateRect (hWnd,NULL,TRUE);
  226. }
  227.  
  228.  
  229. // the details - corner coordinates,width,height,title
  230. void FormLoad (void)
  231. {
  232.     Form1=BCX_Form("PostEdit Capture",0,0,197,170);
  233.     SetClassLong(Form1,GCL_STYLE,GetClassLong(Form1,GCL_STYLE)|CS_DBLCLKS);
  234.     BCX_Set_Form_Color(Form1,RGB(0,0,0));
  235.     //  Now create the MCIWnd
  236.     MCIFrame=MCIWndCreate(Form1,(HINSTANCE)ghInst,WS_CHILD|WS_VISIBLE|MCIWNDF_NOPLAYBAR|MCIWNDF_NOTIFYALL,"");
  237.     AddMenu(Form1);
  238.     Center(Form1);
  239.     Show(Form1);
  240.  
  241. }
  242.  
  243. int InitSaveFileName (void)
  244. {
  245.   *szFile=0;
  246.   *szFileTitle=0;
  247.   OpenFileName.lStructSize=sizeof(OPENFILENAME);
  248.   OpenFileName.hwndOwner=MCIFrame;
  249.   OpenFileName.hInstance=(HINSTANCE)ghInst;
  250.   OpenFileName.lpstrFilter =
  251.     "Bmp Files (*.BMP)\0*.bmp\0All Files(*.*)\0*.*\0\0";
  252.   OpenFileName.lpstrCustomFilter=NULL;
  253.   OpenFileName.nMaxCustFilter=0;
  254.   OpenFileName.nFilterIndex=0;
  255.   OpenFileName.lpstrFile=szFile;
  256.   OpenFileName.nMaxFile=MAX_PATH;
  257.   OpenFileName.lpstrFileTitle=szFileTitle;
  258.   OpenFileName.nMaxFileTitle=MAX_PATH;
  259.   OpenFileName.lpstrInitialDir=curdir();
  260.   OpenFileName.lpstrTitle=NULL;
  261.   OpenFileName.nFileOffset=0;
  262.   OpenFileName.nFileExtension=0;
  263.   OpenFileName.lpstrDefExt="*.bmp";
  264.   OpenFileName.lCustData=0L;
  265.   OpenFileName.Flags=OFN_SHOWHELP|OFN_PATHMUSTEXIST|OFN_HIDEREADONLY;
  266.   OpenFileName.lpfnHook=NULL;
  267.   OpenFileName.lpTemplateName=NULL;
  268.   return 0;
  269. }
  270.  
  271. int PopFileSaveDlg (HWND Form1, char *szFileBmp, char *szFileTitleBmp)
  272. {
  273.   OpenFileName.lpstrTitle="Save bitmap";
  274.   OpenFileName.hwndOwner=MCIFrame;
  275.   OpenFileName.lpstrFile=szFileBmp;
  276.   OpenFileName.lpstrFileTitle=szFileTitleBmp;
  277.   OpenFileName.Flags=OFN_EXPLORER|OFN_CREATEPROMPT;
  278.   return GetOpenFileNamePreview(&OpenFileName);
  279. }
  280.  
  281.  
  282.  
  283. /*
  284. Funzione per scrivere l'handle di una bitmap su file
  285. Thanks to http://www.geocities.com/krishnapg/bitmap.html#SaveBitmap
  286. */
  287. void SaveBitmap(char *szFilename,HBITMAP hBitmap){
  288.       HDC        hdc=NULL;
  289.       FILE*      fp=NULL;
  290.       LPVOID     pBuf=NULL;
  291.       BITMAPINFO bmpInfo;
  292.       BITMAPFILEHEADER  bmpFileHeader;
  293.       do{
  294.             hdc=GetDC(NULL);
  295.             ZeroMemory(&bmpInfo,sizeof(BITMAPINFO));
  296.             bmpInfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
  297.             GetDIBits(hdc,hBitmap,0,0,NULL,&bmpInfo,DIB_RGB_COLORS);
  298.             if(bmpInfo.bmiHeader.biSizeImage<=0)
  299.             bmpInfo.bmiHeader.biSizeImage=bmpInfo.bmiHeader.biWidth*abs(bmpInfo.bmiHeader.biHeight)*(bmpInfo.bmiHeader.biBitCount+7)/8;
  300.             if((pBuf = malloc(bmpInfo.bmiHeader.biSizeImage))==NULL)
  301.             {
  302.                   //MessageBox( NULL, "Unable to Allocate Bitmap Memory", "Error", MB_OK|MB_ICONERROR);
  303.                   break;
  304.             }          
  305.             bmpInfo.bmiHeader.biCompression=BI_RGB;
  306.             GetDIBits(hdc,hBitmap,0,bmpInfo.bmiHeader.biHeight,pBuf, &bmpInfo, DIB_RGB_COLORS);      
  307.             if((fp = fopen(szFilename,"wb"))==NULL)
  308.             {
  309.                   //MessageBox( NULL, "Unable to Create Bitmap File", "Error", MB_OK|MB_ICONERROR);
  310.                   break;
  311.             }
  312.             bmpFileHeader.bfReserved1=0;
  313.             bmpFileHeader.bfReserved2=0;
  314.             bmpFileHeader.bfSize=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+bmpInfo.bmiHeader.biSizeImage;
  315.             bmpFileHeader.bfType='MB';
  316.             bmpFileHeader.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
  317.             fwrite(&bmpFileHeader,sizeof(BITMAPFILEHEADER),1,fp);
  318.             fwrite(&bmpInfo.bmiHeader,sizeof(BITMAPINFOHEADER),1,fp);
  319.             fwrite(pBuf,bmpInfo.bmiHeader.biSizeImage,1,fp);
  320.       }while(false);
  321.             if(hdc)     ReleaseDC(NULL,hdc);
  322.             if(pBuf)    free(pBuf);
  323.             if(fp)      fclose(fp);
  324. }
  325.  
  326.  
  327. // event message handler
  328. LRESULT CALLBACK WndProc (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
  329. {
  330.   static char s[2048];
  331.   memset(&s,0,sizeof(s));
  332.   static char mstr[2048];
  333.   memset(&mstr,0,sizeof(mstr));
  334.   static char mstr1[2048];
  335.   memset(&mstr1,0,sizeof(mstr1));
  336.   while(1)
  337.   {
  338.     if (Msg==WM_CREATE)
  339.     {
  340.       return 0;
  341.       break;
  342.     }
  343.     if (Msg==WM_COMMAND)
  344.     {
  345.       if (LOWORD(wParam)==ID_MENU2)
  346.       {
  347.           MCIWndClose(MCIFrame);
  348.           InitOpenFileName();
  349.          PopFileOpenDlg(Form1,szFile,szFileTitle);
  350. //           strcpy(szFile,"d:\\dati\\amss\\cam_guida2.avi");
  351.           if(strlen(szFile)>0)
  352.           {
  353.               MCIWndOpen(MCIFrame,szFile,0);
  354.   AppendMenu(FileMenu,MF_STRING,ID_MENU6,"&Start frame");
  355.  
  356.  
  357.           }
  358.           return 0;
  359.       }
  360.       if(LOWORD(wParam)==ID_MENU3)
  361.       {
  362.           MCIWndClose(MCIFrame);
  363.           ExitProcess(0);
  364.       }
  365.       //break;
  366.       // if(LOWORD(wParam)==ID_MENU4)
  367.       //{
  368.                                    
  369.       //}
  370.      
  371.      
  372.        if(LOWORD(wParam)==ID_MENU5)
  373.       {
  374. HDC hDc = CreateCompatibleDC(GetDC(MCIFrame));
  375. RECT rcWind;
  376. GetClientRect(MCIFrame, &rcWind);
  377. int width = rcWind.right - rcWind.left;
  378. int height = rcWind.bottom - rcWind.top;
  379.  
  380. static char    szFileAvi[2048];
  381. static char    szFileTitleAvi[2048];
  382.           InitOpenFileName();
  383.          PopFileOpenDlg(Form1,szFileAvi,szFileTitleAvi);
  384. HAVI avi = CreateAvi(szFileAvi,5,NULL);
  385.  
  386. static  char  bmptemp[2048];
  387.     BROWSEINFO bi = { 0 };
  388.     TCHAR path[MAX_PATH];
  389.     bi.lpszTitle = "Pick a Temp Directory";
  390.     bi.pszDisplayName = path;
  391.     LPITEMIDLIST pidl = SHBrowseForFolder ( &bi );
  392.     if ( pidl != 0 )
  393.     {
  394.         // get the name of the folder
  395.  
  396.  
  397.         sprintf(bmptemp, "%s", path);
  398.         // free memory used
  399.         IMalloc * imalloc = 0;
  400.         if ( SUCCEEDED( SHGetMalloc ( &imalloc )) )
  401.         {
  402.             imalloc->Free ( pidl );
  403.             imalloc->Release ( );
  404.         }
  405.     }
  406.  
  407.  
  408.  
  409. char buffer[100];
  410. LONG lFrame;
  411. lFrame = MCIWndGetPosition(MCIFrame);
  412.  
  413. for (LONG i=lFrame_start; i<=lFrame_end; i++)
  414. {
  415.     MCIWndSeek(MCIFrame,i);
  416.   HBITMAP hBmp = CreateCompatibleBitmap(GetDC(MCIFrame), width, height);  
  417.    
  418.    // join em up
  419.    SelectObject(hDc, hBmp);  
  420.    
  421.    // copy from the screen to my bitmap
  422.    BitBlt(hDc, 0, 0, width, height, GetDC(MCIFrame), 0, 0, SRCCOPY);  
  423.  
  424.       // avifile.appendNewFrame(hBitmap);
  425.  
  426.  
  427.  
  428.   //sprintf(buffer, "%s%i.bmp", bmptemp, i); // image a rajouter
  429.   sprintf(buffer, "%s.bmp", bmptemp);
  430.   SaveBitmap(buffer,hBmp);
  431.  
  432.   HBITMAP hBmpDIB =(HBITMAP)LoadImage(NULL,buffer,IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);
  433.  
  434. if (i==lFrame_start) // Set up compression just before the first frame
  435.   {  AVICOMPRESSOPTIONS opts;
  436.     ZeroMemory(&opts,sizeof(opts));
  437.     opts.fccHandler=mmioFOURCC('D','I','V','X');
  438.     SetAviVideoCompression(avi,hBmpDIB,&opts,true,Form1);
  439. }
  440.     AddAviFrame(avi,hBmpDIB);
  441.   DeleteObject(hBmp);
  442.     DeleteObject(hBmpDIB);
  443. }
  444. CloseAvi(avi);
  445. MessageBox(NULL,"Avi saved.","COMPLETED",MB_OK | MB_ICONINFORMATION);
  446.  
  447.                                  
  448.       }
  449.      
  450.      
  451.        if(LOWORD(wParam)==ID_MENU6)
  452.       {
  453.  
  454. lFrame_start = MCIWndGetPosition(MCIFrame);                                  
  455.   AppendMenu(FileMenu,MF_STRING,ID_MENU7,"&End Frame");
  456.             }
  457.        if(LOWORD(wParam)==ID_MENU7)
  458.       {
  459. lFrame_end = MCIWndGetPosition(MCIFrame);                                  
  460.             // AppendMenu(FileMenu,MF_STRING,ID_MENU4,"&Save bmp");
  461.   AppendMenu(FileMenu,MF_STRING,ID_MENU5,"&Save capture");
  462.             }
  463. break;
  464.     }
  465.  
  466.     if (Msg==MCIWNDM_NOTIFYMODE)
  467.     {
  468.       while(1)
  469.       {
  470.         if ((long)lParam==MCI_MODE_NOT_READY)
  471.         {
  472.           SetWindowText(Form1,"Not Ready");
  473.           break;
  474.         }
  475.         if ((long)lParam==MCI_MODE_PAUSE)
  476.         {
  477.           SetWindowText(Form1,"Paused");
  478.           break;
  479.         }
  480.         if ((long)lParam==MCI_MODE_PLAY)
  481.         {
  482.           SetWindowText(Form1,"Playing");
  483.           break;
  484.         }
  485.         if ((long)lParam==MCI_MODE_STOP)
  486.         {
  487.           SetWindowText(Form1,"Stopped");
  488.           break;
  489.         }
  490.         if ((long)lParam==MCI_MODE_OPEN)
  491.         {
  492.           SetWindowText(Form1,"Opening");
  493.           break;
  494.         }
  495.         if ((long)lParam==MCI_MODE_RECORD)
  496.         {
  497.           SetWindowText(Form1,"Recording");
  498.           break;
  499.         }
  500.         if ((long)lParam==MCI_MODE_SEEK)
  501.         {
  502.           SetWindowText(Form1,"Seeking");
  503.         }
  504.         break;
  505.       }
  506.       break;
  507.     }
  508.     if (Msg==MCIWNDM_NOTIFYMEDIA)
  509.     {
  510.       SetWindowText(Form1,(LPSTR)lParam);
  511.       break;
  512.     }
  513.     if (Msg==MCIWNDM_NOTIFYPOS)
  514.     {
  515.       SetWindowText(Form1,str(MCIWndGetPosition(MCIFrame)));
  516.       break;
  517.     }
  518.     if (Msg==MCIWNDM_NOTIFYERROR)
  519.     {
  520.       SetWindowText(Form1,"MCI ERROR");
  521.       break;
  522.     }
  523.     if (Msg==WM_PAINT)
  524.     {
  525.       //  The VideoWindow is restricted to a ratio of 4:3 here
  526.       break;
  527.     }
  528.     if (Msg==WM_SIZE)
  529.     {
  530.       static  WORD  Basedsp;
  531.       memset(&Basedsp,0,sizeof(Basedsp));
  532.       static  WORD  Cntr;
  533.       memset(&Cntr,0,sizeof(Cntr));
  534.       Basedsp=(HIWORD(lParam)-20)/3;
  535.       Cntr=(LOWORD(lParam)-(Basedsp*4))/2;
  536.       // MoveWindow(MCIFrame,Cntr,0,(Basedsp*4),HIWORD(lParam),TRUE);
  537.       //  Don't forget to close opened Files
  538.       break;
  539.     }
  540.     if (Msg==WM_CLOSE)
  541.     {
  542.       MCIWndClose(MCIFrame);
  543.       DestroyWindow(Form1);
  544.       return 0;
  545.       break;
  546.     }
  547.     if (Msg==WM_DESTROY)
  548.     {
  549.       MCIWndClose(MCIFrame);
  550.       PostQuitMessage(0);
  551.       return 0;
  552.     }
  553.     break;
  554.   }
  555.   // tidy up and exit program
  556.   if (Msg==WM_DESTROY)
  557.   {
  558.        UnregisterClass(BCX_ClassName,BCX_hInstance);
  559.        PostQuitMessage(0);
  560.   }
  561.   return DefWindowProc(hWnd,Msg,wParam,lParam);
  562. }
  563.  
  564.  
  565. // tons of options for the neat file dialog box
  566. int InitOpenFileName (void)
  567. {
  568.   *szFile=0;
  569.   *szFileTitle=0;
  570.   OpenFileName.lStructSize=sizeof(OPENFILENAME);
  571.   OpenFileName.hwndOwner=MCIFrame;
  572.   OpenFileName.hInstance=(HINSTANCE)ghInst;
  573.   OpenFileName.lpstrFilter =
  574.     "Avi Files (*.AVI)\0*.avi\0All Files(*.*)\0*.*\0\0";
  575.   OpenFileName.lpstrCustomFilter=NULL;
  576.   OpenFileName.nMaxCustFilter=0;
  577.   OpenFileName.nFilterIndex=0;
  578.   OpenFileName.lpstrFile=szFile;
  579.   OpenFileName.nMaxFile=MAX_PATH;
  580.   OpenFileName.lpstrFileTitle=szFileTitle;
  581.   OpenFileName.nMaxFileTitle=MAX_PATH;
  582.   OpenFileName.lpstrInitialDir=curdir();
  583.   OpenFileName.lpstrTitle=NULL;
  584.   OpenFileName.nFileOffset=0;
  585.   OpenFileName.nFileExtension=0;
  586.   OpenFileName.lpstrDefExt="*.avi";
  587.   OpenFileName.lCustData=0L;
  588.   OpenFileName.Flags=OFN_SHOWHELP|OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY;
  589.   OpenFileName.lpfnHook=NULL;
  590.   OpenFileName.lpTemplateName=NULL;
  591.   return 0;
  592. }
  593.  
  594. int PopFileOpenDlg (HWND Form1, char *szFile, char *szFileTitle)
  595. {
  596.   OpenFileName.lpstrTitle="Open File";
  597.   OpenFileName.hwndOwner=MCIFrame;
  598.   OpenFileName.lpstrFile=szFile;
  599.   OpenFileName.lpstrFileTitle=szFileTitle;
  600.   OpenFileName.Flags=OFN_EXPLORER|OFN_CREATEPROMPT;
  601.   return GetOpenFileNamePreview(&OpenFileName);
  602. }
  603.  
  604.  
  605. BOOL AddMenu (HWND hwndOwner)
  606. {
  607.   MainMenu=CreateMenu();
  608.   FileMenu=CreateMenu();
  609.   InsertMenu(MainMenu,0,MF_POPUP,(UINT)FileMenu,"&File");
  610.   AppendMenu(FileMenu,MF_STRING,ID_MENU2,"&Open");
  611.   AppendMenu(FileMenu,MF_STRING,ID_MENU3,"&Exit");
  612. //  AppendMenu(FileMenu,MF_STRING,ID_MENU4,"&Save bmp");
  613. //  AppendMenu(FileMenu,MF_STRING,ID_MENU5,"&Save capture");
  614.   // activate the menu
  615.   if (!SetMenu(hwndOwner,MainMenu))
  616.   {
  617.       return FALSE;
  618.   }
  619.   return TRUE;
  620. }
  621.  
  622.  
  623.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement