全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1590
推到 Plurk!
推到 Facebook!

貼入文字至上一個視窗...

尚未結案
okeyla
一般會員


發表:51
回覆:20
積分:19
註冊:2003-06-12

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-09-06 16:31:33 IP:220.130.xxx.xxx 未訂閱
我寫了個程式,listbox上有很多常用的字串, 這是要協助我在使用文字編輯器時, double click在這字串上, 便可以自動貼至文字編輯器. idea是: double click時 (1)將指到的字串copy至clipboard (2)視窗焦點移至上一個視窗(也就是文字編輯器) (3)貼入clipboard內的字串 (4)視窗焦點移回 其中的(2)(3)(4)步驟都試不出來ㄟ... 請大家幫幫忙!!!
chtai
高階會員


發表:68
回覆:238
積分:116
註冊:2004-05-21

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-09-07 16:18:37 IP:140.113.xxx.xxx 未訂閱
引言: (1)將指到的字串copy至clipboard (2)視窗焦點移至上一個視窗(也就是文字編輯器) (3)貼入clipboard內的字串 (4)視窗焦點移回
okeyla 您好,小弟幾天前也自個兒寫了個一樣的小程式,並放在站上了. http://delphi.ktop.com.tw/topic.php?TOPIC_ID=55878 雖然寫得不是很完美,裡頭有很多程式碼還有很大的改進空間, bug也還有一些,不過裡頭的一些做法,或許可以提供給您一些幫助 :) -- http://www.csie.nctu.edu.tw/~chtai/software.html 好用免費軟體的收集網頁,歡迎大家跟我分享或一同推廣免費軟體。 若您覺得這網頁不錯,也歡迎您將它傳出去 :)
------
My Web: http://nelson.csie.us
My Blog: http://blog.nelson.csie.us
ys168
初階會員


發表:3
回覆:24
積分:25
註冊:2005-10-14

發送簡訊給我
#3 引用回覆 回覆 發表時間:2006-07-16 17:55:42 IP:59.117.xxx.xxx 未訂閱

這個程式看是否合你用?
//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include
#include
#include
#include <Forms.hpp><br />#include "Trayicon.h"
#include
#include
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TTrayIcon *TrayIcon1;
TPopupMenu *PopupMenu1;
TMenuItem *test11;
TMenuItem *test21;
TMenuItem *test31;
TListBox *ListBox1;
TMenuItem *N1;
TApplicationEvents *ApplicationEvents1;
void __fastcall FormActivate(TObject *Sender);
void __fastcall PopupMenu1Popup(TObject *Sender);
void __fastcall TrayIcon1MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y);
void __fastcall test31Click(TObject *Sender);
void __fastcall test11Click(TObject *Sender);
void __fastcall TrayIcon1Minimize(TObject *Sender);
void __fastcall N1Click(TObject *Sender);
void __fastcall ListBox1DblClick(TObject *Sender);
void __fastcall ApplicationEvents1Idle(TObject *Sender,
bool &Done);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);

};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
//---------------------------------------------------------------------------

#include
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "Trayicon"
#pragma resource "*.dfm"
TForm1 *Form1;
HWND LastEditHandle;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}

//---------------------------------------------------------------------------

void __fastcall TForm1::FormActivate(TObject *Sender)
{
Application->Minimize();
ShowWindow(Application->Handle, SW_HIDE);
}
//---------------------------------------------------------------------------


void __fastcall TForm1::PopupMenu1Popup(TObject *Sender)
{
Form1->Visible = true;
SetForegroundWindow(this->Handle);
// ListBox1->Visible=true;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::TrayIcon1MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
POINT p;
::GetCursorPos(&p);
PopupMenu1->Popup(p.x, p.y);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::test31Click(TObject *Sender)
{
Form1->Close();
}
//---------------------------------------------------------------------------
// 呼叫 ListBox
void __fastcall TForm1::test11Click(TObject *Sender)
{
Application->Restore();
// SetForegroundWindow(this->Handle);

}
//---------------------------------------------------------------------------

void __fastcall TForm1::TrayIcon1Minimize(TObject *Sender)
{
// Form1->WindowState = wsMinimized;
// Form1->Visible = false;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::N1Click(TObject *Sender)
{
FormActivate(Sender);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::ListBox1DblClick(TObject *Sender)
{
HWND hFocusWin;

if(!IsWindow(LastEditHandle)) return;
if( IsZoomed(LastEditHandle) )
ShowWindow(LastEditHandle, SW_SHOWMAXIMIZED); // 若是最大化, 就最大化顯示
else
ShowWindow(LastEditHandle, SW_SHOWNORMAL); // 不然就直接顯示
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, 0, SPIF_SENDCHANGE);
BringWindowToTop(LastEditHandle);
// SetForegroundWindow(LastEditHandle);
if( AttachThreadInput(GetCurrentThreadId(), GetWindowThreadProcessId(LastEditHandle, NULL), true) )
{
BringWindowToTop(LastEditHandle);
// SetForegroundWindow(LastEditHandle);
Application->ProcessMessages();
hFocusWin = GetFocus();
AttachThreadInput(GetCurrentThreadId(), GetWindowThreadProcessId(LastEditHandle, NULL), false);
if( hFocusWin != NULL )
{
int i;
Byte ch;
AnsiString str = ListBox1->Items->Strings[ListBox1->ItemIndex];
for( i = 1; i <= str.Length(); i ) // 注意: 是從 1 開始, 不是從 0 開始
{
ch = Byte(str[i]);
if( IsDBCSLeadByte(ch) ) // 若是雙位元的字, 就和下一個byte合成一個字
PostMessage(hFocusWin, WM_IME_CHAR, MAKEWORD(Byte(str[ i]), ch), 0);
else // 不然就直接送出
PostMessage(hFocusWin, WM_IME_CHAR, WORD(ch), 0);
}
}
else
ShowMessage("GetFocus() failed!");
}
else
ShowMessage("AttachThreadInput() failed!!");
}
//---------------------------------------------------------------------------

void __fastcall TForm1::ApplicationEvents1Idle(TObject *Sender, bool &Done)
{
HWND ForeWindow = ::GetForegroundWindow();
if(ForeWindow != Handle)
{
LastEditHandle = ForeWindow;
char str[255];
SendMessage(LastEditHandle, WM_GETTEXT, 255, (long)str);
ListBox1->Hint = AnsiString("傳送到 - ") str;
}
}
//---------------------------------------------------------------------------

------
yangshuh
系統時間:2024-03-29 18:36:51
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!