[英]Working on Win32 App, would like output to both Win32 window and console window
[英]Win32 App not running in window but in console
我已经通过Platinum用c ++创建了一个Windows应用程序。 当我运行该应用程序时,它将在命令提示符下运行。现在,我想从Windows运行它,因此我设法使其在Windows中运行。但是,问题是我无法在命令提示符和Windows中同时运行该应用程序。 它只允许我在Windows或命令提示符下运行(不能同时在两者中运行)任何人都可以将我引导到正确的路径。
如果需要控制台和窗口,则可以将应用程序作为控制台启动,然后使用Windows API创建窗口。
这里的例子:
#include <iostream>
#include <windows.h>
long __stdcall WindowProcedure( HWND window, unsigned int msg, WPARAM wp, LPARAM lp )
{
switch(msg)
{
case WM_DESTROY:
std::cout << "\ndestroying window\n" ;
PostQuitMessage(0) ;
return 0L ;
case WM_LBUTTONDOWN:
std::cout << "\nmouse left button down at (" << LOWORD(lp)
<< ',' << HIWORD(lp) << ")\n" ;
// fall thru
default:
std::cout << '.' ;
return DefWindowProc( window, msg, wp, lp ) ;
}
}
int main()
{
std::cout << "hello world!\n" ;
const char* const myclass = "myclass" ;
WNDCLASSEX wndclass = { sizeof(WNDCLASSEX), CS_DBLCLKS, (WNDPROC)WindowProcedure,
0, 0, GetModuleHandle(0), LoadIcon(0,IDI_APPLICATION),
LoadCursor(0,IDC_ARROW), HBRUSH(COLOR_WINDOW+1),
0, (LPCWSTR)myclass, LoadIcon(0,IDI_APPLICATION) } ;
if( RegisterClassEx(&wndclass) )
{
HWND window = CreateWindowEx( 0, (LPCWSTR)myclass, (LPCWSTR)"title",
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, GetModuleHandle(0), 0 ) ;
if(window)
{
ShowWindow( window, SW_SHOWDEFAULT ) ;
MSG msg ;
while( GetMessage( &msg, 0, 0, 0 ) ) DispatchMessage(&msg) ;
}
}
}
取自此链接 (取自其他地方)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.