Solved

VB 6.0 Graphics

Posted on 2000-02-21
17
354 Views
Last Modified: 2012-08-13
I am experiencing immense frustration at the moment...

I have created an application in visual basic (v6.0) which will open up a tiff file of an a1/a2 size drawing (using a Wang Image Edit control), and will shrink the file down to 200 x 200 a convert it to an anti-aliased bitmap(using the .Zoom property of the Wang Image control, and PlgBlt ing the resultant image into a picture box).

Here is the catch - the above procedure works fine when the form is visible and uppermost on the screen - however I wish to run the application in the background, without having the form appear on the screen.  Is there any way of fooling the operating system into thinking that the form is visible, so that the following piece of code works whether the form is visible or not?


Thankyou in anticipation

Chris

The subroutine I am using follows....




Private Sub ThumbImage(strFileName As String)
 'Procedure to "Thumbnail" a tiff file
 'Input file is an A1/A2 scanned image, in tiff format.
 'Output (hopefully) is a bitmap file of maximum 200 x 200 pixels
 '
 ' wimgThumbnail  : Wang Image edit control
 ' picThumbnail   : PictureBox control, with autoredraw property set to true

 Const MAX_WIDTH As Integer = 200
 Const MAX_HEIGHT As Integer = 200
 Dim fromDC As Long
 Dim Pll(0 To 2) As POINTAPI
 Dim blnShouldScale As Boolean
 Dim lNewZoom As Long
 Dim lImgWidth As Long
 Dim lImgHeight As Long
 Dim sngAspectRatio As Single
 Dim lRetVal As Long


 'Display the tiff file in the Wang Control
 wimgThumbnail.Image = strFileName
 wimgThumbnail.Display
 wimgThumbnail.Refresh

 blnShouldScale = False
 lImgWidth = wimgThumbnail.ImageWidth
 lImgHeight = wimgThumbnail.ImageHeight


 'Scale the image, so that it can be shrunk into a 200 x 200 picturebox
 lNewZoom = 100
 Do While ((lImgWidth * lNewZoom / 100 * 0.02) > MAX_WIDTH) Or ((lImgHeight * lNewZoom / 100 * 0.02) > MAX_HEIGHT)
  blnShouldScale = True
  lNewZoom = lNewZoom - 1
 Loop

 If (blnShouldScale) Then
  wimgThumbnail.Zoom = lNewZoom
  wimgThumbnail.Refresh
 
  wimgThumbnail.SaveAs "c:\test.tif", 1, 3, 1, 0, True

  wimgThumbnail.Image = "c:\test.tif"
  wimgThumbnail.Display
  wimgThumbnail.Refresh
 End If

 lImgWidth = wimgThumbnail.ImageWidth
 lImgHeight = wimgThumbnail.ImageHeight

 sngAspectRatio = lImgWidth / lImgHeight

 If (sngAspectRatio >= 1#) Then
  wimgThumbnail.Width = MAX_WIDTH + 1
  wimgThumbnail.Height = MAX_HEIGHT / sngAspectRatio + 1
 Else
  wimgThumbnail.Height = MAX_HEIGHT + 1
  wimgThumbnail.Width = MAX_WIDTH * sngAspectRatio + 1
 End If

 imgThumbnail.FitTo 0, True
 'The image in the Wang Image edit control is now correctly scaled
 imgThumbnail.Refresh

 
 Pll(0).x = 0
 Pll(0).y = 0
 Pll(1).x = wimgThumbnail.Width - 1
 Pll(1).y = 0
 Pll(2).x = 0
 Pll(2).y = wimgThumbnail.Height - 1
 
 fromDC = GetDC(imgThumbnail.hwnd)

 'Size the picture box in correct proportions
 picThumbnail.Width = wimgThumbnail.Width - 1
 picThumbnail.Height = wimgThumbnail.Height - 1
 DoEvents

 lRetVal = PlgBlt(picThumbnail.hdc, Pll(0), fromDC, 0, 0, wimgThumbnail.Width - 1, wimgThumbnail.Height - 1, 0, 0, 0)
 ReleaseDC wimgThumbnail.hwnd, fromDC

 'Save the picturebox image to a .bmp file
 SavePicture picThumbnail.Image, "C:\test.bmp"
End Sub

0
Comment
Question by:smith_c
  • 6
  • 5
  • 2
  • +4
17 Comments
 
LVL 32

Expert Comment

by:Erick37
Comment Utility
For regular PictureBoxes, setting
pb.Autoredraw = True
pb.Visible = False
will do the trick.

Perhaps the same is true for the Wang control.
0
 
LVL 1

Expert Comment

by:DragonWolf
Comment Utility
Just posting so I can read later..
0
 

Author Comment

by:smith_c
Comment Utility
Sorry Erick37 - I have tried that, and it does not appear to work...
0
 
LVL 1

Expert Comment

by:James_stillman
Comment Utility
Have you tried calling the picturebox refresh method after you have PLGBlt the picture into the picture box.

This is a difference from vb 5.0 to vb6.0 where as in vb5.0 you did not need to call the refresh method after blting to a picture box in vb6.0 you do. As this is meant to save time if you have a number of blt's to the same picture box you can call the refresh once at the end rather than like in vb5.0 where it would be called automatically after each blt.


Hope this helps

Cheers

James
0
 

Author Comment

by:smith_c
Comment Utility
James_stillman

Like I say in the preamble, the routine works fine when the form is visible, but PLGBlt copies a blank bitmap to the picturebox when the form is not visible.

Thanks

Chris
0
 
LVL 1

Expert Comment

by:prefix
Comment Utility
I'm sorry to say that I think it's not possible. Because the Bltbit must use in a visible enviroment, if it's invisible, where the position you specified, what on the position will be copied. Like your form invisible, the position won't be a picture or any think on it, only a blank there.
---That's I thought.


prefix
0
 
LVL 32

Expert Comment

by:Erick37
Comment Utility
Does lRetVal return a success code?
Is fromDC always <> 0?
Try using StretchBlt instead of PlgBlt.
0
 
LVL 4

Expert Comment

by:wqw
Comment Utility
I dont want to sound nasty but why don't you

     Move 2 * Screen.Width, 0

your form before Show-ing it?

</wqw>
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:smith_c
Comment Utility
Sorry wqw, this answer makes no apparent sense (in the context of my question)

Chris
0
 

Author Comment

by:smith_c
Comment Utility
Adjusted points to 800
0
 

Author Comment

by:smith_c
Comment Utility
Erick37

The result with StretchBlt is the same.  The subroutine works fine when the form is visible, but the bitmap blted is blank when the form is invisible.

Chris
0
 
LVL 4

Expert Comment

by:wqw
Comment Utility
"Is there any way of fooling the operating system into thinking that the form is visible, so that the following piece of code works whether the form is visible or not"

I suppose this way you can "fool" OS it's visible when the user can't see it.

</wqw>
0
 
LVL 4

Expert Comment

by:wqw
Comment Utility
look, there is no way to blit without first showing the DC. you must be happy you can get fromDC from hwnd of a not-shown window.

don't know of a way to "fool" it (like posting WM_PAINT etc. messages) other way than plain showing it somewhere. btw, i'm not sure if showing it outside screen is not optimized to NOT send WM_PAINT at all. (meaning that even Showing it won't work:-)

</wqw>
0
 
LVL 4

Expert Comment

by:wqw
Comment Utility
look, there is no way to blit without first showing the DC. you must be happy you can get fromDC from hwnd of a not-shown window.

don't know of a way to "fool" it (like posting WM_PAINT etc. messages) other way than plain showing it somewhere. btw, i'm not sure if showing it outside screen is not optimized to NOT send WM_PAINT at all. (meaning that even Showing it won't work:-)

</wqw>
0
 
LVL 4

Expert Comment

by:wqw
Comment Utility
look, there is no way to blit without first showing the DC. you must be happy you can get fromDC from hwnd of a not-shown window.

don't know of a way to "fool" it (like posting WM_PAINT etc. messages) other way than plain showing it somewhere. btw, i'm not sure if showing it outside screen is not optimized to NOT send WM_PAINT at all. (meaning that even Showing it won't work:-)

</wqw>
0
 

Author Comment

by:smith_c
Comment Utility
wqw

The painting of the Wang Image control is optimised, but is there no way of invalidating the device context when it is not visible - ie forcing a repaint.

Chris
0
 

Accepted Solution

by:
Mac16426 earned 800 total points
Comment Utility
Use the windows API to increase the size of the desktop, without increasing the screen resolution. Then move your form to a non-visible area of the screen.

Or, resize your form to VERY small, and hide(not literal .hide) it behind the start bar.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now