Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » GTK+
  • » Facing problem in using gtk-sockets [RSS Feed]

#1 Jan. 17, 2011 14:53:55

Lohitha R.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Facing problem in using gtk-sockets


Hi all,I just started using gtk sockets. Facing problem in using it. here ihave given two case(case1 and case2).In case one its working fine, but in case two facing problem. Basicallyin the second case, the button click itself is not possible.I tried both in linux(slackware 12) and windows(xp sp2).what i observed is, always the socket which is created will be in thebeginning of the window(means (0,0)). because of that in the second casei'm not able to plase button first and the socket next.Please help me. Is there any alternative way to do. (I want the secondcase should work)._Case 1:_
/* sock.c */
#ifdef WIN32
#include <windows.h>
#endif
#include <gtk/gtk.h>

void clicked(void)
{
#ifdef WIN32
MessageBox(NULL, "Clicked\n", "sock-test", MB_OK | MB_ICONINFORMATION);
#else
printf("Clicked\n");
#endif
}

int main()
{
GtkWidget *pWindow, *pSocket, *pBox, *pBtn;

gtk_init(NULL, NULL);

pWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(GTK_OBJECT(pWindow), "destroy",
G_CALLBACK(gtk_main_quit), (gpointer)pWindow);

pBox = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(pWindow), pBox);

pSocket = gtk_socket_new();
gtk_widget_set_size_request(pSocket, 320, 240);
gtk_box_pack_start(GTK_BOX(pBox), pSocket, 1,1,1);

pBtn = gtk_button_new_with_label("Click");g_signal_connect(GTK_OBJECT(pBtn), "clicked", G_CALLBACK(clicked),NULL);gtk_box_pack_start(GTK_BOX(pBox), pBtn, 1,1,1);

gtk_widget_show_all(pWindow);
gtk_main();

return 0;
}

This is working fine.

_Case 2:_
/* sock2.c */
#ifdef WIN32
#include <windows.h>
#endif
#include <gtk/gtk.h>

void clicked(void)
{
#ifdef WIN32
MessageBox(NULL, "Clicked\n", "sock-test", MB_OK | MB_ICONINFORMATION);
#else
printf("Clicked\n");
#endif
}

int main()
{
GtkWidget *pWindow, *pSocket, *pBox, *pBtn;

gtk_init(NULL, NULL);

pWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(GTK_OBJECT(pWindow), "destroy",
G_CALLBACK(gtk_main_quit), (gpointer)pWindow);

pBox = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(pWindow), pBox);

pSocket = gtk_socket_new();
gtk_widget_set_size_request(pSocket, 320, 240);
gtk_box_pack_end(GTK_BOX(pBox), pSocket, 1,1,1);

pBtn = gtk_button_new_with_label("Click");g_signal_connect(GTK_OBJECT(pBtn), "clicked", G_CALLBACK(clicked),NULL);gtk_box_pack_end(GTK_BOX(pBox), pBtn, 1,1,1);

gtk_widget_show_all(pWindow);
gtk_main();

return 0;
}

*OR*
/* sock2.c */
#ifdef WIN32
#include <windows.h>
#endif
#include <gtk/gtk.h>

void clicked(void)
{
#ifdef WIN32
MessageBox(NULL, "Clicked\n", "sock-test", MB_OK | MB_ICONINFORMATION);
#else
printf("Clicked\n");
#endif
}

int main()
{
GtkWidget *pWindow, *pSocket, *pBox, *pBtn;

gtk_init(NULL, NULL);

pWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(G_OBJECT(pWindow), "destroy",
G_CALLBACK(gtk_main_quit), (gpointer)pWindow);

pBox = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(pWindow), pBox);

pBtn = gtk_button_new_with_label("Click");
g_signal_connect(G_OBJECT(pBtn), "clicked", G_CALLBACK(clicked), NULL);
gtk_box_pack_start(GTK_BOX(pBox), pBtn, 1,1,1);

pSocket = gtk_socket_new();
gtk_widget_set_size_request(pSocket, 320, 240);
gtk_box_pack_start(GTK_BOX(pBox), pSocket, 1,1,1);

gtk_widget_show_all(pWindow);
gtk_main();

return 0;
}

--
Thank You,
Loh!tha R_______________________________________________
gtk-list mailing list
gtk-list@gnome.orghttp://mail.gnome.org/mailman/listinfo/gtk-list

Offline

  • Root
  • » GTK+
  • » Facing problem in using gtk-sockets [RSS Feed]

Board footer

Moderator control

Enjoy the 11th of December
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support