Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

code using device context

Posted on 2004-11-17
7
Medium Priority
?
139 Views
Last Modified: 2010-05-02
Hi experts

Havent used device contest. Need to see a basic code to use device context to paint on a provided client area

0
Comment
Question by:PradeepYadhav
  • 3
4 Comments
 

Author Comment

by:PradeepYadhav
ID: 12606288
Havent used device context. Need to see a basic code to use device context to paint on a provided client area
0
 
LVL 10

Accepted Solution

by:
fds_fatboy earned 500 total points
ID: 12606449
How about this - I dragged it out of an activeX control I wrote a while time ago.

Public Sub DayGraphic(X As Long, Y As Long, Graphic As HighlightGraphic, Color As OLE_COLOR)
    Dim pic As StdPicture
    Dim hBmp As Long
    Dim bmp As BITMAP
    Dim SrcDC As Long
    Dim HoldingDC As Long
    Dim HoldingBmp As Long
    Dim PrevHoldingBmp As Long
    Dim RGBColor As Long
    Dim rcPaint As RECT
    Dim LlnghBrush As Long

    Const LstrPROCEDURE As String = MstrMODULE & ".DayGraphic" ' The procedure name.
    On Error GoTo ErrorHandler

    Select Case Graphic
    Case [Crossed out date]
        If MlnghCrossDC = 0 Then
            MlnghCrossDC = CreateCompatibleDC(picDates.hdc)
            Set pic = LoadResPicture("CrossedOut", vbResBitmap)

            MlnghCrossBmp = pic.Handle
            MlnghPrevCrossBmp = SelectObject(MlnghCrossDC, MlnghCrossBmp)
        End If

        hBmp = MlnghCrossBmp
        SrcDC = MlnghCrossDC
    Case [Ringed date]
        If MlnghRingDC = 0 Then
            MlnghRingDC = CreateCompatibleDC(picDates.hdc)
            Set pic = LoadResPicture("ringedDate", vbResBitmap)

            MlnghRingBmp = pic.Handle
            MlnghPrevRingBmp = SelectObject(MlnghRingDC, MlnghRingBmp)

        End If

        hBmp = MlnghRingBmp
        SrcDC = MlnghRingDC
    End Select

    GetObject hBmp, Len(bmp), bmp

    rcPaint.Left = 0
    rcPaint.Top = 0
    rcPaint.Right = bmp.bmWidth
    rcPaint.Bottom = bmp.bmHeight

    HoldingDC = CreateCompatibleDC(MlnghBufferDC)
    HoldingBmp = CreateCompatibleBitmap(MlnghBufferDC, rcPaint.Right, rcPaint.Bottom)
    PrevHoldingBmp = SelectObject(HoldingDC, HoldingBmp)

    RGBColor = TranslateOLEColor(Color)

    If RGBColor <> vbWhite Then
        LlnghBrush = CreateSolidBrush(RGBColor)
        FillRect HoldingDC, rcPaint, LlnghBrush
        DeleteObject LlnghBrush
        BitBlt HoldingDC, 0, 0, rcPaint.Right, rcPaint.Bottom, SrcDC, 0, 0, vbSrcPaint
        ReleaseDC HoldingBmp, SrcDC
        TransparentBlt MlnghBufferDC, X, Y, rcPaint.Right, rcPaint.Bottom, HoldingDC, 0, 0, rcPaint.Right, rcPaint.Bottom, vbWhite
        ReleaseDC MlnghBufferBmp, HoldingDC
    Else
        BitBlt HoldingDC, 0, 0, rcPaint.Right, rcPaint.Bottom, SrcDC, 0, 0, vbNotSrcCopy
        ReleaseDC HoldingBmp, SrcDC
        TransparentBlt MlnghBufferDC, X, Y, rcPaint.Right, rcPaint.Bottom, HoldingDC, 0, 0, rcPaint.Right, rcPaint.Bottom, vbBlack
        ReleaseDC MlnghBufferBmp, HoldingDC
    End If

    SelectObject HoldingDC, PrevHoldingBmp
    DeleteObject HoldingBmp
    DeleteDC HoldingDC

    Exit Sub
ErrorHandler:
'Error handler code [Generated 18/05/04 Using LCPEditToolbox Ver 1.2 build 90]
'This code block must be the last code in the procedure.
    'Clean up
    Set pic = Nothing

    With Err
        If .Source = App.Title Then
            .Source = App.Title & "::" & LstrPROCEDURE
        End If

        .Raise .Number, .Source, .Description, .HelpFile, .HelpContext
    End With

End Sub
0
 
LVL 10

Expert Comment

by:fds_fatboy
ID: 12606658
Looking at it that's probably a bit hefty. I haven't got time to knock up an example now and tonight I will be out drinking, but:
The first example here is probably a bit better
http://www.gameprogrammer.com/archive/html/msg06473.html
0
 
LVL 10

Expert Comment

by:fds_fatboy
ID: 12813942
I'm sure we could have got there in a while with more dialogue, but frankly the question was a little vague and my answers were not relly up to much due to being a bit busy.
0

Featured Post

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!

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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.
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…
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…
Suggested Courses

579 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