选择显示字体大小

用php开发gui(一个简单的例子)


环境:w2k+php4.3.1+php/gtk0.5.2
一个简单的记事本(只可以打开文件进行修改)
<?php
set_time_limit (0);  // 设置运行时间

if (!class_exists (&quot;gtk&quot;))  // 判断是否有gtk模块
if (strtoupper (substr (&#36;_server[&quot;os&quot;], 0, 3)) == &quot;win&quot;)
dl (&quot;php_gtk.dll&quot;);
else
dl (&quot;php_gtk.so&quot;);

&#36;window = &new gtkwindow (); // 建一个窗口
&#36;window->set_uposition (100, 100); // 窗口出现位置
&#36;window->set_usize ((gdk::screen_width()-200), (gdk::screen_height()-150)); // 窗口大小
&#36;window->set_title (&quot;windows&quot;);  // 设置窗口标题
&#36;window->connect_object ('destroy', array ('gtk', 'main_quit'));  // 注册窗口的事件

&#36;vbox = &new gtkvbox ();  
&#36;hbox = &new gtkhbox ();  
&#36;window->add (&#36;vbox);


&#36;menubar = &new gtkmenubar ();  // 创建菜单
&#36;vbox->pack_start (&#36;menubar, false, false, 0);

&#36;file = &new gtkmenuitem (&quot;file&quot;);
&#36;menubar->append (&#36;file);

&#36;filemenu = &new gtkmenu ();
&#36;open = &new gtkmenuitem (&quot;open&quot;);
&#36;save = &new gtkmenuitem (&quot;save&quot;);
&#36;line = &new gtkmenuitem ();
&#36;line->set_sensitive (true);
&#36;exit = &new gtkmenuitem (&quot;exit&quot;);
&#36;filemenu->append (&#36;open);
&#36;open->connect_object ('activate', 'showfileselection');
&#36;filemenu->append (&#36;save);
&#36;save->connect_object ('activate', 'savefile');
&#36;filemenu->append (&#36;line);
&#36;filemenu->append (&#36;exit);
&#36;exit->connect_object ('activate', array ('gtk', 'main_quit'));

&#36;file->set_submenu (&#36;filemenu);

&#36;scroll = &new gtkscrolledwindow ();
&#36;scroll->set_border_width (8);
&#36;scroll->set_policy (gtk_policy_automatic, gtk_policy_automatic);
&#36;hbox->pack_start (&#36;scroll, true, true, 0);
&#36;vbox->pack_start (&#36;hbox, true, true, 1);

&#36;text = &new gtktext ();
&#36;text->set_editable (true);
&#36;text->set_word_wrap (true);
&#36;scroll->add (&#36;text);

function showfileselection ()  // 文件选择函数
{
&#36;file = &new gtkfileselection (&quot;file selection&quot;);
&#36;ok_button = &#36;file->ok_button;
&#36;ok_button->connect ('clicked', 'openfile', &#36;file);
&#36;ok_button->connect_object ('clicked', array (&#36;file, 'destroy'));
&#36;cancel_button = &#36;file->cancel_button;
&#36;cancel_button->connect_object ('clicked', array (&#36;file, 'destroy'));
&#36;file->show ();
}

&#36;filepath = null;
function openfile (&#36;button, &#36;f) // 打开文件的函数
{
global &#36;text, &#36;save, &#36;filepath;
&#36;filepath = &#36;f->get_filename ();
if (is_file (&#36;filepath))
{
&#36;fp = fopen (&#36;filepath, 'r');
while (!feof (&#36;fp))
&#36;str .= fgets (&#36;fp, 1024);
&#36;text->insert (null, null, null, &#36;str);
fclose (&#36;fp);
return &#36;filepath;
}
}

function savefile () // 保存文件的函数
{
global &#36;filepath, &#36;text;
if (is_file (&#36;filepath))
{
&#36;str = &#36;text->get_chars (0, -1);
&#36;fp = fopen (&#36;filepath, 'w');
fwrite (&#36;fp, &#36;str);
fclose (&#36;fp);
}
return;
}

&#36;window->show_all ();  // 显示窗体内的所有控件
gtk::main (); // 最重要的一句,不可少的
?>

  


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons