⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 myiweb.c

📁 BREW程序:BREW手机上的Web访问程序
💻 C
📖 第 1 页 / 共 3 页
字号:
							uint16   wIconID = IDB_MENU;
							if (wIconID)
							{
								STRTOWSTR(szName, wszBuf, 32);
								myiweb_AddMenuItem(pMe->m_pIMediaMenu, 0, wszBuf, wIconID, (uint16)(100 + wItemID), 0);
							}
						}
						
						wItemID++;
					}
					if(pMe->m_pIMediaMenu)
						IMENUCTL_SetActive(pMe->m_pIMediaMenu,TRUE);
					IFILEMGR_Release(pMe->m_pIFileMgr);
					pMe->m_pIFileMgr = NULL;
					
				}else{
					AECHAR szEmpty[16];
					IFILEMGR_Release(pMe->m_pIFileMgr);
					pMe->m_pIFileMgr = NULL;
					IDISPLAY_ClearScreen(pMe->a.m_pIDisplay);
					ISHELL_LoadResString(pMe->a.m_pIShell, MYIWEB_RES_FILE, IDS_NO_MEDIA, szEmpty, sizeof(szEmpty));
					myiweb_DisplayInfo(pMe,szEmpty);
				}
				
				
			}
			return(TRUE);
			// If nothing fits up to this point then we'll just break out
        default:
            break;
	}
	
	return FALSE;
}


// this function is called when your application is starting up
boolean myiweb_InitAppData(myiweb* pMe)
{
    // Get the device information for this handset.
    // Reference all the data by looking at the pMe->DeviceInfo structure
    // Check the API reference guide for all the handy device info you can get
    pMe->DeviceInfo.wStructSize = sizeof(pMe->DeviceInfo);
    ISHELL_GetDeviceInfo(pMe->a.m_pIShell,&pMe->DeviceInfo);

    // The display and shell interfaces are always created by
    // default, so we'll asign them so that you can access
    // them via the standard "pMe->" without the "a."
    pMe->pIDisplay = pMe->a.m_pIDisplay;
    pMe->pIShell   = pMe->a.m_pIShell;

    // Insert your code here for initializing or allocating resources...
 // Create each of the controls used by the application.
   if(//(ISHELL_CreateInstance(pIShell, AEECLSID_FILEMGR, (void**)(&pMe->m_pFileMgr)) != SUCCESS) ||
      (ISHELL_CreateInstance(pMe->pIShell, AEECLSID_HTML, (void**)(&pMe->m_pHTMLViewer)) != SUCCESS) ||
    //  (ISHELL_CreateInstance(pIShell, AEECLSID_NET, (void**)(&pMe->m_pINetMgr)) != SUCCESS) ||
      (ISHELL_CreateInstance(pMe->pIShell, AEECLSID_WEB, (void **)(&pMe->m_pIWeb)) != SUCCESS))
   {
      IAPPLET_Release((IApplet*)pMe);
      return FALSE;
   }
   IHTMLVIEWER_SetNotifyFn(pMe->m_pHTMLViewer, (PFNHVIEWNOTIFY)myiwebhtml_NotifyCB, pMe);
   IHTMLVIEWER_SetProperties(pMe->m_pHTMLViewer, HVP_SCROLLBAR);

   // Get device screen rect
   SETAEERECT(&pMe->m_rc, 0, 0, pMe->DeviceInfo.cxScreen, pMe->DeviceInfo.cyScreen);

    // Initialize the IWeb with a few options
   {
      int    i = 0;
      WebOpt awo[10]; 

      // set the IWeb connect timeout to 10 seconds.  this also sets the 
      // failover timeout, if unset, or set to 0, IWeb uses the system 
      // default (30 seconds unless an OEM changes it)
      awo[i].nId  = WEBOPT_CONNECTTIMEOUT;
      awo[i].pVal = (void *)10000;
      i++;

      // test user-agent, uncomment this section to ship your own user-agent 
      // string. if unset, IWeb will send a default.  If set to NULL, no 
      // user agent header will be sent */

      // Set TEST_USER_AGENT in the NetDiagnostics project settings to all
      // shipping of your own user agent.

#ifdef TEST_USER_AGENT
      awo[i].nId  = WEBOPT_USERAGENT;
      awo[i].pVal = (void *)WEBBER_USERAGENT;
      i++;
#endif 

      // test nowaitconn, this only comes into effect if you build webber 
      // with multiple myiwebs (see the definition of struct Webber)
      awo[i].nId  = WEBOPT_FLAGS;
      awo[i].pVal = (void *)WEBREQUEST_NOWAITCONN;
      i++;
      

      // test forcenew, uncomment this section to try multiple simultaneous
      // "forced" new connections. Forced new connections are not kept alive
      // unless they are the first forced new connection to a host
#ifdef TEST_FORCENEWCONN
      awo[i].nId  = WEBOPT_FLAGS;
      awo[i].pVal = (void *)WEBREQUEST_FORCENEWCONN;
      i++;
#endif 

#ifdef TEST_USER_AGENT
      // turn off HTTP over HTTP proxying
      awo[i].nId  = WEBOPT_PROXYSPEC;
      awo[i].pVal = (void *)"http:///";
      i++;

      // turn on ALL proxying.  Proxyspecs are examined in WebOpt
      // order, so in this list, with the above and below PROXYSPECs,
      // everything except HTTP will be proxied through
      // http://webproxy.yourdomain.com:8080, (which you'll have to
      // set up to test, sorry
      awo[i].nId  = WEBOPT_PROXYSPEC;
      awo[i].pVal = (void *)"*:///http://webproxy.yourdomain.com:8080";
      i++;
#endif

      // Marks the end of the array of WebOpts
      awo[i].nId  = WEBOPT_END;
      
      // Add Options
      IWEB_AddOpt(pMe->m_pIWeb,awo);
   }

   	pMe->m_BodyBuffer = NULL;
	pMe->m_BodySize = 0;
	pMe->m_BodyAllocSize = 0;
    // if there have been no failures up to this point then return success
    return TRUE;
}

