Re: Window size



> Hi all,
> I'm walking through gtk 1.2 doc since 1 or 2 hours and I can find a working 
> way to set the size of a window.
> gtk_window_set_geometry_hints don't works, gtk_window_set_default_size too. 
> Have I misunderstanding something ?
> (note the window is opened, but in something like 10x10)
> Thanks a lot
> 
> Jylam
> 
> 
> 
> Here is my code :
> 
> 
> void OpenWindow(int width, int height, unsigned char *title)
> {
>   MyWindow = (LnxWindow*) malloc(sizeof(LnxWindow));
> 
> 	MyWindow->MyGeometry.base_width = width;
>         MyWindow->MyGeometry.base_height = height;  
> 
>         gtk_init(NULL, NULL);         
>         MyWindow->window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
>         gtk_window_set_default_size (GTK_WINDOW(MyWindow->window),            
>         MyWindow->MyGeometry.base_width,  MyWindow->MyGeometry.base_height);
>         gtk_window_set_geometry_hints (GTK_WINDOW(MyWindow->window), NULL,    
>                                                        &MyWindow->MyGeometry, 
>                                                        GDK_HINT_BASE_SIZE);
>         gtk_window_set_title(GTK_WINDOW(MyWindow->window), title);
>         gtk_signal_connect(GTK_OBJECT(MyWindow->window),  "destroy",          
>         GTK_SIGNAL_FUNC(gtk_main_quit), NULL);
>         gtk_window_set_policy (GTK_WINDOW(MyWindow->window), FALSE, FALSE,    
>                                            FALSE);
>         gtk_widget_show((GtkWidget*)MyWindow->window);
>         gdk_flush();
> 
> }

You may use gtk_widget_set_usize():

#include <stdlib.h>
#include <gtk/gtk.h>

static void OpenWindow(int width, int height, unsigned char *title)
{
    typedef struct {
      GtkWidget *window;
      struct {
        int base_width;
        int base_height;
      } MyGeometry;
    } LnxWindow;
    
        LnxWindow *MyWindow = (LnxWindow*) malloc(sizeof(LnxWindow));

	MyWindow->MyGeometry.base_width = width;
        MyWindow->MyGeometry.base_height = height;  

        gtk_init(NULL, NULL);         
        MyWindow->window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
        gtk_window_set_title(GTK_WINDOW(MyWindow->window), title);
        gtk_signal_connect(GTK_OBJECT(MyWindow->window),  "destroy",          
        GTK_SIGNAL_FUNC(gtk_main_quit), NULL);
        gtk_window_set_policy (GTK_WINDOW(MyWindow->window), FALSE, FALSE,    
                                           FALSE);
        gtk_widget_set_usize(MyWindow->window,            
        MyWindow->MyGeometry.base_width,  MyWindow->MyGeometry.base_height);
        gtk_widget_show((GtkWidget*)MyWindow->window);
        gdk_flush();
}

int main(int argc, char **argv)
{
    int h = 100;
    int w = 200;
    if( argc == 3 ) {
      w = atoi(argv[2]);
      h = atoi(argv[1]);
    }
    OpenWindow(w, h, "XXX");
    gtk_main();
}



-- 
Best regards
Pavel.





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]