Solved

Pixel Color and MDI workspace color

Posted on 2000-03-13
6
274 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
[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
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month9 days, 23 hours left to enroll

623 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