Results 1 to 11 of 11

Thread: Need help with DCs...

  1. #1
    Guest

    Question

    Hi all.

    I seem to be having some trouble with DCs.

    How can I create a compatible DC of a picturebox? Can anyone bump in a little code, please? I can't seem to make this work.

    By the way, maybe its just that I don't understand DCs correctly: I have an app which uses 4 picboxes. 3 of them are just used as buffers I use to Bitblit into the main Picturebox (the only visible one). Can I use DCs for the buffer picboxes instead? Shouldn't that make my app faster and lighter weight?

    Thanks for your help, which is gretly needed!


  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Shouldn't be hard to do
    Code:
    Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
    
    YourDC = CreateCompatibleDC(picture1.hdc)
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    Guest

    A little more info...

    Thanks man, but I need a little more info:

    I entered the code you just gave me, but then can the DC is just a long variable; I can't type YourDC.Scalewidth and YourDC.ScaleHeight and so on...

    Even though applying GDI commands works, how do I modify the properties of the DC? Do I have to delete it and recreate it everytime the picturebox will get resized?

    Thanks for replying.

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Eh, the DC doesn't have those properties, it's the bitmap that has them you might want to attach a bitmap you create with Createcompatiblebitmap, using Selectobject.
    Code:
        hbitmap = CreateCompatibleBitmap(Form1.hdc, 100, 100) 'creates a bitmap with dimensions 100X100
        SelectObject Yourdc, hbitmap
        'remember to delete your DC's later before you unload your app:
        DeleteDC Yourdc
        DeleteObject hbitmap
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  5. #5
    Guest

    Thumbs up Ok thanks a lot!

    I'll try this.

    Thanks again!


  6. #6
    Guest

    It works!

    It appears to work fine.

    Thanks again, man.

  7. #7
    Fanatic Member MoMad's Avatar
    Join Date
    Oct 2000
    Location
    Seattle, WA
    Posts
    625

    I have a similar question...

    hey, i have a similar question, but this question is not about dc and stuff....

    I am trying to make a picture box duplicate.....

    I currently know of two methods for duplicateing the picturebox and i am looking for a better way to dupe it...

    method 1:
    (at design time)
    create an array of 10 pictures and stack them on top of each other and evrytime some one presses the "duplicate" button, one will just move down... and so on... (not too smooth because after 10, there will be no more...)

    method 2:
    (at design-time)

    i will create an imagebox as follows:

    Object: picLetters()
    Property: Index
    Value/Setting: 0 to 10

    and then the do the same as method 1... note that the value/setting for Index property is a constant 0 to 10 and not dynamic...


    Basically I want to be able to do method 2 at runtime instead of design time...

    Example: (but doesnt work)

    Code:
    Private Sub Command1_Click()
    Dim tempTxt As String
    Dim textLen, i As Integer
    Dim picLetters() As PictureBox
    
    tempTxt = LCase(Text1.Text) 'the name
    textLen = Len(tempTxt)      'length of the name
    
    ReDim picLetters(0 To textLen) As PictureBox
    
    For i = 0 To textLen
        ''get an image for each letter of the name; "block_[letter].gif"
        picLetters(i) = LoadPicture(App.Path & "/images/block_" & Mid(tempTxt, i + 1, 1) & ".gif")
        picLetters(i).Top = picLetters(i - 1).Top + 1000 'move picBox 1000 units below previous picBox
    
    Next i
    
    End Function
    can anyone please help?

    Thank you.
    :MoMad:
    Nice Sig!

    http://go.to/momad/ Status: Not Ready

  8. #8
    Guest

    Try this...

    Add this code:

    Code:
    'Declaration
    Private Picboxes() as PictureBox1
    
    Redim Preserve Picboxes(0 to textlen)
    For i = 0 to textlen
        Set Picboxes(i) = New PictureBox1
        Picboxes(i).top = whereeveryouwant
        Picboxes(i).left = whereeveryouwant
        '
        '
        '....your code...
        '
        '
    next
    Picturebox1 is an existing picturebox in your form. It will be copied as run time for every:

    Code:
    Set Picboxes(i) = New PictureBox1
    That will create an array of pictureboxes . You should be able to apply the code you typed in your thread.

    Good luck!


  9. #9
    Guest

    OOps!

    Forget about the whole "Redim Preserve" statement, I didn't see you already had it in your code.


  10. #10
    Guest

    Actually, no....

    The code I've typed earlier is totally wrong. Ignore it. It works greate with forms, but not with pictureboxes.

    Sorry for the mistake....

  11. #11
    Fanatic Member MoMad's Avatar
    Join Date
    Oct 2000
    Location
    Seattle, WA
    Posts
    625

    Thanx everyone...

    hey thanks everyone, I finally got it it to work... my code just needed to 'load' the image boxes instead of trying to create new ones since they were on an array.

    anyways, its working now... so thanks to evryone that helped.




    :MoMad:
    Nice Sig!

    http://go.to/momad/ Status: Not Ready

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