打印html网页,是否打印页眉页脚

打印html网页,是否打印页眉页脚










                                                        



           

BOOL Print_html(const char *sURL) 

{
 HRESULT hr;  
 CLSID clsid;  
 IUnknown     *pUnknown = NULL;  
 IWebBrowser2 *pWebBrowser2 = NULL;  
 IOleCommandTarget* pCommandTarget = NULL;  
 IDispatch *pDispatch = NULL;  
 VARIANT va;  
 OLECHAR sOleChar[MAX_PATH];  
 CoInitialize(NULL);  
 CLSIDFromProgID(L"InternetExplorer.Application", &clsid);  
 hr = CoCreateInstance(clsid, NULL, CLSCTX_ALL, IID_IUnknown, (void  **)&pUnknown);
 if (SUCCEEDED(hr))  
 {
  hr = pUnknown->QueryInterface(IID_IWebBrowser2, (void **)&pWebBrowser2);  
  if (SUCCEEDED(hr))
  {  
   //pWebBrowser2->put_Visible(TRUE);  
   VariantInit(&va);  
   va.vt = VT_I4;  
   va.lVal = 0;  
   MultiByteToWideChar(CP_ACP, 0, sURL, -1, sOleChar, sizeof sOleChar);  
   BSTR bstrURL = SysAllocString(sOleChar);  
   hr = pWebBrowser2->Navigate(bstrURL, &va, &va, &va, &va);  
   SysFreeString (bstrURL);  
   hr = pWebBrowser2->get_Document(&pDispatch);  
   if (SUCCEEDED(hr))  
   {  
    hr =  pDispatch->QueryInterface(IID_IOleCommandTarget,(void**)&pCommandTarget);  
    if (SUCCEEDED(hr))  
    {  
     hr = pCommandTarget->Exec(NULL, OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER, NULL, NULL);
     Sleep(2000);  
     pCommandTarget->Release();  
    }  
    else  
    {  
     pDispatch->Release();  
     pWebBrowser2->Release();  
     pUnknown->Release();  
     CoUninitialize();  
     return FALSE;
    }  
    pDispatch->Release();  
   }  
   else
   {  
    pWebBrowser2->Release();  
    pUnknown->Release();  
    CoUninitialize();  
    return FALSE;
   }  
   pWebBrowser2->Release();  
  }
  else
  {
   pUnknown->Release();  
   CoUninitialize();  
   return FALSE;
  }  
  pUnknown->Release();  
 }  
 else
 {
  CoUninitialize();  
  return FALSE;
 }
 CoUninitialize();  
 return TRUE;
}
//是否打印页眉、页脚
//i_sign: 0-打印
//    1-不打印
BOOL Print_header_footer(int i_sign)
{
 char lp_header[KEY_LEN];
 char lp_footer[KEY_LEN];
 char *str_keyname = "Software\\Microsoft\\Internet Explorer\\PageSetup\\";
 HKEY hKey;
 int err;
 if(RegOpenKeyEx(HKEY_CURRENT_USER,str_keyname,0,KEY_WRITE,&hKey) != ERROR_SUCCESS)
 {
  err = GetLastError();
  return FALSE;
 }
 if(i_sign == 0)
 {
  memset(lp_header,0,sizeof(lp_header));
  memset(lp_footer,0,sizeof(lp_footer));
  strcpy(lp_header,"&w&b页码,&p/&P"); //"&w&b页码,&p/&P";
  strcpy(lp_footer,"&u&b&d");    //"&u&b&d";

  if(RegSetValueEx(hKey, "header", 0, REG_SZ, (const unsigned char *)lp_header, strlen(lp_header))!=ERROR_SUCCESS)
  {
   RegCloseKey(hKey);
   return FALSE;
  }
  if(RegSetValueEx(hKey, "footer", 0, REG_SZ, (const unsigned char *)lp_footer, strlen(lp_footer))!=ERROR_SUCCESS)
  {
   RegCloseKey(hKey);
   return FALSE;
  }
  RegCloseKey(hKey);
  return TRUE;
 }
 if(i_sign == 1)
 {
  memset(lp_header,0,sizeof(lp_header));
  memset(lp_footer,0,sizeof(lp_footer));

  if(RegSetValueEx(hKey, "header", 0, REG_SZ, (const unsigned char *)lp_header, strlen(lp_header))!=ERROR_SUCCESS)
  {
   RegCloseKey(hKey);
   return FALSE;
  }
  if(RegSetValueEx(hKey, "footer", 0, REG_SZ, (const unsigned char *)lp_footer, strlen(lp_footer))!=ERROR_SUCCESS)
  {
   RegCloseKey(hKey);
   return FALSE;
  }
  RegCloseKey(hKey);
  return TRUE;
 }

 return TRUE;
}

http://hi.baidu.com/iceflyingcity/item/53bbb10f716054c12e4c6b98

你可能感兴趣的:(打印html网页,是否打印页眉页脚)