// this function is called when your application is exiting
void myiweb_FreeAppData(myiweb* pMe)
{
    // insert your code here for freeing any resources you have allocated...
	
	if( pMe->m_pIMenu )
	{
		IMENUCTL_Release(pMe->m_pIMenu);
		pMe->m_pIMenu = NULL;
	}
	if(pMe->m_pIStatic)
	{
		ISTATIC_Release(pMe->m_pIStatic);
		pMe->m_pIStatic = NULL;
	}

	if(pMe->m_pHTMLViewer)
	{
		IHTMLVIEWER_SetNotifyFn(pMe->m_pHTMLViewer, NULL, pMe);
		IHTMLVIEWER_Release(pMe->m_pHTMLViewer);
		pMe->m_pHTMLViewer = NULL;
	}
	if(pMe->m_pIWeb)
	{
		IWEB_Release(pMe->m_pIWeb);
		pMe->m_pIWeb = NULL;
	}
}
static void  myiweb_ShowMenu(myiweb* pMe)
{	
	CtlAddItem  ai;
	if (! pMe->m_pIMenu)
		ISHELL_CreateInstance(pMe->pIShell, AEECLSID_MENUCTL, (void **)&pMe->m_pIMenu) ;
	
	IMENUCTL_SetTitle(pMe->m_pIMenu,MYIWEB_RES_FILE,IDS_TITLE,NULL);

	ai.pText = NULL;
	ai.pImage = NULL;
	ai.pszResImage = MYIWEB_RES_FILE;
	ai.pszResText = MYIWEB_RES_FILE;
	ai.wFont = AEE_FONT_NORMAL;
	ai.dwData = NULL;
	
	ai.wText = IDS_WCONNECT;   
	ai.wImage = IDB_MENU;
	ai.wItemID = IDS_WCONNECT;
	
	
	// Add the item to the menu control
	if(IMENUCTL_AddItemEx(pMe->m_pIMenu, &ai )==FALSE)
	{
		IMENUCTL_Release(pMe->m_pIMenu);
		return;
	}
	
	ai.wText = IDS_FILE_MGR;
	ai.wItemID = IDS_FILE_MGR;
	
	// Add the item to the menu control
	IMENUCTL_AddItemEx( pMe->m_pIMenu, &ai );

	ai.wText = IDS_FAVOURITE;
	ai.wItemID = IDS_FAVOURITE;
	
	// Add the item to the menu control
	IMENUCTL_AddItemEx( pMe->m_pIMenu, &ai );

	ai.wText = IDS_ABOUT;
	ai.wItemID = IDS_ABOUT;
	
	// Add the item to the menu control
	IMENUCTL_AddItemEx( pMe->m_pIMenu, &ai );
	
	IMENUCTL_SetActive(pMe->m_pIMenu,TRUE);
	pMe->m_iAppStatus = 0;
}
static void	 myiweb_DisplayInfo(myiweb* pMe,AECHAR* pInfo)
{
		AEERect rct;
	
	if(!pMe->m_pIStatic)
		ISHELL_CreateInstance(pMe->pIShell, AEECLSID_STATIC, (void **)&pMe->m_pIStatic);
	SETAEERECT(&rct, 16, 16, pMe->DeviceInfo.cxScreen-32, pMe->DeviceInfo.cyScreen-32);
	ISTATIC_SetRect(pMe->m_pIStatic, &rct);
	ISTATIC_SetText(pMe->m_pIStatic, NULL,pInfo, AEE_FONT_BOLD, AEE_FONT_NORMAL);
	ISTATIC_Redraw(pMe->m_pIStatic);
}
static void myiwebhtml_NotifyCB( void* pvUser, HViewNotify* pNotify )
{
   myiweb* pMe = (myiweb*) pvUser;   

   switch( pNotify->code )
   {

   case HVN_REDRAW_SCREEN:
      IDISPLAY_ClearScreen(pMe->a.m_pIDisplay);
      IHTMLVIEWER_Redraw(pMe->m_pHTMLViewer);
      break;

   case HVN_JUMP:
   case HVN_SUBMIT:
	   STRCPY(pMe->targetUrl,TEST_HOST);
	   pMe->m_pszFileName = (char*)MALLOC(16);
	   FIND_STRING(pNotify->u.jump.pszURL, "PIC")
	   {
			STRCAT(pMe->targetUrl,pNotify->u.jump.pszURL+4);
			STRCPY(pMe->m_pszFileName,pNotify->u.jump.pszURL+4);
			pMe->m_iMediaType = 1;
	   }
	   FIND_STRING(pNotify->u.jump.pszURL, "MUSIC")
	   {
		   STRCAT(pMe->targetUrl,pNotify->u.jump.pszURL+6);
		   STRCPY(pMe->m_pszFileName,pNotify->u.jump.pszURL+6);
		   pMe->m_iMediaType = 2;
	   }
	 //  IHTMLVIEWER_SetNotifyFn(pMe->m_pHTMLViewer, NULL, pMe);
	   myiweb_Stop(pMe);
		myiweb_Start(pMe,pMe->targetUrl,1);

      break;

   case HVN_DONE:
      IHTMLVIEWER_SetRect(pMe->m_pHTMLViewer, &pMe->m_rc);
      IHTMLVIEWER_Redraw( pMe->m_pHTMLViewer );
      break;

   }
}
static void myiweb_Start(myiweb *pMe, char *pszUrl,int iPage)
{
   ISourceUtil *pisu;
	pMe->m_iAppStatus = 1;
   // look to see if there's POST data, this is totally non-standard, but 
   // easy to put into tests
   pMe->pszPostData = STRCHR(pszUrl, 1);
   
   // if there's post data, construct a stream for IWeb to consume
   if ((char *)0 != pMe->pszPostData) 
   {
      *pMe->pszPostData = 0;
      if (SUCCESS == ISHELL_CreateInstance(pMe->a.m_pIShell,AEECLSID_SOURCEUTIL, (void **)&pisu)) 
	  {
         
         ISOURCEUTIL_PeekFromMemory(pisu, pMe->pszPostData + 1, 
                                    STRLEN(pMe->pszPostData + 1), 0, 0,
                                    &pMe->pipPostData);
         ISOURCEUTIL_Release(pisu);
      }
   }

   // initialize the callback, where I'll be called when the request
   // completes
   if(iPage == 0)
   {
	   CALLBACK_Cancel(&pMe->cb);
	   CALLBACK_Init(&pMe->cb, myiweb_GotResp, pMe);
   }else if(iPage ==1)
   {
	   CALLBACK_Cancel(&pMe->cb);
	   CALLBACK_Init(&pMe->cb, myiweb_DownloadFile, pMe);
   }
   pMe->uStart = GETUPTIMEMS();
   // start transaction, pass callbacks for web status, web headers
   // the extra WEBOPT_HEADER is used to help test what's sent 
   // (snoop.sh above shows all the headers)
   if(!pMe->m_pIWeb)
	   ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_WEB, (void**)(&pMe->m_pIWeb));
   if ((IPeek *)0 != pMe->pipPostData) {
      IWEB_GetResponse(pMe->m_pIWeb,
                       (pMe->m_pIWeb, &pMe->piWResp, &pMe->cb, pszUrl, 
                        WEBOPT_HANDLERDATA, pMe,
                        WEBOPT_HEADER, "X-Method: POST\r\n", /* for kicks */
                        WEBOPT_HEADERHANDLER, myiweb_Header, 
                        WEBOPT_STATUSHANDLER, myiweb_Status, 
                        WEBOPT_METHOD, "POST",
                        WEBOPT_BODY, pMe->pipPostData,
                        WEBOPT_CONTENTLENGTH, STRLEN(pMe->pszPostData + 1),
                        WEBOPT_END));
   } else {
      IWEB_GetResponse(pMe->m_pIWeb,
                       (pMe->m_pIWeb, &pMe->piWResp, &pMe->cb, pszUrl, 
                        WEBOPT_HANDLERDATA, pMe, 
                        WEBOPT_HEADER, "X-Method: GET \r\n",
                        WEBOPT_HEADERHANDLER, myiweb_Header, 
                        WEBOPT_STATUSHANDLER, myiweb_Status, 
                        WEBOPT_END));
   }
}

static void myiweb_GotResp(void *p)
{
	myiweb *pwa = (myiweb *)p;
	
	WebRespInfo *pwri;
	
	// get information about how the web transaction went
	// pwa->piWResp is ***NEVER NULL***, even though the transaction may fail

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -