Results 1 to 6 of 6

Thread: I'm so confused!!! [RESOLVED]

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2002
    Posts
    229

    I'm so confused!!! [RESOLVED]

    Code:
    Option Explicit
    
    Public Function LoadGraphics(FileName As String, PosX As Long, PosY As Long, Width As Long, Height As Long) As Long
        On Error GoTo ErrHandler
        
        Dim DC As Long
        Dim DestDC As Long
        Dim Image As Long
        Dim NewTile As Integer
        
        NewTile = frmMain.MapTiles.Count
        
        Load frmMain.MapTiles(NewTile)
        frmMain.MapTiles(NewTile).Visible = True
        frmMain.MapTiles(NewTile).Move Rnd * 1000, Rnd * 1000
        
        FileName = App.Path & "\Maps\" & FileName
        
        DestDC = GetDC(frmMain.MapTiles(NewTile).hwnd)
        
        DC = CreateCompatibleDC(DestDC)
        
        Image = LoadImage(0, FileName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE)
        
        SelectObject DC, Image
        
        BitBlt DestDC, 0, 0, Width, Height, DC, PosX, PosY, SRCCOPY
        
        DeleteDC DC
        DeleteDC DestDC
        DeleteObject Image
        
        Exit Function
        
    ErrHandler:
        MsgBox Err.Number & Err.Description
    End Function
    That's my code to retrieve a part of an image and put it in a picture box. But it's not working !! WHHHHHYYY???? WHHHHHHHHHHYYYYYYYY GOOOOOOOOOODDD!!!! Can someone please check it out for me or give me SIMPLE WORKING CODE. thank you!
    Last edited by INF3RN0666; May 18th, 2003 at 03:13 PM.

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Have you set the AutoRedraw property of the picture box? A picture box also have a hDC property so you don't really have to call GetDC.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2002
    Posts
    229
    Umm the autoredraw feature is on but now it just gives me grey squares!

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Mar 2002
    Posts
    229

    PLEH

    WELL...I know what's causing the problem, but I don't know how i'm gonna fix it! If I give the code the DC of the form, it works fine! but if i give it the DC of the image box, it's messed up! Is it because it's a control array?

  5. #5
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: PLEH

    Originally posted by INF3RN0666
    WELL...I know what's causing the problem, but I don't know how i'm gonna fix it! If I give the code the DC of the form, it works fine! but if i give it the DC of the image box, it's messed up! Is it because it's a control array?
    Is it an image box and not a picture box?

  6. #6
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    Your code works for me if I include a line to refresh the new control before the code to load the image.


    Load frmMain.MapTiles(NewTile)
    frmMain.MapTiles(NewTile).Visible = True
    frmMain.MapTiles(NewTile).Move Rnd * 1000, Rnd * 1000
    frmMain.MapTiles(NewTile).Refresh

    ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width