如何在作为控制台启动的应用程序中创建窗口?

时间:2023-01-19 23:40:11

I know the way window is created when the app is windowed one from the start, that is you call

我知道当应用程序从一开始就被窗口化时创建窗口的方式,就是你打电话

LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
int WinMain(HINSTANCE hInst,HINSTANCE,LPSTR,int nCmdShow);

But what to do if I want to get user an option to display a console application output when it ends. That is display its data in more readable form in ad-hoc created window instead of text-only mode that console permits.

但是如果我想让用户在结束时显示控制台应用程序输出的选项该怎么办。这是在ad-hoc创建的窗口中以更易读的形式显示其数据,而不是控制台允许的纯文本模式。

In console app I have a function that watches for user key press, and when my program ends it shows message: press D to display result in a window instead of console, and in code:

在控制台应用程序中,我有一个监视用户按键的功能,当我的程序结束时显示消息:按D在窗口而不是控制台中显示结果,并在代码中:

if (virtual_key == 0x44) {
  HWND myWindow = myCreateWindFunc(/* data */);
}

That is I need to pack all the code for creating window into one function an then just call function on it with the data to fill it's controlls.

那就是我需要将创建窗口的所有代码打包到一个函数中,然后只需要调用函数来填充它的控件。

1 个解决方案

#1


3  

A console application can create child windows or dialog boxes using any related WinAPI function (MessageBox, DialogBox etc).

控制台应用程序可以使用任何相关的WinAPI函数(MessageBox,DialogBox等)创建子窗口或对话框。

The only caveat is that the create function may require the handle of the console window. To obtain it, you could use the example here How To Obtain a Console Window Handle

唯一需要注意的是,create函数可能需要控制台窗口的句柄。要获得它,您可以使用此处的示例如何获取控制台窗口句柄

#1


3  

A console application can create child windows or dialog boxes using any related WinAPI function (MessageBox, DialogBox etc).

控制台应用程序可以使用任何相关的WinAPI函数(MessageBox,DialogBox等)创建子窗口或对话框。

The only caveat is that the create function may require the handle of the console window. To obtain it, you could use the example here How To Obtain a Console Window Handle

唯一需要注意的是,create函数可能需要控制台窗口的句柄。要获得它,您可以使用此处的示例如何获取控制台窗口句柄