- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm using compaque visual fortran/Intel visual fortranfor creating a Win32 API application. I'm try to create a split window with its upper part to show graphics and its low part to be a console window (like that in a console application or quickwin in which it can be easily created by using Open command) that I can interact with it easily such as output text and get data from input. I don't know how to open a console window in Windows environment (not quickWin or console applications). I'll appreciate it much if anybody teach me about it.
thanks,
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can open a console window by calling the Win32 API routine AllocConsole. (Use USE KERNEL32 tomake its definition available.) Once you do that, you can do normal Fortran "console" I/O to it. It will open as a separate window - I don't know if there's a way to set its size or position.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
However, that would require a replacement of WRITE(*) statements with edit-box handling functions; if you want to avoid that, you can redirect the output to a pipe and "listen" to the pipe in GUI code. See this thread.
(Yes, I know it's a bit complicated. Decide for yourself whether you want to do that--I just wanted to let you know about an alternative approach)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you very much. The example and your related website seem very helpful. I appreciate it a lot.
If using edit box, output text is OK. Can I still get input from keyboard easily by "read (*,*)a,b,c " like that in a console window?
The commercial softwares AutoCAD, Matlab etc. all use this kind of interface for their main window which I like, since it is more direct and saving a lot of effort needed for dialog boxes.
I wonder if the win 32 API functions: createWindow() or createWindowEx() can provide a window type for console window like those for edit, list, treeview, or graphic windows instead of use allocConsole(). Thenit will be much easier for us.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Console windows are fairly peculiar: while they have certain aspects of a window, it's fairly difficult to control them in a similar way as edit boxes. It's even difficult to grab their handle, for a start (GetConsoleWindow is relatively new API, check if it's implemented in your compiler). From then on, you can move it, maybe even change its style (to remove the borders and caption, for example, didn't try it myself), but you must resort to READ/WRITE and/or console APIs to control the text.
AutoCAD, Matlab etc. apparently "cook their own" solutions. I can't even figure using Spy++ out how Matlab 6.0 lies them out -- it appears it has only the frame window and that "sub-windows" including "Command window" are drawn over it. There is a window named "Matlab Command window", but it's overlapped and hidden--it seems that they do a lot of forth/back copying between it and its "image" on the screen.
You can also check out XTabEditor sample -- it uses the multi-line edit control to mimic the Notepad behavior (more or less). So, you should be able to "cook your own" solution, with some effort, to get the appropriate behavior. Note that it subclasses the control (XBindWindow->xEdit_OnKeyDown) to enable Col/Line display -- it should be possible to override the key behaviors to do something else (e.g. Arrow up/down repeat the last command instead of moving the cursor, Enter executes the command instead of breaking the line etc.) Feel free to ask if you encounter problems.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you very much. All your suggestions are valuable to me. I've wondered a long time how to get the handle of the whole console window. The functions in the documentation seem to be only for handles of output, input or error. We've just brought Visual studio 2005 and IVF 9.1, so I'll switch from CVF to IVF. I shall first try GetConsolewindow, to see if then I can use the handle to change console window's size and position.
thanks again and best regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Here's how (in C, but it's easy to translate it to Fortran):
INT iret;
BOOL statConsole;
HWND hwnd;
HANDLE hStdOut;
CHAR ConsoleTitle[128];
DWORD dwCharsRead;
COORD ScrSize;
CONSOLE_SCREEN_BUFFER_INFO ScrBuff;
SMALL_RECT srWindowRect;
statConsole = AllocConsole();
statConsole = SetConsoleTitle("This is MyConsole");
dwCharsRead = GetConsoleTitle(ConsoleTitle, sizeof(ConsoleTitle));
hwnd = FindWindow(NULL,ConsoleTitle);
iret = SetWindowPos(hwnd,NULL,0,0,0,0,SWP_NOSIZE | SWP_NOZORDER); // Top lh corner
hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
iret = GetConsoleScreenBufferInfo(hStdOut,&ScrBuff);
ScrSize.X = 2*ScrBuff.dwMaximumWindowSize.X; // The defaultis 80
ScrSize.Y = 50*ScrBuff.dwMaximumWindowSize.Y; // The defaultis 25
iret = SetConsoleScreenBufferSize(hStdOut,ScrSize);
srWindowRect.Right = 35; //width
srWindowRect.Bottom = 15; //height
srWindowRect.Left = srWindowRect.Top = (SHORT) 0;
statConsole = SetConsoleWindowInfo(hStdOut, TRUE, &srWindowRect);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks a lot. I tried your sample code until line
iret = SetWindowPos(...)
It does change the position and size of the opened console window. I'm trying to generate a split window with its upper part as an openGL window to show the graphics while its lower partbeing theconsole window as an I/O interface such asking data for an rectangle, after getting necessary data, then the resulting rectangle may be draw in the upper openGL window.
Do you have any sample code like that? Maybe I'm asking too much. Sorry for that. I generated the two windows separately, however the split part doesn't work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Nah, Jugoslav. The snippet is written in C, not Fortran.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page