Solved

VB 6.0 Graphics

Posted on 2000-02-21
17
361 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
ID: 2543342
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
ID: 2544642
Just posting so I can read later..
0
 

Author Comment

by:smith_c
ID: 2545076
Sorry Erick37 - I have tried that, and it does not appear to work...
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:James_stillman
ID: 2545346
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
ID: 2545361
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
ID: 2545849
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
ID: 2546850
Does lRetVal return a success code?
Is fromDC always <> 0?
Try using StretchBlt instead of PlgBlt.
0
 
LVL 4

Expert Comment

by:wqw
ID: 2547351
I dont want to sound nasty but why don't you

     Move 2 * Screen.Width, 0

your form before Show-ing it?

</wqw>
0
 

Author Comment

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

Chris
0
 

Author Comment

by:smith_c
ID: 2549407
Adjusted points to 800
0
 

Author Comment

by:smith_c
ID: 2549408
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
ID: 2549442
"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
ID: 2549460
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
ID: 2549486
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
ID: 2549513
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
ID: 2549716
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
ID: 2559280
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VBA filters 2 70
Access 2013 combo box not working 3 56
Excel Automation VBA 19 101
Formula problem with Excel attachment 6 42
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

680 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