YOU CAN CODE!

 

With The Case Of UCanCode.net  Release The Power OF  Visual C++ !   HomeProducts | PurchaseSupport | Downloads  
Download Evaluation
Pricing & Purchase?
E-XD++Visual C++/ MFC Products
Overview
Features Tour 
Electronic Form Solution
Visualization & HMI Solution
Power system HMI Solution
CAD Drawing and Printing Solution

Bar code labeling Solution
Workflow Solution

Coal industry HMI Solution
Instrumentation Gauge Solution

Report Printing Solution
Graphical modeling Solution
GIS mapping solution

Visio graphics solution
Industrial control SCADA &HMI Solution
BPM business process Solution

Industrial monitoring Solution
Flowchart and diagramming Solution
Organization Diagram Solution

Graphic editor Source Code
UML drawing editor Source Code
Map Diagramming Solution

Architectural Graphic Drawing Solution
Request Evaluation
Purchase
ActiveX COM Products
Overview
Download
Purchase
Technical Support
  General Q & A
Discussion Board
Contact Us

Links

Get Ready to Unleash the Power of UCanCode .NET


UCanCode Software focuses on general application software development. We provide complete solution for developers. No matter you want to develop a simple database workflow application, or an large flow/diagram based system, our product will provide a complete solution for you. Our product had been used by hundreds of top companies around the world!

"100% source code provided! Free you from not daring to use components because of unable to master the key technology of components!"


MFC Source Code: WindowFromPoint and GetDlgItem or ScreenToClient

 
 

Code Snippet

This codes demonstrates what is involved in writing a dialog-based application for Windows® using nothing but C and the Windows API. It further explores concepts pertaining to the GDI, with a focus on device contexts and bit block transfers. And, it shows how to manipulate the clipboard.

There was a workaround needed for the "Grab Color" feature. The reason being is that I used the GetPixel function for it; therefore, if you have coordinates for a non-client area in a window, it returns -1. This is not a valid color, so I used BitBlt to rectify the problem by copying the pixel to a static control and then using GetPixel on the control, thus returning a valid color. The following code demonstrates this technique.

Collapse Copy Code
// get a handle to the window under the cursor
hWndxy = WindowFromPoint(spoint);

// get a handle to the preview pane
hPreview = GetDlgItem(hWnd,IDC_STATIC_PREVIEW);

// get the dc for the window in question
hDC = GetDC(hWndxy);

// GetPixel() requires client coordinates
ScreenToClient(hWndxy, &cursor);
rgb = GetPixel(hDC, cursor.x, cursor.y);

/*/
/ / The following is a workaround for the GetPixel API. If the
/ / cursor is over a titlebar or other non-client areas of the
/ / window it'll return -1 for the RGB intensities. In this case
/ / we use BitBlt to copy the color to our control and extract
/ / the the intensities from that.
/*/

// check to see if intensities are valid
if(rgb == -1)
{
    HDC hDCPrev = GetDC(hPreview);

    BitBlt(hDCPrev, 0, 0, 1, 1, hDC, 
           cursor.x, cursor.y, SRCCOPY);
    rgb = GetPixel(hDCPrev, 0, 0);

    // clean up
    ReleaseDC(hPreview, hDCPrev);
}

// clean up
ReleaseDC(hWndxy, hDC);

 

 

Copyright ?1998-2009 UCanCode.Net Software , all rights reserved.
Other product and company names herein may be the trademarks of their respective owners.

Please direct your questions or comments to webmaster@ucancode.net