Solved

Pixel Color and MDI workspace color

Posted on 2000-03-13
6
242 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
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…

747 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

13 Experts available now in Live!

Get 1:1 Help Now