Drawing rectangles in picture (data)


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Drawing rectangles in picture (data)

  1. #1
    Join Date
    Dec 2005
    Posts
    4

    Unhappy Drawing rectangles in picture (data)

    A friendly 'hello' to everybody!

    I really don't like to ask you about some code, but I tried and tried and tried and I didn't get my code to work

    I'm working with VBA.
    I receive a picture from an interface and this picture is stored in memory in the variable pic (defined as stdPicture).
    Now i want to draw rectangles and circles into this picture, but unfortunately I don't have a PictureBox or Image Control. I have a special Control (ocx) to display the picture. How can I do this??

    I tried to get it to work with createDC, SelectObject, MoveTo, LineTo,... but it didn't work, obviously because I don't know how to use these commands right.

    You can believe me, I really tried several hours, but as time is nearly up I'm asking for your help...

    Can anyone pleeeaaase give me some lines of code??

    Thanks in advance

    Daniel

  2. #2
    Join Date
    Nov 2003
    Location
    Alameda, CA
    Posts
    1,737
    Gosh... without knowing the specifics of that "special" control, it is not easy for us to help you...
    The stdPicture is just a picture holder, and you cannot do any graphics in it (AFAIK, but I never tried). You can get the handle of the bitmap object from the stdPicture and do the graphics using API (this is what I do), or you can load the picture in a control that allows graphics (like the PictureBox)
    Marco
    "There are two ways to write error-free programs. Only the third one works."
    Unknown

  3. #3
    Join Date
    Mar 2006
    Posts
    11
    The following code works with the picture from an image control, you have to do something to make the image refresh afterwards though, like resizing or making visible.
    The problem with working in VBA is that it doesn't give you any handles to windows or DCs, I solved this using the FindWindow command: "ThunderDFrame" is the class name for userforms (I found it using an EnumWindows, I can give you that code as well if you want), so there must be a userform running to make this work.
    If anyone knows an easier way, I would like to know because I've been trying to do this for ages and this is the only way I've found.


    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
    Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
    Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
    Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
    Private Declare Function CreateEllipticRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
    Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
    Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
    Private Declare Function FillRgn Lib "gdi32" (ByVal hdc As Long, ByVal hRgn As Long, ByVal hBrush As Long) As Long

    Sub DrawOnPic(Pic As StdPicture)
    Dim hImgDC As Long
    'This line finds a userform, gets its DC and creates a new
    'compatible DC which should also be compatible with the pic's DC
    hImgDC = CreateCompatibleDC(GetDC(FindWindow("ThunderDFrame", vbNullString)))
    Dim hPrevBM As Long 'storing previous values isnt actually necessary
    hPrevBM = SelectObject(hImgDC, Pic)

    Dim hCircle As Long
    hCircle = CreateEllipticRgn(3, 20, 20, 57) 'create a circle
    Dim hRect As Long
    hRect = CreateRectRgn(10, 2, 45, 8) 'create a rectangle
    Dim hBrush As Long

    hBrush = CreateSolidBrush(RGB(10, 200, 250))
    FillRgn hImgDC, hRect, hBrush 'draw rectangle
    DeleteObject hBrush

    hBrush = CreateSolidBrush(RGB(120, 45, 2))
    FillRgn hImgDC, hCircle, hBrush 'draw circle
    DeleteObject hBrush

    DeleteObject hRect 'delete and reset everything
    DeleteObject hCircle
    SelectObject hImgDC, hPrevBM
    DeleteDC hImgDC
    End Sub

Similar Threads

  1. Importing .NET data Grid to the SQL server database
    By software_develo in forum Database
    Replies: 2
    Last Post: 11-21-2005, 10:18 AM
  2. Data Junction Announces XML Junction 7.51
    By Tim Frost in forum xml.announcements
    Replies: 0
    Last Post: 04-02-2001, 10:53 AM
  3. Replies: 0
    Last Post: 07-22-2000, 04:07 AM
  4. DataGrid - Enter data in a cell at run time
    By William Gaddam in forum VB Classic
    Replies: 1
    Last Post: 05-02-2000, 09:19 PM
  5. Complex Data Consumer Data Aware Classes
    By Desmond Cassidy in forum authorevents.kurata
    Replies: 3
    Last Post: 04-19-2000, 03:54 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center