c++builder记录:[去掉滚动条][打开网页][屏蔽右击]

来源:互联网 发布:windows离线补丁包 编辑:程序博客网 时间:2024/05/20 06:54

去掉WebBrowser的滚动条:

或者在HTML页面里面加上CSS:html,body{overflow-x: hidden;overflow-y: hidden;}

void __fastcall TForm1::Button1Click(TObject *Sender){    // 打开馊糊网    CppWebBrowser1->Navigate(WideString("sohu.com"));}//---------------------------------------------------------------------------//void __fastcall TForm1::Button2Click(TObject *Sender){    // 打开抠抠网    CppWebBrowser1->Navigate(WideString("qq.com"));}//---------------------------------------------------------------------------void __fastcall TForm1::CppWebBrowser1DocumentComplete(TObject *Sender,      LPDISPATCH pDisp, Variant *URL){    // 等打开完毕后隐藏浏览器滚动条    Variant vObj = CppWebBrowser1->OleObject;    Variant vBody;    String strDocCompatMode = vObj.OlePropertyGet("document").OlePropertyGet("compatMode");    if (SameText(strDocCompatMode, "CSS1Compat"))        vBody = vObj.OlePropertyGet("Document").OlePropertyGet("documentElement");    else        vBody = vObj.OlePropertyGet("Document").OlePropertyGet("body");    vBody.OlePropertyGet("style").OlePropertySet("overflow", "hidden");}

打开网页:

WebBrowser->Navigate2(TVariant("http://www.xxxxx.com"), NULL, NULL, NULL, NULL);WebBrowser->Height=425;WebBrowser->Width=620;


//屏蔽WebBrowser右击
Application-> OnMessage=AEMessage;

/**************************************************************** 输入: tagMsg Msg** 输出:Bool Handled** 功能描述: ApplicationEvents OnMessge  /蔽WebBrowser右击****************************************************************/void __fastcall TForm2::AEMessage(tagMSG &Msg, bool &Handled) {  const _KeyPressMask = 0x80000000;  if (Msg.message == WM_KEYDOWN) {    if ( ((Msg.lParam & _KeyPressMask) == 0) && ((GetKeyState(VK_CONTROL) < 0) && (Msg.wParam == 0x4E)) ) {      Handled = true;    }  }  if (Msg.message == WM_NCRBUTTONDBLCLK ||      Msg.message == WM_NCRBUTTONDOWN ||      Msg.message == WM_RBUTTONDOWN ||      Msg.message == WM_RBUTTONDBLCLK ||      Msg.message == WM_CONTEXTMENU) {    if (IsChild(WebBrowser->Handle, Msg.hwnd)) {      Handled = true;    }  }}