Facebook Sharer
选择您要替换的背景颜色:
【农历新年】背景图片:
个性化设定
 注册  找回密码
查看: 828|回复: 1
打印 上一主题 下一主题

关于C++ MFC 加载网页问题(附代码)

[复制链接]

8

主题

0

好友

11

积分

初级会员

Rank: 1

跳转到指定楼层
1#
发表于 2010-12-14 11:23 AM |只看该作者 |倒序浏览
请问为什么我在VC++ MFC 建立一个图片然后再建立一个区域显示网页,当网页显示flash会出现一直闪的情况,不过这个情况是在一些电脑,某一些电脑没出现这个问题,经过测试 window XP 没问题,window 7 (64bit) 和 window vista ,window 7 32bit 某些电脑会出现这个问题,我问了很多人都答不了我,有些说是 双缓冲 关系 但是我是用 IE控件 API 不是已经自带了吗?

一下代码
  1. // tttttDlg.cpp : 实现文件
  2. //
  3. #include "stdafx.h"
  4. #include "ttttt.h"
  5. #include "tttttDlg.h"
  6. #include <winuser.h>
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #endif

  10. // 用于应用程序“关于”菜单项的 CAboutDlg 对话框

  11. class CAboutDlg : public CDialog
  12. {
  13. public:
  14.         CAboutDlg();

  15. // 对话框数据
  16.         enum { IDD = IDD_ABOUTBOX };

  17.         protected:
  18.         virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持

  19. // 实现
  20. protected:
  21.         DECLARE_MESSAGE_MAP()
  22. };

  23. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  24. {
  25. }

  26. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  27. {
  28.         CDialog::DoDataExchange(pDX);
  29. }

  30. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  31. END_MESSAGE_MAP()


  32. // CtttttDlg 对话框



  33. CtttttDlg::CtttttDlg(CWnd* pParent /*=NULL*/)
  34.         : CDialog(CtttttDlg::IDD, pParent)
  35. {
  36.         m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  37. }

  38. void CtttttDlg::DoDataExchange(CDataExchange* pDX)
  39. {
  40.         CDialog::DoDataExchange(pDX);

  41.         DDX_Control(pDX, IDC_EXPLORER1, myiebrowser);
  42. }

  43. BEGIN_MESSAGE_MAP(CtttttDlg, CDialog)
  44.         ON_WM_SYSCOMMAND()
  45.         ON_WM_PAINT()
  46.         ON_WM_QUERYDRAGICON()
  47.         //}}AFX_MSG_MAP
  48. END_MESSAGE_MAP()
  49. HDC g_backgroundhdc;
  50. HDC g_CloseButtonhdc;

  51. HBITMAP         g_hbkBmp ;
  52.                 BITMAP g_Buttombi;
  53. int g_iButtomPosX = 1010;
  54. int g_iButtomPosY = 280;
  55. CRect ButtomCloseRect;


  56. CDC* dcMain;
  57. CDC dcCanvas;
  58. CBrush                ctlBrush( RGB( 255,0,255 ) );
  59. CBitmap         bmpCanvas;      // 画布位图
  60.         static int IELEFT = 165;
  61.         static int IETOP = 330;
  62.         int IEW = 848;
  63.         int IEH = 140000;
  64. // CtttttDlg 消息处理程序

  65. BOOL CtttttDlg::OnInitDialog()
  66. {
  67.         CDialog::OnInitDialog();

  68.         // 将\“关于...\”菜单项添加到系统菜单中。

  69.         // IDM_ABOUTBOX 必须在系统命令范围内。
  70.         ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  71.         ASSERT(IDM_ABOUTBOX < 0xF000);

  72.         CMenu* pSysMenu = GetSystemMenu(FALSE);
  73.         if (pSysMenu != NULL)
  74.         {
  75.                 CString strAboutMenu;
  76.                 strAboutMenu.LoadString(IDS_ABOUTBOX);
  77.                 if (!strAboutMenu.IsEmpty())
  78.                 {
  79.                         pSysMenu->AppendMenu(MF_SEPARATOR);
  80.                         pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  81.                 }
  82.         }

  83.         // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
  84.         //  执行此操作
  85.         SetIcon(m_hIcon, TRUE);                        // 设置大图标
  86.         SetIcon(m_hIcon, FALSE);                // 设置小图标

  87.         // TODO: 在此添加额外的初始化代码
  88.         CBitmap bmp;   
  89.     if(bmp.LoadBitmap(IDB_BITMAP1))
  90.     {
  91.         HRGN rgn;
  92.         rgn = BitmapToRegion((HBITMAP)bmp, RGB(255,255, 0), RGB(0, 0, 0));
  93.         SetWindowRgn(rgn, TRUE);
  94.         bmp.DeleteObject();
  95.     }   

  96.         myiebrowser.SetWindowPos( NULL, IELEFT, IETOP, IEW+ IELEFT, IEH + IETOP, 0 );
  97.     myiebrowser.ShowWindow( SW_NORMAL );
  98.         myiebrowser.Navigate( "http://www.163.com", 0, 0, 0, 0 );



  99.     dcMain = GetDC();
  100.     dcMain->SelectObject( GetFont() );
  101.     //dcMain->SelectObject( GetStockObject( HOLLOW_BRUSH ) );
  102.         dcMain->SelectObject( ctlBrush );
  103.     dcMain->SetBkColor( RGB(255, 0, 255) );
  104.                 HWND hWnd = GetSafeHwnd();
  105. #define WS_EX_LAYERED           0x00080000
  106.         HWND hAlpha = hWnd;//CreateDialog( AfxGetInstanceHandle(), MAKEINTRESOURCE( IDD_DHTML_FORM ), hWnd, AlphaProc );

  107.         g_backgroundhdc = CreateCompatibleDC(0);

  108.         CBitmap bmp2;   
  109.     bmp2.LoadBitmap(IDB_BITMAP1);
  110.         HBITMAP hbmp = (HBITMAP)bmp2.GetSafeHandle();//LoadImage(0, "2.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
  111.         SelectObject(g_backgroundhdc, hbmp );

  112.         g_CloseButtonhdc = CreateCompatibleDC(0);
  113.        
  114.         //g_hbkBmp = (HBITMAP)LoadImage(0, "mini.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
  115.        
  116.         //SelectObject(g_CloseButtonhdc, g_hbkBmp );
  117.         CBitmap bmpCloseButton;   
  118.         bmpCloseButton.LoadBitmap(IDB_CLOSE);

  119.         SelectObject(g_CloseButtonhdc, (HBITMAP)bmpCloseButton.GetSafeHandle() );

  120.         ::GetObject( (HBITMAP)bmpCloseButton.GetSafeHandle(), sizeof(BITMAP), &g_Buttombi);

  121.                 COLORREF first = GetPixel(g_CloseButtonhdc,0,0);
  122.                 for(int ix = 0 ; ix < g_Buttombi.bmWidth ; ix++)
  123.                 {
  124.                         for(int iy = 0 ; iy < g_Buttombi.bmWidth ; iy++)
  125.                         {
  126.                                 COLORREF tmp = GetPixel(g_CloseButtonhdc,ix,iy);
  127.                                 if(tmp != first)
  128.                                         SetPixel(g_backgroundhdc,g_iButtomPosX+ix,g_iButtomPosY+iy,tmp);
  129.                         }
  130.                 }



  131.                 HDC        MiniButtonhdc = CreateCompatibleDC(0);
  132.                 CBitmap bmpMiniButton;   
  133.     bmpMiniButton.LoadBitmap(IDB_MINI);

  134.         //g_hbkBmp = (HBITMAP)LoadImage(0, "close.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
  135.         //        SelectObject(MiniButtonhdc, (HBITMAP)g_hbkBmp );
  136.         SelectObject(MiniButtonhdc, (HBITMAP)bmpMiniButton.GetSafeHandle() );

  137.         ::GetObject( (HBITMAP)bmpMiniButton.GetSafeHandle(), sizeof(BITMAP), &g_Buttombi);

  138.                  first = GetPixel(MiniButtonhdc,0,0);
  139.                 for(int ix = 0 ; ix < g_Buttombi.bmWidth ; ix++)
  140.                 {
  141.                         for(int iy = 0 ; iy < g_Buttombi.bmWidth ; iy++)
  142.                         {
  143.                                 COLORREF tmp = GetPixel(MiniButtonhdc,ix,iy);
  144.                                 if(tmp != first)
  145.                                         SetPixel(g_backgroundhdc,g_iButtomPosX+ix -50,g_iButtomPosY+iy,tmp);
  146.                         }
  147.                 }


  148. ButtomCloseRect.left = g_iButtomPosX;
  149. ButtomCloseRect.right = ButtomCloseRect.left + g_Buttombi.bmWidth;
  150. ButtomCloseRect.top = g_iButtomPosY;
  151. ButtomCloseRect.bottom =  ButtomCloseRect.top  + g_Buttombi.bmHeight;




  152.         return TRUE;  // 除非设置了控件的焦点,否则返回 TRUE
  153. }

  154. void CtttttDlg::OnSysCommand(UINT nID, LPARAM lParam)
  155. {
  156.         if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  157.         {
  158.                 CAboutDlg dlgAbout;
  159.                 dlgAbout.DoModal();
  160.         }
  161.         else
  162.         {
  163.                 CDialog::OnSysCommand(nID, lParam);
  164.         }
  165. }

  166. // 如果向对话框添加最小化按钮,则需要下面的代码
  167. //  来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
  168. //  这将由框架自动完成。

  169. void CtttttDlg::OnPaint()
  170. {
  171.         if (1)
  172.         {
  173.                 CPaintDC dc(this); // 用于绘制的设备上下文

  174.                 SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

  175.                 // 使图标在工作矩形中居中
  176.                 int cxIcon = GetSystemMetrics(SM_CXICON);
  177.                 int cyIcon = GetSystemMetrics(SM_CYICON);
  178.                 CRect rect;
  179.                 GetClientRect(&rect);
  180.                 int x = (rect.Width() - cxIcon + 1) / 2;
  181.                 int y = (rect.Height() - cyIcon + 1) / 2;
  182.                 static int ttx = 0;
  183.                 static int tty = 0;
  184.                 BitBlt( dc,0,0, 1224, 900,g_backgroundhdc, ttx, tty, SRCCOPY );

  185.                 //BitBlt( dc,150,100, 1224, 900,g_CloseButtonhdc, 0, 0, SRCCOPY );



  186.                
  187. //dcMain->BitBlt(  0,0, 316, 126,&dcCanvas, 0, 0, SRCCOPY );
  188. //RECT fd;
  189. //fd.left =fd.top = 50;
  190. //fd.right =fd.bottom = 400;
  191. //dc.DrawText("DDDDD",4,&fd,DT_CENTER);
  192.                 // 绘制图标
  193.                 //dc.DrawIcon(x, y, m_hIcon);
  194.                 CDialog::OnPaint();
  195.         }
  196.         else
  197.         {
  198.                 CDialog::OnPaint();
  199.         }
  200. }

  201. //BOOL CUpdateDlg::OnMsgComing( UINT message, WPARAM wParam, LPARAM lParam )
  202. LRESULT CtttttDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
  203. {
  204.         switch(message)
  205.         {
  206.         case WM_LBUTTONDOWN:
  207.                 {

  208.                            
  209. CRect minibuttom = ButtomCloseRect;
  210. minibuttom.left -= 50;
  211. minibuttom.right -= 50;
  212.             CPoint pt( LOWORD( lParam ), HIWORD( lParam ) );

  213.             if ( ::PtInRect( &ButtomCloseRect, pt ) )
  214.             {
  215.                 theApp.CWinThread::GetMainWnd()->DestroyWindow();
  216.             }
  217.                         else  if ( ::PtInRect( &minibuttom, pt ) )
  218.             {
  219.                 ShowWindow(SW_SHOWMINIMIZED);
  220.             }else
  221.                                  SendMessage(WM_SYSCOMMAND,0xf012,0);
  222.                 }
  223.                 break;
  224.         default:
  225.                 break;
  226.         }
  227. return CDialog::WindowProc( message, wParam, lParam );
  228. }
