16,473
社区成员
发帖
与我相关
我的任务
分享
Image image(L"bk.png", TRUE); //GDI+中的类
int w = image.GetWidth();
int h = image.GetHeight();
int t = graph.DrawImage(&image, 0,0, 267,160);大小,否则会失真
MoveWindow(rct.left,rct.top, 267,160); //设置窗体大小和图片大小一致,无边框的对话框
//得到 w = 267 h = 154 t=0
BOOL CTestApp::InitInstance()
{
AfxEnableControlContainer();
IsSupportGDIPlus();
GdiplusStartupInput gdiplusStartupInput;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
……
}
BOOL CTestDlg::OnInitDialog()
{
CDialog::OnInitDialog();
……
// TODO: Add extra initialization here
//初始化GDI+.
m_Blend.BlendOp=0; //theonlyBlendOpdefinedinWindows2000
m_Blend.BlendFlags=0; //nothingelseisspecial...
m_Blend.AlphaFormat=1; //...
m_Blend.SourceConstantAlpha=255;//AC_SRC_ALPHA
//窗体样式为0x80000为层级窗体
DWORD dwExStyle=GetWindowLong(m_hWnd,GWL_EXSTYLE);
SetWindowLong(m_hWnd,GWL_EXSTYLE,dwExStyle^0x80000);
//绘制内存位图
//HDC hdcTemp=GetDC()->m_hDC;
CDC* pDC = GetDC();
//m_hdcMemory=CreateCompatibleDC(hdcTemp);
m_hdcMemory=CreateCompatibleDC(pDC->m_hDC);
//HBITMAP hBitMap=CreateCompatibleBitmap(hdcTemp,500,500);
HBITMAP hBitMap=CreateCompatibleBitmap(pDC->m_hDC, 500,500);
SelectObject(m_hdcMemory, hBitMap);
::DeleteObject(hBitMap);
//::DeleteDC(hdcTemp);
ReleaseDC(pDC);
//使用GDI+载入PNG图片
HDC hdcScreen=::GetDC(m_hWnd);
RECT rct;
GetWindowRect(&rct);
POINT ptWinPos={rct.left, rct.top};
Graphics graph(m_hdcMemory); //GDI+中的类
Image image(L"bk.png", TRUE); //GDI+中的类
graph.DrawImage(&image, 0,0, 267,160); //后面两个参数要设置成跟图片一样大小,否则会失真
MoveWindow(rct.left,rct.top, 267,160); //设置窗体大小和图片大小一致,无边框的对话框
//使用UpdateLayerWindow进行窗口透明处理
HMODULE hFuncInst=LoadLibrary("User32.DLL");
typedef BOOL (WINAPI *MYFUNC)(HWND, HDC, POINT*, SIZE*, HDC, POINT*, COLORREF, BLENDFUNCTION*, DWORD);
MYFUNC UpdateLayeredWindow;
UpdateLayeredWindow=(MYFUNC)GetProcAddress(hFuncInst, "UpdateLayeredWindow");
SIZE sizeWindow={267, 160};
POINT ptSrc={0, 0};
UpdateLayeredWindow( m_hWnd, hdcScreen, &ptWinPos, &sizeWindow, m_hdcMemory, &ptSrc, 0, &m_Blend, 2);
GetWindowRect(&m_oldRect); //记录窗体初始化大小的位置
::ReleaseDC(m_hWnd, hdcScreen);
::FreeLibrary(hFuncInst);
return TRUE; // return TRUE unless you set the focus to a control
}
// 这里开始要注意
Image image(L"bk.png", TRUE); //GDI+中的类