C++ win32图形用户界面c++。bmp图像未显示
我实际上是在学习一个教程。我真的很想得到一个答案,因为我需要在下面的窗口中添加图标。让图像显示在窗口中是第一步 抱歉,由于某些原因,我添加的更新以前没有通过。我的解决方案面向Unicode 更正后的更新文件如下:C++ win32图形用户界面c++。bmp图像未显示,c++,winapi,bitmap,bmp,win32com,C++,Winapi,Bitmap,Bmp,Win32com,我实际上是在学习一个教程。我真的很想得到一个答案,因为我需要在下面的窗口中添加图标。让图像显示在窗口中是第一步 抱歉,由于某些原因,我添加的更新以前没有通过。我的解决方案面向Unicode 更正后的更新文件如下: #include <windows.h> #include <commctrl.h> using namespace std; LPCWSTR szClassName = L"myWindowClass"; HWND hLogo; HBITMAP hLog
#include <windows.h>
#include <commctrl.h>
using namespace std;
LPCWSTR szClassName = L"myWindowClass";
HWND hLogo;
HBITMAP hLogoImage;
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
void loadPictures();
void parentControls(HWND);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int icmdshow)
{
HWND hWnd;
WNDCLASSW wc = { 0 };
wc.style = 0;
wc.lpszMenuName = NULL;
wc.lpszClassName = szClassName;
wc.lpfnWndProc = WndProc;
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wc.hInstance = hInstance;
wc.hIcon = LoadIconW(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursorW(NULL, IDC_ARROW);
wc.cbWndExtra = 0;
wc.cbClsExtra = 0;
if (!RegisterClassW(&wc))
{
const wchar_t Error01[] = L"Register Issue To Check On : "; /// Notice this
const wchar_t Error01_Caption[] = L"Error 01";
MessageBoxW(NULL, Error01, Error01_Caption, MB_OK | MB_ICONERROR);
return 0;
}
LPCWSTR parentWinTitle = L"My Window";
hWnd = CreateWindowW(szClassName, parentWinTitle, WS_OVERLAPPEDWINDOW | WS_VISIBLE, 100, 100, 250, 200, NULL, NULL, NULL, NULL);
if (hWnd == NULL)
{
const wchar_t Error02[] = L"Window Creation Issue To Check On : ";
const wchar_t Error02_Caption[] = L"Window Creation Issue To Check On : ";
MessageBoxW(NULL, Error02, Error02_Caption, MB_OK | MB_ICONERROR);
}
ShowWindow(hWnd, icmdshow);
UpdateWindow(hWnd);
MSG msg = { 0 };
while (GetMessageW(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
return 0;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
loadPictures(); /// Must be called first, Calling the Images function in Create
parentControls(hWnd);
break;
/* case WM_COMMAND:
switch (wParam)
{
}
break;
*/
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProcW(hWnd, message, wParam, lParam);
}
return 0;
}
void parentControls(HWND hWnd)
{
hLogo = CreateWindowW(WC_STATICW, NULL, WS_VISIBLE | WS_CHILD | SS_BITMAP, 70, 25, 100, 100, hWnd, NULL, NULL, NULL);
SendMessageW(hLogo, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hLogoImage);
}
void loadPictures()
{ /// bmp image save in file with main.cpp
LPCWSTR myBmp = L"bitmap1.bmp";
hLogoImage = (HBITMAP)LoadImageW(NULL, myBmp, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
}
#包括
#包括
使用名称空间std;
LPCWSTR szClassName=L“myWindowClass”;
HWND hLogo;
HBITMAP-hLogoImage;
LRESULT回调WndProc(HWND、UINT、WPARAM、LPARAM);
无效加载图片();
无效家长控制(HWND);
int WINAPI WinMain(HINSTANCE HINSTANCE、HINSTANCE hPrevInstance、PSTR szCmdLine、int icmdshow)
{
HWND-HWND;
WNDCLASSW wc={0};
wc.style=0;
wc.lpszMenuName=NULL;
wc.lpszClassName=szClassName;
wc.lpfnWndProc=WndProc;
wc.hbrBackground=(HBRUSH)(彩色窗口+1);
wc.hInstance=hInstance;
wc.hIcon=LoadIconW(空,IDI_应用程序);
wc.hCursor=LoadCursorW(空,IDC_箭头);
wc.cbWndExtra=0;
wc.cbClsExtra=0;
如果(!RegisterClassW(&wc))
{
const wchar_t Error01[]=L“要检查的寄存器问题:;///注意这一点
const wchar_t Error 01_Caption[]=L“Error 01”;
MessageBoxW(NULL,Error01,Error01_标题,MB_OK | MB_图标错误);
返回0;
}
LPCWSTR parentWinTitle=L“我的窗口”;
hWnd=CreateWindowW(szClassName,parentWinTitle,WS|u OVERLAPPEDWINDOW | WS|u VISIBLE,100100250200,NULL,NULL,NULL,NULL);
if(hWnd==NULL)
{
const wchar_t Error02[]=L“要检查的窗口创建问题:”;
const wchar_t Error02_Caption[]=L“要检查的窗口创建问题:”;
MessageBoxW(NULL,Error02,Error02_标题,MB_OK | MB_图标错误);
}
显示窗口(hWnd、icmdshow);
更新窗口(hWnd);
MSG={0};
while(GetMessageW(&msg,NULL,0,0))
{
翻译信息(&msg);
DispatchMessageW(&msg);
}
返回0;
}
LRESULT回调WndProc(HWND HWND,UINT消息,WPARAM WPARAM,LPARAM LPARAM)
{
开关(信息)
{
案例WM_创建:
必须首先调用loadPictures();//,调用Create中的Images函数
家长控制(hWnd);
打破
/*case WM_命令:
交换机(wParam)
{
}
打破
*/
案例WM_销毁:
PostQuitMessage(0);
打破
违约:
返回DefWindowProcW(hWnd、message、wParam、lParam);
}
返回0;
}
无效父控件(HWND HWND)
{
hLogo=CreateWindowW(WC_STATICW,NULL,WS_可见| WS_CHILD | SS_位图,70,25,100,100,hWnd,NULL,NULL,NULL);
SendMessageW(hLogo、STM_SETIMAGE、IMAGE_位图、(LPARAM)hlogimage);
}
void loadPictures()
{///bmp图像用main.cpp保存在文件中
LPCWSTR myBmp=L“bitmap1.bmp”;
hLogoImage=(HBITMAP)LoadImageW(NULL,myBmp,图像\u位图,0,0,LR\u LOADFROMFILE);
}
有人告诉我答案应该在这里,而不是在上面更新。我相信如果我把它加在这里,我会意识到这是错误的。我想这就是为什么我以前在上面的原始帖子中尝试更新时,更新没有被采纳的原因。无论哪种方式,更新/答案如下
#include <windows.h>
#include <commctrl.h>
using namespace std;
LPCWSTR szClassName = L"myWindowClass";
HWND hLogo;
HBITMAP hLogoImage;
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
void loadPictures();
void parentControls(HWND);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int icmdshow)
{
HWND hWnd;
WNDCLASSW wc = { 0 };
wc.style = 0;
wc.lpszMenuName = NULL;
wc.lpszClassName = szClassName;
wc.lpfnWndProc = WndProc;
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wc.hInstance = hInstance;
wc.hIcon = LoadIconW(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursorW(NULL, IDC_ARROW);
wc.cbWndExtra = 0;
wc.cbClsExtra = 0;
if (!RegisterClassW(&wc))
{
const wchar_t Error01[] = L"Register Issue To Check On : "; /// Notice this
const wchar_t Error01_Caption[] = L"Error 01";
MessageBoxW(NULL, Error01, Error01_Caption, MB_OK | MB_ICONERROR);
return 0;
}
LPCWSTR parentWinTitle = L"My Window";
hWnd = CreateWindowW(szClassName, parentWinTitle, WS_OVERLAPPEDWINDOW | WS_VISIBLE, 100, 100, 250, 200, NULL, NULL, NULL, NULL);
if (hWnd == NULL)
{
const wchar_t Error02[] = L"Window Creation Issue To Check On : ";
const wchar_t Error02_Caption[] = L"Window Creation Issue To Check On : ";
MessageBoxW(0, Error02, Error02_Caption, MB_OK | MB_ICONERROR);
}
ShowWindow(hWnd, icmdshow);
UpdateWindow(hWnd);
MSG msg = { 0 };
while (GetMessageW(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
return 0;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
loadPictures(); /// Must be called first, Calling the Images function in Create
parentControls(hWnd);
break;
/* case WM_COMMAND:
switch (wParam)
{
}
break;
*/
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProcW(hWnd, message, wParam, lParam);
}
return 0;
}
void parentControls(HWND hWnd)
{
hLogo = CreateWindowW(WC_STATICW, NULL, WS_VISIBLE | WS_CHILD | SS_BITMAP, 70, 25, 100, 100, hWnd, NULL, NULL, NULL);
SendMessageW(hLogo, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hLogoImage);
}
void loadPictures()
{ /// bmp image save in file with main.cpp
LPCWSTR myBmp = L"bitmap1.bmp";
hLogoImage = (HBITMAP)LoadImageW(NULL, myBmp, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
}
#包括
#包括
使用名称空间std;
LPCWSTR szClassName=L“myWindowClass”;
HWND hLogo;
HBITMAP-hLogoImage;
LRESULT回调WndProc(HWND、UINT、WPARAM、LPARAM);
无效加载图片();
无效家长控制(HWND);
int WINAPI WinMain(HINSTANCE HINSTANCE、HINSTANCE hPrevInstance、PSTR szCmdLine、int icmdshow)
{
HWND-HWND;
WNDCLASSW wc={0};
wc.style=0;
wc.lpszMenuName=NULL;
wc.lpszClassName=szClassName;
wc.lpfnWndProc=WndProc;
wc.hbrBackground=(HBRUSH)(彩色窗口+1);
wc.hInstance=hInstance;
wc.hIcon=LoadIconW(空,IDI_应用程序);
wc.hCursor=LoadCursorW(空,IDC_箭头);
wc.cbWndExtra=0;
wc.cbClsExtra=0;
如果(!RegisterClassW(&wc))
{
const wchar_t Error01[]=L“要检查的寄存器问题:;///注意这一点
const wchar_t Error 01_Caption[]=L“Error 01”;
MessageBoxW(NULL,Error01,Error01_标题,MB_OK | MB_图标错误);
返回0;
}
LPCWSTR parentWinTitle=L“我的窗口”;
hWnd=CreateWindowW(szClassName,parentWinTitle,WS|u OVERLAPPEDWINDOW | WS|u VISIBLE,100100250200,NULL,NULL,NULL,NULL);
if(hWnd==NULL)
{
const wchar_t Error02[]=L“要检查的窗口创建问题:”;
const wchar_t Error02_Caption[]=L“要检查的窗口创建问题:”;
MessageBoxW(0,Error02,Error02_标题,MB_OK | MB_图标错误);
}
显示窗口(hWnd、icmdshow);
更新窗口(hWnd);
MSG={0};
while(GetMessageW(&msg,NULL,0,0))
{
翻译信息(&msg);
DispatchMessageW(&msg);
}
返回0;
}
LRESULT回调WndProc(HWND HWND,UINT消息,WPARAM WPARAM,LPARAM LPARAM)
{
开关(信息)
{
案例WM_创建:
必须首先调用loadPictures();//,调用Create中的Images函数
家长控制(hWnd);
打破
/*case WM_命令:
交换机(wParam)
{
}
打破
*/
案例WM_销毁:
PostQuitMessage(0);
打破
违约:
返回DefWindowProcW(hWnd、message、wParam、lParam);
}
返回0;
}
无效父控件(HWND HWND)
{
hLogo=CreateWindowW(WC_STATICW,NULL,WS_可见| WS_CHILD | SS_位图,70,25,100,100,hWnd,NULL,NULL,NULL);
SendMessageW(hLogo、STM_SETIMAGE、IMAGE_位图、(LPARAM)hlogimage);
}
void loadPictures()
{///bmp图像用main.cpp保存在文件中
LPCWSTR myBmp=L“bitmap1.bmp”;
hLogoImage=(HBITMAP)LoadImageW(NULL,myBmp,图像\u位图,0,0,LR\u LOADFROMFILE);
}
您没有检查返回值是否有错误,也没有进行任何调试。为什么不呢?你指的是我登记册的if声明吗。如果(!RegisterCla
case WM_CREATE:
loadPictures(); /// Calling the Images function in Create
parentControls(hWnd);
break;
#include <windows.h>
#include <commctrl.h>
using namespace std;
LPCWSTR szClassName = L"myWindowClass";
HWND hLogo;
HBITMAP hLogoImage;
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
void loadPictures();
void parentControls(HWND);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int icmdshow)
{
HWND hWnd;
WNDCLASSW wc = { 0 };
wc.style = 0;
wc.lpszMenuName = NULL;
wc.lpszClassName = szClassName;
wc.lpfnWndProc = WndProc;
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wc.hInstance = hInstance;
wc.hIcon = LoadIconW(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursorW(NULL, IDC_ARROW);
wc.cbWndExtra = 0;
wc.cbClsExtra = 0;
if (!RegisterClassW(&wc))
{
const wchar_t Error01[] = L"Register Issue To Check On : "; /// Notice this
const wchar_t Error01_Caption[] = L"Error 01";
MessageBoxW(NULL, Error01, Error01_Caption, MB_OK | MB_ICONERROR);
return 0;
}
LPCWSTR parentWinTitle = L"My Window";
hWnd = CreateWindowW(szClassName, parentWinTitle, WS_OVERLAPPEDWINDOW | WS_VISIBLE, 100, 100, 250, 200, NULL, NULL, NULL, NULL);
if (hWnd == NULL)
{
const wchar_t Error02[] = L"Window Creation Issue To Check On : ";
const wchar_t Error02_Caption[] = L"Window Creation Issue To Check On : ";
MessageBoxW(0, Error02, Error02_Caption, MB_OK | MB_ICONERROR);
}
ShowWindow(hWnd, icmdshow);
UpdateWindow(hWnd);
MSG msg = { 0 };
while (GetMessageW(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
return 0;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
loadPictures(); /// Must be called first, Calling the Images function in Create
parentControls(hWnd);
break;
/* case WM_COMMAND:
switch (wParam)
{
}
break;
*/
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProcW(hWnd, message, wParam, lParam);
}
return 0;
}
void parentControls(HWND hWnd)
{
hLogo = CreateWindowW(WC_STATICW, NULL, WS_VISIBLE | WS_CHILD | SS_BITMAP, 70, 25, 100, 100, hWnd, NULL, NULL, NULL);
SendMessageW(hLogo, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hLogoImage);
}
void loadPictures()
{ /// bmp image save in file with main.cpp
LPCWSTR myBmp = L"bitmap1.bmp";
hLogoImage = (HBITMAP)LoadImageW(NULL, myBmp, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
}