|
Problem From within a php-gtk application, one can launch an external application, for example a browser, by using system, exec or popen.
When deploying php-gtk applications, we usually run php-gtk scripts using php-win.exe so that there's no visible cmd window. However, the problem is that when we launch an external application using the method mentioned above, one will always see a brief flashing of a cmd window before the external application launches. Though this cmd window goes away by itself, many people find this irritating.
So is there a way to stop this cmd window from appearing?
Solution
This solution makes use of the technique as presented by Elizabeth Smith and André Jansen in php-gtk-general mailing list.
Sample Code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| <?php $window = new GtkWindow(); $window->set_size_request(400, 200); $window->set_title('launch browser');
$window->connect_simple('destroy', array('Gtk','main_quit'));
$window->add($vbox = new GtkVBox());
// displays a title
$title = new GtkLabel("Launch External Application in winxp\n without the flashing of cmd window"); $title->modify_font(new PangoFontDescription("Times New Roman Italic 10")); $title->modify_fg(Gtk::STATE_NORMAL, GdkColor::parse("#0000ff")); $title->set_size_request(-1, 40); $vbox->pack_start($title, 0, 0); $vbox->pack_start(new GtkLabel(''));
// create the clickable label
$clickable_label = new GtkHBox(); $clickable_label->set_size_request(-1, 24); $vbox->pack_start($clickable_label,0 ,0); $clickable_label->pack_start(new GtkLabel("reference: php-gtk2 "), 0, 0); $clickable_label->pack_start(link("manual", "http://gtk.php.net/manual/en/gtkclasses.php"), 0, 0);
$clickable_label->pack_start(new GtkLabel(" and "), 0, 0); $clickable_label->pack_start(link("mailing list", "http://www.nabble.com/Php---GTK---General-f171.html"), 0, 0);
$vbox->pack_start(new GtkLabel(''));
$status = new GtkLabel(''); $status->set_alignment(0, 0); $vbox->pack_start($status, 0, 0);
// function to setup the link
function link($title, $url) { $label = new GtkLabel($title); $label->set_markup('<span color="blue"><u>'.$title."</u></span>"); $eventbox = new GtkEventBox; $eventbox->add($label); $eventbox->connect('button-press-event', 'on_click', $title, $url); $eventbox->connect('enter-notify-event', 'on_enter', $title, $url); $eventbox->connect('leave-notify-event', 'on_leave', $title, $url); return $eventbox; }
|
- Note that this is only 70% of the sample code. You have to be a registered member to see the entire sample code. Please login or register.
- Registration is free and immediate.
- Have some doubt about the registration? Please read this forum article.
Explanation This example makes use of the code in the article How to put a clickable link in GtkLabel - Part 2?
What's new here:
- Use COM and WScript.Shell to display the url in default browser.
Related Links
User reviews There are no user reviews yet. Note: You have to be a registered member to leave a comment. Free registration here. |