Thread: How to center the main application window of a MOTIF Widget in the center !

  1. #1
    Registered User
    Join Date
    Feb 2019
    Posts
    6

    How to center the main application window of a MOTIF Widget in the center !

    How to center the main application window of a MOTIF Widget in the center of the computer screen ? for example a form Widget here.The code is ready and working but the window appears on the left upper side on the screen.IN NORMAL C PROGRAMMING ! Of course no ++This MOTIF Windows is working correct already.The only thing i want to do is to position it in the middle of the computerscreen.It has something to do with the command Xtscreen.The code is attached as file form.cWBRSennenmutIll try to insert code here correct :===========================================
    Code:
     
    
    #include <Xm/Xm.h>
    #include <Xm/Form.h>
    #include <Xm/Label.h>
    #include <Xm/PushB.h>
    
    
    void main ( int argc, char ** argv )
    
    {
        Widget              shell, form, label, button;
        XtAppContext app;
        int  i;
        
            
        shell = XtAppInitialize ( &app, "Formtest", NULL, 0,
                                  &argc, argv, NULL, NULL, 0 );
                        
        
        form = XtCreateManagedWidget ( "form", xmFormWidgetClass,
                                        shell, NULL, 0 );
                                        
        XtVaSetValues ( form,
                      XmNwidth, 500, 
                      XmNheight, 300, 
                      NULL );               
        
     
        label = XtVaCreateManagedWidget ( "label", xmLabelWidgetClass,
                                        form, NULL, 0 );
        
        button = XtVaCreateManagedWidget ( "button", xmPushButtonWidgetClass,
                                        form, 
                                        XmNbottomAttachment,       XmATTACH_FORM,
                                         0 );
        XtVaSetValues ( button,
                      XmNwidth, 100, 
                      XmNheight, 50, 
                      NULL );
        
                                            
        XtRealizeWidget ( shell );
        XtAppMainLoop ( app );
        
    }
    Attached Files Attached Files
    Last edited by Sennenmut; 02-12-2019 at 02:08 PM. Reason: Code insert attemption 2

  2. #2
    Registered User
    Join Date
    Feb 2019
    Posts
    6
    ok C programming friend. without ++

    i have pasted the code here already. my first posting here so i have 3 attempts.

    here a GUI in plain C language with MOTIF is ready.

    Only position in the center of screen is the task and reason for my posting here !!!

    I thin the MOTIF command Xtscreen has something to do with that !

  3. #3
    Registered User
    Join Date
    Dec 2017
    Posts
    1,626
    Code:
    #include <Xm/Xm.h>
    #include <Xm/Form.h>
    #include <Xm/PushB.h>
     
    #define WIDTH  500
    #define HEIGHT 300
     
    int main(int argc, char **argv)
    {
        XtAppContext app;
        Widget shell = XtVaAppInitialize(
            &app, "Formtest", NULL, 0, &argc, argv, NULL, NULL);
     
        Screen *screen = XtScreen(shell);
        Position width = WidthOfScreen(screen);
        Position height = HeightOfScreen(screen);
     
        XtVaSetValues(shell,
            XmNx, (width - WIDTH) / 2,
            XmNy, (height - HEIGHT) / 2, NULL);
     
        Widget form = XtVaCreateManagedWidget(
            "form", xmFormWidgetClass, shell,
            XmNwidth, WIDTH, XmNheight, HEIGHT, NULL);
     
        Widget button = XtVaCreateManagedWidget(
            "button", xmPushButtonWidgetClass, form,
            XmNbottomAttachment, XmATTACH_FORM, NULL);
     
        XtRealizeWidget(shell);
        XtAppMainLoop(app);
        return 0;
    }
    A little inaccuracy saves tons of explanation. - H.H. Munro

  4. #4
    Registered User
    Join Date
    Feb 2019
    Posts
    6
    he he he ALLRIGHT !
    It works.
    I am a C Programmer beginning with MOTIF GUI Programming.
    The concept and syntax of MOTIF i find better than other GUI toolkits.
    This first WINDOW is the start !
    Thank you john for that posting.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. center text
    By Emerald in forum C Programming
    Replies: 4
    Last Post: 09-02-2009, 06:09 AM
  2. How do you center a window?
    By Queatrix in forum Windows Programming
    Replies: 4
    Last Post: 05-28-2005, 06:25 PM
  3. center the GetOpenFileName
    By Joelito in forum Windows Programming
    Replies: 4
    Last Post: 04-15-2005, 11:26 AM
  4. Center text
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 05-29-2002, 11:18 AM

Tags for this Thread