[英]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.