GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The best of both worlds; CUI and GUI

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
axpen
Familiar Face


Joined: 27 Aug 2007
Posts: 14

PostPosted: Sun Feb 17, 2008 1:12 am    Post subject: The best of both worlds; CUI and GUI Reply with quote

Ok I have a question about GTK and how it handles GUI and CUI. Basically I started using Visual C++ and thought that it was causing the problem (and i'm sure I had everything set right, I even tried xaos5's vsprops files too). Turns out that wasn't the problem, I ran into the same thing with GCC command line and Dev-CPP.

The problem is how do you output to the console while not having the command prompt open with a window. I want no console window open with my window, but I want the program to be able to output to the console if it was called from there. I have the following;

Code: (C)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

#include <gtk/gtk.h>
#include <glib.h>

int main ( int argc, char* argv[] ) {
  GtkWidget *dialog = NULL;
  g_print("Hello Console!");

  gtk_init (&argc, &argv);
  dialog = gtk_message_dialog_new (GTK_WINDOW(NULL),
                                   GTK_DIALOG_DESTROY_WITH_PARENT,
                                   GTK_MESSAGE_INFO,
                                   GTK_BUTTONS_CLOSE,
                                   "Hello Window!");
  gtk_dialog_run (GTK_DIALOG (dialog));
  g_signal_connect_swapped (dialog, "response",
                            G_CALLBACK (gtk_widget_destroy),
                            dialog);
  gtk_widget_destroy (dialog);

  return 0;
}

(I tried replacing g_print with printf from stdio.h, but no luck either)

if I compile without -mwindows it opens a command prompt window and outputs "Hello Console!" then "Hello Window!" in a messagebox as expected, but if opened with double click (i.e. not from the command prompt) it will open a command prompt with it. Now if I do it with -mwindows it will eliminate the command prompt, but douse my ability to output to stdout via g_print or any other method.

It is very import that I have GUI and CUI, as most linux programs do, I believe that power lies in mostly CUI with mapping to the CUI using GUI. I have a full featured set of command line options with GOption and am not willing to choose either GUI or CUI or have a command prompt open with the GUI if not opened from the command line.

I also would not like to have to use hacks to close the CUI on load. I know this has to be a common problem, like in -mwindows the STDOUT get's re-routed or something.

Any help will be very much appriciated,
--Alex (http://www.axpen.com/)
Back to top
axpen
Familiar Face


Joined: 27 Aug 2007
Posts: 14

PostPosted: Sun Feb 17, 2008 1:54 am    Post subject: Reply with quote

Man this sucks I've studied some of the gimp and test programs with the GTK environment and it seems the best way they've figured out is to make a console and GUI one separately, and newbie windows users will just use myprog.exe and people who like CUI will use myprog-console.exe. This flusters me greatly as in Linux you see things like **ERROR** when closing apps opened from the command line, but if you just double click em you never see the messages.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP