Solved

Pixel Color and MDI workspace color

Posted on 2000-03-13
6
257 Views
Last Modified: 2010-05-02
How can I get the color of the bottom most right most pixel of an mdi forms picture (i.e. MDIform1.picture) and set the back ground property of the mdi form to that color.

I don't want to use any extra picture box controls if i dont have to.
0
Comment
Question by:hess
6 Comments
 
LVL 1

Expert Comment

by:fbtcell
ID: 2611509
May be you can try GetPixel API function to have the color of the pixel :
color = GetPixel(MDIform1.picture.hdc, x, y)
where x and y stand for the right (and top or left) most coordinates.

And then set the back ground property of the mdi form :
MDIform1.BackColor = color

0
 
LVL 3

Expert Comment

by:paulstamp
ID: 2612739
fbtCell - one problem with that answer : there is no hdc property of an MDI form's picture.
0
 
LVL 1

Expert Comment

by:fbtcell
ID: 2612972
I tried on an MDI form.
Make sure that MDIform1.HasDC = True and then call :
color = GetPixel(MDIform1.hDC, x, y)

(i just belived that MDIform1.picture was a PictureBox, and PictureBox used to have one hdc).
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 32

Accepted Solution

by:
Erick37 earned 50 total points
ID: 2614170
Here is a way that does not require an hDC property of the MDI main form:

'~~~~MDI MAIN FORM CODE~~~~
Option Explicit

Private Sub MDIForm_Load()
    Show
    Me.BackColor = GetLRPicPel(Me.Picture)
End Sub



'~~~~(BAS) MODULE CODE~~~~
Option Explicit
Public Const MM_HIMETRIC = 3
Public Const MM_TEXT = 1
Type POINTAPI
    x As Long
    y As Long
End Type
Declare Function LPtoDP Lib "gdi32" _
    (ByVal hdc As Long, lpPoint As POINTAPI, ByVal nCount As Long) As Long
Declare Function SetMapMode Lib "gdi32" _
    (ByVal hdc As Long, ByVal nMapMode As Long) As Long
Declare Function CreateCompatibleDC Lib "gdi32" _
    (ByVal hdc As Long) As Long
Declare Function SelectObject Lib "gdi32" _
    (ByVal hdc As Long, ByVal hObject As Long) As Long
Declare Function GetPixel Lib "gdi32" _
    (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Declare Function DeleteDC Lib "gdi32" _
    (ByVal hdc As Long) As Long

Public Function GetLRPicPel(pic As StdPicture) As OLE_COLOR
    Dim lcDC As Long
    Dim lColor As Long
    Dim lRet As Long
    Dim pt As POINTAPI
    On Error GoTo PICERR
    If (pic.Handle = 0) Then Err.Raise 1050, , "Invalid Picture"
    pt.x = pic.Width
    pt.y = pic.Height
    lcDC = CreateCompatibleDC(0)
    lRet = SetMapMode(lcDC, MM_HIMETRIC)
    lRet = SelectObject(lcDC, pic.Handle)
    lRet = LPtoDP(lcDC, pt, 1)
    lRet = SetMapMode(lcDC, MM_TEXT)
    lColor = GetPixel(lcDC, pt.x - 1, (-pt.y) - 1)
    If (lColor = -1) Then Err.Raise 1050, , "Invalid Color from GetPixel"
    GetLRPicPel = lColor
    lRet = DeleteDC(lcDC)
    Exit Function
PICERR:
    If (lcDC <> 0) Then Call DeleteDC(lcDC)
    GetLRPicPel = vbApplicationWorkspace
    MsgBox Err.Description, , "GetLRPicPel"
End Function
 
0
 

Author Comment

by:hess
ID: 2632224
Sorry, Eric37 Has the answer i'm looking for.
0
 

Author Comment

by:hess
ID: 2632226
This was great and did exactly what i needed
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to create a duplicate finder Application 9 122
VB6 - Compare and highlight cell not the same 3 53
Visual Studio 2005 text editor 10 44
Automatic Email Reminder 4 58
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

831 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