Chinaunix首页 | 论坛 | 博客
  • 博客访问: 473556
  • 博文数量: 88
  • 博客积分: 1677
  • 博客等级: 上尉
  • 技术积分: 667
  • 用 户 组: 普通用户
  • 注册时间: 2011-11-03 22:17
文章分类

全部博文(88)

文章存档

2013年(1)

2012年(18)

2011年(69)

分类: 嵌入式

2011-11-25 22:10:58

转载:http://blog.csdn.net/rattles/article/details/5538272

cone.h:

//gcc -g -Wall -o login login.c -I/usr/include/mysql -L/usr/lib/mysql -lmysqlclient `pkg-config --cflags --libs gtk+-2.0`
#include

#include
#define MYSQL_PORT 3306

MYSQL *myconnect=NULL;
//gboolean connect=FALSE;
static GtkWidget *entry1;
static GtkWidget *entry2;
static GtkWidget *mlabel=NULL;
gboolean my_connect1(gchar *usernam,gchar *passwor)
{
  gchar *query_buf ="USE ourdb1";
  myconnect=mysql_init(myconnect);
  if(mysql_real_connect(myconnect,"localhost",usernam,passwor,"ourdb1",MYSQL_PORT,NULL,0))//ourdb1是我建立的数据库
    {
      if(mysql_query(myconnect,query_buf)==0)
    {
      return TRUE;
        }
      else
    {
      return FALSE;
        }   
    }else
    {
      myconnect=NULL;
      return FALSE;
    }
 
}

void on_button_clicked(GtkWidget *button,gpointer data)//输入用户名和密码了。
{
  const gchar *username=gtk_entry_get_text(GTK_ENTRY(entry1));
  const gchar *password=gtk_entry_get_text(GTK_ENTRY(entry2));
  if(my_connect1(username,password))
   {
    gtk_label_set_text(GTK_LABEL(mlabel),"可以进入了");
//    connect=TRUE;

 //   show_credits();
   }
   else
   {
    gtk_label_set_text(GTK_LABEL(mlabel),"密码或用户名错误");
   }
 
}

GtkWidget *create_log()
{
  GtkWidget *window;
  GtkWidget *vbox,*hbox;
  GtkWidget *box1;
  GtkWidget *box2;
  GtkWidget *label1;
  GtkWidget *label2;
  GtkWidget *button;
  GtkWidget *sep,*viewport;
 
 
  window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
  g_signal_connect(G_OBJECT(window),"destroy",G_CALLBACK(gtk_main_quit),NULL);
  gtk_window_set_title(GTK_WINDOW(window),"land window");
  gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER);
  gtk_container_set_border_width(GTK_CONTAINER(window),25);

  vbox=gtk_vbox_new(FALSE,0);
  gtk_container_add(GTK_CONTAINER(window),vbox);
  box1=gtk_hbox_new(FALSE,0);
  gtk_box_pack_start(GTK_BOX(vbox),box1,FALSE,FALSE,5);
  box2=gtk_hbox_new(FALSE,0);
  gtk_box_pack_start(GTK_BOX(vbox),box2,FALSE,FALSE,5);
  

  label1=gtk_label_new("用户名: ");
  gtk_box_pack_start(GTK_BOX(box1),label1,FALSE,FALSE,5);
  entry1=gtk_entry_new();
  gtk_box_pack_start(GTK_BOX(box1),entry1,FALSE,FALSE,5);

  label2=gtk_label_new("  密码:  ");
  entry2=gtk_entry_new();
  gtk_entry_set_visibility(GTK_ENTRY(entry2),FALSE);
  gtk_box_pack_start(GTK_BOX(box2),label2,FALSE,FALSE,5);
  gtk_box_pack_start(GTK_BOX(box2),entry2,FALSE,FALSE,5);
 
 
  viewport=gtk_viewport_new(NULL,NULL);
  gtk_box_pack_start(GTK_BOX(vbox),viewport,FALSE,FALSE,5);
  mlabel=gtk_label_new(NULL);
  gtk_container_add(GTK_CONTAINER(viewport),mlabel);
  sep=gtk_hseparator_new();//
    gtk_box_pack_start(GTK_BOX(vbox),sep,FALSE,FALSE,5);

  hbox=gtk_hbox_new(FALSE,0);
  gtk_container_add(GTK_CONTAINER(vbox),hbox);
  button=gtk_button_new_with_label("教师登录");
  g_signal_connect(G_OBJECT(button),"clicked",G_CALLBACK(on_button_clicked),NULL);// show_credits
//===================================================================================
 
//  g_signal_connect_swapped(G_OBJECT(window),"clicked",G_CALLBACK(gtk_widget_destroy),window);
  gtk_box_pack_start(GTK_BOX(hbox),button,FALSE,FALSE,5);
  button=gtk_button_new_with_label("同学登录");
  g_signal_connect(G_OBJECT(button),"clicked",G_CALLBACK(on_button_clicked),NULL);
  gtk_box_pack_start(GTK_BOX(hbox),button,FALSE,FALSE,5);
 button=gtk_button_new_with_label("    取消    ");
  g_signal_connect(G_OBJECT(button),"clicked",G_CALLBACK(gtk_main_quit),NULL);
  gtk_box_pack_start(GTK_BOX(hbox),button,FALSE,FALSE,5);
  gtk_widget_show_all(window);
  return window;

}

 

 

main.c:

 

#include
#include
#include"conet.h"
int main(int argc,char *argv[])
{
   GtkWidget *window;
   gtk_init(&argc,&argv);
   window=create_log();
  gtk_main();
  return FALSE;
}

 

makefile:

LIB = -I/usr/include/mysql -L/usr/lib/mysql -lmysqlclient
all:main.o
    gcc -g -Wall -o main main.o $(LIB) `pkg-config --cflags --libs gtk+-2.0`
main.o:main.c conet.h
    gcc -c main.c $(LIB) `pkg-config --cflags --libs gtk+-2.0`
clean:
    rm -r *.o

阅读(4123) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~