这只是一个极简主义的控制台应用程序,应该显示动态创建的窗口:
#include <windows.h>
void main()
{
WNDCLASSEX _c4w = {0};
_c4w.cbSize = sizeof(WNDCLASSEX);
//_c4w.hCursor = ::LoadCursor(0, IDC_APPLICATION);
//_c4w.hIcon = ::LoadIcon(0, IDI_APPLICATION);
_c4w.hInstance = 0;
_c4w.hbrBackground = (HBRUSH)(COLOR_BACKGROUND);
_c4w.lpszClassName = "c4w";
HWND _h;
if(!::RegisterClassEx(&_c4w))
{ _h = ::CreateWindowEx( 0, "c4w",
"Minimal Windows Application",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
0, 0, 640, 480,
HWND_DESKTOP,
0,
::GetModuleHandle(0), NULL
);
::ShowWindow(_h, SW_SHOW);
}
....
}
不幸的是,RegisterClassEx函数实际上总是失败。
我正在使用C++ Builder 5并编译一个控制台应用程序,该应用程序被选择为MultiThreaded,但没有.
发布于 2022-03-31 10:51:49
就像@WhozCraig说的,你的窗口类没有wndproc。如果你想很好地使用维纳比,请根据官方文件学习。你的程序需要一个wndproc。
这是MSDN中的如何创建空白窗口。
注意,程序没有显式地调用WindowProc函数,尽管我们说过这是定义大多数应用程序逻辑的地方。Windows通过传递一系列消息与程序进行通信。
在代码中,wc.lpfnWndProc = WindowProc
指定进程回调函数。
发布于 2022-04-11 12:54:16
我理解使用HWND和WNDPROC的普通Win32应用程序不是我所做的,但以下是我的解决方案:
HWND GetSTD()
{ static
HWND _result(0);
static
bool _lock(false);
static
bool _setup(false);
while(_lock) ::Sleep(0);
if(_setup == false)
{ _lock = true;
OSVERSIONINFO _os;
_os.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
::GetVersionEx(&_os);
if(_os.dwPlatformId != VER_PLATFORM_WIN32s)
{ char _title[1024];
::GetConsoleTitle(_title, sizeof(_title));
_result = ::FindWindow(0, _title);
if(_os.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
{ _result = ::GetWindow(_result, GW_CHILD);
if(_result != 0)
{ char _class[128];
::GetClassName(_result, _class, sizeof(_class));
while(::strcmp(_class, "ttyGrab") != 0)
{ _result = ::GetNextWindow(_result, GW_HWNDNEXT);
if(_result != 0)
::GetClassName(_result, _class, sizeof(_class));
}
}
}
}
_setup = true;
_lock = false;
}
return _result;
}
使用生成的HWND,我们可以使用::GetDC()和::ReleaseDC()机制绘制控制台.
注意:静态变量用于确保每次调用只返回一个STD句柄.
https://stackoverflow.com/questions/71606480
复制相似问题