Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Capturing a Picturebox in Windows 8

Capturing a Picturebox in Windows 8

Scheduled Pinned Locked Moved Visual Basic
helpcareer
24 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G gwittlock

    That would be my mistake then.

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #11

    Here's a simple suggestion: rewrite the above code in VB.NET and see what the results are.

    I 1 Reply Last reply
    0
    • D Dave Kreskowiak

      The problem you're going to have asking questions about VB6 is that very few people still have it installed to test the code and come up with a solution! This is going to be true at ANY forum, unless it's specifically dedicated to VB6.

      A guide to posting questions on CodeProject

      Click this: Asking questions is a skill. Seriously, do it.
      Dave Kreskowiak

      G Offline
      G Offline
      gwittlock
      wrote on last edited by
      #12

      OK OK! I get it! Don't ask questions. Done and Done.

      L D 2 Replies Last reply
      0
      • G gwittlock

        OK OK! I get it! Don't ask questions. Done and Done.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #13

        There's nothing wrong with asking questions. But you need to understand that using a programming language that is years out of date is going to be difficult for people to answer. Also, that the later versions of Windows use features that VB6 was never designed to handle.

        G 1 Reply Last reply
        0
        • L Lost User

          There's nothing wrong with asking questions. But you need to understand that using a programming language that is years out of date is going to be difficult for people to answer. Also, that the later versions of Windows use features that VB6 was never designed to handle.

          G Offline
          G Offline
          gwittlock
          wrote on last edited by
          #14

          I understand about it being out of date. I also know there are a lot of people still programming in VB6. When a whole product works except for 1 feature it is difficult to justify the cost of totally re writing an app. I feel like I asked a simple question just to get bashed because of the language. If people do not have an answer why be little someone for asking a question.

          L M 2 Replies Last reply
          0
          • G gwittlock

            I understand about it being out of date. I also know there are a lot of people still programming in VB6. When a whole product works except for 1 feature it is difficult to justify the cost of totally re writing an app. I feel like I asked a simple question just to get bashed because of the language. If people do not have an answer why be little someone for asking a question.

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #15

            gwittlock wrote:

            why be little someone for asking a question.

            No one has belittled you. We are just trying to get you to understand that VB6 is so long out of support that almost no one (particularly on this forum) uses it any more. The problem you are seeing may well be due to the fact that you are trying to use very old libraries and code on a much later OS which uses many new features. I have given you one suggestion to try and isolate whether the problem is definitely due to VB6, and you could save some time by trying it.

            G 1 Reply Last reply
            0
            • L Lost User

              gwittlock wrote:

              why be little someone for asking a question.

              No one has belittled you. We are just trying to get you to understand that VB6 is so long out of support that almost no one (particularly on this forum) uses it any more. The problem you are seeing may well be due to the fact that you are trying to use very old libraries and code on a much later OS which uses many new features. I have given you one suggestion to try and isolate whether the problem is definitely due to VB6, and you could save some time by trying it.

              G Offline
              G Offline
              gwittlock
              wrote on last edited by
              #16

              I agreed with you in my second post. I will just delete this post and everyone will be happy.

              1 Reply Last reply
              0
              • G gwittlock

                I understand about it being out of date. I also know there are a lot of people still programming in VB6. When a whole product works except for 1 feature it is difficult to justify the cost of totally re writing an app. I feel like I asked a simple question just to get bashed because of the language. If people do not have an answer why be little someone for asking a question.

                M Offline
                M Offline
                Mycroft Holmes
                wrote on last edited by
                #17

                gwittlock wrote:

                just to get bashed because of the language

                I don't think any of us were belittling you, we have all used VB6 in the past, I doubt the VB6 is your choice and I can understand supporting legacy code. While it maybe a single feature that has failed now the problem is only going to get worse as the OS moves forward and you are stuck in the 90s, alright early 00s. You should have had a migration plan in place 10 years ago if it is part of your core business (millions of lines of code indicates it is a major commitment). To give you some perspective, MS have announced the sun setting of Silverlight in 2020 (I think) we are looking at rewriting 34 applications into either MVC or WPF and yeah possibly as much as 1m LOC.

                Never underestimate the power of human stupidity RAH

                1 Reply Last reply
                0
                • G gwittlock

                  OK OK! I get it! Don't ask questions. Done and Done.

                  D Offline
                  D Offline
                  Dave Kreskowiak
                  wrote on last edited by
                  #18

                  I never said "don't ask questions". I just told you why you're going to have a hard time getting an answer to it. It's not just "a simple question".

                  A guide to posting questions on CodeProject

                  Click this: Asking questions is a skill. Seriously, do it.
                  Dave Kreskowiak

                  G 1 Reply Last reply
                  0
                  • D Dave Kreskowiak

                    I never said "don't ask questions". I just told you why you're going to have a hard time getting an answer to it. It's not just "a simple question".

                    A guide to posting questions on CodeProject

                    Click this: Asking questions is a skill. Seriously, do it.
                    Dave Kreskowiak

                    G Offline
                    G Offline
                    gwittlock
                    wrote on last edited by
                    #19

                    I want to thank everyone for their responses. As a matter of fact Richard has helped me out before with I question I asked about .net and I greatly appreciate it. I do program in .net and have done so for awhile. All of may main products have be upgraded as some suggested here. I do believe my question was detailed, I provided the particular code that I believed was the issue and did explain the issue I was having. It is probably my fault for this question getting off track. Just as much as ask the right question, answering the question should be just as important. If someone has an answer that is great. That is what these forums are for IMO anyways. Saying you should upgrade the code to .net doesn't answer the question (at least I do not think so because that is certainly the way to go. If you can justify the cost VS benefit). Maybe I asked it in the wrong forum. I agreed that programming in VB6 was not the greatest but it is what I had to work with. I was hoping that someone else had encounter the same issue. Here another way of looking at it. You have lived in your house for 10 years and you discover a leak in your plumbing. Now the plumbing is not the latest and greatest technology. Do you replace all of your plumbing? Do you say that the plumbing is 10 years old so you should buy a new house? Of course not. (No sarcasm intended here. Just trying to relay an analogy). You just fix the leak I am sure. As I said this question got a little off track, so again I want to thank everyone for their input it is always appreciated

                    L 2 Replies Last reply
                    0
                    • G gwittlock

                      I want to thank everyone for their responses. As a matter of fact Richard has helped me out before with I question I asked about .net and I greatly appreciate it. I do program in .net and have done so for awhile. All of may main products have be upgraded as some suggested here. I do believe my question was detailed, I provided the particular code that I believed was the issue and did explain the issue I was having. It is probably my fault for this question getting off track. Just as much as ask the right question, answering the question should be just as important. If someone has an answer that is great. That is what these forums are for IMO anyways. Saying you should upgrade the code to .net doesn't answer the question (at least I do not think so because that is certainly the way to go. If you can justify the cost VS benefit). Maybe I asked it in the wrong forum. I agreed that programming in VB6 was not the greatest but it is what I had to work with. I was hoping that someone else had encounter the same issue. Here another way of looking at it. You have lived in your house for 10 years and you discover a leak in your plumbing. Now the plumbing is not the latest and greatest technology. Do you replace all of your plumbing? Do you say that the plumbing is 10 years old so you should buy a new house? Of course not. (No sarcasm intended here. Just trying to relay an analogy). You just fix the leak I am sure. As I said this question got a little off track, so again I want to thank everyone for their input it is always appreciated

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #20

                      gwittlock wrote:

                      I was hoping that someone else had encounter the same issue.

                      The number of responses you received suggest that no one has. Have you tried that code in VB.NET as I suggested, just to see if that really is the issue?

                      1 Reply Last reply
                      0
                      • G gwittlock

                        I have the following code which works on windows 7 but when I run my app on windows 8 I just get a black box. I am using VB6 and have seen several capture submissions here but they all do the same thing (or at least the several I have tried. Here is my code

                        Public Function CaptureWindow(ByVal hWndSrc As Long, ByVal Client As Boolean, ByVal LeftSrc As Long, ByVal TopSrc As Long, ByVal WidthSrc As Long, ByVal HeightSrc As Long) As Picture

                        Dim hDCMemory As Long
                        Dim hBmp As Long
                        Dim hBmpPrev As Long
                        Dim hDCSrc As Long
                        Dim hPal As Long
                        Dim hPalPrev As Long
                        Dim RasterCapsScrn As Long
                        Dim HasPaletteScrn As Long
                        Dim PaletteSizeScrn As Long
                        Dim LogPal As LOGPALETTE
                        
                        On Error Resume Next
                        
                        If Client Then
                            hDCSrc = GetDC(hWndSrc)
                        Else
                            hDCSrc = GetWindowDC(hWndSrc)
                        End If
                        hDCMemory = CreateCompatibleDC(hDCSrc)
                        hBmp = CreateCompatibleBitmap(hDCSrc, WidthSrc, HeightSrc)
                        hBmpPrev = SelectObject(hDCMemory, hBmp)
                        RasterCapsScrn = GetDeviceCaps(hDCSrc, RASTERCAPS)
                        HasPaletteScrn = RasterCapsScrn And RC\_PALETTE
                        PaletteSizeScrn = GetDeviceCaps(hDCSrc, SIZEPALETTE)
                        If HasPaletteScrn And (PaletteSizeScrn = 256) Then
                            LogPal.palVersion = &H300
                            LogPal.palNumEntries = 256
                            GetSystemPaletteEntries hDCSrc, 0, 256, LogPal.palPalEntry(0)
                            hPal = CreatePalette(LogPal)
                            hPalPrev = SelectPalette(hDCMemory, hPal, 0)
                            RealizePalette hDCMemory
                        End If
                        BitBlt hDCMemory, 0, 0, WidthSrc, HeightSrc, hDCSrc, LeftSrc, TopSrc, vbSrcCopy
                        hBmp = SelectObject(hDCMemory, hBmpPrev)
                        If HasPaletteScrn And (PaletteSizeScrn = 256) Then
                            hPal = SelectPalette(hDCMemory, hPalPrev, 0)
                        End If
                        DeleteDC hDCMemory
                        ReleaseDC hWndSrc, hDCSrc
                        Set CaptureWindow = CreateBitmapPicture(hBmp, hPal)
                        

                        End Function

                        Any help in changing or making it work on windows 7 & 8 is much appreciated

                        Richard DeemingR Offline
                        Richard DeemingR Offline
                        Richard Deeming
                        wrote on last edited by
                        #21

                        On the Windows 7 computer that works, have you disabled Aero? It sounds like your code doesn't work with layered windows. Most Google results seem to suggest that you need to pass the CAPTUREBLT flag (&H40000000L) to the BitBlt function[^]. It's not declared in the RasterOp enum[^], because VB6 came out a long time before Aero, so you'll need to declare it yourself. My VB's a bit rusty, but something like this should work:

                        BitBlt hDCMemory, 0, 0, WidthSrc, HeightSrc, hDCSrc, LeftSrc, TopSrc, CLng(vbSrcCopy Or &H40000000L)

                        Edit: Forgot that VB6 uses Long for 32-bit integers. :-O


                        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                        "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                        1 Reply Last reply
                        0
                        • G gwittlock

                          I want to thank everyone for their responses. As a matter of fact Richard has helped me out before with I question I asked about .net and I greatly appreciate it. I do program in .net and have done so for awhile. All of may main products have be upgraded as some suggested here. I do believe my question was detailed, I provided the particular code that I believed was the issue and did explain the issue I was having. It is probably my fault for this question getting off track. Just as much as ask the right question, answering the question should be just as important. If someone has an answer that is great. That is what these forums are for IMO anyways. Saying you should upgrade the code to .net doesn't answer the question (at least I do not think so because that is certainly the way to go. If you can justify the cost VS benefit). Maybe I asked it in the wrong forum. I agreed that programming in VB6 was not the greatest but it is what I had to work with. I was hoping that someone else had encounter the same issue. Here another way of looking at it. You have lived in your house for 10 years and you discover a leak in your plumbing. Now the plumbing is not the latest and greatest technology. Do you replace all of your plumbing? Do you say that the plumbing is 10 years old so you should buy a new house? Of course not. (No sarcasm intended here. Just trying to relay an analogy). You just fix the leak I am sure. As I said this question got a little off track, so again I want to thank everyone for their input it is always appreciated

                          L Offline
                          L Offline
                          Lost User
                          wrote on last edited by
                          #22

                          gwittlock wrote:

                          Do you say that the plumbing is 10 years old so you should buy a new house?

                          You did not even replace a part with something newer when it was broken, you waited until it became obsolete in the industry. So, you already new that your 10 year old house was using an out of date plumbing, and went ahead with it because it is cheaper. You have chosen to become obsolete. And yes, I will keep hammering that point, because someone else "might" think that your argument is valid. It was, 2004. Not in 2014.

                          Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

                          1 Reply Last reply
                          0
                          • L Lost User

                            Here's a simple suggestion: rewrite the above code in VB.NET and see what the results are.

                            I Offline
                            I Offline
                            i00
                            wrote on last edited by
                            #23

                            You wouldn't do it that way at all in .Net.... Kris

                            L 1 Reply Last reply
                            0
                            • I i00

                              You wouldn't do it that way at all in .Net.... Kris

                              L Offline
                              L Offline
                              Lost User
                              wrote on last edited by
                              #24

                              Well obviously. But that is not what the issue is about.

                              1 Reply Last reply
                              0
                              Reply
                              • Reply as topic
                              Log in to reply
                              • Oldest to Newest
                              • Newest to Oldest
                              • Most Votes


                              • Login

                              • Don't have an account? Register

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • World
                              • Users
                              • Groups