5 Replies - 6910 Views - Last Post: 23 January 2012 - 03:44 AM Rate Topic: -----

#1 brewsom4me  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 04-May 09

Copy picturebox to drive (not screenprint)

Posted 17 June 2011 - 12:47 PM

Hi all and thanks for taking a look at this!

I have a project I'm doing that I thought was done, but I guess you never should think that way.

This was a project that I took pieces from something existing and changed to suit the users request. Basically, it takes a variety of business benchmarks and shows them graphically (see attached JPG). Initially, this was a program that a user would run when they wanted to manually. I got a request to make this where it runs every morning and users can sign up for up to 24 of these "alerts". They would be shown on a jpg (which I converted from a bmp in my program) which would be attached to an email that the user would get. As I mentioned, it looked to work spiffy and I thought I was done, but instead of running it on my local PC for testing, I put it out for live. As it turns out, there is no graphic to the jpg now. I am thinking that it must have needed an active screen to use for a screen print in the picturebox. It works great when I test locally, but no graphic output when run from a server. It would work fine if I had it run from my PC every morning, but that isn't an option.

I have been searching all over trying to find an alternative to getting the graphic to work, but so far no luck. I have the code shown below where I save the picturebox. Does anyone have any other ideas as to how I could get what I need saved to use in an email? I haven't done much with pictureboxes, so sorry if I don't sound to knowledgeable. Thanks for your time and any help you can offer!!!

Public Sub SaveFormImageToFile(ByRef ContainerForm As Form, _
                               ByRef PictureBoxControl As PictureBox, _
                               ByVal ImageFileName As String)
  Dim FormInsideWidth As Long
  Dim FormInsideHeight As Long
  Dim PictureBoxLeft As Long
  Dim PictureBoxTop As Long
  Dim PictureBoxWidth As Long
  Dim PictureBoxHeight As Long
  Dim FormAutoRedrawValue As Boolean
  
  With PictureBoxControl
    'Set PictureBox properties
    .Visible = False
    .AutoRedraw = True
    .Appearance = 0 ' Flat
    .AutoSize = False
    .BorderStyle = 0 'No border
    '.Name = "Picture2"
    'Store PictureBox Original Size and location Values
    PictureBoxHeight = .Height: PictureBoxWidth = .Width
    PictureBoxLeft = .Left: PictureBoxTop = .Top
    
    'Make PictureBox to size to inside of form.
    .Align = vbAlignTop: .Align = vbAlignLeft
    DoEvents
    
    FormInsideHeight = .Height: FormInsideWidth = .Width
    
    'Restore PictureBox Original Size and location Values
    .Align = vbAlignNone
    .Height = FormInsideHeight: .Width = FormInsideWidth
    .Left = PictureBoxLeft: .Top = PictureBoxTop
    
    FormAutoRedrawValue = ContainerForm.AutoRedraw
    ContainerForm.AutoRedraw = False
    DoEvents
    
    'Copy Form Image to Picture Box
    ' line below was un remd as test
    BitBlt .hdc, 0, 0, _
    1600, _
    1800, _
    ContainerForm.hdc, 0, 0, _
    vbSrcCopy
    'line below was remd. it was original..above was initially remd and not used
   ' BitBlt .hdc, 0, 0, _
    FormInsideWidth / Screen.TwipsPerPixelX, _
    FormInsideHeight / Screen.TwipsPerPixelY, _
    ContainerForm.hdc, 0, 0, _
    vbSrcCopy
    
    DoEvents
    SavePicture .Image, ImageFileName
    DoEvents
    
    ContainerForm.AutoRedraw = FormAutoRedrawValue
    DoEvents
  End With
End Sub




Kurt

Attached image(s)

  • Attached Image


Is This A Good Question/Topic? 0
  • +

Replies To: Copy picturebox to drive (not screenprint)

#2 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: Copy picturebox to drive (not screenprint)

Posted 20 June 2011 - 01:06 PM

googling "vb6 picturebox save image" reveals a number of examples. Have none of those worked for you?
Was This Post Helpful? 0
  • +
  • -

#3 brewsom4me  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 04-May 09

Re: Copy picturebox to drive (not screenprint)

Posted 23 June 2011 - 01:21 PM

I have searched all over for several weeks and put a dent in Google search.....and unfortunately no. I have a variety of different things happen like blank bmp's, absolutely nothing and errors, but not what I need. Hence my posting here!

Thanks,

Kurt

View PostBobRodes, on 20 June 2011 - 02:06 PM, said:

googling "vb6 picturebox save image" reveals a number of examples. Have none of those worked for you?

Was This Post Helpful? 0
  • +
  • -

#4 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: Copy picturebox to drive (not screenprint)

Posted 23 June 2011 - 01:54 PM

Hmm. This link http://www.vbforums....ad.php?t=315452 describes the same problem, and says that it was solved by setting AutoRedraw to true. I notice that AutoRedraw is false when you do a savepicture. Could that be it?
Was This Post Helpful? 0
  • +
  • -

#5 brewsom4me  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 04-May 09

Re: Copy picturebox to drive (not screenprint)

Posted 27 June 2011 - 05:26 AM

Yeh, I thought that too. I changed AutoRedraw to true and still no luck. I do get the files created, but they are blank. Works fine when you run it manually, but from a server through scheduled tasks, I get nada. Also, If I use the task scheduler on my PC, then lock the PC and let the program run while it's locked, I also get blank bmp's. It looks like you need to be able to see the form with the picturebox on the monitor. You would think there would be a way to get the capture of the picturebox without needing the monitor to be on while the program runs. I must be missing something!! Thanks again for your help!!

Kurt

View PostBobRodes, on 23 June 2011 - 02:54 PM, said:

Hmm. This link http://www.vbforums....ad.php?t=315452 describes the same problem, and says that it was solved by setting AutoRedraw to true. I notice that AutoRedraw is false when you do a savepicture. Could that be it?

Was This Post Helpful? 0
  • +
  • -

#6 jeakins01  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 10-August 08

Re: Copy picturebox to drive (not screenprint)

Posted 23 January 2012 - 03:44 AM

I think your problem is that a program run from the scheduler runs in process that does not have access to your screen. I don't think the problem is with the program but rather that the program is reproducing a screen that is not "there". Like you said if you run the program on your compute it runs fine. That is because it does have access to your screen at that point. Maybe you could run this on a spare computer and just time the task in VB so the task runs in the normal process with access to the screen.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1