Solved

Pixel Color and MDI workspace color

Posted on 2000-03-13
6
245 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
DO Loop not working 4 72
Help in WHSCRIPT 9 47
VB6 - Convert HH:MM into Decimal 8 53
clicking a shape in a frame array vb6 3 40
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…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

867 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now