CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Mar 2009
    Posts
    5

    Unhappy Problem with the clipboard

    hello , sorry for my bad english ....

    i have a problem with the clipbaord

    i try to get a image from a picture control and to put it in the clipboard ...
    I used something like that :

    void SendToClipboard(void)
    {
    HBITMAP hBitmap = NULL;

    hBitmap = (HBITMAP)SendMessage(GetDlgItem(hWnd,IDC_STATIC),STM_GETIMAGE,(WPARAM) IMAGE_BITMAP,(LPARAM) 0);

    OpenClipboard(hWnd);
    EmptyClipboard();

    if (hBitmap)
    {
    SetClipboardData(CF_BITMAP, hBitmap);
    CloseClipboard();
    }
    }

    This function is called from a button ...
    The first time , no problem, when i press the button , i have a correct bitmap in the clipboard ( verify with paint) but if i press the button a second time , i have an incorrect bitmap in the clipboard ... when i try to paste the bitmap in paint , i have an error message ( "erreur d'obtention des données du presse-papiers" in french)
    do you have any idea ?
    Thanks.
    Dooug

  2. #2
    Join Date
    Jul 2002
    Posts
    2,543

    Re: Problem with the clipboard

    Test hBitmap value after SendImage for NULL.
    Set unique ID for the picture control instead of IDC_STATIC. How many controls do you have on the dialog with IDC_STATIC ID?

  3. #3
    Join Date
    Mar 2009
    Posts
    5

    Re: Problem with the clipboard

    thanks for your response ...
    I have only one control with the IDC_STATIC ID , i change the id instead of, but no effect ... the first time is ok , but not the second time except if i reload a bitmap in the Picture box ... I don't understand why ?
    Last edited by douggy; March 26th, 2009 at 07:46 AM.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Problem with the clipboard

    As Alex wrote:
    Quote Originally Posted by Alex F
    Test hBitmap value after SendMessage for NULL
    Did you check it to be not NULL?
    Victor Nijegorodov

  5. #5
    Join Date
    Mar 2009
    Posts
    5

    Re: Problem with the clipboard

    oupsss sorry

    yes i check it and it not be null ...

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Problem with the clipboard

    Did you check the return values of yor clipboard function to be nonzero / not NULL?
    Victor Nijegorodov

  7. #7
    Join Date
    Mar 2009
    Posts
    5

    Re: Problem with the clipboard

    yes , i check all the function return , ans all is ok !!!

    the return value of the SetClipboardData function is the same that the handle input parameter ...

    Thanks for your help

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Problem with the clipboard

    Quote Originally Posted by douggy View Post
    the return value of the SetClipboardData function is the same that the handle input parameter ...
    Then what is your problem?
    Victor Nijegorodov

  9. #9
    Join Date
    May 2002
    Posts
    1,435

    Re: Problem with the clipboard

    Why don't you post the same code above with all of the changes you have made?

  10. #10
    Join Date
    Mar 2009
    Posts
    5

    Re: Problem with the clipboard

    Quote Originally Posted by VictorN View Post
    Then what is your problem?
    When i press twice the button to set the bitmap in the clipboard , i can't paste it, there is an error...

    i know , i can press once the button, the second press is useless but that irritates me to not understand. In theory it should crush the old bitmap in the clipboard even if it's the same

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

Featured