본문 바로가기

공부/컴퓨터

[MFC] 클립보드 사용하기

반응형
http://www.devpia.com/forum/BoardView.aspx?no=438217&page=1&Tpage=6&forumname=vc_qa&stype=&ctType=&answer=&KeyR=title&KeyC=
클립보드에 Text 설정하기
===========================================================================


            HGLOBAL         hMem;

            if( OpenClipboard() )

            {

                if( EmptyClipboard() )

                {

                    hMem = GlobalAlloc( GMEM_MOVEABLE | GMEM_DDESHARE,

                                        sizeof("원하는텍스트") );

                    if( hMem )

                    {

                        LPTSTR pClipData = (LPTSTR) GlobalLock(hMem);

                        pClipData[0] = 0;



                        strcpy( pClipData, "원하는텍스트" );



                        SetClipboardData( CF_OEMTEXT, hMem );



                        GlobalUnlock( hMem );

                    }



                    CloseClipboard();



                    GlobalFree( hMem );

                }

            }



클립보드 열고 -> 메모리생성해서 거기다 데이타 복사주해고 ->  클립보드 닫고, 메모리해제


클립보드는 락,언락을 해주어야 합니다..푸힛~리소스를 공유하기 때문이죠.

==========================================================================




http://www.devpia.com/forum/BoardView.aspx?no=438217&page=1&Tpage=6&forumname=vc_qa&stype=&ctType=&answer=&KeyR=title&KeyC=
비트맵 화면에 뿌려주가
==========================================================================
    HDC hdc;

    PAINTSTRUCT ps;

    HBITMAP hBit,hOldBitmap;

    HDC hMemDC;

    BITMAP bmp;

    if(::OpenClipboard(m_hWnd)){

        hBit=(HBITMAP)GetClipboardData(CF_BITMAP);

        CloseClipboard();

        hdc=::GetDC(m_hWnd);

        hMemDC=CreateCompatibleDC(hdc);

        hOldBitmap=(HBITMAP)SelectObject(hMemDC,hBit);

        GetObject(hBit,sizeof(BITMAP),&bmp);

        BitBlt(hdc,0,0,bmp.bmWidth,bmp.bmHeight,hMemDC,0,0,SRCCOPY);

        SelectObject(hMemDC,hOldBitmap);

        DeleteDC(hMemDC);

        ::ReleaseDC(m_hWnd,hdc);

    }

===========================================================================






http://www.devpia.com/forum/BoardView.aspx?no=438217&page=1&Tpage=6&forumname=vc_qa&stype=&ctType=&answer=&KeyR=title&KeyC=

클립보드에 데이터 복사 및 가져오기

===========================================================================
programming windows , charles petzold의 p679 내용 입니다.



<클립보드에 복사>



HGLOBAL hGlobal = GlobalAlloc(GHND | GMEM_SHARE, (lstrlen(pText) + 1) *sizeof(TCHAR));

PTSTR pGlobal = GlobalLock(hGlobal);

lstrcpy(pGlobal, TEXT("Hello"));

GlobalUnlock(hGlobal);



OpenClipboard(윈도우 핸들);

EmptyClipboard();

SetClipboardData(CF_TCHAR, hGlobal);

CloseClipboard();



<클립보드에서 가져오기>

OpenClipboard(윈도우 핸들);


HGLOBAL hGlobal = GetClipboardData(CF_TEXT);
char a[1024];
if(hGlobal)
{

        PTSTR pGlobal = (char*)GlobalLock(hGlobal);

        lstrcpy( a,pGlobal);

        GlobalUnlock(hGlobal);

}

CloseClipboard();
반응형