how to create window in an application that started as console one?
c++, console, winapi, window
Solution
A console application can create child windows or dialog boxes using any related WinAPI function (`MessageBox`, `DialogBox` etc).
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
Problem
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. 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: ``` 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.