Question

Get client area without borders

Asked by: List244

I am in need of getting an applications client-area without borders. Since the borders in different Windows versions change, borders are causing me problems.

I have a static pixel location, let's say 10,10. I want to be able to monitor this pixel's color. My problem is, with borders, the pixel is not always at 10,10. What if the application has no border? What if the windows scheme creates larger or smaller borders?

Is there a way to get pixels with 0,0 always starting at the top-left of the client area rather than of the window area?

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-05-13 at 08:39:36ID24405210
Tags

C++ windows border

Topics

Windows Programming

,

Microsoft Visual C++

,

C++ Programming Language

Participating Experts
4
Points
125
Comments
19

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Black border
    It's fairly simple, all I want is a table with a BLACK border (in Netscape). I have set the bordercolor, bordercolorlight and bordercolordark properties. But still it's NOT black... I hope someone can help me. My HTML is a bit rusty :-/ Regards, CJ
  2. Table Border
    Hi Guys How could I make this table appear to look like this with an image in the corner : ***************** * * * * * * * * * * * ...
  3. border question
    Hello, I'm trying to have a border around the h2 at this address: http://www.customer2.com/features/Customer_Convenience/ to look similiar to number 2 here: http://www.whatisflash.com/polls/logo-finals.php with the CUSTOMER text and 2.0 seperated by a vertical line meeti...
  4. border
    Hi I want to remove the border and title bar of the flash swf file or projector file. I used the flash jestor jugglor, it worked nicely for me but its costly. Plz some one refer me a free software , or other technique to do this work. THANX

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: abelPosted on 2009-05-13 at 08:48:55ID: 24376269

Isn't what you are after the function GetClientRect? It retrieves a RECT structure without the borders. And the (0, 0) position is always inside the border for any painting functions.

 

by: ZoppoPosted on 2009-05-13 at 08:52:25ID: 24376308

Hi List244,

I'm not sure if I understand - the rect returned by GetClientRect() always returns the rectangle of the window's client area with 0, 0 as the top/left point.

So I guess the problem is how you monitor the pixel at 10, 10 - IMO you need a DC for the client area of the window - this is returned by GetDC().

Maybe you should post some code so we could see what the problem is ...

ZOPPO

 

by: ZoppoPosted on 2009-05-13 at 08:52:52ID: 24376314

Sorry abel - you were faster ...

 

by: alb66Posted on 2009-05-13 at 09:04:09ID: 24376464

It should be

HDC hDC = ::GetDC( hWnd );
COLORREF cref = ::GetPixel( hDC, 10, 10 );

 

by: List244Posted on 2009-05-13 at 10:11:36ID: 24377241

I am basically looking for some sort of translate.. Firstly, I have a color-picker. This color-picker grabs a color off the screen and gets a pixel position. This is how I find the static position (10,10). How this color picker works is it uses GetWindowRect and gets the DC of desktop. It then gets the current mouse coords and subtracts the left/top from the rect. This gives me the current position in the window of the pixel under the mouse.

However, when I go back to check this position (10,10), it is no longer returning the same position since getpixel is ignoring borders and the previous method of subtracting the rect is not.

 

by: abelPosted on 2009-05-13 at 10:24:51ID: 24377385

It is easier to use GetPixel and GetWindowDC on the desktop window, because GetPixel is free of the current window and the desktop window is borderless you don't have offset problems. Then they'll work. I saw that technique in this code: http://www.codeguru.com/vb/gen/vb_graphics/article.php/c2357

 

by: itsmeandnobodyelsePosted on 2009-05-13 at 10:48:32ID: 24377615

I don't know whether I understand your problem correctly but let me try:

Assuming the (10, 10) are relative coords to the window's client area and you need the absolute screen coords out of this, do

   POINT pt = { 10, 10};
   ClientToScreen(hwndClient,  &pt);

If the (10, 10) are screen coordinates use

   POINT pt = { 10, 10};
   ScreenToClient(hwndClient,  &pt);

to make it client coords.



 

by: List244Posted on 2009-05-14 at 06:13:44ID: 24384534

I am assuming that my problem is borders, but I will explain my problem:

I use GetDC on the desktop. I then get the current window (WindowFromPoint) and subtract the top-left. This gives me my pixel location in the current window.

I then take what I get from that to another application. It again uses GetDC on the desktop. Then, it adds the top-left of the window to the static (10,10), or whatever the pixels may be. But, when I do this , I am getting two different pixels.

I need to be able to use one program to grab a pixel and it's location, and I need to take that to my other program which is needs to find that pixel and monitor it.

 

by: abelPosted on 2009-05-14 at 06:18:25ID: 24384589

