Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Get window title in linux

Posted on 2007-11-21
4
Medium Priority
?
2,110 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 150 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

704 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