Solved

Get window title in linux

Posted on 2007-11-21
4
2,087 Views
Last Modified: 2012-08-13
Hai all, i need to develop a program to get the title of the active window and if it contains some words that are not allowed in the lab session i need to close it.Thatz the question in a nutshell.
Now i'll explian it a little more.
I'm studying. In our lab, the systems are mainly used to do our c,c++,java programs and we're permitted to browse the web in off lab hours.But most of us do these two at the same time i,e browse the net in our lab hours.Now i'm assigned by our HOD  to develop a tool to avoid this.What i need is a program to check the active window title continuously and if it contains some word like "FireFox,Opera,Orkut etc" it will spawn a command box to enter the Auth no: from our lab admin and if it is correct then allow the person to continue else close that window.This is coz when we are dng our lab peoples from other departments will be using it for browsing.
Now you got the main idea.Now tell me how to get the active window title, close it and start automatically upon system startup using C++. we're using RedHat,Debian, fedora etc........

0
Comment
Question by:aczire
  • 2
  • 2
4 Comments
 
LVL 11

Expert Comment

by:cup
ID: 20339347
Which window manager are you using?  You can get the title but the API for each window manager is different, unless you use native-X.  You also have to make sure nobody plays with the X-windows resource file.  You can modify the resource file to disguise the title.  The app can pick the resource file from one of 13 places.
0
 
LVL 1

Author Comment

by:aczire
ID: 20348599
Hai,
we are using KDE.Now tell me how can i get the title of the active window and get a handle to close it if it confirms to the specifications.
0
 
LVL 11

Accepted Solution

by:
cup earned 50 total points
ID: 20352594
I don't know a lot about KDE.  All I know is that it is based on Trolltech Qt.  You could use editres to find out what the title is called in the widget tree and then use XtVaGetValues to get the titles.

Build a simple app.  Add editres to the app

#include <X11/Xmu/Editres.h>

After you've created the app

XtAddEventHandler (shell, (EventMask)0, True, _XEditResCheckMessages, NULL);

where shell is the Application shell widget.  When you link, link with -lXmu

Start up your app and then run editres.  This is a pretty ancient program from the time of athena widgets.  The cursor is the box in the top left corner.  It is the window on a very large canvas.    From the Command menu, GetWidgetTree.   Select your app and you will get the widget tree of your app.  Expand the nodes until you find the title.  It will be something like label, toplabel or even title.  You can get editres to flash the widget you've selected to make sure you've got the right one.  

Once you've got the right one, show the resource box from the commands menu.  That will give you a brief idea of how to get to the title starting from the app widget.

You may need to start at the window manager, ask it for all its children and go through in turn getting the titles and the pids.

To close it, find out the pid and send it a kill -9.

Sorry - I cannot tell you any more than that.  I'm using Motif/CDE which is completely different from Qt/KDE.
0
 
LVL 1

Author Closing Comment

by:aczire
ID: 31410342
I'll check it out and tell u.Thanks a lot
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now