Win32-Clipboard
view release on metacpan or search on metacpan
Clipboard.xs view on Meta::CPAN
/*
#######################################################################
#
# Win32::Clipboard - Interaction with the Windows clipboard
#
# Version: 0.58
# Created: 19 Nov 96
# Author: Aldo Calpini <dada@perl.it>
#
# Modified: 24 Jul 2004
# By: Hideyo Imazu <h@imazu.net>
#
#######################################################################
*/
/* uncomment next line for debug messages */
// #define WIN32__CLIPBOARD__DEBUG
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <string.h>
#include <wchar.h>
#include <winuser.h>
#include <shellapi.h>
#define __TEMP_WORD WORD /* perl defines a WORD, yikes! */
#ifdef __cplusplus
#include <stdlib.h>
#include <math.h>
extern "C" {
#endif
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#ifdef __cplusplus
}
#endif
#include "ppport.h"
#undef WORD
#define WORD __TEMP_WORD
// Section for the constant definitions.
#define CROAK croak
#define MAX_LENGTH 2048
#define TMPBUFSZ 1024
static HWND hwndThisViewer;
static HWND hwndNextViewer;
static HANDLE hEvt;
static HANDLE hThread;
/* DLL entry point */
BOOL WINAPI DllMain(HINSTANCE hDll, DWORD reason, LPVOID reserved) {
// BOOL ccb;
#ifdef WIN32__CLIPBOARD__DEBUG
printf("!XS(DllMain): DLL entry point called with reason: %ld\n", reason);
printf("!XS(DllMain): ClipboardViewer is: %ld\n", GetClipboardViewer());
#endif
if((reason == DLL_THREAD_ATTACH ||
Clipboard.xs view on Meta::CPAN
p_hdr->bfSize = (DWORD) (sizeof(BITMAPFILEHEADER) + dib_size);
p_hdr->bfReserved1 = 0;
p_hdr->bfReserved2 = 0;
p_hdr->bfOffBits = (DWORD) (sizeof(BITMAPFILEHEADER) + dib_offset);
return dib_size;
}
MODULE = Win32::Clipboard PACKAGE = Win32::Clipboard
PROTOTYPES: DISABLE
long
constant(name, arg)
char *name
int arg
CODE:
RETVAL = constant(name, arg);
OUTPUT:
RETVAL
void
StartClipboardViewer(...)
PPCODE:
if(hThread == NULL)
hThread = StartClipboardViewer();
void
StopClipboardViewer(...)
PPCODE:
char NextText[1024];
if(hwndThisViewer) {
#ifdef WIN32__CLIPBOARD__DEBUG
printf("XS(StartClipboardViewer): hwndThisViewer=%ld\n", hwndThisViewer);
printf("XS(StartClipboardViewer): hwndNextViewer=%ld\n", hwndNextViewer);
#endif
GetWindowText(hwndNextViewer, NextText, 1024);
// DestroyWindow(hwndThisViewer);
SendMessage(hwndThisViewer, WM_DESTROY, 0, 0);
SendMessage(hwndThisViewer, WM_QUIT, 0, 0);
// PostQuitMessage(0);
// ChangeClipboardChain(hwndThisViewer, hwndNextViewer);
if(IsWindow(hwndThisViewer)) {
XSRETURN_IV((long) -1);
} else {
hwndThisViewer = NULL;
XSRETURN_YES;
}
} else {
XSRETURN_NO;
}
void
WaitForChange(...)
PPCODE:
DWORD cause;
DWORD timeout;
if(hThread == NULL) {
#ifdef WIN32__CLIPBOARD__DEBUG
printf("XS(WaitForChange): Starting the clipboard viewer...\n");
#endif
hThread = StartClipboardViewer();
}
// set the event to be waited for
ResetEvent(hEvt);
timeout = INFINITE;
if(items == 1 && !SvROK(ST(0))) { timeout = (DWORD)SvIV(ST(0)); }
if(items == 2) { timeout = (DWORD)SvIV(ST(1)); }
cause = WaitForSingleObject(hEvt, timeout);
EXTEND(SP,1);
if(cause == WAIT_OBJECT_0)
XST_mIV(0, 1);
else if ( cause == WAIT_TIMEOUT )
XST_mIV(0, 0);
else
XST_mNO(0);
XSRETURN(1);
void
GetText(...)
PPCODE:
HANDLE myhandle;
if(OpenClipboard(NULL)) {
EXTEND(SP,1);
if(myhandle = GetClipboardData(CF_TEXT))
XST_mPV(0, (char *) myhandle);
else
XST_mNO(0);
CloseClipboard();
XSRETURN(1);
} else {
XSRETURN_NO;
}
void
GetFiles(...)
PPCODE:
HANDLE myhandle;
LPTSTR filename;
UINT namelength;
UINT i, toreturn;
UINT count;
if ( OpenClipboard(NULL) ) {
if ( myhandle = GetClipboardData(CF_HDROP) ) {
count = DragQueryFile((HDROP) myhandle, 0xFFFFFFFF, NULL, 0);
EXTEND(SP, count);
for ( i = 0 ; i < count ; i++ ) {
namelength = DragQueryFile((HDROP) myhandle, i, NULL, 0);
filename = (LPTSTR) safemalloc(namelength+1);
DragQueryFile((HDROP) myhandle, i, filename, namelength+1);
XST_mPV(i, (char *)filename);
safefree(filename);
}
toreturn = count;
}
else {
( run in 1.831 second using v1.01-cache-2.11-cpan-a5162978ef8 )