;---------- ---------- ---------- ---------- ---------- ; 作成者のURL ---> http://www.setsuki.com/ ;---------- ---------- ---------- ---------- ---------- ;========== ========== ========== ========== ========== ; クリップボードの操作 ;---------- ---------- ---------- ---------- ---------- ; ; ■ clipget ; クリップボードテキスト取得 ; ; ■ clipset ; クリップボードテキスト転送 ; ; ■ clipsetg ; クリップボード画像転送 ; ;---------- ---------- ---------- ---------- ---------- ; ; hspext と同じ操作ですので ; 詳細は、HSPのヘルプを見てください。 ; ま、要するに、hspext を ; モジュール化した感じです。(^^; ; ;========== ========== ========== ========== ========== ; ; ■ clipgetg ; クリップボード画像を取得 ; ; クリップボードの画像サイズに合わせて ; 画面サイズも変更します。 ; ; [ 2006/09/01 ] clipgetg 1 と指定すると、 ; 画面サイズの変更せずに取得できるようにしました。 ; ;========== ========== ========== ========== ========== ; ; □ すべてのモジュールで以下の stat が返ります。 ; stat = 0 操作の失敗 ; stat = 1 操作の成功 ; ; □ kernel32.as などを使用する場合は、 ; このファイルの前に設定して下さい。 ; ;========== ========== ========== ========== ========== #ifdef __hsp30__ #ifndef __KERNEL32__ #define global __KERNEL32__ #uselib "KERNEL32.DLL" #func global GlobalAlloc "GlobalAlloc" sptr,sptr #func global GlobalFree "GlobalFree" sptr #func global GlobalLock "GlobalLock" sptr #func global GlobalUnlock "GlobalUnlock" sptr #endif #ifndef __USER32__ #define global __USER32__ #uselib "USER32.DLL" #func global IsClipboardFormatAvailable "IsClipboardFormatAvailable" sptr #func global OpenClipboard "OpenClipboard" sptr #func global GetClipboardData "GetClipboardData" sptr #func global EmptyClipboard "EmptyClipboard" #func global SetClipboardData "SetClipboardData" sptr, sptr // #func global BeginPaint "BeginPaint" sptr,sptr #func global CloseClipboard "CloseClipboard" // #func global EndPaint "EndPaint" sptr,sptr #func global GetDC "GetDC" sptr #endif #ifndef __GDI32__ #define global __GDI32__ #uselib "GDI32.DLL" #define global GetObject GetObjectA #func global GetObjectA "GetObjectA" sptr,sptr,sptr #func global CreateCompatibleDC "CreateCompatibleDC" sptr #func global CreateCompatibleBitmap "CreateCompatibleBitmap" sptr, sptr, sptr #func global SelectObject "SelectObject" sptr,sptr #func global BitBlt "BitBlt" sptr,sptr,sptr,sptr,sptr,sptr,sptr,sptr,sptr #func global DeleteDC "DeleteDC" sptr #endif #endif #module ;---------- ---------- ---------- ---------- ---------- #define CF_TEXT 1 #define CF_BITMAP 2 #define CF_METAFILEPICT 3 #define CF_SYLK 4 #define CF_DIF 5 #define CF_TIFF 6 #define CF_OEMTEXT 7 #define CF_DIB 8 #define CF_PALETTE 9 #define CF_PENDATA 10 #define CF_RIFF 11 #define CF_WAVE 12 #define CF_UNICODETEXT 13 #define CF_ENHMETAFILE 14 #define CF_HDROP 15 #define CF_LOCALE 16 #define CF_MAX 17 #define CF_OWNERDISPLAY 0x0080 #define CF_DSPTEXT 0x0081 #define CF_DSPBITMAP 0x0082 #define CF_DSPMETAFILEPICT 0x0083 #define CF_DSPENHMETAFILE 0x008E ;---------- ---------- ---------- ---------- ---------- ; 変数のサイズを減少させるためのマクロ #define data bm #define size i #define hText aval #define pText bval #define hBitmap hObj #define hdc_mem i #define hdc2 aval #define pbit bval ;---------- ---------- ---------- ---------- ---------- #deffunc clipget var p1, int p2 mref stt,64 if( p2 > 0 ): size=p2 : else : size=64 ;指定したフォーマットの存在を検索 IsClipboardFormatAvailable CF_TEXT if( stat = 0 ): return ;クリップボードを開く OpenClipboard hwnd if( stat = 0 ): return ;ポインタ取得 GetClipboardData CF_TEXT hText = stat if( hText ! 0 ){ ;クリップボードのデータを読み込み sdim data, size : dupptr data, hText, size, 2 ;クリップボードのデータを変数に保存 p1 = data : hText = 1 } ;クリップボードを閉じる CloseClipboard stt = hText return ;---------- ---------- ---------- ---------- ---------- #deffunc clipset str p1 mref stt,64 size = strlen(p1)+1 ;グローバルメモリを作成、ロックする GlobalAlloc 0x2002, size : hText = stat GlobalLock hText : pText = stat ;グローバルメモリにコピー dupptr data, pText, size, 2 : data = p1 ;ロックの解除 GlobalUnlock hText ;クリップボードを開く OpenClipboard 0 if( stat = 0 ): return ;クリップボードを空にする EmptyClipboard ;クリップボードに値を設定する SetClipboardData CF_TEXT, hText if( stat = 0 ): pText = 0 : else : pText = 1 ;クリップボードを閉じる CloseClipboard ;グローバグメモリを閉じる GlobalFree hText stt = pText return ;---------- ---------- ---------- ---------- ---------- #deffunc clipsetg mref stt,64 #define imgx ginfo(12) #define imgy ginfo(13) ;デバイスコンテキストを作成 ;( hdc を使用すると、他のアプリでエラーになる ) GetDC hwnd : hdc2=stat ;メモリデバイスコンテキストを作成 CreateCompatibleDC hdc2 hdc_mem=stat ;hdc_memと互換性のあるビットマップを作成 CreateCompatibleBitmap hdc2, imgx, imgy hBitmap=stat : if( stat = 0 ): return ;ビットマップを選択する SelectObject hdc_mem, hBitmap hOldBitmap=stat ;ビットマップをコピー BitBlt hdc_mem, 0, 0, imgx, imgy, hdc2, 0, 0, $CC0020 ;オブジェクトを元に戻す SelectObject hdc_mem, hOldBitmap ;クリップボードを開く OpenClipboard hwnd : if( stat = 0 ): return ;クリップボードを空にする EmptyClipboard ;クリップボードに値を設定する SetClipboardData CF_BITMAP, hBitmap if( stat = 0 ): pbit = 0 : else : pbit = 1 #undef imgx #undef imgy ;クリップボードを閉じる CloseClipboard ;メモリデバイスコンテキストを削除 DeleteDC hdc_mem ;デバイスコンテキストを削除 DeleteDC hdc2 stt = pbit return ;---------- ---------- ---------- ---------- ---------- #deffunc clipgetg int p1 mref bm ,67 : hdc2=bm.17 : i=bm.3 mref stt,64 ;指定したフォーマットの存在を検索 IsClipboardFormatAvailable CF_BITMAP if( stat = 0 ): return ;クリップボードを開く OpenClipboard hwnd if( stat = 0 ): return ;ポインタ取得(BITMAPINFOHEADER構造体) GetClipboardData CF_BITMAP if( stat = 0 ){ ;クリップボードを閉じる CloseClipboard : stt=0 : return } hBitmap=stat dim bm,24 ;ビットマップオブジェクト情報取得 GetObject hBitmap,24,varptr(bm) if( stat = 0 ){ ;クリップボードを閉じる CloseClipboard : stt=0 : return } #define imgx bm.1 #define imgy bm.2 ;画像の色bit数 pbit = bm.3>>16&0xFF ;画面を初期化 if( p1 == 0 ){ if( pbit < 8 ): i=1 : else : i=0 if( hdc2 = 1 ) : buffer ginfo_sel,imgx,imgy,i if( hdc2 = 2 ) : screen ginfo_sel,imgx,imgy,i if( hdc2 = 3 ) : bgscr ginfo_sel,imgx,imgy,i } ;パレット取得 if( pbit < 9 )&&( i == 1 ){ i=40 repeat 1<