如何在win32中使用visual studio c拉伸背景图像
how to stretch a background image in win32 using visual studio c
我试图用c++在Win32 api中创建一个应用程序,我想让它在没有任何栏的情况下全屏,我成功了,但我在背景图像中仍然有问题。图像是重复的,但我希望它被拉伸。你知道吗?代码的下面部分:
int WINAPI WinMain (HINSTANCE cetteInstance, HINSTANCE precedenteInstance,
LPSTR lignesDeCommande, int modeDAffichage)
{
HWND fenetrePrincipale;
MSG message;
WNDCLASS classeFenetre;
instance = cetteInstance;
classeFenetre.style = 0;
classeFenetre.lpfnWndProc = procedureFenetrePrincipale;
classeFenetre.cbClsExtra = 0;
classeFenetre.cbWndExtra = 0;
classeFenetre.hInstance = NULL;
classeFenetre.hIcon = LoadIcon(NULL, MAKEINTRESOURCE(IDI_APPLICATION));
classeFenetre.hCursor = LoadCursor(NULL, IDC_ARROW);
// classeFenetre.hbrBackground = (HBRUSH)(1 + COLOR_BTNFACE);
//classeFenetre.hbrBackground = CreatePatternBrush(LoadBitmap( instance, MAKEINTRESOURCE("imagesImage1.bmp" ) ) );
HBITMAP hbmp = LoadBitmap(instance,MAKEINTRESOURCE(IDB_BITMAP1));
if(NULL == hbmp)
{
MessageBox(NULL,L"BitMap Loading Failed.",L"Error",MB_ICONEXCLAMATION | MB_OK);
}
else
{
HBRUSH hbr = CreatePatternBrush(hbmp);
if(NULL == hbr)
{
MessageBox(NULL,L"Brush Creation Failed.",L"Error",MB_ICONEXCLAMATION | MB_OK);
}
else
{
//StretchBlt();
HDC hdcMem = GetDC (NULL) ;
HDC wndHDC = GetDC (fenetrePrincipale) ;
StretchBlt(hdcMem, 0, 0, 800, 600, wndHDC, 0, 0, 1280, 1024, SRCCOPY);
classeFenetre.hbrBackground = hbr ;
}
}
classeFenetre.lpszMenuName = NULL;
classeFenetre.lpszClassName = L"classeF";
//fullscreen mode and delete minimize and max buttons
// On prévoit quand même le cas où ça échoue
if(!RegisterClass(&classeFenetre)) return FALSE;
//WS_OVERLAPPEDWINDOW
fenetrePrincipale = CreateWindow(L"classeF", L"Ma premiere fenetre winAPI !",WS_MAXIMIZE|WS_POPUP ,
CW_USEDEFAULT, CW_USEDEFAULT, 800, 630,
NULL,
NULL,//LoadMenu(instance, L"ID_MENU"),
cetteInstance,
NULL);
if (!fenetrePrincipale) return FALSE;
//ShowWindow(fenetrePrincipale, modeDAffichage);
ShowWindow(fenetrePrincipale,SW_MAXIMIZE);
UpdateWindow(fenetrePrincipale);
while (GetMessage(&message, NULL, 0, 0))
{
TranslateMessage(&message);
DispatchMessage(&message);
}
return message.wParam;
}
谢谢
您没有显示确切的代码,但看起来您加载了一个位图,从中创建了一个画笔,然后将该画笔设置为窗口的画笔。笔刷确实会导致你报告的重复图像行为。要获得拉伸位图,您可以跳过任何与笔刷相关的代码。相反,处理发送到窗口的WM_ERASEBKGND
消息。在其中,调用StretchBlt
将您的位图绘制到窗口的客户端区域。要绘制的HDC
在消息的wParam
参数中给出。
步骤1、创建窗口
2,设置twindowpos将你的窗口放在所有窗口和全屏的顶部
在你的windows的windowprocess句柄WM_PAINT消息
4、加载位图 5、使用CreateCompatibleDC创建内存dc 通过调用SelectObject 将位图选择到内存dc中7、对实际dc执行StretchBlt,使用准备好的内存dc作为源,您应该知道位图的实际宽度和高度,以便进行适当的拉伸相关文章:
- 将图像从 Android Studio 发送到 CPP
- (C++)(Visual Studio) 将高斯模糊滤镜应用于 RGB 中的灰度图像
- Qt Creator 在从 Visual Studio 2015 迁移后未显示 Qlabel 的边框图像
- 如何在Visual Studio中使用ITK配置的C 读取图像
- 加载图像约500次后,此错误显示在Visual Studio Qimage:不记忆,返回空图像
- 如何保持我在 Visual Studio SDL 中编写的图像窗口处于打开状态
- MS Visual Studio 2012和OpenCV 2.4.5-未显示图像
- Visual Studio不使用SDL渲染图像
- 线程加载图像的速度更快,直到它们在Studio中消失
- 在visual Studio 2012上使用SDL加载.BMP图像时,它只显示一个帧
- 如何计算图像的间距Visual studio
- 如果我在Visual Studio项目中将图像作为资源包含在内,这些图像是否会编译到可执行文件中
- 使用DevIL和Visual Studio 2010加载图像时出现问题
- 如何使用Visual studio将OpenCV图像查看窗口推送到QT GUI中
- 在visual studio 2010中使用c++将彩色图像转换为灰度
- Visual Studio 2010调试器可视化Qt图像类型
- 从visual studio IDE运行时,项目无法加载图像资源
- 如何将c++ (Visual Studio 2010)链接到图像输出事件监听器
- Visual Studio with OpenCV:即使程序退出,我也能保持图像窗口打开吗
- Visual Studio 2012 Express - 图像不会被编译/复制