![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
Буфер обмена. [D7]
msdn11 © (2004-10-27 18:40:00)Всем привет. Вопрос такой:как емулировать вставку из буфера на делфи(только не в едит или мемо а в "левое" окно). Другими словами надо заставить винду вставить из буфера текст. Я устанавливаю курсор в нужное мне поле IE(там у меня форма html TWebBrowser и всё такое), храню в буфере то, что мне нужно, а как вставить не знаю. Помогите.
alena.svt (2004-10-27 20:34:00) [1]>>msdn11 (27.10.04 20:18) [19]
>>А если не в своей?
Открой блокнот
и напиши для кнопки код (пост 5)
Если что то есть в буфере ты увидишь это блокноте
потом открой IE и поставь курсор в поле(Combobox) URL
Сверни его
В коде замени 'Notepad',nil на 'IEFrame',nil
Компиль и дави кнопку
Только в буфере надо чтоб URl был
msdn11 (2004-10-27 20:24:00) [2]Всё работает!!!!!!!!!!!!!!!!!!!!!!
Всем спасибо за помощь.
PVOzerski (2004-10-27 20:20:00) [3]Ну вот, ошибся: во-первых, не "развираться", а "разбираться", во-вторых, последний кусок только проверяет соответствие числа элементов ожидаемому. Но всё-таки это может помочь. BTW, имей в виду: IE-штука еще та... Когда я пытался просто через Windows-сообщения изменять выделение элементов, на экране всё получалось, а вот при отправлении содержимого формы на cgi IE об этом изменении не знал. Не вышло бы так же и с paste...
msdn11 (2004-10-27 20:18:00) [4]
> Просто если в своей форме
> То SetFocus для компонента
> а потом PostKeyEx32(VK_TAB,[],false);
> или PostKeyEx32(Ord('V'),[ssCtrl],false);// Вставка
> а FindWindow и т.д. не надо
А если не в своей?
PVOzerski (2004-10-27 20:15:00) [5]Мне развираться с конкретной задачей некогда, я нарыл это из своих кладовок (кстати, кто-то из Мастаков выслал).
IWebBrowser = interface(IDispatch)
['{EAB22AC1-30C1-11CF-A7EB-0000C05BAE0B}']
procedure GoBack; safecall;
procedure GoForward; safecall;
procedure GoHome; safecall;
procedure GoSearch; safecall;
procedure Navigate(const URL: WideString; var Flags: OleVariant;
var TargetFrameName: OleVariant; var PostData: OleVariant;
var Headers: OleVariant); safecall;
procedure Refresh; safecall;
procedure Refresh2(var Level: OleVariant); safecall;
procedure Stop; safecall;
function Get_Application: IDispatch; safecall;
function Get_Parent: IDispatch; safecall;
function Get_Container: IDispatch; safecall;
function Get_Document: IDispatch; safecall;
function Get_TopLevelContainer: WordBool; safecall;
function Get_Type_: WideString; safecall;
function Get_Left: Integer; safecall;
procedure Set_Left(pl: Integer); safecall;
function Get_Top: Integer; safecall;
procedure Set_Top(pl: Integer); safecall;
function Get_Width: Integer; safecall;
procedure Set_Width(pl: Integer); safecall;
function Get_Height: Integer; safecall;
procedure Set_Height(pl: Integer); safecall;
function Get_LocationName: WideString; safecall;
function Get_LocationURL: WideString; safecall;
function Get_Busy: WordBool; safecall;
property Application: IDispatch read Get_Application;
property Parent: IDispatch read Get_Parent;
property Container: IDispatch read Get_Container;
property Document: IDispatch read Get_Document;
property TopLevelContainer: WordBool read Get_TopLevelContainer;
property Type_: WideString read Get_Type_;
property Left: Integer read Get_Left write Set_Left;
property Top: Integer read Get_Top write Set_Top;
property Width: Integer read Get_Width write Set_Width;
property Height: Integer read Get_Height write Set_Height;
property LocationName: WideString read Get_LocationName;
property LocationURL: WideString read Get_LocationURL;
property Busy: WordBool read Get_Busy;
end;
IWebBrowserApp = interface(IWebBrowser)
['{0002DF05-0000-0000-C000-000000000046}']
procedure Quit; safecall;
procedure ClientToWindow(var pcx: SYSINT; var pcy: SYSINT); safecall;
procedure PutProperty(const Property_: WideString; vtValue: OleVariant); safecall;
function GetProperty(const Property_: WideString): OleVariant; safecall;
function Get_Name: WideString; safecall;
function Get_HWND: Integer; safecall;
function Get_FullName: WideString; safecall;
function Get_Path: WideString; safecall;
function Get_Visible: WordBool; safecall;
procedure Set_Visible(pBool: WordBool); safecall;
function Get_StatusBar: WordBool; safecall;
procedure Set_StatusBar(pBool: WordBool); safecall;
function Get_StatusText: WideString; safecall;
procedure Set_StatusText(const StatusText: WideString); safecall;
function Get_ToolBar: SYSINT; safecall;
procedure Set_ToolBar(Value: SYSINT); safecall;
function Get_MenuBar: WordBool; safecall;
procedure Set_MenuBar(Value: WordBool); safecall;
function Get_FullScreen: WordBool; safecall;
procedure Set_FullScreen(pbFullScreen: WordBool); safecall;
property Name: WideString read Get_Name;
property HWND: Integer read Get_HWND;
property FullName: WideString read Get_FullName;
property Path: WideString read Get_Path;
property Visible: WordBool read Get_Visible write Set_Visible;
property StatusBar: WordBool read Get_StatusBar write Set_StatusBar;
property StatusText: WideString read Get_StatusText write Set_StatusText;
property ToolBar: SYSINT read Get_ToolBar write Set_ToolBar;
property MenuBar: WordBool read Get_MenuBar write Set_MenuBar;
property FullScreen: WordBool read Get_FullScreen write Set_FullScreen;
end;
IWebBrowser2 = interface(IWebBrowserApp)
['{D30C1661-CDAF-11D0-8A3E-00C04FC9E26E}']
procedure Navigate2(var URL: OleVariant; var Flags: OleVariant;
var TargetFrameName: OleVariant; var PostData: OleVariant;
var Headers: OleVariant); safecall;
function QueryStatusWB(cmdID: OLECMDID): OLECMDF; safecall;
procedure ExecWB(cmdID: OLECMDID; cmdexecopt: OLECMDEXECOPT; var pvaIn: OleVariant;
var pvaOut: OleVariant); safecall;
procedure ShowBrowserBar(var pvaClsid: OleVariant; var pvarShow: OleVariant;
var pvarSize: OleVariant); safecall;
function Get_ReadyState: tagREADYSTATE; safecall;
function Get_Offline: WordBool; safecall;
procedure Set_Offline(pbOffline: WordBool); safecall;
function Get_Silent: WordBool; safecall;
procedure Set_Silent(pbSilent: WordBool); safecall;
function Get_RegisterAsBrowser: WordBool; safecall;
procedure Set_RegisterAsBrowser(pbRegister: WordBool); safecall;
function Get_RegisterAsDropTarget: WordBool; safecall;
procedure Set_RegisterAsDropTarget(pbRegister: WordBool); safecall;
function Get_TheaterMode: WordBool; safecall;
procedure Set_TheaterMode(pbRegister: WordBool); safecall;
function Get_AddressBar: WordBool; safecall;
procedure Set_AddressBar(Value: WordBool); safecall;
function Get_Resizable: WordBool; safecall;
procedure Set_Resizable(Value: WordBool); safecall;
property ReadyState: tagREADYSTATE read Get_ReadyState;
property Offline: WordBool read Get_Offline write Set_Offline;
property Silent: WordBool read Get_Silent write Set_Silent;
property RegisterAsBrowser: WordBool read Get_RegisterAsBrowser write Set_RegisterAsBrowser;
property RegisterAsDropTarget: WordBool read Get_RegisterAsDropTarget write Set_RegisterAsDropTarget;
property TheaterMode: WordBool read Get_TheaterMode write Set_TheaterMode;
property AddressBar: WordBool read Get_AddressBar write Set_AddressBar;
property Resizable: WordBool read Get_Resizable write Set_Resizable;
end;
Обрати внимание на свойство Document. Вот кусок, где я изменяю выделение в элементах Select'a (списка):
var
IE:IWebBrowser2;
...
Document:=IE.Document;
FunCat:=0;
EC:=0;
for m:=0 to Document.forms.Length-1 do
begin
ovElements:=Document.forms.Item(m).elements;
for i:=ovElements.Length-1 downto 0 do
if ovElements.item(i).type='select-multiple' then
begin
l:=ovElements.item(i).options.length;
if l=FunCatCount then
begin
FunCat:=ovElements.item(i).options;
FunCatFound:=true;
end
else if l=EcCount then
begin
EC:=ovElements.item(i).options;
ECFound:=true;
end;
end;
end;
За лишнее прошу прощение: выбирать некогда...
begin...end (2004-10-27 20:08:00) [6]На то она и Добрая Девочка ;-)
msdn11 (2004-10-27 20:07:00) [7]Работает. Но пока коряво(поправим). Спасибо Вам Лена. Вы меня спасли.
alena.svt (2004-10-27 20:07:00) [8]Просто если в своей форме
То SetFocus для компонента
а потом PostKeyEx32(VK_TAB,[],false);
или PostKeyEx32(Ord('V'),[ssCtrl],false);// Вставка
а FindWindow и т.д. не надо
alena.svt (2004-10-27 20:03:00) [9]Если просто таб
то PostKeyEx32(VK_TAB,[],false);
msdn11 (2004-10-27 20:01:00) [10]А как PostKeyEx32 tab нажать?
alena.svt (2004-10-27 19:55:00) [11]if SetForegroundWindow(H) then
begin
Combobox1.SetFocus;
keybd_event(VK_CONTROL, MapVirtualKey(VK_CONTROL, 0), 0, 0);
................
....................
.....................
end;
msdn11 (2004-10-27 19:50:00) [12]хотя что - то стало получаться :-)
alena.svt (2004-10-27 19:49:00) [13]а чего пост 5 не работает не может быть
procedure TForm1.Button1Click(Sender: TObject);
var
H :THandle;
begin
H := FindWindow('TForm1',nil);
if H > 0 then
if SetForegroundWindow(H) then
begin
keybd_event(VK_CONTROL, MapVirtualKey(VK_CONTROL, 0), 0, 0);
keybd_event(Ord('V'), MapVirtualKey(Ord('V'), 0), 0, 0);
keybd_event(Ord('V'), MapVirtualKey(Ord('V'), 0), KEYEVENTF_KEYUP, 0);
keybd_event(VK_CONTROL, MapVirtualKey(VK_CONTROL, 0), KEYEVENTF_KEYUP, 0);
end;
end;
msdn11 (2004-10-27 19:40:00) [14]не выходит...
msdn11 (2004-10-27 19:38:00) [15]пытаюсь так
procedure TForm1.Button2Click(Sender: TObject);
var
input:OleVariant;
i:integer;
href:string;
begin
WebBrowser1.Navigate(ExtractFilePath(application.ExeName)+'1.html');
for i:=0 to WebBrowser1.OleObject.document.all.tags('input').length-2 do
begin
WebBrowser1.OleObject.document.all.tags('input').item(i).focus;
sendmessage(getfocus,wm_paste,0,0);
WebBrowser1.Stop;
end;
msdn11 (2004-10-27 19:36:00) [16]не скромный вопрос: а как?
TUser (2004-10-27 19:34:00) [17]
> Почитай об OLE-интерфейсах, поддерживаемых IE.
Об этом он уже читал - смотрите 2 вопроса за сегодня.
Послать ему Ctrl-V, наверное проще всего
alena.svt (2004-10-27 19:33:00) [18]procedure PostKeyEx32(Key: Word; const Shift: TShiftState; SpecialKey: Boolean);
{************************************************************
* Procedure PostKeyEx32
*
* Parameters:
* key : virtual keycode of the key to send. For printable
* keys this is simply the ANSI code (Ord(character)).
* shift : state of the modifier keys. This is a set, so you
* can set several of these keys (shift, control, alt,
* mouse buttons) in tandem. The TShiftState type is
* declared in the Classes Unit.
* specialkey: normally this should be False. Set it to True to
* specify a key on the numeric keypad, for example.
* Description:
* Uses keybd_event to manufacture a series of key events matching
* the passed parameters. The events go to the control with focus.
* Note that for characters key is always the upper-case version of
* the character. Sending without any modifier keys will result in
* a lower-case character, sending it with [ssShift] will result
* in an upper-case character!
*Created: 17.7.98 by P. Below
************************************************************}
type
TShiftKeyInfo = record
Shift: Byte;
Vkey : Byte;
end;
ByteSet = set of 0..7;
const
ShiftKeys: array [1..3] of TShiftKeyInfo =
((Shift: Ord(ssCtrl); Vkey: VK_CONTROL),
(Shift: Ord(ssShift); Vkey: VK_SHIFT),
(Shift: Ord(ssAlt); Vkey: VK_MENU));
var
Flag: DWORD;
bShift: ByteSet absolute Shift;
I: Integer;
begin
for I := 1 to 3 do begin
if ShiftKeys[I].Shift In bShift Then
keybd_event(ShiftKeys[I].Vkey,MapVirtualKey(ShiftKeys[I].Vkey,0),0,0);
end;
if SpecialKey then
Flag := KEYEVENTF_EXTENDEDKEY
else
Flag := 0;
keybd_event(Key,MapvirtualKey(Key,0),Flag,0);
Flag := Flag or KEYEVENTF_KEYUP;
keybd_event(Key, MapvirtualKey(Key,0),Flag,0);
for i := 3 downto 1 do begin
if ShiftKeys[I].Shift In bShift then
keybd_event(ShiftKeys[I].Vkey,MapVirtualKey(ShiftKeys[I].Vkey,0),KEYEVENTF_KEYUP,0);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var h:thandle;
begin
H := FindWindow('Notepad',nil);
if H > 0 then
if SetForegroundWindow(H) then
PostKeyEx32(Ord('V'),[ssCtrl],false);
end;
msdn11 (2004-10-27 19:30:00) [19]два дня рою, ни фига нету
PVOzerski (2004-10-27 19:25:00) [20]Почитай об OLE-интерфейсах, поддерживаемых IE. Думаю, в Интернете найти это можно.