Sample Code 209: How to get the size of display screen? |
|
Written by kksou
|
|
Saturday, 24 March 2007 |
|
Problem You want to get the size of the display screen as shown below:

Solution
Sample Code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| <?php $window = new GtkWindow(); $window->connect_simple('destroy', array('Gtk','main_quit')); $window->add($vbox = new GtkVBox());
// display title
$title = new GtkLabel("Set the window size to\n". "2/3 of screen width and 2/3 of screen height\n\n"); $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); $title->set_justify(Gtk::JUSTIFY_CENTER); $alignment = new GtkAlignment(0.5, 0.5, 0, 0); $alignment->add($title); $vbox->pack_start($alignment);
$screen = $window->get_screen(); // note 1
$screen_width = $screen->get_width(); // note 2
|
- 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
- Get the GdkScreen.
- Get the screen width.
- Get the screen height.
Notes
set_size_request works on most other widgets, including hbox, vbox, buttons, labels, etc.
For example, you can use $label->set_size_request(48,36) to set the size of a label.
User reviews Average user ratings: 5.0 (from 2 users) Note: You have to be a registered member to leave a comment. Free registration here. |
|
June 16, 2007 6:09am
If the user is using a multi-monitor setup, this method actually returns the total dimensions of all of the monitors combined.
July 03, 2008 6:15am