Solved

Pixel Color and MDI workspace color

Posted on 2000-03-13
6
252 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
change vba from autofit to 13.5 width? 4 29
VBA error replacing data 6 40
MS Access Search and Replace Using VBA 6 72
Getting warning: You are about to delete 1 row(s) 9 49
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
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…

777 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