JBTALKS.CC
标题:
关于C++ MFC 加载网页问题(附代码)
[打印本页]
作者:
Jacker
时间:
2010-12-14 11:23 AM
标题:
关于C++ MFC 加载网页问题(附代码)
请问为什么我在VC++ MFC 建立一个图片然后再建立一个区域显示网页,当网页显示flash会出现一直闪的情况,不过这个情况是在一些电脑,某一些电脑没出现这个问题,经过测试 window XP 没问题,window 7 (64bit) 和 window vista ,window 7 32bit 某些电脑会出现这个问题,我问了很多人都答不了我,有些说是 双缓冲 关系 但是我是用 IE控件 API 不是已经自带了吗?
一下代码
// tttttDlg.cpp : 实现文件
//
#include "stdafx.h"
#include "ttttt.h"
#include "tttttDlg.h"
#include <winuser.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// 用于应用程序“关于”菜单项的 CAboutDlg 对话框
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// 对话框数据
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
// 实现
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()
// CtttttDlg 对话框
CtttttDlg::CtttttDlg(CWnd* pParent /*=NULL*/)
: CDialog(CtttttDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CtttttDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_EXPLORER1, myiebrowser);
}
BEGIN_MESSAGE_MAP(CtttttDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
HDC g_backgroundhdc;
HDC g_CloseButtonhdc;
HBITMAP g_hbkBmp ;
BITMAP g_Buttombi;
int g_iButtomPosX = 1010;
int g_iButtomPosY = 280;
CRect ButtomCloseRect;
CDC* dcMain;
CDC dcCanvas;
CBrush ctlBrush( RGB( 255,0,255 ) );
CBitmap bmpCanvas; // 画布位图
static int IELEFT = 165;
static int IETOP = 330;
int IEW = 848;
int IEH = 140000;
// CtttttDlg 消息处理程序
BOOL CtttttDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 将\“关于...\”菜单项添加到系统菜单中。
// IDM_ABOUTBOX 必须在系统命令范围内。
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
// 执行此操作
SetIcon(m_hIcon, TRUE); // 设置大图标
SetIcon(m_hIcon, FALSE); // 设置小图标
// TODO: 在此添加额外的初始化代码
CBitmap bmp;
if(bmp.LoadBitmap(IDB_BITMAP1))
{
HRGN rgn;
rgn = BitmapToRegion((HBITMAP)bmp, RGB(255,255, 0), RGB(0, 0, 0));
SetWindowRgn(rgn, TRUE);
bmp.DeleteObject();
}
myiebrowser.SetWindowPos( NULL, IELEFT, IETOP, IEW+ IELEFT, IEH + IETOP, 0 );
myiebrowser.ShowWindow( SW_NORMAL );
myiebrowser.Navigate( "http://www.163.com", 0, 0, 0, 0 );
dcMain = GetDC();
dcMain->SelectObject( GetFont() );
//dcMain->SelectObject( GetStockObject( HOLLOW_BRUSH ) );
dcMain->SelectObject( ctlBrush );
dcMain->SetBkColor( RGB(255, 0, 255) );
HWND hWnd = GetSafeHwnd();
#define WS_EX_LAYERED 0x00080000
HWND hAlpha = hWnd;//CreateDialog( AfxGetInstanceHandle(), MAKEINTRESOURCE( IDD_DHTML_FORM ), hWnd, AlphaProc );
g_backgroundhdc = CreateCompatibleDC(0);
CBitmap bmp2;
bmp2.LoadBitmap(IDB_BITMAP1);
HBITMAP hbmp = (HBITMAP)bmp2.GetSafeHandle();//LoadImage(0, "2.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
SelectObject(g_backgroundhdc, hbmp );
g_CloseButtonhdc = CreateCompatibleDC(0);
//g_hbkBmp = (HBITMAP)LoadImage(0, "mini.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
//SelectObject(g_CloseButtonhdc, g_hbkBmp );
CBitmap bmpCloseButton;
bmpCloseButton.LoadBitmap(IDB_CLOSE);
SelectObject(g_CloseButtonhdc, (HBITMAP)bmpCloseButton.GetSafeHandle() );
::GetObject( (HBITMAP)bmpCloseButton.GetSafeHandle(), sizeof(BITMAP), &g_Buttombi);
COLORREF first = GetPixel(g_CloseButtonhdc,0,0);
for(int ix = 0 ; ix < g_Buttombi.bmWidth ; ix++)
{
for(int iy = 0 ; iy < g_Buttombi.bmWidth ; iy++)
{
COLORREF tmp = GetPixel(g_CloseButtonhdc,ix,iy);
if(tmp != first)
SetPixel(g_backgroundhdc,g_iButtomPosX+ix,g_iButtomPosY+iy,tmp);
}
}
HDC MiniButtonhdc = CreateCompatibleDC(0);
CBitmap bmpMiniButton;
bmpMiniButton.LoadBitmap(IDB_MINI);
//g_hbkBmp = (HBITMAP)LoadImage(0, "close.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
// SelectObject(MiniButtonhdc, (HBITMAP)g_hbkBmp );
SelectObject(MiniButtonhdc, (HBITMAP)bmpMiniButton.GetSafeHandle() );
::GetObject( (HBITMAP)bmpMiniButton.GetSafeHandle(), sizeof(BITMAP), &g_Buttombi);
first = GetPixel(MiniButtonhdc,0,0);
for(int ix = 0 ; ix < g_Buttombi.bmWidth ; ix++)
{
for(int iy = 0 ; iy < g_Buttombi.bmWidth ; iy++)
{
COLORREF tmp = GetPixel(MiniButtonhdc,ix,iy);
if(tmp != first)
SetPixel(g_backgroundhdc,g_iButtomPosX+ix -50,g_iButtomPosY+iy,tmp);
}
}
ButtomCloseRect.left = g_iButtomPosX;
ButtomCloseRect.right = ButtomCloseRect.left + g_Buttombi.bmWidth;
ButtomCloseRect.top = g_iButtomPosY;
ButtomCloseRect.bottom = ButtomCloseRect.top + g_Buttombi.bmHeight;
return TRUE; // 除非设置了控件的焦点,否则返回 TRUE
}
void CtttttDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// 如果向对话框添加最小化按钮,则需要下面的代码
// 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
// 这将由框架自动完成。
void CtttttDlg::OnPaint()
{
if (1)
{
CPaintDC dc(this); // 用于绘制的设备上下文
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// 使图标在工作矩形中居中
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
static int ttx = 0;
static int tty = 0;
BitBlt( dc,0,0, 1224, 900,g_backgroundhdc, ttx, tty, SRCCOPY );
//BitBlt( dc,150,100, 1224, 900,g_CloseButtonhdc, 0, 0, SRCCOPY );
//dcMain->BitBlt( 0,0, 316, 126,&dcCanvas, 0, 0, SRCCOPY );
//RECT fd;
//fd.left =fd.top = 50;
//fd.right =fd.bottom = 400;
//dc.DrawText("DDDDD",4,&fd,DT_CENTER);
// 绘制图标
//dc.DrawIcon(x, y, m_hIcon);
CDialog::OnPaint();
}
else
{
CDialog::OnPaint();
}
}
//BOOL CUpdateDlg::OnMsgComing( UINT message, WPARAM wParam, LPARAM lParam )
LRESULT CtttttDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_LBUTTONDOWN:
{
CRect minibuttom = ButtomCloseRect;
minibuttom.left -= 50;
minibuttom.right -= 50;
CPoint pt( LOWORD( lParam ), HIWORD( lParam ) );
if ( ::PtInRect( &ButtomCloseRect, pt ) )
{
theApp.CWinThread::GetMainWnd()->DestroyWindow();
}
else if ( ::PtInRect( &minibuttom, pt ) )
{
ShowWindow(SW_SHOWMINIMIZED);
}else
SendMessage(WM_SYSCOMMAND,0xf012,0);
}
break;
default:
break;
}
return CDialog::WindowProc( message, wParam, lParam );
}
复制代码
作者:
Jacker
时间:
2010-12-14 11:24 AM
//当用户拖动最小化窗口时系统调用此函数取得光标显示。
HCURSOR CtttttDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
HRGN CtttttDlg::BitmapToRegion(HBITMAP hBmp, COLORREF cTransparentColor, COLORREF cTolerance)
{
HRGN hRgn = NULL;
if (hBmp)
{
HDC hMemDC = CreateCompatibleDC(NULL);
if (hMemDC)
{
BITMAP bm;
GetObject(hBmp, sizeof(bm), &bm);
//创建一个32位色的位图,并选进内存设备环境
BITMAPINFOHEADER RGB32BITSBITMAPINFO = {
sizeof(BITMAPINFOHEADER), // biSize
bm.bmWidth, // biWidth;
bm.bmHeight, // biHeight;
1, // biPlanes;
32, // biBitCount
BI_RGB, // biCompression;
0, // biSizeImage;
0, // biXPelsPerMeter;
0, // biYPelsPerMeter;
0, // biClrUsed;
0 // biClrImportant;
};
VOID * pbits32;
HBITMAP hbm32 = CreateDIBSection(hMemDC,(BITMAPINFO *)&RGB32BITSBITMAPINFO, DIB_RGB_COLORS, &pbits32, NULL, 0);
if (hbm32)
{
HBITMAP holdBmp = (HBITMAP)SelectObject(hMemDC, hbm32);
// Create a DC just to copy the bitmap into the memory DC
HDC hDC = CreateCompatibleDC(hMemDC);
if (hDC)
{
// Get how many bytes per row we have for the bitmap bits (rounded up to 32 bits)
BITMAP bm32;
GetObject(hbm32, sizeof(bm32), &bm32);
while (bm32.bmWidthBytes % 4)
bm32.bmWidthBytes++;
// Copy the bitmap into the memory DC
HBITMAP holdBmp = (HBITMAP)SelectObject(hDC, hBmp);
BitBlt(hMemDC, 0, 0, bm.bmWidth, bm.bmHeight, hDC, 0, 0, SRCCOPY);
// For better performances, we will use the ExtCreateRegion() function to create the
// region. This function take a RGNDATA structure on entry. We will add rectangles by
// amount of ALLOC_UNIT number in this structure.
#define ALLOC_UNIT 100
DWORD maxRects = ALLOC_UNIT;
HANDLE hData = GlobalAlloc(GMEM_MOVEABLE, sizeof(RGNDATAHEADER) + (sizeof(RECT) * maxRects));
RGNDATA *pData = (RGNDATA *)GlobalLock(hData);
pData->rdh.dwSize = sizeof(RGNDATAHEADER);
pData->rdh.iType = RDH_RECTANGLES;
pData->rdh.nCount = pData->rdh.nRgnSize = 0;
SetRect(&pData->rdh.rcBound, MAXLONG, MAXLONG, 0, 0);
// Keep on hand highest and lowest values for the "transparent" pixels
BYTE lr = GetRValue(cTransparentColor);
BYTE lg = GetGValue(cTransparentColor);
BYTE lb = GetBValue(cTransparentColor);
BYTE hr = min(0xff, lr + GetRValue(cTolerance));
BYTE hg = min(0xff, lg + GetGValue(cTolerance));
BYTE hb = min(0xff, lb + GetBValue(cTolerance));
// Scan each bitmap row from bottom to top (the bitmap is inverted vertically)
BYTE *p32 = (BYTE *)bm32.bmBits + (bm32.bmHeight - 1) * bm32.bmWidthBytes;
for (int y = 0; y < bm.bmHeight; y++)
{
// Scan each bitmap pixel from left to right
for (int x = 0; x < bm.bmWidth; x++)
{
// Search for a continuous range of "non transparent pixels"
int x0 = x;
LONG *p = (LONG *)p32 + x;
while (x < bm.bmWidth)
{
BYTE b = GetRValue(*p);
if (b >= lr && b <= hr)
{
b = GetGValue(*p);
if (b >= lg && b <= hg)
{
b = GetBValue(*p);
if (b >= lb && b <= hb)
// This pixel is "transparent"
break;
}
}
p++;
x++;
}
if (x > x0)
{
// Add the pixels (x0, y) to (x, y+1) as a new rectangle in the region
if (pData->rdh.nCount >= maxRects)
{
GlobalUnlock(hData);
maxRects += ALLOC_UNIT;
hData = GlobalReAlloc(hData, sizeof(RGNDATAHEADER) + (sizeof(RECT) * maxRects), GMEM_MOVEABLE);
pData = (RGNDATA *)GlobalLock(hData);
}
RECT *pr = (RECT *)&pData->Buffer;
SetRect(&pr[pData->rdh.nCount], x0, y, x, y+1);
if (x0 < pData->rdh.rcBound.left)
pData->rdh.rcBound.left = x0;
if (y < pData->rdh.rcBound.top)
pData->rdh.rcBound.top = y;
if (x > pData->rdh.rcBound.right)
pData->rdh.rcBound.right = x;
if (y+1 > pData->rdh.rcBound.bottom)
pData->rdh.rcBound.bottom = y+1;
pData->rdh.nCount++;
// On Windows98, ExtCreateRegion() may fail if the number of rectangles is too
// large (ie: > 4000). Therefore, we have to create the region by multiple steps.
if (pData->rdh.nCount == 2000)
{
HRGN h = ExtCreateRegion(NULL, sizeof(RGNDATAHEADER) + (sizeof(RECT) * maxRects), pData);
if (hRgn)
{
CombineRgn(hRgn, hRgn, h, RGN_OR);
DeleteObject(h);
}
else
hRgn = h;
pData->rdh.nCount = 0;
SetRect(&pData->rdh.rcBound, MAXLONG, MAXLONG, 0, 0);
}
}
}
// Go to next row (remember, the bitmap is inverted vertically)
p32 -= bm32.bmWidthBytes;
}
// Create or extend the region with the remaining rectangles
HRGN h = ExtCreateRegion(NULL, sizeof(RGNDATAHEADER) + (sizeof(RECT) * maxRects), pData);
if (hRgn)
{
CombineRgn(hRgn, hRgn, h, RGN_OR);
DeleteObject(h);
}
else
hRgn = h;
// Clean up
GlobalFree(hData);
SelectObject(hDC, holdBmp);
DeleteDC(hDC);
}
DeleteObject(SelectObject(hMemDC, holdBmp));
}
DeleteDC(hMemDC);
}
}
return hRgn;
}
复制代码
欢迎光临 JBTALKS.CC (https://jbtalks.my/)
Powered by Discuz! X2.5