Hi ich wollte eine möglichkeit schaffen unter Windows einen Text in den Clipboard zu kopieren, beim erstellen keine Fehlermeldung, Clipboard wird "resetet", doch Text wird nicht übergeben!
copy_to_clip("Test")
PRINT "OK",10,10
SHOWSCREEN
MOUSEWAIT
FUNCTION WeNeedOne:
ENDFUNCTION
INLINE
DECLARE_C_ALIAS(CloseClip, "user32.dll", "CloseClipboard", (), void);
DECLARE_C_ALIAS(EmptyClip, "user32.dll", "EmptyClipboard", (), void);
DECLARE_C_ALIAS(OpenClip, "user32.dll", "OpenClipboard", (int), void);
DECLARE_C_ALIAS(SetClipData, "user32.dll", "SetClipboardData", (int, char), void);
ENDINLINE
FUNCTION copy_to_clip: txt$
INLINE
OpenClip(0);
EmptyClip();
SetClipData(1,txt_Str);
CloseClip();
ENDINLINE
ENDFUNCTIONEDIT:
Hab noch so versucht, gleiches Ergebniss:
copy_to_clip("CF_TEXT","Test")
PRINT "OK",10,10
SHOWSCREEN
MOUSEWAIT
FUNCTION WeNeedOne:
ENDFUNCTION
INLINE
DECLARE_C_ALIAS(CloseClip, "user32.dll", "CloseClipboard", (), void);
DECLARE_C_ALIAS(EmptyClip, "user32.dll", "EmptyClipboard", (), void);
DECLARE_C_ALIAS(OpenClip, "user32.dll", "OpenClipboard", (int), void);
DECLARE_C_ALIAS(SetClipData, "user32.dll", "SetClipboardData", (char, char), void);
ENDINLINE
FUNCTION copy_to_clip: type$, txt$ //types : CF_TEXT = Text
INLINE
OpenClip(0);
EmptyClip();
SetClipData(type_Str,txt_Str);
CloseClip();
ENDINLINE
ENDFUNCTION
der zweite Parameter von SetClipboardData ist eigentlich auch ein Long-Wert. glaube ist dann ein Zeiger auf die Daten (Text, Bilder etc.)
Korrekt char* statt char.
und CF_TEXT ist kein String, sondern eine Konstante. Nämlich
/*
* Predefined Clipboard Formats
*/
#define CF_TEXT 1
#define CF_BITMAP 2
#define CF_METAFILEPICT 3
#define CF_OEMTEXT 7
#define CF_DIB 8
#define CF_UNICODETEXT 13
#define CF_ENHMETAFILE 14
Dacht ich mir schon aber irgendwie will der noch nicht ganz ...
copy_to_clip("TEST")
SHOWSCREEN
MOUSEWAIT
FUNCTION WeNeedOne:
ENDFUNCTION
INLINE
#define CF_TEXT 1
DECLARE_C_ALIAS(CloseClip, "user32.dll", "CloseClipboard", (), void);
DECLARE_C_ALIAS(EmptyClip, "user32.dll", "EmptyClipboard", (), void);
DECLARE_C_ALIAS(OpenClip, "user32.dll", "OpenClipboard", (int), void);
DECLARE_C_ALIAS(SetClipData, "user32.dll", "SetClipboardData", (const int, char*), void);
ENDINLINE
FUNCTION copy_to_clip: txt$
INLINE
OpenClip(0);
EmptyClip();
SetClipData(CF_TEXT,txt_Str);
CloseClip();
ENDINLINE
ENDFUNCTIONFehler:
C:/DOKUME~1/SCHRAN~1/LOKALE~1/Temp/glbasic/gpc_temp0.cpp: In function `DGInt __GLBASIC__::copy_to_clip(__GLBASIC__::DGStr)':
C:/DOKUME~1/SCHRAN~1/LOKALE~1/Temp/glbasic/gpc_temp0.cpp:37: error: argument of type `const char*(__GLBASIC__::DGStr::)() const' does not match `char*'
hab noch mal ein wenig rumprobiert. So gehts bei mir
also nicht den String als solches übergeben mit txt_Str, sondern als Pointer mit txt_Str.c_str(). In der Deklaration dann entsprechen mit const char* anpassen.
a$ = "Ein clipboard-Test"
copy_to_clip(a$)
PRINT "OK",10,10
SHOWSCREEN
MOUSEWAIT
FUNCTION WeNeedOne:
ENDFUNCTION
INLINE
DECLARE_C_ALIAS(OpenClip, "user32.dll", "OpenClipboard", (void*), void);
DECLARE_C_ALIAS(EmptyClip, "user32.dll", "EmptyClipboard", (), void);
DECLARE_C_ALIAS(CloseClip, "user32.dll", "CloseClipboard", (), void);
DECLARE_C_ALIAS(SetClipData, "user32.dll", "SetClipboardData", (int, const char*),void);
ENDINLINE
FUNCTION copy_to_clip: txt$
IF txt$="" THEN RETURN
INLINE
OpenClip(GLBASIC_HWND());
EmptyClip();
SetClipData(1, txt_Str.c_str());
CloseClip();
ENDINLINE
ENDFUNCTION
Sehr geil!
Hatte ich mal so, nur hatte ich das () bei txt_Str.c_str() vergessen :D
EDIT.: Sowas könnte man für eine inputroute gebrauchen ;)
Oh misst zu langsam :(
Wenn man kein GLB drauf hat kann man sowas auch nicht testen *schmoll*
Nevermind ich geh in die ecke und schäm mich ;)
funktioniert das auch mit der glbasic-demo?
soviel ich weiß ja. Probiers doch einfach mal aus ;)
jetzt funktioniert es.
kam immer eine fehlermeldung , habe glbasicdemo neu installiert.