Page 1 of 2 12 LastLast
Results 1 to 40 of 80

Thread: [RESOLVED] Can MsPaint.exe be packaged as a VB control?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    Resolved [RESOLVED] Can MsPaint.exe be packaged as a VB control?

    I want to wrap MsPaint.exe as a VB control, so that we can make the pictures copy-paste more convenient. This VB control needs to implement the following four functions:

    1. Embed MsPaint.exe into the VB container.
    (I know this step can be achieved through the SetParent API, I'm wondering if there is a better way?)

    2. Hide the MsPaint's window border, menu and toolbox.
    (I don't know what APIs can be used to achieve this goal.)

    3. Change the size of the MsPaint's canvas.

    4. Control the MsPaint's copy and paste operations by sending Windows messages.


    I don't know whether my idea is feasible, please give your advice, thanks very much.
    Last edited by dreammanor; Mar 23rd, 2017 at 07:56 AM.

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    Re: Can MsPaint.exe be packaged as a VB control?

    I tried the OLE method, but this way does not control MsPaint.exe very well.

    1. In WinXP, MsPaint.exe can not be registered as OLE Server.
    2. In Win10, MsPaint.exe can not be embedded in the OLE container.
    Last edited by dreammanor; Mar 23rd, 2017 at 07:55 AM.

  3. #3
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,852

    Re: Can MsPaint.exe be packaged as a VB control?

    Hi dreammanor,

    I do occasionally "Shell" some images to MsPaint. However, I've never tried to "wrap" it into one of my existing VB6 apps.

    You might do better to outline here what you're actually wanting to do. Are you wanting the user to take some image and do sophisticated image editing? Or are you possibly wanting some quick function like a crop, rotation, or resizing?

    If you just want something quick, there are probably VB6 routines floating around to get that done for you, and then you can just show the results in a PictureBox. If you want sophisticated editing abilities, you might want to consider one of the VB6 "paint-like" programs floating around. One that I'm quite impressed with is Tanner's PhotoDemon. He distributes it as open source such that you could incorporate the whole thing into your application. You can grab his program here.

    Maybe this'll help,
    Elroy
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  4. #4
    Hyperactive Member
    Join Date
    Mar 2017
    Posts
    500

    Re: Can MsPaint.exe be packaged as a VB control?

    Embed MSPaint into a Picturebox. Use the Picturebox to hide everything except the canvas

    Or maybe this VB Paint project might help you
    Attached Files Attached Files
    Last edited by Ordinary Guy; Mar 23rd, 2017 at 11:26 AM.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    Re: Can MsPaint.exe be packaged as a VB control?

    Quote Originally Posted by Elroy View Post
    You might do better to outline here what you're actually wanting to do. Are you wanting the user to take some image and do sophisticated image editing? Or are you possibly wanting some quick function like a crop, rotation, or resizing?
    Thanks for your reply. I don't need to do sophisticated image editing, nor do I need any quick function like a crop, rotation, or resizing. My purpose is to make full use of Windows clipboard's powerful features, because VB6's clipboard is very weak, especially in copy-paste pictures.

    Quote Originally Posted by Elroy View Post
    If you just want something quick, there are probably VB6 routines floating around to get that done for you, and then you can just show the results in a PictureBox. If you want sophisticated editing abilities, you might want to consider one of the VB6 "paint-like" programs floating around. One that I'm quite impressed with is Tanner's PhotoDemon. He distributes it as open source such that you could incorporate the whole thing into your application. You can grab his program here.
    Tanner's PhotoDemon is excellent, its clipboard is very close to the Windows system clipboard, and I am learning PhotoDemon's clipboard source code. But if we can encapsulate MsPaint as a VB control, things will be much simpler.
    Last edited by dreammanor; Mar 23rd, 2017 at 09:58 PM.

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    Re: Can MsPaint.exe be packaged as a VB control?

    Quote Originally Posted by Ordinary Guy View Post
    Embed MSPaint into a Picturebox. Use the Picturebox to hide everything except the canvas

    Or maybe this VB Paint project might help you
    Thank you for your reply. The attached *VB_Paint* is very good, maybe I can use it in the future. Now I mainly want to take full advantage of MsPaint's clipboard.

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    Re: Can MsPaint.exe be packaged as a VB control?

    Quote Originally Posted by Elroy View Post
    Yeah, many think that the clipboard is a fairly simple thing, but that's actually very far from the truth. When you start thinking about it, it's actually rather amazing that it does some of the things it does.

    One thing that's pretty cool is that it works hard to find a common format when copying-pasting between two entirely different programs. And just to be able to handle all the different formats, and to also have them nested to any level you like, is rather amazing. Just think; you can take a VB6 form maybe with frames and pictureboxes on it that also have controls (nested to any level you want), and then draw a carat-box around them to select them, and then Ctrl-C, and voila, they're all in the clipboard, all organized just as they should be.

    Also, certainly copies to the clipboard can be quite memory intensive.

    I've messed around a bit with clipboard-stack type programs in the past, but always given up when I realized how difficult it would be to make a truly universal clipboard-stack program. Also, it'd almost certainly require some kind of disk-cache so that it didn't overflow memory. Ideally, you could set limits as to how much it'd store in memory versus flush it to disk-cache. It all just winds up being a monumental undertaking.

    Also, just as an FYI, VB6's access/use of the clipboard (via its clipboard object) is fairly primitive considering all that the clipboard actually does.

    Best Regards,
    Elroy
    Elroy, I totally agree with you. It will take a lot of time to fully understand the Windows clipboard. That's why I want to wrap MsPaint into a VB control. Sometimes a good solution can reduce a lot of source code and a lot of work.

    Note: I copied Elroy's view from the following post to this post, for a better explanation of my purpose.
    http://www.vbforums.com/showthread.p...01#post5136001
    Last edited by dreammanor; Mar 23rd, 2017 at 09:59 PM.

  8. #8
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,852

    Re: Can MsPaint.exe be packaged as a VB control?

    Hmmm, interesting dreammanor. So, if I understand, you're trying to get different image formats into the clipboard, for possible pasting into other applications.

    That's still a bit confusing to me because VB6 can copy any of Bitmap(bmp), Metafile(WMF), or Device-Independent Bitmap(DIB) into the clipboard. These may not be as memory efficient as GIF or JPG, but they're certain acceptable for pasting to virtually any other Windows image program.

    Are you trying to fetch/read another image type? Possibly reading a JPG into your program? Actually, without use of the clipboard, and using LoadPicture instead, VB6 is even more versatile and can read GIF, JPG, and other formats.

    So ... I still don't understand the task at hand. However, if it's just about using MSPaint for a moment, why not load a copy of it, make it invisible (with API), make it perform our task (possibly with API calls to send it keys), and then unload it?

    Take Care,
    Elroy
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  9. #9
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Can MsPaint.exe be packaged as a VB control?

    I suspect he is struggling with EMF+ images with intermixed GDI+ operations. Pasting in VB6 he gets the GDI-subset image instead of the multimode image. Can't do much about that since IPicture/StdPicture doesn't support GDI+.

    About all you could do is get the EMF+ and render it to a memory hDC using the GDI+ Flat API, then going from there to a GDI hBitmap and converting that into a StdPicture so he can do anything with it.

    I got the idea he wants to have users copy from Word, paste into a VB6 progam, have the program store the image in a database and be able to retrieve and display it later.

    I still think this whole copy/paste from Word is an enormous mistake, but he seems to be trying to use it to compose text and images to be stored in a database.


    Previously he wanted text as plain text, and that's easily enough done within VB. So perhaps what he needs is a drawing control, but he wants one as fancy as WordArt operations in Word I guess.

    There should be tons of "drawing programs" in VB floating around. Maybe even a few UserControls. So you'd think something like that could be used and he could throw Word away entirely.

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    Re: Can MsPaint.exe be packaged as a VB control?

    Quote Originally Posted by Elroy View Post
    Hmmm, interesting dreammanor. So, if I understand, you're trying to get different image formats into the clipboard, for possible pasting into other applications.

    That's still a bit confusing to me because VB6 can copy any of Bitmap(bmp), Metafile(WMF), or Device-Independent Bitmap(DIB) into the clipboard. These may not be as memory efficient as GIF or JPG, but they're certain acceptable for pasting to virtually any other Windows image program.

    Are you trying to fetch/read another image type? Possibly reading a JPG into your program? Actually, without use of the clipboard, and using LoadPicture instead, VB6 is even more versatile and can read GIF, JPG, and other formats.

    So ... I still don't understand the task at hand. However, if it's just about using MSPaint for a moment, why not load a copy of it, make it invisible (with API), make it perform our task (possibly with API calls to send it keys), and then unload it?

    Take Care,
    Elroy
    When I copy pictures from MS-Word to RichTextBox, some pictures' color is changed and some pictures' edge appears jagged ( anti-aliasing disappeared). If I copy pictures from MS-Word to MsPaint, all the pictures are not changed (high fidelity).

    So, each time our customers copy the pictures, they need to first copy the pictures from Word to MsPaint, and then copy them from Mspaint to RichTextBox. This is very troublesome to do so. If we can encapsulate the MsPaint into a VB control, we can put the control on the VB-Form and implement an automatic copy of the image from MsPaint to RichTextBox.
    Last edited by dreammanor; Mar 24th, 2017 at 10:33 PM.

  11. #11

    Thread Starter
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    Re: Can MsPaint.exe be packaged as a VB control?

    Quote Originally Posted by dilettante View Post
    I suspect he is struggling with EMF+ images with intermixed GDI+ operations. Pasting in VB6 he gets the GDI-subset image instead of the multimode image. Can't do much about that since IPicture/StdPicture doesn't support GDI+.

    About all you could do is get the EMF+ and render it to a memory hDC using the GDI+ Flat API, then going from there to a GDI hBitmap and converting that into a StdPicture so he can do anything with it.

    I got the idea he wants to have users copy from Word, paste into a VB6 progam, have the program store the image in a database and be able to retrieve and display it later.

    I still think this whole copy/paste from Word is an enormous mistake, but he seems to be trying to use it to compose text and images to be stored in a database.


    Previously he wanted text as plain text, and that's easily enough done within VB. So perhaps what he needs is a drawing control, but he wants one as fancy as WordArt operations in Word I guess.

    There should be tons of "drawing programs" in VB floating around. Maybe even a few UserControls. So you'd think something like that could be used and he could throw Word away entirely.
    Hi dilettante, nice to see your reply, you helped me a lot. Copy data from MsWord is the user's decision, I can not change it. I'm not doing a vb drawing program, all I have done is just to make up for the shortcomings of the RichTextBox -- make pictures high fidelity.

    About the RichTextBox, there is the last question to be solved, once the problem is solved, this project is basically completed. And then I will start to develop a new project (Web project), hoping to get your guidance and advice, thank you very much.
    Last edited by dreammanor; Mar 24th, 2017 at 10:33 PM.

  12. #12
    Hyperactive Member
    Join Date
    Mar 2017
    Posts
    500

    Re: Can MsPaint.exe be packaged as a VB control?

    Embed MS Paint into a User Control. You have the handle and from that you can get the other handles you need to use API's (SendMessage, fex) to control the copy/paste features

  13. #13
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Can MsPaint.exe be packaged as a VB control?

    I've found two problems. One is the color, the other is the size.

    The image in your sample that shows as a black & white drawing in Word is actually a color image!

    However it was stored into a Word "picture" and that has formatted as black & white and resized to smaller than the original metafile image. The only thing that gets pasted into the RichTextBox is the raw metafile and a bounding-box. I have no real idea how to get the bounding-box.

    By the way... using GDI+ to render the EMF (or EMF+?) image made no difference at all. Metafile graphics don't carry any hPalette so there is no way to know from the pasted picture what rendering should be used ("automatic," "black & white," "grayscale," and "washout" are the options I find in Word 2003, there might be more in later versions of Word).

    How MSPaint gets the info I'm not certain. Either it knows about Word/Office clipboard formats and how to use them or else ???

    I see nothing in the EMF+ specs to suggest the info is carried there and lost in pasting in VB6, but I suppose I might have missed it.

    Didn't you try to use somebody's implementation of a Cairo wrapper around GDI+? How did that pan out?

  14. #14
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Can MsPaint.exe be packaged as a VB control?

    I'm beginning to think Office uses CF_DSPMETAFILEPICT and maybe CF_DSPENHMETAFILE but those aren't directly supported in VB6 and there is very little information about them... as far as I can find anyway.

    They probably also don't work for RichTextBox, so it ends up just getting the CF_ENHMETAFILE upon pasting.

  15. #15
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,852

    Re: Can MsPaint.exe be packaged as a VB control?

    Ahhh, I'm now beginning to see the problem. Dilettante, you are certainly more on top of all the image formats than I, especially things like EMF+.

    However, just as an FYI, I specifically keep a copy of the old Microsoft Photo Editor installed (with a shortcut on my taskbar), just for getting images out of Word, Excel, PowerPoint, etc. That's the only program that I've ever found that can accurately "extract" (through copy-paste) an image from other Microsoft products and correctly preserve the original size and fidelity. In fact, I don't think MS-Paint will even do it (or at least older versions of MS-Paint wouldn't).

    Just as an example, when I do a bit of image-editing, I tend to use Paint-Shop-Pro (PSP). However, copying from Word and pasting into PSP has problems similar to what are being described in this thread. However, if I copy from Word, paste to Photo Editor, and then copy from Photo Editor and paste into PSP, I get the original image (size and fidelity).

    Dreammanor, if you're copying images from Word (or Excel, etc), I'm sure you're running into a similar issue, regardless of whether you're pasting into a RTB, PictureBox, or whatever.

    When copying from Word (etc), the original image is certainly in the clipboard (in some format) or Photo Editor wouldn't be able to "receive" it. Ideally, what you're looking for is some way for VB6 to "receive" it in its original form (without going through some other program). I certainly don't have the answer to that, but I'll be very curious if that gets worked out here, as I'd be interested as well.

    Good Luck,
    Elroy
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  16. #16
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Can MsPaint.exe be packaged as a VB control?

    I'm pretty sure that Word puts multiple formats on the clipboard and to paste you must pick one, or pick one then another etc. as desired.

    I don't know when MSPaint began to handle these Word-copied images, but I suspect it was in Vista. Can't test that right now but it certainly works in Windows 10 if not also in Windows 7.

    MS Office didn't support EMF+ until Office 2002/XP from what I saw while hunting for info.

  17. #17
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Can MsPaint.exe be packaged as a VB control?

    I'm pretty sure that Word puts multiple formats on the clipboard and to paste you must pick one, or pick one then another etc. as desired.
    If anyone was truly curious, they could enumerate the clipboard formats to see what was placed there. In one of my custom controls that is image-based, I created and used a custom clipboard format that would be recognized by my control, in other applications, to be used for pasting or drag/drop. This is not uncommon. Of course, without having documentation of the format, it does little good.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  18. #18

    Thread Starter
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    Re: Can MsPaint.exe be packaged as a VB control?

    Quote Originally Posted by Ordinary Guy View Post
    Embed MS Paint into a User Control. You have the handle and from that you can get the other handles you need to use API's (SendMessage, fex) to control the copy/paste features
    Thank you, I'll try it.
    Last edited by dreammanor; Mar 26th, 2017 at 06:26 AM.

  19. #19

    Thread Starter
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    Re: Can MsPaint.exe be packaged as a VB control?

    Quote Originally Posted by dilettante View Post
    Didn't you try to use somebody's implementation of a Cairo wrapper around GDI+? How did that pan out?
    I have used Olaf's vbRichClient5 to convert EMZ files into png files, and vbRichClient5 works very well (pictures are not jagged). But before vbRichClient5's conversion, pictures stored in the EMZ files have been distorted. Because MsWord has automatically converted some black-white pictures into color pictures.
    Last edited by dreammanor; Mar 26th, 2017 at 06:27 AM.

  20. #20

    Thread Starter
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    Re: Can MsPaint.exe be packaged as a VB control?

    Quote Originally Posted by LaVolpe View Post
    If anyone was truly curious, they could enumerate the clipboard formats to see what was placed there. In one of my custom controls that is image-based, I created and used a custom clipboard format that would be recognized by my control, in other applications, to be used for pasting or drag/drop. This is not uncommon. Of course, without having documentation of the format, it does little good.
    Hi Lavolpe, I have just tested your AlphaImage control, which can read the Windows Clipboard data without distortion.

    Just a little problem: In Win10, the picture is zoomed in many times, but under XP, the image size is normal. I will do further testing.

    Thank you very much.
    Last edited by dreammanor; Mar 26th, 2017 at 07:12 AM.

  21. #21
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Can MsPaint.exe be packaged as a VB control?

    Just a little problem: In Win10, the picture is zoomed in many times, but under XP, the image size is normal. I will do further testing.
    If I ever get curious, I'll look into it. The Alpha Image Control uses the image size reported by GDI+ GdipGetImageBounds function, without applying DPI scaling. That is likely the reason. The control does not parse the EMF header. At the time when I wrote the control, that logic seemed fine; looks like it needs a tweak. Thanx for the heads up.

    Edited much later...
    Ok, curiosity resolved. If I were to apply the same DPI scaling to that image as I do WMFs, then I'd get the same dimensions reported by VB if it were opened in VB. There was a reason I didn't initially go that route for EMFs & I'll have to revisit that in the future.
    Last edited by LaVolpe; Mar 26th, 2017 at 01:07 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  22. #22
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Can MsPaint.exe be packaged as a VB control?

    Quote Originally Posted by dreammanor View Post
    I have used Olaf's vbRichClient5 to convert EMZ files into png files, and vbRichClient5 works very well (pictures are not jagged).
    What EMZ files? Pasted from the clipboard as you are seeking? If not, who cares?

    Quote Originally Posted by dreammanor View Post
    But before vbRichClient5's conversion, pictures stored in the EMZ files have been distorted. Because MsWord has automatically converted some black-white pictures into color pictures.
    So no help there.

    Word didn't "convert" anything, the pictures are indeed colored. Your sample file has instructions to Word to render the image in black and white. Those instructions use RTF markup that the RichTextBox does not support, which is probably why they get discarded.

  23. #23
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Can MsPaint.exe be packaged as a VB control?

    Quote Originally Posted by dreammanor View Post
    Hi Lavolpe, I have just tested your AlphaImage control, which can read the Windows Clipboard data without distortion.
    This surprises me if your "distortion" is the image rendering in its actual colors instead of black and white. I'm curious what it is pasting that retains Word's rendering instructions. Those also include the image rendering size which doesn't seem to be getting picked up and acted upon.


    I wouldn't expect that AlphaImage control to accept RTF from the clipboard, so you seem to have moved the goalposts again. I thought this was all about copy/pasting a blob of text from Word that may or may not contain embedded images.

  24. #24
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Can MsPaint.exe be packaged as a VB control?

    Here is what I'm talking about:

    Name:  sshot.png
Views: 1396
Size:  26.9 KB

  25. #25
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Can MsPaint.exe be packaged as a VB control?

    @dilettante. No my control doesn't accept RTF, but does except text/unicode when appropriate, i.e., file name, Base64, etc.

    I'm confused as to what an EMZ file is. Distortion isn't well defined by the OP. Could be result of scaling down to extreme ratios, losing original aspect ratio, as well as other scenarios. I also am not sure how Word could apply colors to a black & white image. Though I have seen where a B&W image can be scaled down significantly and other rendering effects are used that gives the image a grayscale look vs just B&W. Anyway, I've tried to follow this thread, but am honestly lost at this point.

    A point to ponder regarding Word drawing color from black & white. I have seen GDI+ create from a 2 color (2 palette entries), where the palette entries are not vbBlack & vbWhite, to a metafile that results in B&W image rendered by GDI+ even though the source image was color. I don't know if this is the case and would love some sample images posted by the OP. BTW, to get past that issue, any 2 color, 2 palette entry, image, not B&W, was converted to 16bit before converting to metafile.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  26. #26
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Can MsPaint.exe be packaged as a VB control?

    EMZ seems to be a format newer versions of MS Office use, as far as I know it is gzipped EMF/EMF+ data. I have no idea whether it is a clipboard format though. Seems very unlikely.

    Probably nothing but a red herring somebody threw into the pie.

  27. #27

    Thread Starter
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    Re: Can MsPaint.exe be packaged as a VB control?

    Quote Originally Posted by dilettante View Post
    EMZ seems to be a format newer versions of MS Office use, as far as I know it is gzipped EMF/EMF+ data. I have no idea whether it is a clipboard format though. Seems very unlikely.

    Probably nothing but a red herring somebody threw into the pie.
    Yes, EMZ is a compressed EMF file. Word will generate EMZ files when saving doc as html.
    Last edited by dreammanor; Mar 27th, 2017 at 08:09 AM.

  28. #28
    Fanatic Member
    Join Date
    Aug 2013
    Posts
    806

    Re: Can MsPaint.exe be packaged as a VB control?

    I doubt MS Paint has any "special knowledge" of Office formats.

    Much more likely? It just grabs a raster copy of the clipboard data (CF_BITMAP, CF_DIB, etc). Raster copies are likely to be identical to the original MS Word result.

    Again, it may be possible to coerce an RTB into doing the same thing, but as mentioned earlier, raster formats come with all the usual caveats (much larger, no high-fidelity resizing, etc).

    LaVolpe's Alpha Image Ctl may be doing the same thing (e.g. preferentially using raster clipboard formats over metafile ones), but I don't know that for certain - maybe LaVolpe himself can clarify.
    Check out PhotoDemon, a pro-grade photo editor written completely in VB6. (Full source available at GitHub.)

  29. #29

    Thread Starter
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    Re: Can MsPaint.exe be packaged as a VB control?

    Hi Tanner_H, I think MSPaint hasn't any "special knowledge" of Office formats, but MsPaint and Word both understand the Clipboard very deeply, so they can exchange data smoothly.

    LaVolpe's Alpha Image Ctl can read the clipboard data well and show it exactly on XP. Only a few days later I will have time to do further testing on Win10.

  30. #30
    Fanatic Member
    Join Date
    Aug 2013
    Posts
    806

    Re: Can MsPaint.exe be packaged as a VB control?

    We need LaVolpe to chime in, but I've just looked through LaVolpe's AlphaImage Control, and unfortunately it's difficult to tell what order he loads clipboard objects.

    There's a block of code that relies on something called "g_ClipboardFormat", and this block preferentially looks for PNG data above all else. Word places PNG data on the clipboard, so if a normal Paste operation triggers that code path, then the AlphaImage control will grab the PNG copy of whatever Word pasted. Metafiles are not involved.

    If that code block is not triggered, a different code block is used. In this code block, if a metafile is found, he loads it via VB's Clipboard.GetData(). We know this doesn't involve any GDI+ code - it's the default VB clipboard object!

    So once again, we may be overthinking this. The clipboard really isn't complicated, at least not for a task like this. The clipboard just provides a list of possible formats for the current clipboard data. You pick a format that works for you and load it.

    The question here is: which format carries the *best* version of the Office data, and how can you coerce a rich text box into grabbing *that* format specifically?

    On Windows 8 or later you can subclass and watch for the EN_CLIPFORMAT message. On Windows 7 or earlier, you'd probably need an uglier solution.

    But none of this matters until we can figure out which clipboard data format is the "right one." That should be our first task, I think, before messing with anything else.
    Check out PhotoDemon, a pro-grade photo editor written completely in VB6. (Full source available at GitHub.)

  31. #31
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,852

    Re: Can MsPaint.exe be packaged as a VB control?

    I might be a bit off-point here, and I mentioned this above, but I've found that the old Microsoft Photo Editor is the only program that reliably "accepts" images copied from Word without screwing them up. I'm surprised that dreammanor is actually getting what he wants with Paint.

    You guys are way more on-top of the different image formats than I am, but, using Photo Editor (my version is 3.0.2.3), I can get the original image from Word, regardless of how much it's been "tweaked" (resized etc) in Word. I'm not totally sure that's what dreammanor is after though. I've never even come close to being able to get the original image (on the clipboard from Word) with any VB6 program, but that would be super cool if someone figured this out.

    Best Regards,
    Elroy
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  32. #32

    Thread Starter
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    Re: Can MsPaint.exe be packaged as a VB control?

    Quote Originally Posted by Tanner_H View Post
    So once again, we may be overthinking this. The clipboard really isn't complicated, at least not for a task like this. The clipboard just provides a list of possible formats for the current clipboard data. You pick a format that works for you and load it.

    The question here is: which format carries the *best* version of the Office data, and how can you coerce a rich text box into grabbing *that* format specifically?

    On Windows 8 or later you can subclass and watch for the EN_CLIPFORMAT message. On Windows 7 or earlier, you'd probably need an uglier solution.

    But none of this matters until we can figure out which clipboard data format is the "right one." That should be our first task, I think, before messing with anything else.
    Yes, if Microsoft could provide some source code about MSPaint's clipboard , so that we can understand some of the details more clearly. Unfortunately, Microsoft will not do so. I know it is a very difficult thing to go inside the clipboard and inside the Office, so I wanted to wrap MsPaint as a VB control, but nobody is interested in it.

  33. #33

    Thread Starter
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    Re: Can MsPaint.exe be packaged as a VB control?

    Quote Originally Posted by Elroy View Post
    I might be a bit off-point here, and I mentioned this above, but I've found that the old Microsoft Photo Editor is the only program that reliably "accepts" images copied from Word without screwing them up. I'm surprised that dreammanor is actually getting what he wants with Paint.

    You guys are way more on-top of the different image formats than I am, but, using Photo Editor (my version is 3.0.2.3), I can get the original image from Word, regardless of how much it's been "tweaked" (resized etc) in Word. I'm not totally sure that's what dreammanor is after though. I've never even come close to being able to get the original image (on the clipboard from Word) with any VB6 program, but that would be super cool if someone figured this out.

    Best Regards,
    Elroy
    I have not used Microsoft Photo Editor, it is not a Windows embedded application and it needs to be downloaded from some websites. This is too cumbersome for our customers. MsPaint is very simple for copying-pasting pictures from MsWord.

    LaVolpe's AlphaImage control has been able to meet the needs of my work, but it will take some time to fully understand it. If you are free, I suggest you also look at the source code of that excellent control. It's very powerful.

  34. #34
    Hyperactive Member
    Join Date
    Mar 2017
    Posts
    500

    Re: Can MsPaint.exe be packaged as a VB control?

    What do you really want. Please make up your mind. Do you want MSPaint embedded or not and please do not say no one is interested as I have already suggested it but all I got from you was "I'll try it" which didn't sound like you had much concern or interest about it so I just left it at that

  35. #35
    Fanatic Member
    Join Date
    Aug 2013
    Posts
    806

    Re: Can MsPaint.exe be packaged as a VB control?

    @dreammanor: thanks for your patience. I think many of us do want to help you, but we feel that embedding an entire application *just* to handle clipboard data is probably overkill. I personally would like to find an easier, faster, simpler solution, if possible.

    Can I ask for your help? I don't have an up-to-date version of Microsoft Office, which makes it difficult to test this problem. But maybe we can work around this.

    There are many different clipboard viewer programs. I like this free, simple one from Nirsoft:

    http://www.nirsoft.net/utils/inside_clipboard.html

    Using that program (or another clipboard viewer program if you have one), can you copy a chart or other image from Microsoft Word, then load the InsideClipboard app and take a screenshot of what it shows? That will let us know the exact formats that Microsoft Office places on the clipboard. Once we know that, we can help further.
    Check out PhotoDemon, a pro-grade photo editor written completely in VB6. (Full source available at GitHub.)

  36. #36
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Can MsPaint.exe be packaged as a VB control?

    I can confirm that opening his RTF file in Word 2003, copying that first image, then pasting it into Windows 10 Paint retains the "black and white" information instead of rendering the actual colors.

    Name:  sshotClip.jpg
Views: 1379
Size:  34.9 KB

    JFIF is JPEG as far as I can recall.

  37. #37
    Fanatic Member
    Join Date
    Aug 2013
    Posts
    806

    Re: Can MsPaint.exe be packaged as a VB control?

    Thanks, dilettante. Very strange to me that there are actually *two* EMF copies on the clipboard. I wonder if that's a glitch in the viewer, or if Office does that intentionally. (And if it's intentional, how does a program differentiate between the two copies?)

    From this, we should be able to retrieve a byte-accurate copy of the metafile. Off the top of my head, The API calls would be...

    OpenClipboard()
    GetClipboardData(CF_ENHMETAFILE)
    CloseClipboard
    CopyEnhMetaFileW (passing the handle returned by GetClipboardData, and some new filename)

    Once we have an actual EMF in hand, this conversation might actually go somewhere useful...
    Check out PhotoDemon, a pro-grade photo editor written completely in VB6. (Full source available at GitHub.)

  38. #38
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Can MsPaint.exe be packaged as a VB control?

    Ok, this seems weird.

    I get a monochrome EMF at the original size (much larger than shown by Word or Paint).

    So there is still the size issue, and for whatever reason VB6's Clipboard picks the colored EMF.

    Attachment has an API-based demo as well as the saved EMF file.
    Attached Files Attached Files

  39. #39
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Can MsPaint.exe be packaged as a VB control?

    Quote Originally Posted by dilettante View Post
    ... and for whatever reason VB6's Clipboard picks the colored EMF.
    Wrong!

    This gets the monochrome EMF:

    Code:
    Option Explicit
    
    Private Sub Form_Load()
        Set Picture = Clipboard.GetData(vbCFEMetafile)
    End Sub
    Now I'm confused, but this case did not go through pasting into a RichTextBox so maybe that's the culprit?

  40. #40
    Fanatic Member
    Join Date
    Aug 2013
    Posts
    806

    Re: Can MsPaint.exe be packaged as a VB control?

    ??? Yeah, I'm all kinds of confused, too. All the software I just tested (including MS Paint) also gets a monochrome copy of the EMF. (Well, monochrome-ish - in MS Paint, the shapes are antialiased, so there's some grayscale going on, but the text is *not* antialiased?)

    What's weird is that the EMF file is relatively huge, for what it holds... I also don't know why that would be.

    Do you also get a monochrome EMF in VB if you use the WMF constant? (Clipboard.GetData(VBCFMetafile), I think?)
    Check out PhotoDemon, a pro-grade photo editor written completely in VB6. (Full source available at GitHub.)

Page 1 of 2 12 LastLast

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