Gdi+显示问题
在窗口中显示png无法成功,代码如下
#include "StdAfx.h"
#include "images.h"
images::images(void)
{
init();
}
images::images(HWND parent):
baseControl(parent)
{
init();
}
images::~images(void)
{
}
void images::init()
{
mImagePath = _T("2.png");
HINSTANCE hInst = AfxGetInstanceHandle();
WNDCLASS wndclass; //窗体类
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hbrBackground = (HBRUSH)GetStockObject( WHITE_BRUSH );
wndclass.hCursor = LoadCursor( 0, IDC_HAND );
wndclass.hIcon = LoadIcon( 0, IDI_INFORMATION );
wndclass.hInstance = AfxGetInstanceHandle();
wndclass.lpfnWndProc = MyWindowProc;
wndclass.lpszClassName = TEXT("hg");
wndclass.lpszMenuName = NULL;
wndclass.style = CS_HREDRAW | CS_VREDRAW ; // 指定窗体风格
//注册类
if (!RegisterClass( &wndclass ) )
{
ShowLog(Priority::WARN, "image window class register error.");
}
//创建窗体
mHwnd = CreateWindow( TEXT("hg"), TEXT("Helloworldhhh"), WS_CHILD, 0, 0, 300, 600, mParentWindow,NULL,AfxGetInstanceHandle(), NULL );
if ( !mHwnd)
{
DWORD lastError = GetLastError();
ShowLog(Priority::WARN, "image window create error, error code : %d.", lastError);
}
}
LRESULT CALLBACK images::MyWindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
images *image = reinterpret_cast<images *>(wParam);
PAINTSTRUCT ps;
HDC hdc;
switch(uMsg)
{
case WM_CONTROL_SHOW:
if (image)
{
ShowLog(Priority::NOTICE, "image wm_control_show.");
image->Show();
}
break;
case WM_PAINT:
{
ShowLog(Priority::NOTICE, "image wm_paint.");
if (image)
{
image->Show();
RedrawWindow(hwnd,NULL,NULL,RDW_INVALIDATE | RDW_UPDATENOW);
}
else
{
hdc = BeginPaint(hwnd, &ps);
EndPaint(hwnd, &ps);
//return DefWindowProc( hwnd, uMsg, wParam, lParam );
}
}
break;
default:
return DefWindowProc( hwnd, uMsg, wParam, lParam );
}
return 0;
}
void images::Show()
{
PAINTSTRUCT ps; // 点结构
HDC hdc; // DC句柄
hdc = BeginPaint (mHwnd , &ps); // 获得DC句柄,开始绘制,其中hWnd为窗口句柄
RECT rc;
GetClientRect(mHwnd,&rc);
Graphics graphics( hdc);
Image image(mImagePath.c_str(), FALSE);
graphics.DrawImage(&image, 0, 0, rc.right, rc.bottom); //绘制背景
EndPaint(mHwnd, &ps) ; // 绘制结束
ShowLog(Priority::NOTICE, "Image Show Finish.");
}
#include "StdAfx.h"
#include "images.h"
images::images(void)
{
init();
}
images::images(HWND parent):
baseControl(parent)
{
init();
}
images::~images(void)
{
}
void images::init()
{
mImagePath = _T("2.png");
HINSTANCE hInst = AfxGetInstanceHandle();
WNDCLASS wndclass; //窗体类
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hbrBackground = (HBRUSH)GetStockObject( WHITE_BRUSH );
wndclass.hCursor = LoadCursor( 0, IDC_HAND );
wndclass.hIcon = LoadIcon( 0, IDI_INFORMATION );
wndclass.hInstance = AfxGetInstanceHandle();
wndclass.lpfnWndProc = MyWindowProc;
wndclass.lpszClassName = TEXT("hg");
wndclass.lpszMenuName = NULL;
wndclass.style = CS_HREDRAW | CS_VREDRAW ; // 指定窗体风格
//注册类
if (!RegisterClass( &wndclass ) )
{
ShowLog(Priority::WARN, "image window class register error.");
}
//创建窗体
mHwnd = CreateWindow( TEXT("hg"), TEXT("Helloworldhhh"), WS_CHILD, 0, 0, 300, 600, mParentWindow,NULL,AfxGetInstanceHandle(), NULL );
if ( !mHwnd)
{
DWORD lastError = GetLastError();
ShowLog(Priority::WARN, "image window create error, error code : %d.", lastError);
}
}
LRESULT CALLBACK images::MyWindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
images *image = reinterpret_cast<images *>(wParam);
PAINTSTRUCT ps;
HDC hdc;
switch(uMsg)
{
case WM_CONTROL_SHOW:
if (image)
{
ShowLog(Priority::NOTICE, "image wm_control_show.");
image->Show();
}
break;
case WM_PAINT:
{
ShowLog(Priority::NOTICE, "image wm_paint.");
if (image)
{
image->Show();
RedrawWindow(hwnd,NULL,NULL,RDW_INVALIDATE | RDW_UPDATENOW);
}
else
{
hdc = BeginPaint(hwnd, &ps);
EndPaint(hwnd, &ps);
//return DefWindowProc( hwnd, uMsg, wParam, lParam );
}
}
break;
default:
return DefWindowProc( hwnd, uMsg, wParam, lParam );
}
return 0;
}
void images::Show()
{
PAINTSTRUCT ps; // 点结构
HDC hdc; // DC句柄
hdc = BeginPaint (mHwnd , &ps); // 获得DC句柄,开始绘制,其中hWnd为窗口句柄
RECT rc;
GetClientRect(mHwnd,&rc);
Graphics graphics( hdc);
Image image(mImagePath.c_str(), FALSE);
graphics.DrawImage(&image, 0, 0, rc.right, rc.bottom); //绘制背景
EndPaint(mHwnd, &ps) ; // 绘制结束
ShowLog(Priority::NOTICE, "Image Show Finish.");
}
...全文
相关推荐
GDI +双缓冲助手类
模板化的帮助程序类,用于执行GDI +初始化/反初始化,并负责双缓冲/缓存
VB.NET将使用GDI转换坐标系(矩阵镜像后),让文字正常显示,为正的方法
该代码示意了,在使用VB.NET的GDI的坐标系矩阵镜像后,如何将镜像后反显示的文字,正常显示的过程,使文字正常显示
GDI与GDI+图像显示处理
做YUV播放器时在网上收集到的一些MFC+GDI图像显示的文档和例子。其中涉及窗口重绘时图像重绘的问题,还有图像显示的双缓冲技术等等!还是比较全面的!另外还有窗口尺寸发生改变,窗口控件的变化问题!
vc_GDI+显示PNG图片
vc_GDI+显示PNG图片.doc
GDI+在窗口中显示图片
工程内容为;对话框内显示图片。方法很简单,可以把它用到实际当中。GDI+网上的资料真的不多,但是会以后,用起来很方便。


其它技术问题
