Announcement

Collapse
No announcement yet.

How to modify a Visual Basic Picturebox with Powerbasic?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to modify a Visual Basic Picturebox with Powerbasic?

    I'm trying to modify an image stored in a Visual Basic Pictute control using a PowerBasic Dll.

    The function below works fine changing the back color, but I can not draw an elipse in the same image.

    Someone know how to do it?


    '________________________________________________________

    #COMPILE DLL
    #DIM ALL

    %USEMACROS = 1
    #INCLUDE "Win32API.inc"

    GLOBAL ghInstance AS DWORD

    '-------------------------------------------------------------------------------
    ' Main DLL entry point called by Windows...
    '
    FUNCTION LIBMAIN (BYVAL hInstance AS LONG, _
    BYVAL fwdReason AS LONG, _
    BYVAL lpvReserved AS LONG) AS LONG

    SELECT CASE fwdReason

    CASE %DLL_PROCESS_ATTACH
    'Indicates that the DLL is being loaded by another process (a DLL
    'or EXE is loading the DLL). DLLs can use this opportunity to
    'initialize any instance or global data, such as arrays.

    ghInstance = hInstance

    FUNCTION = 1 'success!

    'FUNCTION = 0 'failure! This will prevent the EXE from running.

    CASE %DLL_PROCESS_DETACH
    'Indicates that the DLL is being unloaded or detached from the
    'calling application. DLLs can take this opportunity to clean
    'up all resources for all threads attached and known to the DLL.

    FUNCTION = 1 'success!

    'FUNCTION = 0 'failure!

    CASE %DLL_THREAD_ATTACH
    'Indicates that the DLL is being loaded by a new thread in the
    'calling application. DLLs can use this opportunity to
    'initialize any thread local storage (TLS).

    FUNCTION = 1 'success!

    'FUNCTION = 0 'failure!

    CASE %DLL_THREAD_DETACH
    'Indicates that the thread is exiting cleanly. If the DLL has
    'allocated any thread local storage, it should be released.

    FUNCTION = 1 'success!

    'FUNCTION = 0 'failure!

    END SELECT

    END FUNCTION

    SUB ReplaceColor_and_elipse ALIAS "ReplaceColor_and_elipse" (BYVAL hDC_ORIGINAL AS LONG, _
    BYVAL xOffset AS LONG, _
    BYVAL yOffset AS LONG, _
    BYVAL nWidth AS LONG, _
    BYVAL nHeight AS LONG, _
    BYVAL UseWidth AS LONG, _
    BYVAL UseHeight AS LONG, _
    BYVAL WasColor AS LONG, _
    BYVAL NewColor AS LONG) EXPORT

    REGISTER x AS LONG, y AS LONG

    DIM BITMAP1 AS BITMAP
    DIM BITMAP1_informacion AS BITMAPINFO
    DIM pDW AS DWORD PTR

    IF UseWidth = 0 THEN UseWidth = nWidth
    IF UseHeight = 0 THEN UseHeight = nHeight


    WasColor = RGB(GetBValue(WasColor), GetGValue(WasColor), GetRValue(WasColor))
    NewColor = RGB(GetBValue(NewColor), GetGValue(NewColor), GetRValue(NewColor))

    BITMAP1_informacion.bmiHeader.biSize = SIZEOF(BITMAP1_informacion.bmiHeader)
    BITMAP1_informacion.bmiHeader.biWidth = nWidth
    BITMAP1_informacion.bmiHeader.biHeight = nHeight
    BITMAP1_informacion.bmiHeader.biPlanes = 1
    BITMAP1_informacion.bmiHeader.biBitCount = 32
    BITMAP1_informacion.bmiHeader.biCompression = %BI_RGB

    DIM hDC_TEMPORAL AS LONG
    DIM hTmpBmp AS LONG

    hDC_TEMPORAL = CreateCompatibleDC (hDC_ORIGINAL)
    hTmpBmp = CreateDIBSection(hDC_TEMPORAL, BITMAP1_informacion, %DIB_RGB_COLORS, 0, 0, 0)

    CALL GlobalLock(hTmpBmp)

    CALL SelectObject(hDC_TEMPORAL, hTmpBmp)
    CALL BitBlt( hDC_TEMPORAL, 0, 0, nWidth, nHeight, hDC_ORIGINAL, 0, 0, %SRCCOPY)
    CALL GetObject( hTmpBmp, SIZEOF(BITMAP1), BITMAP1)

    FOR pDW = BITMAP1.bmBits TO BITMAP1.bmBits + (BITMAP1.bmWidth * BITMAP1.bmHeight * 4) STEP 4
    IF @pDW = WasColor THEN @pDW = NewColor
    NEXT

    '**** ON THIS PART, I'M TRYING TO DRAW AN ELIPSE
    GRAPHIC ATTACH hDC_TEMPORAL, hTmpBmp
    GRAPHIC ELLIPSE (0, 0) - (nWidth, nHeight) , RGB(0,0,0),RGB(0,255,0),1
    '************************************************************************************

    CALL BitBlt(hDC_ORIGINAL, xOffset, yOffset, UseWidth, UseHeight, hDC_TEMPORAL, xOffset, yOffset, %SRCCOPY)

    ' Deallocate system resources.
    CALL GlobalUnLock( hTmpBmp )
    CALL DeleteDC( hDC_TEMPORAL )
    CALL DeleteObject( hTmpBmp )

    END SUB
    '________________________________________________________

    There is atached a winzip file with the source code in Powerbasic and Visual Basic.
    Attached Files

  • #2
    Code:
    **** ON THIS PART, I'M TRYING TO DRAW AN ELIPSE
    GRAPHIC ATTACH hDC_TEMPORAL, hTmpBmp
    GRAPHIC ELLIPSE (0, 0) - (nWidth, nHeight) , RGB(0,0,0),RGB(0,255,0),1
    AFAIK you may not use the GRAPHIC XXX commands except against windows created with either GRAPHIC WINDOW or CONTROL ADD GRAPHIC.

    But you can use the WinAPI Ellipse() function... ASSUMING Visual BASIC does not mind you screwing with its picture box control.

    PS: Please use CODE TAGS when posting code. http://www.powerbasic.com/support/pb....php?do=bbcode

    MCM
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Roberto,

      IIRC you will have to use COM to draw your ellipse on a VB PictureBox control from PB.
      Later...

      JR

      "When governments fear the people there is liberty. When people fear the government there is tyranny." - Thomas Jefferson

      Comment

      Working...
      X