/* This is the source code for avidll.cpp file This Sample NetScape Plugin was developed at Vijay Mukhi's Computer Institute, Bombay, India by Kersi Tavadia, Viraf Adajania and Nimesh Gajera Throughout we have tried to use MCI commands to maintain uniformity The following files/settings need to be there npapi.h,npupp.h in current directory winmm.lib and vfw32.lib should be added to your linker-library modules The DLL File so created will have to be copied into netscape\system\program\plugins subdirectory as npavi32.dll In Netscape the MIME types should be set to vmci/proj and file extents should be avi. (The MIME types should correspond to the ones defined in the .DEF file) */ #include <afxwin.h> #include <afxext.h> #include <vfw.h> #include <mmsystem.h> #include <digitalv.h> #include "npapi.h" #include "npupp.h" //int i,x;long j;char bb[200];LPRECT lprect; // defining the variables here char aa[100];RECT r; NPNetscapeFuncs *g; CString es1,es2; class yyy; /* The structure 'ourstruct' is created to substitute the global variables in the system, which would create problems if multiple embeds are used. */ struct ourstruct { yyy *w; // this provides a linklist HWND hwnd; char fname[100]; int done; long maxframe; BOOL fplay,fpause,fstop; }; class xxx:public CDialog { public: // struct ourstruct *ss; char s[20],s1[20], s11[10],s12[10],s13[10],s14[10]; int k; long maxframe; CRect c; xxx(int x):CDialog(9) { maxframe=x; k=4; } xxx(int y,long x):CDialog(y) { maxframe=x; if (y==11) // playto dialog & seek k=0; else if (y==9) // playfrom k=4; else if (y==10) k=1; //play from to } xxx(CRect r) : CDialog(12) { c=r; k=3; } // passing default values in the dialog box void DoDataExchange(CDataExchange *p) { if (k==1) { DDX_Text(p,1001,es1); DDX_Text(p,1002,es2); } else if ( k==0) DDX_Text(p,1004,es1); else if ( k==4) DDX_Text(p,1012,es1); else if (k==3) { DDX_Text(p,1007,c.left); DDX_Text(p,1008,c.top); DDX_Text(p,1009,c.right); DDX_Text(p,1010,c.bottom); } } // validating the parameters in dialog boxes void OnOk0() { int erflg; GetDlgItemText(1001,s,5); erflg=0; GetDlgItemText(1002,s1,5); for (unsigned i=0;i<strlen(s);i++) { if( s[i]<'0' || s[i]>'9') erflg=1; } for (i=0;i<strlen(s1);i++) { if( s1[i]<'0' || s1[i]>'9') erflg=1; } if( atoi(s) < 0||(atoi(s)>maxframe) || atoi(s1)<0 ||( atoi(s1)>maxframe) || erflg==1) ::MessageBox(0,"Range Value Incorrect","ERROR",0); else EndDialog(1); } void OnOk1() { int erflg; GetDlgItemText(1004,s,5); erflg=0; for (unsigned i=0;i<strlen(s);i++) { if( s[i]<'0' || s[i]>'9') erflg=1; } if( atoi(s) < 0||(atoi(s)>maxframe) || erflg==1) ::MessageBox(0,"Range Value Incorrect","ERROR",0); else EndDialog(1); } void OnOk2() { int erflg; GetDlgItemText(1007,s11,5); GetDlgItemText(1008,s12,5); GetDlgItemText(1009,s13,5); GetDlgItemText(1010,s14,5); erflg=0; for (unsigned i=0;i<strlen(s11);i++) { if( s11[i]<'0' || s11[i]>'9') erflg=1; } for (i=0;i<strlen(s12);i++) { if( s12[i]<'0' || s12[i]>'9') erflg=1; } for (i=0;i<strlen(s13);i++) { if( s13[i]<'0' || s13[i]>'9') erflg=1; } for (i=0;i<strlen(s13);i++) { if( s13[i]<'0' || s13[i]>'9') erflg=1; } if( atoi(s11) < c.left||(atoi(s12)<c.top) || atoi(s13)>c.right ||( atoi(s14)>c.bottom) || erflg==1) ::MessageBox(0,"Range Value Incorrect","ERROR",0); else EndDialog(1); } void OnOk3() { int erflg; GetDlgItemText(1012,s,5); erflg=0; for (unsigned i=0;i<strlen(s);i++) { if( s[i]<'0' || s[i]>'9') erflg=1; ::MessageBox(0,"in for loop","bye",0); } if( atoi(s) < 0||(atoi(s)>maxframe) || erflg==1) ::MessageBox(0,"Range Value Incorrect","ERROR",0); else EndDialog(1); } DECLARE_MESSAGE_MAP() }; BEGIN_MESSAGE_MAP(xxx,CDialog) ON_BN_CLICKED(1003,OnOk0) ON_BN_CLICKED(1013,OnOk3) ON_BN_CLICKED(1005,OnOk1) ON_BN_CLICKED(1006,OnOk2) END_MESSAGE_MAP() class yyy :public CWnd { public: struct ourstruct *ss; // passes the pointer to struct // of variables for every instance // CMenu *m; CPoint p; RECT c; int i,j; // for creating popup menus , first create all the child menus // pass their handles to their respective parent menu void OnRButtonDown(UINT, CPoint p) { CMenu cmPopup,cm1; UINT hplay,hsettings,hvolume,hspeed,htimer,hzoom,htimerformat,hcontrol; UINT uState=MF_ENABLED; // play menu CMenu cmPopup1; cmPopup1.CreatePopupMenu(); cmPopup1.AppendMenu(uState,102,"&Forward") ; cmPopup1.AppendMenu(uState,110,"&Playreverse"); cmPopup1.AppendMenu(uState,109,"&Goto frame") ; cmPopup1.AppendMenu(uState,111,"P&layfrom") ; cmPopup1.AppendMenu(uState,112,"Play&to") ; cmPopup1.AppendMenu(uState,113,"Pl&ayfromto") ; hplay=(UINT)cmPopup1.GetSafeHmenu(); //---------- // zoom menu CMenu cmPopup3; cmPopup3.CreatePopupMenu(); cmPopup3.AppendMenu(uState,20111,"&Normal") ; cmPopup3.AppendMenu(uState,20112,"&Half") ; cmPopup3.AppendMenu(uState,20113,"&Quarter"); cmPopup3.AppendMenu(uState,20114,"&Double") ; hzoom=(UINT)cmPopup3.GetSafeHmenu(); // volume menu CMenu cmPopup4; cmPopup4.CreatePopupMenu(); cmPopup4.AppendMenu(uState,20121,"&Normal") ; cmPopup4.AppendMenu(uState,20122,"&Half") ; cmPopup4.AppendMenu(uState,20123,"&Quarter"); cmPopup4.AppendMenu(uState,20124,"&Double") ; hvolume=(UINT)cmPopup4.GetSafeHmenu(); //speed menu CMenu cmPopup5; cmPopup5.CreatePopupMenu(); cmPopup5.AppendMenu(uState,20131,"&Normal") ; cmPopup5.AppendMenu(uState,20132,"&Half") ; cmPopup5.AppendMenu(uState,20133,"&Quarter"); cmPopup5.AppendMenu(uState,20134,"&Double") ; hspeed=(UINT)cmPopup5.GetSafeHmenu(); //set timer format menu CMenu cmPopup7; cmPopup7.CreatePopupMenu(); cmPopup7.AppendMenu(uState,20146,"Use &Time") ; cmPopup7.AppendMenu(uState,20147,"Use &Frames") ; htimerformat=(UINT)cmPopup7.GetSafeHmenu(); //timer menu CMenu cmPopup6; cmPopup6.CreatePopupMenu(); cmPopup6.AppendMenu(uState,20141,"Set &Both") ; cmPopup6.AppendMenu(uState,20142,"Set &Active") ; cmPopup6.AppendMenu(uState,20143,"Set &Inactive"); cmPopup6.AppendMenu(uState,20144,"Get A&ctive") ; cmPopup6.AppendMenu(uState,20145,"Get I&nactive"); cmPopup6.AppendMenu(MF_POPUP,htimerformat,"Set &Time Format") ; htimer=(UINT)cmPopup6.GetSafeHmenu(); // Settings Menu CMenu cmPopup2; cmPopup2.CreatePopupMenu(); cmPopup2.AppendMenu(MF_POPUP,hzoom,"&Zoom ") ; cmPopup2.AppendMenu(MF_POPUP,hvolume,"&Volume ") ; cmPopup2.AppendMenu(MF_POPUP,hspeed,"&Speed "); cmPopup2.AppendMenu(MF_POPUP,htimer,"&Timer "); cmPopup2.AppendMenu(uState,2014,"&Repeat") ; cmPopup2.AppendMenu(uState,2016,"&Magnify Part Image"); cmPopup2.AppendMenu(uState,2017,"&Compress Image"); cmPopup2.AppendMenu(uState,2020,"Restore &Image"); cmPopup2.AppendMenu(uState,2018,"&Getsource ") ; cmPopup2.AppendMenu(uState,2019,"Get&dest "); hsettings=(UINT)cmPopup2.GetSafeHmenu(); // device control menu CMenu cmPopup10; cmPopup10.CreatePopupMenu(); cmPopup10.AppendMenu(uState,201,"Can&Config") ; cmPopup10.AppendMenu(uState,202,"Can&Eject"); cmPopup10.AppendMenu(uState,203,"Can&Play") ; cmPopup10.AppendMenu(uState,204,"Can&Record") ; cmPopup10.AppendMenu(uState,205,"Can&Save") ; cmPopup10.AppendMenu(uState,206,"Can&Window") ; hcontrol=(UINT)cmPopup10.GetSafeHmenu(); // MAIN MENU cmPopup.CreatePopupMenu(); cmPopup.AppendMenu(uState,100,"&Open"); if (ss->hwnd) uState=MF_ENABLED; else uState=MF_DISABLED; cmPopup.AppendMenu(MF_POPUP,hsettings,"&Settings") ; cmPopup.AppendMenu(MF_POPUP,hplay,"&Play "); cmPopup.AppendMenu(MF_POPUP,hcontrol,"&Device Controls "); cmPopup.AppendMenu(uState,103,"S&top") ; cmPopup.AppendMenu(uState,104,"P&ause") ; cmPopup.AppendMenu(uState,105,"&Resume") ; cmPopup.AppendMenu(uState,106,"&Home") ; cmPopup.AppendMenu(uState,107,"&End") ; cmPopup.AppendMenu(uState,101,"&Close"); cmPopup.AppendMenu(uState,115,"&New file"); cmPopup.AppendMenu(uState,108,"&Destroy") ; ClientToScreen(&p); cmPopup.TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON,p.x,p.y,this,NULL); } void open() { ss->hwnd=MCIWndCreate(this->GetSafeHwnd(),AfxGetInstanceHandle(),WS_CHILD|WS_CAPTION|WS_VISIBLE|WS_OVERLAPPEDWINDOW|MCIWNDF_SHOWPOS|MCIWNDF_SHOWNAME,ss->fname); ss->maxframe =MCIWndGetLength(ss->hwnd); } void opennew() { MCIWndOpenDialog(ss->hwnd); } void close() { if (ss->hwnd!=NULL) MCIWndClose(ss->hwnd); } void play() { if (ss->hwnd!=NULL) { MCIWndPlay(ss->hwnd); } } void stop() { if (ss->hwnd!=NULL ) MCIWndStop(ss->hwnd); } void pause() { if (ss->hwnd!=NULL ) { MCIWndPause(ss->hwnd); } } void resume() { if (ss->hwnd!=NULL ) //&& (ss->fpause || ss->fstop)) { MCIWndResume(ss->hwnd); } } void home() { if (ss->hwnd!=NULL) MCIWndHome(ss->hwnd); } void end() { if (ss->hwnd!=NULL) MCIWndEnd(ss->hwnd); } void destroy() { if (ss->hwnd!=NULL) MCIWndDestroy(ss->hwnd); ss->hwnd=NULL; } void seekframe() { if (ss->hwnd!=NULL) { xxx *q; q=new xxx(11,ss->maxframe); //calling constructor with //dialog box no & maxframes q->DoModal(); MCIWndSeek(ss->hwnd,atoi(q->s)); } } void playreverse() { if (ss->hwnd!=NULL) { MCIWndPlayReverse(ss->hwnd); ss->fplay=TRUE; } } void playfrom() { if (ss->hwnd!=NULL) { xxx *q; q=new xxx(9,ss->maxframe); q->DoModal(); MCIWndPlayFrom(ss->hwnd,atoi(q->s)); ss->fplay=TRUE; } } void playto() { if (ss->hwnd!=NULL) { xxx *q; q=new xxx(11,ss->maxframe); q->DoModal(); MCIWndPlayTo(ss->hwnd,atoi(q->s)); ss->fplay=TRUE; } } void playfromto() { if (ss->hwnd!=NULL) { xxx *q; q=new xxx(10,ss->maxframe); q->DoModal(); MCIWndPlayFromTo(ss->hwnd,atoi(q->s),atoi(q->s1)); // ss->fplay=TRUE; } } void zoomnormal() { MCIWndSetZoom(ss->hwnd,100); } void zoomhalf() { MCIWndSetZoom(ss->hwnd,50); } void zoomquarter() { MCIWndSetZoom(ss->hwnd,25); } void zoomdouble() { MCIWndSetZoom(ss->hwnd,200); } void volumenormal() { MCIWndSetVolume(ss->hwnd,1000); } void volumehalf() { MCIWndSetVolume(ss->hwnd,250); } void volumequarter() { MCIWndSetVolume(ss->hwnd,125); } void volumedouble() { MCIWndSetVolume(ss->hwnd,750); } void speednormal() { MCIWndSetSpeed(ss->hwnd,500); } void speedhalf() { MCIWndSetSpeed(ss->hwnd,500); } void speedquarter() { MCIWndSetSpeed(ss->hwnd,250); } void speeddouble() { MCIWndSetSpeed(ss->hwnd,2000); } void repeat() { MCIWndSetRepeat(ss->hwnd,TRUE); } void send() { MCIWndSendString(ss->hwnd, "our own string"); } void magnify() { MCIWndGetSource(ss->hwnd,&r); c=r; xxx *q; q=new xxx(r); q->DoModal(); r.left=atoi(q->s11);r.top=atoi(q->s12); r.right=atoi(q->s13);r.bottom=atoi(q->s14); MCIWndPutSource(ss->hwnd, &r); j=1; } void compress() { xxx *q; MCIWndGetDest(ss->hwnd,&r); q=new xxx(r); q->DoModal(); r.left=atoi(q->s11);r.top=atoi(q->s12); r.right=atoi(q->s13);r.bottom=atoi(q->s14); MCIWndPutDest(ss->hwnd, &r); j=2; } void restoreimage() { if(j==1) { MCIWndGetDest(ss->hwnd, &c); MCIWndPutSource(ss->hwnd, &c); } else if(j==2) { MCIWndGetSource(ss->hwnd, &r); MCIWndPutDest(ss->hwnd, &r); } j=0; } void getsource() { MCIWndGetSource(ss->hwnd, &r); sprintf(aa,"Original Frame Coordinates\n" "Left = %d , Top = %d \n Right = %d, Bottom= %d", r.left,r.top,r.right,r.bottom); ::MessageBox(0,aa,"Get Source",0); } void getdest() { MCIWndGetDest(ss->hwnd, &r); sprintf(aa,"Current Frame Coordinates \n" "Left = %d , Top = %d \n Right = %d, Bottom= %d", r.left,r.top,r.right,r.bottom); ::MessageBox(0,aa,"Get Destination",0); } void setactivetimer() { MCIWndSetActiveTimer(ss->hwnd, 200); } void setinactivetimer() { MCIWndSetInactiveTimer(ss->hwnd, 300); } void setboth() { MCIWndSetTimers(ss->hwnd,200,300); } void getactivetimer() { i=MCIWndGetActiveTimer(ss->hwnd); sprintf(aa,"ActiveTimer= %d millisecs",i); ::MessageBox(0,aa,"Timer",0); } void getinactivetimer() { i=MCIWndGetInactiveTimer(ss->hwnd); sprintf(aa,"InActiveTimer= %d millisecs",i); ::MessageBox(0,aa,"Timer",0); } void usetime() { MCIWndUseTime(ss->hwnd); sprintf(aa,"Time format in millisecs"); MessageBox(aa); } void useframe() { i=MCIWndUseFrames(ss->hwnd); sprintf(aa,"Time format in Frames"); MessageBox(aa); } void canconfig() { if(MCIWndCanConfig(ss->hwnd)) { ::MessageBox(0,"Device can be configured","CanConfig",0); } else ::MessageBox(0,"Device cannot be configured","CanConfig",0); } void caneject() { if(MCIWndCanEject(ss->hwnd)) { ::MessageBox(0,"CanEject","HI",0); MCIWndEject(ss->hwnd); } else ::MessageBox(0,"Device Cannot Eject","Eject",0); } void canplay() { if(MCIWndCanPlay(ss->hwnd)) { ::MessageBox(0,"Device Can Play","Play",0); } else ::MessageBox(0,"Device cannot Play","Play",0); } void canrecord() { if(MCIWndCanRecord(ss->hwnd)) { ::MessageBox(0,"Device Can Record","Recording",0); } else ::MessageBox(0,"Device Cannot Record","Recording",0); } void cansave() { if(MCIWndCanSave(ss->hwnd)) { ::MessageBox(0,"Device Can Save","Saving",0); MCIWndSaveDialog(ss->hwnd); } else ::MessageBox(0,"Device Cannot Save","Saving",0); } void canwindow() { if(MCIWndCanWindow(ss->hwnd)) { ::MessageBox(0,"Device Supports Window Functions","Windows",0); } else ::MessageBox(0,"Device Does not Support Windows functions","Windows",0); } WNDPROC* GetSuperWndProcAddr() { return CWnd::GetSuperWndProcAddr(); } DECLARE_MESSAGE_MAP() }; BEGIN_MESSAGE_MAP(yyy,CWnd) ON_WM_RBUTTONDOWN() ON_COMMAND(100,open) ON_COMMAND(102,play) ON_COMMAND(103,stop) ON_COMMAND(104,pause) ON_COMMAND(105,resume) ON_COMMAND(106,home) ON_COMMAND(107,end) ON_COMMAND(101,close) ON_COMMAND(115,opennew) ON_COMMAND(108,destroy) ON_COMMAND(201,canconfig) ON_COMMAND(202,caneject) ON_COMMAND(203,canplay) ON_COMMAND(204,canrecord) ON_COMMAND(205,cansave) ON_COMMAND(206,canwindow) ON_COMMAND(109,seekframe) ON_COMMAND(110,playreverse) ON_COMMAND(111,playfrom) ON_COMMAND(112,playto) ON_COMMAND(113,playfromto) ON_COMMAND(20111,zoomnormal) ON_COMMAND(20112,zoomhalf) ON_COMMAND(20113,zoomquarter) ON_COMMAND(20114,zoomdouble) ON_COMMAND(20121,volumenormal) ON_COMMAND(20122,volumehalf) ON_COMMAND(20123,volumequarter) ON_COMMAND(20124,volumedouble) ON_COMMAND(20131,speednormal) ON_COMMAND(20132,speedhalf) ON_COMMAND(20133,speedquarter) ON_COMMAND(20134,speeddouble) ON_COMMAND(20141,setboth) ON_COMMAND(20142,setactivetimer) ON_COMMAND(20143,setinactivetimer) ON_COMMAND(20144,getactivetimer) ON_COMMAND(20145,getinactivetimer) ON_COMMAND(20146,usetime) ON_COMMAND(20147,useframe) ON_COMMAND(2014,repeat) ON_COMMAND(2016,magnify) ON_COMMAND(2017,compress) ON_COMMAND(2018,getsource) ON_COMMAND(2019,getdest) ON_COMMAND(2020,restoreimage) END_MESSAGE_MAP() CWinApp A; NPError _stdcall NP_Initialize(NPNetscapeFuncs *p) { g=p; return 0; } // The last function to be called when netscape quits NPError _stdcall NP_Shutdown() { return 0; } NPError OUR_New(void *pluginType,NPP instance,unsigned short mode ,short argc,char *argn[],char *argv[],NPSavedData *saved) { struct ourstruct *s; // Allocating memory for our variables s=(struct ourstruct *)g->memalloc(sizeof(ourstruct)); s->done=0; instance->pdata=s; // passing the pointer to ourstruct return 0; } NPError OUR_Destroy(NPP instance,NPSavedData **save) { struct ourstruct *s; s=(ourstruct *)instance->pdata; if (s->hwnd) {s->w->destroy(); s->hwnd=NULL; } WNDPROC* l=s->w->GetSuperWndProcAddr(); ::SetWindowLong(s->w->m_hWnd,GWL_WNDPROC,(LONG)*l); return 0; } NPError OUR_SetWindow(NPP instance,NPWindow* np_window) { struct ourstruct *s; s=(ourstruct *)instance->pdata; if(s->done==0 && np_window->window) { yyy *c; c=new yyy; s->done=1; c->SubclassWindow((HWND)np_window->window); c->ss=(ourstruct *)instance->pdata; s-> w=c; } return 0; } NPError OUR_NewStream(NPP instance,char *t,NPStream *st,NPBool s1,unsigned short *a) { *a=NP_ASFILE; return 0; } void OUR_AsFile(NPP instance,NPStream *stream, const char *f) { struct ourstruct *s; s=(ourstruct *)instance->pdata; strcpy(s->fname,f); } long OUR_WriteReady(NPP instance,NPStream *stream) { return 0xffff; // read entire file } long OUR_Write(NPP instance,NPStream *stream,long offset,long len, void *b) { return len; } NPError _stdcall NP_GetEntryPoints(NPPluginFuncs* p) { p->version = (NP_VERSION_MAJOR<<8)|NP_VERSION_MINOR; p->newp =OUR_New; p->destroy =OUR_Destroy; p->setwindow =OUR_SetWindow; p->newstream =OUR_NewStream; p->asfile =OUR_AsFile; p->writeready = OUR_WriteReady; p->write = OUR_Write; return 0; } // Netscape Plug-in ends here
Email us your suggestions,queries, comments at vmukhi@giasbm01.vsnl.net.in .