;---------- ---------- ---------- ---------- ---------- ; 作成者のURL ---> http://www.setsuki.com/ ;---------- ---------- ---------- ---------- ---------- /* [ サンプル ] #include "clipboard.as" ; HTMLデータの取得 sdim ans, 65535 clipget ans, 65535, clipname("HTML Format") ; ※ UTF-8フォーマットなので、 ; jcode.as の UTF8toSJIS が必要です。 mesbox ans, ginfo_winx, ginfo_winy screen 1,256,256 line 0,0,256,256 line 256,0,0,256 ; 画像をクリップボードに登録 clipsetg ; クリップボードの画像データを取得 screen 2,,,2 clipgetg if( stat == 0 ){ dialog "クリップボードの取得に失敗しました。" } stop */ ;========== ========== ========== ========== ========== ; クリップボードの操作 ;---------- ---------- ---------- ---------- ---------- ; ; ■ clipget ; クリップボードテキスト取得 (拡張あり) ; ; ■ clipset ; クリップボードテキスト転送 ; ; ■ clipsetg ; クリップボード画像転送 ; ; ■ clipgetg ; クリップボード画像を取得 ; ; クリップボードの画像サイズに合わせて ; 画面サイズも変更します。 ; ; [ 2006/09/01 ] clipgetg 1 と指定すると、 ; 画面サイズの変更せずに取得できるようにしました。 ; ; ■ clipname ; 新しいデータ形式を登録して使用 (文字列を指定) ; ;========== ========== ========== ========== ========== ; ; 基本的に hspext と同じ操作ですので ; 詳細は、HSPのヘルプを見てください。 ; ま、要するに、hspext を ; モジュール化した感じです。(^^; ; ;========== ========== ========== ========== ========== ; ; □ すべてのモジュールで以下の 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 #func global GlobalSize "GlobalSize" 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 #define global RegisterClipboardFormat RegisterClipboardFormatA #func global RegisterClipboardFormatA "RegisterClipboardFormatA" 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 ;---------- ---------- ---------- ---------- ---------- #defcfunc clipname str p1 sdim data, 64 : data = p1 RegisterClipboardFormat varptr(data) format = stat return format ;---------- ---------- ---------- ---------- ---------- #deffunc clipget var p1, int p2, int p3 if( p2 > 0 ): size = p2 : else : size = 64 if( p3 == 0 ): format = CF_TEXT : else : format = p3 ;指定したフォーマットの存在を検索 ;IsClipboardFormatAvailable format ;if( stat == 0 ): return ;クリップボードを開く OpenClipboard hwnd if( stat == 0 ): return ;ポインタ取得 GetClipboardData format hText = stat if( hText != 0 ){ ;クリップボードのデータを読み込み dupptr data, hText, size, 2 GlobalSize hText : if( stat < size ) : size = stat ;クリップボードのデータを変数に保存 memcpy p1, data, size hText = 1 } ;クリップボードを閉じる CloseClipboard return hText ;---------- ---------- ---------- ---------- ---------- #deffunc clipset str p1 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 return pText ;---------- ---------- ---------- ---------- ---------- #deffunc clipsetg #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 return pbit ;---------- ---------- ---------- ---------- ---------- #deffunc clipgetg int p1 mref bm ,67 : hdc2 = bm.17 : i = bm.3 ;指定したフォーマットの存在を検索 IsClipboardFormatAvailable CF_BITMAP if( stat == 0 ): return ;クリップボードを開く OpenClipboard hwnd if( stat == 0 ): return ;ポインタ取得(BITMAPINFOHEADER構造体) GetClipboardData CF_BITMAP if( stat == 0 ){ ;クリップボードを閉じる CloseClipboard : return 0 } hBitmap = stat dim bm,24 ;ビットマップオブジェクト情報取得 GetObject hBitmap,24,varptr(bm) if( stat == 0 ){ ;クリップボードを閉じる CloseClipboard : return 0 } #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<