C/C++ on Linux/Unix

Moderators: Lundin
Number of threads: 336
Number of posts: 663

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
writting program in its own "window" Posted by rookie7799 on 25 Feb 2009 at 1:07 PM
is there a way to write a C++ program that doesn't do "clear screen" but actually has its own "window" just like vi or nano?

thanks!
Report
Re: writting program in its own "window" Posted by Ed Hall on 26 Feb 2009 at 8:39 AM
I think what you might be referring to is covered in GTK programming. This will allow you to build programs that have their own windows on the desktop instead of running in a terminal window.

Take Care,
Ed
Report
Re: writting program in its own "window" Posted by rookie7799 on 26 Feb 2009 at 8:50 AM
Thanks for reply, but no that's not what I'm asking. I don't even have X Windows based linux... i'm only working in command line.
Report
Re: writting program in its own "window" Posted by richfell on 26 Feb 2009 at 3:17 PM
I believe you are referring to a feature of the terminal where a program can use a "alternate" terminal screen for its output and then reset the terminal to the "main" screen when it exits. To do that your program would have to output the character sequences that tell the terminal to do the window switching.

I wrote this test program and it works in my environment where TERM=xterm:

#include <iostream>
#include <unistd.h>

int main(int argc, char *argv[])
{
    // switch the terminal to its alternate screen
    std::cout << "\033[?1049h";

    for(int i = 0; i < 15; ++i)
        std::cout << i + 1 << ": line of text" << std::endl;

    sleep(3);

    // switch the terminal back to its main screen
    std::cout << "\033[?1049l";

    return 0;
}


This program should switch to the alternate screen, output some (useless) lines of text and then switch the terminal back to its main screen just before exiting. This may or may not work in your environment but give it a try. If it works you can use the same technique in your own program.



Report
Re: writting program in its own "window" Posted by rookie7799 on 26 Feb 2009 at 4:06 PM
hey, thank you for replying!
can you please explain what these magic numbers(characters) are ?
"\033[?1049h"
Report
Re: writting program in its own "window" Posted by richfell on 26 Feb 2009 at 7:30 PM
Those strings are control sequences that the terminal can recognize. I'm not very familiar with these terminal sequences but when I saw your question I had a feeling it was terminal related. For more info see what you can glean from this:

rtfm / Xterm / Escape Sequences




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.