Remove the part where you do a WindowFromPoint. The GetPixel works fine with only the desktop DC, regardless the windows on top of it. In fact, you should not need any offset calculations at all.

 

by: List244Posted on 2009-05-14 at 06:37:04ID: 24384791

Well, the reason I am doing that is to get the coord in the app for my other application. Because if I just get the point... I don't know that when my other app runs that it will be in the same spot.

Should I replace that with ScreenToClient on the WindowFromPoint? Rather than subtracting top-left?

 

by: List244Posted on 2009-05-14 at 18:17:29ID: 24391584

Here is an update with more specifics:

ScreenToClient(WindowFromPoint(*Mouse),Mouse); //Mouse is an LPPOINT

That is how the original X,Y are grabbed(489,469)

Then the following is done:

POINT Pos;
Pos.x = 489;
Pos.y = 469;
ClientToScreen(WinHandle,&Pos); //WinHandle is a known handle to the window in question

Now I get: 1184,673.

I use SetCursorPos(Pos.x,Pos.y)

Now, it sets the cursor to the wrong position. It is not the position I wanted it at. Also, when I return to the color picker, it tells me that the position it set it to is:

(487,438)


Maybe now that I have included the code someone can help me out.

 

by: abelPosted on 2009-05-15 at 03:50:33ID: 24394007

I'd love to help you out, but something tells me that I'm not certain about what you are doing. Let me try to put it in my words, and perhaps you can tell me whether I am correct or not.

  1. Get the color under the mouse pointer, regardless under what window or process
     
  2. Run another program, which monitors this pixel
     
  3. If the window where the pixel was found, moves, the relative position should be used of that window. 
I'm not sure about step 3. If you want any static position relative to the top-left of the screen there should be no problem at all, because that's just absolute. But since you seem to have problems, I assume that step 3 is important. Can you confirm / elaborate?

 

by: abelPosted on 2009-05-15 at 03:51:47ID: 24394017

Btw: I have no idea what SetCursorPos does in this thread, is that some other requirement, moving the mouse pointer? Let's focus on the monitoring bit first... ;)

 

by: List244Posted on 2009-05-15 at 06:14:33ID: 24395092

Abel, SetCursorPos is a test. It is my way of seeing what the program is doing. It is not working, I know this, so I added that to see where the program is trying to monitor vs. where I wanted it to. And in doing so I found that it is actually a bit off from the pixel I wanted it to monitor.

Abel, not quite. Here is the best way I can explain it:

Say you have a 3rd party app which has a circle in the corner of the app. This circle changes colors depending on the status. This color is a code which has meaning. Let's say red is an error, black is a slow-down, and green means it is running good. So, I make a color-picker, this application's sole purpose is so that I can find the position of this circle, or at least, a pixel in the circle. I take this coord, and I take it to my REAL application, the one I am developing. And I use this application to monitor that circle... if GetPixel returns Red, it notes the error, black, it notes the slow-down, green, it does nothing.

Now, my problem is the pixel I am getting from the picker is not matching up with the pixel the real application is grabbing.

I've tried to fix this most recently by using ScreenToClient and ClientToScreen. I got the pixel with the color picker by getting the general cursor pos and using ScreenToClient. This gave me the pixel at 489,469. I took that number to the real app and did ClientToScreen. This failed to grab the correct pixel. So to test it, I set the cursor position. It set it a bit off from where I wanted.

So my problem is.. how do I get the cursor position relative to a window, and then save that so that I can get that position relative to that window at any time?

 

by: abelPosted on 2009-05-15 at 08:20:24ID: 24396724

Ok, that makes sense. Am I correct in saying that the circle is relative to a certain windows topleft corner? In other words, you will need the window position containing that circle and find the pixel relative to that top left corner. And monitor that.

 

by: List244Posted on 2009-05-15 at 08:33:06ID: 24396893

Yes.

 

by: List244Posted on 2009-05-20 at 08:19:26ID: 24432889

Anyone have ideas?

 

by: List244Posted on 2009-05-22 at 11:54:04ID: 24454116

I got it working:

I was using:

GetCursorPos
ScreenToClient(WindowFromPoint,Pos)
ClientToScreen(WindowFromPoint,Pos)

It was not working correctly. I changed it to:

GetCursorPos
WIN = WindowFromPoint
ScreenToClient(WIN,Pos)
ClientToScreen(WIN,Pos)

This fixed it. Apparently somehow, even though the application was not changing, it was not liking the recall to getting the HWND.

 

by: abelPosted on 2009-05-22 at 12:14:29ID: 24454250

Funny, we were working on it together, but I was a bit busy so it went on slowly... But I have a nice color picker now which can monitor any pixel on the screen ;)

Quite odd that the change you show, actually makes a difference. Glad it eventually works though.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...