Win32程序编译,但没有窗口出现
Win32 program compiles but no window appears
我正在编译一个简单的Win32 api程序,但问题是它编译很好,但没有窗口出现。我在任务管理器中检查了进程,程序在那里,但没有显示窗口。我在windows 7 32位下使用CodeBlocks IDE 10.05与GNU GCC编译器。我知道在stackoverflow上有一个类似的问题,但给出的解决方案是'=='而不是'='。下面是代码:
#include <windows.h>
#include <tchar.h>
/* Global Vars */
HINSTANCE hInst;
HWND wndHandle;
int winWidth = 640;
int winHeight = 480;
//func prototypes
bool InitWindow(HINSTANCE hInst, int width, int height);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
/********************************************************
* WINMAIN FUNCTION
*********************************************************/
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
hInst = hInstance;
//app window
if (!InitWindow(hInst, winWidth, winHeight))
{
return false;
}
// MESSAGE LOOP
MSG msg = {0};
while (WM_QUIT != msg.message)
{
//window messages
while(PeekMessage(&msg, NULL,0,0, PM_REMOVE) == TRUE)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
//additional logic
}
return (int)msg.wParam;
}
/*******************************************************************
* InitWindow
* Inits and creates and main app window
* Inputs - application instance - HINSTANCE
Window width - int
Window height - int
* Outputs - true if successful, false if failed - bool
*******************************************************************/
bool InitWindow(HINSTANCE hInstance, int width, int height)
{
// Register class
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = 0;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH) + (COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = TEXT("DirectX 10 Example");
wcex.hIconSm = 0;
if(!RegisterClassEx(&wcex))
{
return false;
}
// resize window
RECT rect = { 0, 0, width, height };
AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, false);
// create the window from the class above
wndHandle = CreateWindow( TEXT("DX 10 Example"),
TEXT("DX10 WINDOW"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
rect.right - rect.left,
rect.bottom - rect.top,
0,
0,
hInstance,
0);
if(wndHandle == 0)
{
return false;
}
ShowWindow(wndHandle, SW_SHOW);
UpdateWindow(wndHandle);
return true;
}
/*******************************************************************
* WndProc
* The main window procedure for the application
* Inputs - application window handle - HWND
message sent to the window - UINT
wParam of the message being sent - WPARAM
lParam of the message being sent - LPARAM
* Outputs - LRESULT
*******************************************************************/
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
// Allow the user to press the escape key to end the application
case WM_KEYDOWN:
switch(wParam)
{
// Check if the user hit the escape key
case VK_ESCAPE:
PostQuitMessage(0);
break;
}
break;
// The user hit the close button, close the application
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
你有wcex。lpszClassName = TEXT("DirectX 10示例");
和
wndHandle = CreateWindow(TEXT("DX 10示例"),文本("DX10窗口"),
您必须为"CreateWindow"使用与"RegisterClass"相同的类名。
在源代码中这两个是不同的:
wcex.lpszClassName = TEXT("DirectX 10 Example");
...
wndHandle = CreateWindow(TEXT("DX 10 Example"), ...
相关文章:
- 如何将一个窗口保留在另一个应用程序窗口的前面
- 如何从 Win32 C++ 应用程序输出到父控制台窗口?
- 从运行服务的应用程序代码中提取窗口句柄
- 没有运算符"="与这些操作数匹配,JUCE 窗口演示应用程序
- 如何使用C++确定应用程序是否已在窗口中启动?
- 是否可以从控制台应用程序使用 C++/WinRT 创建窗口?
- 在Visual Studio中单实例Qt应用程序版本5.11.1中,在所有其他窗口的顶部打开Qt MainWindow
- 返回主窗口/ C ++后,应用程序正在关闭
- 如何在 Win32 控制台应用程序中注册不可见的窗口类?
- C++ 如何在 OpenGL 程序中远程调用控制台窗口
- 如何从 CLion 的运行窗口中删除程序项目路径
- 无法在 consol 应用程序中更新窗口
- Opencv在2013年第5季度不起作用.应用程序总是在窗口中崩溃
- 用C++编写.Net窗口应用程序
- 在C++中获取应用程序窗口的大小
- 如何编写一个可以在BitDefender下运行的无窗口程序
- 我的C++窗口程序运行,但我看不到
- 在运行 X 窗口程序时未获得任何输出
- 无法创建关闭窗口程序C++
- 多窗口程序-在第二个窗口上创建按钮