CreateWindowEx失败.我如何让我的窗口(与按钮)实际上一次弹出
Failed CreateWindowEx. How do I get my window (with the button) to actually pop up for once?
我只能假设这大部分工作,因为我不能通过CreateWindowEx检查。如果有人能仔细检查我所有的有趣按钮代码,那就太好了。
#include <windows.h>
#include <tchar.h> //I was told I needed this line but I don't believe I do.
#define ID_BTNENCRYPT 0
const char g_szClassName[] = "MyWindowClass";
HWND button;
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch(msg) { //Fun button stuff
case WM_CREATE: {
button = CreateWindow("button",
"Encrypt Message",
WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
450, 620, 200, 30,
hwnd, (HMENU) ID_BTNENCRYPT, GetModuleHandle(NULL), NULL);
break;
}
case WM_COMMAND: { //More fun button stuff
switch (LOWORD(wParam)){
case ID_BTNENCRYPT: {
::MessageBox(hwnd, "This will be your message once I get my $h!t together", "Encrypted Message", MB_OK);
}
}
break;
}
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
FreeConsole();
WNDCLASSEX wc;
HWND hwnd;
MSG Msg;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
wc.lpszMenuName = NULL;
wc.lpszClassName = g_szClassName;
if (!RegisterClassEx(&wc)) {
::MessageBox(NULL, "Window Registration Status: Hopelessly F***ed", "", MB_OK);
return 0;
} //No apparent error in Window Registration
这就是我需要帮助的地方
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
"Great Window",
WS_OVERLAPPEDWINDOW,
300, 300,
350, 350,
NULL, NULL, hInstance, NULL);
if (hwnd == NULL) {
::MessageBox(NULL,"Window Creation Status: Gone to $h!t", "", MB_OK);
}
我不幸得到错误消息,是的,我的窗口创建已经失败。
ShowWindow(hwnd, nCmdShow); //Just the end of my code from here on out.
UpdateWindow(hwnd); //Hopefully there aren't any fatal errors.
while(GetMessage(&Msg, NULL, 0, 0) > 0) {
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
您的WndProc()
没有返回未处理消息的DefWindowProc()
的返回值。有一个缺失的return
语句,所以你最终落到return 0
的所有消息。当WM_NCCREATE
返回0时,CreateWindowEx()
失败:
如果应用程序处理此消息,它应该返回TRUE以继续创建窗口。如果应用程序返回FALSE, CreateWindow或CreateWindowEx函数将返回NULL句柄。
你需要改变这个:
default:
DefWindowProc(hwnd, msg, wParam, lParam);
:
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
相关文章:
- 如何确保用户在一行上提示输入一次时输入名字和姓氏?
- 只需按一次按钮即可通过USB发送数据
- C++如何使用lambda表达式来捕获上一次迭代的值
- (C++)for循环中的空初始语句是否保存所有编译器中变量的上一次初始化
- 我应该只在免费商店上为一次调用创建对象吗?
- GoogleMock:如何保存参数,以便在模拟上的下一次调用中使用
- 为什么我的破坏者只称呼一次,而不是在删除(a)调用上
- 在功能静态变量上调用Setter一次
- C++ 和 SDL 一次在屏幕上显示的图像不能超过 3 张
- 在 Eclipse 上,有没有办法一次修改多个包含路径
- 仅在 CUDA 上修改设备内存一次
- 如何在C++中的while循环中存储上一次迭代
- Qt - 解决一个插槽上的两个顺序调用,并且仅执行一次操作
- 重复上一次输入两次
- 如何在 Windows11(x7) 上使用 EPM 一次将 64 个浏览器帮助程序对象 dll 注册到 IE7 中
- pthread_create()在Xeon Phi上每60个线程失败一次(参数无效)
- 调用从上一次执行中保存的函数指针会失败吗
- CreateWindowEx失败.我如何让我的窗口(与按钮)实际上一次弹出
- Opencv未能捕获上一次之后的早期点击
- (WINSOCK) c++游戏服务器:TCPAccept上一次有太多TCP连接