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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. losing dimensions in metafile

losing dimensions in metafile

Scheduled Pinned Locked Moved C / C++ / MFC
graphics
8 Posts 3 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.
  • F Offline
    F Offline
    Force Code
    wrote on last edited by
    #1

    I have a word processing app (no source) in which a user can copy bitmaps onto the client area, resize them on the client, and then paste them somewhere else in the client area with their new size (nothing unusual here). I'm intercepting the paste command msgs of this app (through subclassing, etc.), and for the moment, all I'm trying to do is retrieve the content of the clipboard, duplicate it, and replace the original clipboard content with the duplicate. (not my ultimate objective obviously). However, no matter how I try to retrieve the data and put it back to the clipboard, its apparently being altered, because the bitmap dimensions are destroyed, and when the app pastes the item, its it has the original dimensions (not the user-resized dimensions). The bitmap is being copied by the app as a metafile, so when I intercept the paste message, I'm retrieving it and putting it back to the clipboard as a metafile. The data can be retrieved from the clipboard as an enhanced metafile or plain metafile, and it makes no difference. I've tried Copy[Enh]MetaFile, Get[Enh]MetaFileBits/Set[Enh]MetaFileBits, Create[Enh]MetaFile/Play[Enh]MetaFile, etc - no matter how I try to copy the clipboard data and just put it back unchanged, everthing *is* unchanged, EXCEPT the dimensions, which always lose the most current dimensions and instead revert to the original dimensions.

    M C 2 Replies Last reply
    0
    • F Force Code

      I have a word processing app (no source) in which a user can copy bitmaps onto the client area, resize them on the client, and then paste them somewhere else in the client area with their new size (nothing unusual here). I'm intercepting the paste command msgs of this app (through subclassing, etc.), and for the moment, all I'm trying to do is retrieve the content of the clipboard, duplicate it, and replace the original clipboard content with the duplicate. (not my ultimate objective obviously). However, no matter how I try to retrieve the data and put it back to the clipboard, its apparently being altered, because the bitmap dimensions are destroyed, and when the app pastes the item, its it has the original dimensions (not the user-resized dimensions). The bitmap is being copied by the app as a metafile, so when I intercept the paste message, I'm retrieving it and putting it back to the clipboard as a metafile. The data can be retrieved from the clipboard as an enhanced metafile or plain metafile, and it makes no difference. I've tried Copy[Enh]MetaFile, Get[Enh]MetaFileBits/Set[Enh]MetaFileBits, Create[Enh]MetaFile/Play[Enh]MetaFile, etc - no matter how I try to copy the clipboard data and just put it back unchanged, everthing *is* unchanged, EXCEPT the dimensions, which always lose the most current dimensions and instead revert to the original dimensions.

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      I'm confused (not a rare event :)). Are you actually changing the metafile before you put it back on the clipboard? If so, what methods/APIs are you using to do so? Mark

      Mark Salsbery Microsoft MVP - Visual C++ This episode brought to you by the letter Z

      F 1 Reply Last reply
      0
      • M Mark Salsbery

        I'm confused (not a rare event :)). Are you actually changing the metafile before you put it back on the clipboard? If so, what methods/APIs are you using to do so? Mark

        Mark Salsbery Microsoft MVP - Visual C++ This episode brought to you by the letter Z

        F Offline
        F Offline
        Force Code
        wrote on last edited by
        #3

        Mark Salsbery wrote:

        I'm confused (not a rare event ). Are you actually changing the metafile before you put it back on the clipboard? If so, what methods/APIs are you using to do so?

        As I stated, my goal for the moment is just to succeed in copying the data from the clipboard and replacing the content of the clipboard with the copy. However, the metafile's dimensions I put back to the clipboard are screwed up somehow. Here's one code sample: HENHMETAFILE henh = (HENHMETAFILE)GetClipboardData(CF_ENHMETAFILE); int nSize = GetEnhMetaFileBits(henh,0,NULL); BYTE* data = new BYTE[nSize]; GetEnhMetaFileBits(henh,nSize,data); EmptyClipboard(); henh = SetEnhMetaFileBits(nSize,data); SetClipboardData(CF_ENHMETAFILE,henh); (yeah, its straight SDK.) The copy that's put back has bitmap dimension info that has been altered. I say that, because if I don't mess with the clipboard at all, (as above) the bitmap is pasted with the dimensions most recently altered by user. With the code above, (which seemingly does nothing but replace the clipboard with a duplicate) when the paste is completed, the image has reverted to some previous dimensions. In the above, I'm using GetEnhMetaFileBits/SetEnhMetaFileBits. However the same result occurs when just using CopyEnhMetaFile (as well as with yet another method for copying the metafile). -- modified at 13:00 Monday 9th July, 2007

        M 1 Reply Last reply
        0
        • F Force Code

          I have a word processing app (no source) in which a user can copy bitmaps onto the client area, resize them on the client, and then paste them somewhere else in the client area with their new size (nothing unusual here). I'm intercepting the paste command msgs of this app (through subclassing, etc.), and for the moment, all I'm trying to do is retrieve the content of the clipboard, duplicate it, and replace the original clipboard content with the duplicate. (not my ultimate objective obviously). However, no matter how I try to retrieve the data and put it back to the clipboard, its apparently being altered, because the bitmap dimensions are destroyed, and when the app pastes the item, its it has the original dimensions (not the user-resized dimensions). The bitmap is being copied by the app as a metafile, so when I intercept the paste message, I'm retrieving it and putting it back to the clipboard as a metafile. The data can be retrieved from the clipboard as an enhanced metafile or plain metafile, and it makes no difference. I've tried Copy[Enh]MetaFile, Get[Enh]MetaFileBits/Set[Enh]MetaFileBits, Create[Enh]MetaFile/Play[Enh]MetaFile, etc - no matter how I try to copy the clipboard data and just put it back unchanged, everthing *is* unchanged, EXCEPT the dimensions, which always lose the most current dimensions and instead revert to the original dimensions.

          C Offline
          C Offline
          Chris Losinger
          wrote on last edited by
          #4

          any chance the app is caching them ?

          image processing toolkits | batch image processing | blogging

          F 1 Reply Last reply
          0
          • C Chris Losinger

            any chance the app is caching them ?

            image processing toolkits | batch image processing | blogging

            F Offline
            F Offline
            Force Code
            wrote on last edited by
            #5

            Chris Losinger wrote:

            any chance the app is caching them ?

            Not entirely sure what you're implying. The only state change in the process is that code snippet I supplied where I manipulate the clipboard. Comment that out, and everything is back to normal. The only conclusion I can reach is that what I'm putting back to the clipboard isn't really a copy. I've just been working with metafiles for the last couple of days.

            1 Reply Last reply
            0
            • F Force Code

              Mark Salsbery wrote:

              I'm confused (not a rare event ). Are you actually changing the metafile before you put it back on the clipboard? If so, what methods/APIs are you using to do so?

              As I stated, my goal for the moment is just to succeed in copying the data from the clipboard and replacing the content of the clipboard with the copy. However, the metafile's dimensions I put back to the clipboard are screwed up somehow. Here's one code sample: HENHMETAFILE henh = (HENHMETAFILE)GetClipboardData(CF_ENHMETAFILE); int nSize = GetEnhMetaFileBits(henh,0,NULL); BYTE* data = new BYTE[nSize]; GetEnhMetaFileBits(henh,nSize,data); EmptyClipboard(); henh = SetEnhMetaFileBits(nSize,data); SetClipboardData(CF_ENHMETAFILE,henh); (yeah, its straight SDK.) The copy that's put back has bitmap dimension info that has been altered. I say that, because if I don't mess with the clipboard at all, (as above) the bitmap is pasted with the dimensions most recently altered by user. With the code above, (which seemingly does nothing but replace the clipboard with a duplicate) when the paste is completed, the image has reverted to some previous dimensions. In the above, I'm using GetEnhMetaFileBits/SetEnhMetaFileBits. However the same result occurs when just using CopyEnhMetaFile (as well as with yet another method for copying the metafile). -- modified at 13:00 Monday 9th July, 2007

              M Offline
              M Offline
              Mark Salsbery
              wrote on last edited by
              #6

              Force Code wrote:

              the bitmap is pasted with the dimensions most recently altered by user.

              Probably a dumb question, but are you creating a new metafile created by drawing using the new dimensions or editing an existing metafile when the user alters something? Also, what do you mean by "the bitmap is pasted"? Mark

              Mark Salsbery Microsoft MVP - Visual C++ This episode brought to you by the letter Z

              F 1 Reply Last reply
              0
              • M Mark Salsbery

                Force Code wrote:

                the bitmap is pasted with the dimensions most recently altered by user.

                Probably a dumb question, but are you creating a new metafile created by drawing using the new dimensions or editing an existing metafile when the user alters something? Also, what do you mean by "the bitmap is pasted"? Mark

                Mark Salsbery Microsoft MVP - Visual C++ This episode brought to you by the letter Z

                F Offline
                F Offline
                Force Code
                wrote on last edited by
                #7

                Mark Salsbery wrote:

                Probably a dumb question, but are you creating a new metafile created by drawing using the new dimensions or editing an existing metafile when the user alters something? Also, what do you mean by "the bitmap is pasted"?

                OK, here's the scenario: A user copies a bitmap from some source to the client area of this application. Then, in the client area, he resizes the bitmap by dragging an edge of it. Then he copies this resized bitmap (ctrl-c) and pastes it somewhere else in the client area (ctrl-v). Once he resized the image, the application converted it from a bitmap to a memory metafile. So, when it is copied with ctrl-c, it is copied as a metafile and then pasted as a metafile. What I have done is just intercept the paste message right before the image (i.e. the meta file) is pasted. Then, for now, i.e. *strictly for testing purposes*, all I've done is make a duplicate of the clipboard data (i.e. the metafile), and replaced the clipboard data with this duplicate metafile. So basically NOTHING should be changed *AT ALL*. But when the image is pasted, its size has reverted to what it was before the user resized it. Understand? Maybe I should have asked to begin with - have you ever copied metafiles from the clipboard. Here is the complete code I used to intercept the paste msg: //following excerpt is from a subclassed WndProc in a DLL //injected into an application's address space: . . . case CM_PASTE_WP: { OpenClipboard(hwnd); if (IsClipboardFormatAvailable(CF_ENHMETAFILE)) { HENHMETAFILE henh = (HENHMETAFILE)GetClipboardData(CF_ENHMETAFILE); int nSize = GetEnhMetaFileBits(henh,0,NULL); BYTE* data = new BYTE[nSize]; GetEnhMetaFileBits(henh,nSize,data); EmptyClipboard(); henh = SetEnhMetaFileBits(nSize,data); SetClipboardData(CF_ENHMETAFILE,henh); } CloseClipboard(); } break; . . . return CallWindowProc(r_obj->WordProcPrev,hwnd,message,wParam,lParam); }

                M 1 Reply Last reply
                0
                • F Force Code

                  Mark Salsbery wrote:

                  Probably a dumb question, but are you creating a new metafile created by drawing using the new dimensions or editing an existing metafile when the user alters something? Also, what do you mean by "the bitmap is pasted"?

                  OK, here's the scenario: A user copies a bitmap from some source to the client area of this application. Then, in the client area, he resizes the bitmap by dragging an edge of it. Then he copies this resized bitmap (ctrl-c) and pastes it somewhere else in the client area (ctrl-v). Once he resized the image, the application converted it from a bitmap to a memory metafile. So, when it is copied with ctrl-c, it is copied as a metafile and then pasted as a metafile. What I have done is just intercept the paste message right before the image (i.e. the meta file) is pasted. Then, for now, i.e. *strictly for testing purposes*, all I've done is make a duplicate of the clipboard data (i.e. the metafile), and replaced the clipboard data with this duplicate metafile. So basically NOTHING should be changed *AT ALL*. But when the image is pasted, its size has reverted to what it was before the user resized it. Understand? Maybe I should have asked to begin with - have you ever copied metafiles from the clipboard. Here is the complete code I used to intercept the paste msg: //following excerpt is from a subclassed WndProc in a DLL //injected into an application's address space: . . . case CM_PASTE_WP: { OpenClipboard(hwnd); if (IsClipboardFormatAvailable(CF_ENHMETAFILE)) { HENHMETAFILE henh = (HENHMETAFILE)GetClipboardData(CF_ENHMETAFILE); int nSize = GetEnhMetaFileBits(henh,0,NULL); BYTE* data = new BYTE[nSize]; GetEnhMetaFileBits(henh,nSize,data); EmptyClipboard(); henh = SetEnhMetaFileBits(nSize,data); SetClipboardData(CF_ENHMETAFILE,henh); } CloseClipboard(); } break; . . . return CallWindowProc(r_obj->WordProcPrev,hwnd,message,wParam,lParam); }

                  M Offline
                  M Offline
                  Mark Salsbery
                  wrote on last edited by
                  #8

                  Force Code wrote:

                  OK, here's the scenario

                  Thanks! I don't see anything in THAT code that changes anything in the metafile. It seems to me you may want to look in the "Once he resized the image, the application converted it from a bitmap to a memory metafile" code and/or the PlayEnhMetaFile() code and make sure everything is consistent with the DCs (resolution/units) and bounding rects. Mark

                  Mark Salsbery Microsoft MVP - Visual C++ This episode brought to you by the letter Z

                  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