سلام دوستان
می خوام با استفاده از کد زیر که با جی تی کا 3 و سی پلاس پلاس نوشته شده یک صفحه لاگین درست کنم.
#include <gtk/gtk.h>
#pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup")
GtkWidget *u_name;
GtkWidget *pass;
GtkWidget *window;
static void create_window(GtkWidget *widget, gpointer data);
int main(int argc, char *argv[]){
GtkWidget *grid;
GtkWidget *Login_button, *Quit_button;
GtkWidget *label_user;
GtkWidget *label_pass;
GtkWidget *button_container;
GdkColor color;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Login page");
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_container_set_border_width(GTK_CONTAINER(window), 10);
gtk_window_set_resizable(GTK_WINDOW(window), FALSE);
grid = gtk_grid_new();
gtk_grid_set_row_spacing(GTK_GRID(grid), 3);
gtk_container_add(GTK_CONTAINER(window), grid);
label_user = gtk_label_new("Username ");
label_pass = gtk_label_new("Password ");
u_name = gtk_entry_new();
gtk_entry_set_placeholder_text(GTK_ENTRY(u_name), "Username");
gtk_grid_attach(GTK_GRID(grid), label_user, 0, 1, 1, 1);
gtk_grid_attach(GTK_GRID(grid), u_name, 1, 1, 2, 1);
pass = gtk_entry_new();
gtk_entry_set_placeholder_text(GTK_ENTRY(pass), "Password");
gtk_grid_attach(GTK_GRID(grid), label_pass, 0, 2, 1, 1);
gtk_entry_set_visibility(GTK_ENTRY(pass), 0);
gtk_grid_attach(GTK_GRID(grid), pass, 1, 2, 1, 1);
Login_button = gtk_button_new_with_label("Log in");
gdk_color_parse("blue", &color);
gtk_widget_modify_bg(GTK_WIDGET(Login_button), GTK_STATE_NORMAL, &color);
g_signal_connect(Login_button, "clicked", G_CALLBACK(create_window), NULL);
gtk_grid_attach(GTK_GRID(grid), Login_button, 0, 3, 2, 1);
Quit_button = gtk_button_new_with_label("Quit");
gdk_color_parse("red", &color);
gtk_widget_modify_bg(GTK_WIDGET(Quit_button), GTK_STATE_NORMAL, &color);
g_signal_connect(Quit_button, "clicked", G_CALLBACK(gtk_main_quit), NULL);
gtk_grid_attach(GTK_GRID(grid), Quit_button, 0, 4, 2, 1);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
static void create_window(GtkWidget *widget, gpointer data) {
GtkWidget *win, *label;
//Username and Password to validate credentials
const gchar *USERNAME = "user";
const gchar *PASSWORD = "123456";
if (USERNAME == gtk_entry_get_text(GTK_ENTRY(u_name)) && PASSWORD == gtk_entry_get_text(GTK_ENTRY(pass)))
{
label = gtk_label_new("Username and Password is correct.");
win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_container_add(GTK_CONTAINER(win), label);
gtk_widget_show_all(win);
}
gtk_widget_destroy(window);
if (USERNAME != gtk_entry_get_text(GTK_ENTRY(u_name)) || PASSWORD != gtk_entry_get_text(GTK_ENTRY(pass)))
{
GtkWidget *dialog;
dialog = gtk_message_dialog_new(GTK_WINDOW(window), GTK_DIALOG_MODAL,
GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
"The username or password is incorrect.\n"
"Please insert correct them.");
gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER);
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
}
}
ولی نمی تونم یوزر پسورد رو بهش اعمال کنم. اگه میشه منو راهنمایی کنید.
ممنون