Environment: w2k+php4.3.1+php/gtk0.5.2
A simple Notepad (you can only open the file for modification)
Set_time_limit (0); Set run time
if (!class_exists ("GTK"))//Determine if there is a GTK module
if (Strtoupper (substr ($_server["OS"], 0, 3) = = = "WIN")
DL ("Php_gtk.dll");
Else
DL ("php_gtk.so");
$window = &new Gtkwindow (); Build a Window
$window->set_uposition (100, 100); Where the window appears
$window->set_usize ((Gdk::screen_width () -200), (Gdk::screen_height ()-150)); Window size
$window->set_title ("WINDOWS"); Set Window Caption
$window->connect_object (' Destroy ', Array (' GTK ', ' main_quit ')); Registering events for Windows
$vbox = &new Gtkvbox ();
$hbox = &new Gtkhbox ();
$window->add ($vbox);
$menuBar = &new Gtkmenubar (); Create a Menu
$vbox->pack_start ($menuBar, False, False, 0);
$file = &new Gtkmenuitem ("file");
$menuBar->append ($file);
$fileMenu = &new Gtkmenu ();
$open = &new Gtkmenuitem ("open");
$save = &new Gtkmenuitem ("Save");
$line = &new Gtkmenuitem ();
$line->set_sensitive (TRUE);
$exit = &new Gtkmenuitem ("exit");
$fileMenu->append ($open);
$open->connect_object (' Activate ', ' showfileselection ');
$fileMenu->append ($save);
$save->connect_object (' Activate ', ' saveFile ');
$fileMenu->append ($line);
$fileMenu->append ($exit);
$exit->connect_object (' Activate ', Array (' GTK ', ' main_quit '));
$file->set_submenu ($fileMenu);
$scroll = &new Gtkscrolledwindow ();
$scroll->set_border_width (8);
$scroll->set_policy (gtk_policy_automatic, gtk_policy_automatic);
$hbox->pack_start ($scroll, True, true, 0);
$vbox->pack_start ($hbox, True, true, 1);
$text = &new Gtktext ();
$text->set_editable (TRUE);
$text->set_word_wrap (TRUE);
$scroll->add ($text);
function showfileselection ()//File selection functions
{
$file = &new gtkfileselection ("File Selection");
$ok _button = $file->ok_button;
$ok _button->connect (' clicked ', ' OpenFile ', $file);
$ok _button->connect_object (' clicked ', Array ($file, ' destroy '));
$cancel _button = $file->cancel_button;
$cancel _button->connect_object (' clicked ', Array ($file, ' destroy '));
$file->show ();
}
$filePath = null;
function OpenFile ($button, $f)//functions for opening files
{
GLOBAL $text, $save, $filePath;
$filePath = $f->get_filename ();
if (Is_file ($filePath))
{
$fp = fopen ($filePath, ' R ');
while (!feof ($FP))
$str. = Fgets ($fp, 1024);
$text->insert (null, NULL, NULL, $STR);
Fclose ($FP);
return $filePath;
}
}
function SaveFile ()//functions for saving files
{
GLOBAL $filePath, $text;
if (Is_file ($filePath))
{
$str = $text->get_chars (0,-1);
$fp = fopen ($filePath, ' w ');
Fwrite ($fp, $STR);
Fclose ($FP);
}
Return
}
$window->show_all (); Show all controls in the window body
Gtk::main (); The most important sentence, no less.
?>
Attached: PHP/GTK configuration
Actual combat PHP/GTK (reprint)
Diao Chan Posted in 2002-2-19 15:25 PHP programming ← Back to Layout
Previously PHP was supposed to be used only to write server-side CGI programs, if PHP can develop a GUI (graphical user interface) program under Windows, do you believe it? Recently, the PHP development team successfully developed a bundle of GTK + PHP, then you can develop a GUI program under Windows.
First, the establishment of PHP/GTK operating environment:
In fact, GUI program and ordinary phpcgi program no difference, but PHP/GTK program by GTK class to generate GUI interface, they are also open source code, rely on PHP to parse the build window. If you have set up a debugging environment for PHP, it is easier to install the PHP/GTK environment:
1. Download Php_gtk.dll (This DLL file is used to parse the GTK code inside the PHP source program) and unzip it to the PHP extension (extension) directory after downloading;
2, download the other PHP/GTK DLL files (altogether 6), unzip them into the Windows System32 directory;
3, open php.ini, in the Extended Settings section "Windows Extensions" the bottom of the "Extension=php_gtk.dll" statement, it is recommended to back up the php.ini, to avoid the failure of the modification of the establishment of a good PHP running environment obsolete;
Now we have established the PHP/GTK environment. Of course, you can also add "DL (' Php_gtk.dll ')" to the first line of each PHP/GTK program source code instead of the second step to dynamically load GTK support.
If you have not yet built a PHP runtime environment, it is easier to install:
1, download the entire PHP/GTK bundle support package, and then unzip them to the C-drive under the PHP4 directory;
2. Copy the DLL files from the Winnt directory to the Windows System32 directory and copy the php.ini files to the Windows directory;
After the PHP/GTK is established, you can run a PHP/GTK program with command-line php: Enter "C:\php4\php-q Gtkprogrampath" in the Run, where "c:\php4\php" is changed to PHP.EXE path, " Gtkprogrampath "is the path to the PHP/GTK program. For example, "C:\php4\php-q c:\php4\samples\hello.php" will run the example "Hello World" program that accompanies the PHP/GTK run package.
Second, compile the PHP/GTK program:
If you make a PHP/GTK application, you need the other person's computer to build PHP environment and use the PHP command line mode to parse to be able to execute, it is too complex. So how is it possible to compile a PHP/GTK program? After a search, the author found phpcompiler this software.
Phpcompiler is developed by www.deskcode.com (Http://www.deskcode.com/phpcompiler), PHP can be compiled into EXE executable file, built-in PHP support, if you want to compile a php/ GTK program, you must establish the operating environment of the PHP/GTK (refer to the previous steps). The steps to compile a PHP/GTK program are as follows:
1, open Phpcompiler (), in the "Script to" Select the PHP program you want to compile the source code, "Destination" in the successful compilation of the EXE file after the path;
2, click "Compile" button, will pop up a dialog box to ask for the compilation mode (if the PHP/GTK program to choose No, is simply the PHPCGI program to choose Yes);
3. A dialog box will then pop up asking if you want to copy the Php4ts.dll file to the compiled EXE directory and select Yes.
After the above steps, a PHP/GTK program compiles successfully, but there are a few points to note about compiling the PHP/GTK program:
1, after the completion of the implementation of the executable file, if necessary, the PC must have a GTK runtime environment required several DLL files (that is, the previous download), if necessary to make the application, Several DLL files can be copied to the System32 directory at the time of installation (but this is not a "green software" ^_^).
2, Phpcompiler itself for the support of PHP very good, but some people have tried to extend the support of some functions, such as "Gzopen" and so on, before the compilation is good, after the compilation is not ready to use. In fact, after the completion of the executable file, the equivalent of only the default PHP support (even the GTK support is not), so if you apply any function in the program that need to extend support, you must dynamically load the supporting function DLL file, such as "DL (' Php_gtk.dll ')", This will not be an error until the compilation is complete.
3, run a compiled executable file, will pop up a DOS window, and then automatically close, because each GUI window is "drawn" through GTK, so there must be a window.
4, perhaps before PHP can not be said to be true oop (object-oriented program) language, but to php/gtk, any window by the GTK object to "draw", if there is no strong OOP skills, it is difficult to write GUI program.
Third, PHP/GTK resources:
1, the official website of Http://gtk.php.net:PHP/GTK, although said to be the official website, but is very humble, out of a FAQ and mailing list, almost no useful things,
2, http://www.phpgtk.com: A better interface of the PHP/GTK site, with the latest version information.
3, Http://developer.gnome.org/doc/API/gtk/gtkobjects.html:PHP/GTK function and class of the Encyclopedia/Handbook website, which has a very rich php/gtk information.
4, http://www.phpuk.org/gtk/: Unofficial version of the GTK Handbook website, easy to understand.
If you think E is ugly, you can also come to zphp.com to download the latest PHP/GTK Runtime environment and support package.
http://www.bkjia.com/PHPjc/314812.html www.bkjia.com true http://www.bkjia.com/PHPjc/314812.html techarticle Environment: w2k+php4.3.1+php/gtk0.5.2 A simple Notepad (can only open files for modification)? PHP set_time_limit (0);//Set run time if (!class_exists ("GTK"))// The judgment is ...