复制代码




收藏收藏0

8

主题

0

好友

11

积分

初级会员

Rank: 1

2#
发表于 2010-12-14 11:24 AM |只看该作者
  1. //当用户拖动最小化窗口时系统调用此函数取得光标显示。
  2. HCURSOR CtttttDlg::OnQueryDragIcon()
  3. {
  4.         return static_cast<HCURSOR>(m_hIcon);
  5. }
  6. HRGN CtttttDlg::BitmapToRegion(HBITMAP hBmp, COLORREF cTransparentColor, COLORREF cTolerance)
  7. {
  8.     HRGN hRgn = NULL;
  9.    
  10.     if (hBmp)
  11.     {
  12.         HDC hMemDC = CreateCompatibleDC(NULL);
  13.         if (hMemDC)
  14.         {
  15.             BITMAP bm;
  16.             GetObject(hBmp, sizeof(bm), &bm);
  17.             
  18.             //创建一个32位色的位图,并选进内存设备环境
  19.             BITMAPINFOHEADER RGB32BITSBITMAPINFO = {
  20.                         sizeof(BITMAPINFOHEADER),        // biSize
  21.                             bm.bmWidth,                    // biWidth;
  22.                             bm.bmHeight,                // biHeight;
  23.                             1,                            // biPlanes;
  24.                             32,                            // biBitCount
  25.                             BI_RGB,                        // biCompression;
  26.                             0,                            // biSizeImage;
  27.                             0,                            // biXPelsPerMeter;
  28.                             0,                            // biYPelsPerMeter;
  29.                             0,                            // biClrUsed;
  30.                             0                            // biClrImportant;
  31.                                                     };
  32.             VOID * pbits32;
  33.             HBITMAP hbm32 = CreateDIBSection(hMemDC,(BITMAPINFO *)&RGB32BITSBITMAPINFO, DIB_RGB_COLORS, &pbits32, NULL, 0);
  34.             if (hbm32)
  35.             {
  36.                 HBITMAP holdBmp = (HBITMAP)SelectObject(hMemDC, hbm32);
  37.                
  38.                 // Create a DC just to copy the bitmap into the memory DC
  39.                 HDC hDC = CreateCompatibleDC(hMemDC);
  40.                 if (hDC)
  41.                 {
  42.                     // Get how many bytes per row we have for the bitmap bits (rounded up to 32 bits)
  43.                     BITMAP bm32;
  44.                     GetObject(hbm32, sizeof(bm32), &bm32);
  45.                     while (bm32.bmWidthBytes % 4)
  46.                         bm32.bmWidthBytes++;
  47.                     
  48.                     // Copy the bitmap into the memory DC
  49.                     HBITMAP holdBmp = (HBITMAP)SelectObject(hDC, hBmp);
  50.                     BitBlt(hMemDC, 0, 0, bm.bmWidth, bm.bmHeight, hDC, 0, 0, SRCCOPY);
  51.                     
  52.                     // For better performances, we will use the ExtCreateRegion() function to create the
  53.                     // region. This function take a RGNDATA structure on entry. We will add rectangles by
  54.                     // amount of ALLOC_UNIT number in this structure.
  55. #define ALLOC_UNIT    100
  56.                     DWORD maxRects = ALLOC_UNIT;
  57.                     HANDLE hData = GlobalAlloc(GMEM_MOVEABLE, sizeof(RGNDATAHEADER) + (sizeof(RECT) * maxRects));
  58.                     RGNDATA *pData = (RGNDATA *)GlobalLock(hData);
  59.                     pData->rdh.dwSize = sizeof(RGNDATAHEADER);
  60.                     pData->rdh.iType = RDH_RECTANGLES;
  61.                     pData->rdh.nCount = pData->rdh.nRgnSize = 0;
  62.                     SetRect(&pData->rdh.rcBound, MAXLONG, MAXLONG, 0, 0);
  63.                     
  64.                     // Keep on hand highest and lowest values for the "transparent" pixels
  65.                     BYTE lr = GetRValue(cTransparentColor);
  66.                     BYTE lg = GetGValue(cTransparentColor);
  67.                     BYTE lb = GetBValue(cTransparentColor);
  68.                     BYTE hr = min(0xff, lr + GetRValue(cTolerance));
  69.                     BYTE hg = min(0xff, lg + GetGValue(cTolerance));
  70.                     BYTE hb = min(0xff, lb + GetBValue(cTolerance));
  71.                     
  72.                     // Scan each bitmap row from bottom to top (the bitmap is inverted vertically)
  73.                     BYTE *p32 = (BYTE *)bm32.bmBits + (bm32.bmHeight - 1) * bm32.bmWidthBytes;
  74.                     for (int y = 0; y < bm.bmHeight; y++)
  75.                     {
  76.                         // Scan each bitmap pixel from left to right
  77.                         for (int x = 0; x < bm.bmWidth; x++)
  78.                         {
  79.                             // Search for a continuous range of "non transparent pixels"
  80.                             int x0 = x;
  81.                             LONG *p = (LONG *)p32 + x;
  82.                             while (x < bm.bmWidth)
  83.                             {
  84.                                 BYTE b = GetRValue(*p);
  85.                                 if (b >= lr && b <= hr)
  86.                                 {
  87.                                     b = GetGValue(*p);
  88.                                     if (b >= lg && b <= hg)
  89.                                     {
  90.                                         b = GetBValue(*p);
  91.                                         if (b >= lb && b <= hb)
  92.                                             // This pixel is "transparent"
  93.                                             break;
  94.                                     }
  95.                                 }
  96.                                 p++;
  97.                                 x++;
  98.                             }
  99.                            
  100.                             if (x > x0)
  101.                             {
  102.                                 // Add the pixels (x0, y) to (x, y+1) as a new rectangle in the region
  103.                                 if (pData->rdh.nCount >= maxRects)
  104.                                 {
  105.                                     GlobalUnlock(hData);
  106.                                     maxRects += ALLOC_UNIT;
  107.                                     hData = GlobalReAlloc(hData, sizeof(RGNDATAHEADER) + (sizeof(RECT) * maxRects), GMEM_MOVEABLE);
  108.                                     pData = (RGNDATA *)GlobalLock(hData);
  109.                                 }
  110.                                 RECT *pr = (RECT *)&pData->Buffer;
  111.                                 SetRect(&pr[pData->rdh.nCount], x0, y, x, y+1);
  112.                                 if (x0 < pData->rdh.rcBound.left)
  113.                                     pData->rdh.rcBound.left = x0;
  114.                                 if (y < pData->rdh.rcBound.top)
  115.                                     pData->rdh.rcBound.top = y;
  116.                                 if (x > pData->rdh.rcBound.right)
  117.                                     pData->rdh.rcBound.right = x;
  118.                                 if (y+1 > pData->rdh.rcBound.bottom)
  119.                                     pData->rdh.rcBound.bottom = y+1;
  120.                                 pData->rdh.nCount++;
  121.                                 
  122.                                 // On Windows98, ExtCreateRegion() may fail if the number of rectangles is too
  123.                                 // large (ie: > 4000). Therefore, we have to create the region by multiple steps.
  124.                                 if (pData->rdh.nCount == 2000)
  125.                                 {
  126.                                     HRGN h = ExtCreateRegion(NULL, sizeof(RGNDATAHEADER) + (sizeof(RECT) * maxRects), pData);
  127.                                     if (hRgn)
  128.                                     {
  129.                                         CombineRgn(hRgn, hRgn, h, RGN_OR);
  130.                                         DeleteObject(h);
  131.                                     }
  132.                                     else
  133.                                         hRgn = h;
  134.                                     pData->rdh.nCount = 0;
  135.                                     SetRect(&pData->rdh.rcBound, MAXLONG, MAXLONG, 0, 0);
  136.                                 }
  137.                             }
  138.                         }
  139.                         
  140.                         // Go to next row (remember, the bitmap is inverted vertically)
  141.                         p32 -= bm32.bmWidthBytes;
  142.                     }
  143.                     
  144.                     // Create or extend the region with the remaining rectangles
  145.                     HRGN h = ExtCreateRegion(NULL, sizeof(RGNDATAHEADER) + (sizeof(RECT) * maxRects), pData);
  146.                     if (hRgn)
  147.                     {
  148.                         CombineRgn(hRgn, hRgn, h, RGN_OR);
  149.                         DeleteObject(h);
  150.                     }
  151.                     else
  152.                         hRgn = h;
  153.                     
  154.                     // Clean up
  155.                     GlobalFree(hData);
  156.                     SelectObject(hDC, holdBmp);
  157.                     DeleteDC(hDC);
  158.                 }               
  159.                 DeleteObject(SelectObject(hMemDC, holdBmp));
  160.             }            
  161.             DeleteDC(hMemDC);
  162.         }
  163.     }   
  164.     return hRgn;   
  165. }
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

JBTALKS.CC |联系我们 |隐私政策 |Share

GMT+8, 2024-6-26 07:40 PM , Processed in 0.090449 second(s), 26 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

Ultra High-performance Dedicated Server powered by iCore Technology Sdn. Bhd.
Domain Registration | Web Hosting | Email Hosting | Forum Hosting | ECShop Hosting | Dedicated Server | Colocation Services
本论坛言论纯属发表者个人意见,与本论坛立场无关
Copyright © 2003-2012 JBTALKS.CC All Rights Reserved
合作联盟网站:
JBTALKS 马来西亚中文论坛 | JBTALKS我的空间 | ICORE TECHNOLOGY SDN. BHD.
回顶部