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

关于图像画布(绘矩形)

尚未結案
chenliyan163
一般會員


發表:30
回覆:30
積分:12
註冊:2003-09-15

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-11-10 10:32:37 IP:61.175.xxx.xxx 未訂閱
http://www.my2000.biz/temp1/test.jpg 如何才能在image中画一个筐,而且画好后可以通过六点可以调整大小(如上图所示); 各位大哥,帮帮我.
aquarius
資深會員


發表:3
回覆:347
積分:330
註冊:2003-05-21

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-11-10 11:40:37 IP:211.23.xxx.xxx 未訂閱
引言: http://www.my2000.biz/temp1/test.jpg 如何才能在image中画一个筐,而且画好后可以通过六点可以调整大小(如上图所示); 各位大哥,帮帮我.
懶得再寫一次範例, 請參考這一篇 http://delphi.ktop.com.tw/topic.php?TOPIC_ID=40245 ...Aquarius
------
水瓶男的blog: http://791909.blogspot.com
chenliyan163
一般會員


發表:30
回覆:30
積分:12
註冊:2003-09-15

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-11-11 10:44:28 IP:61.175.xxx.xxx 未訂閱
我看了都不符合我的要求,只有再麻烦您这位大哥了. 我要的就像delphi中放一个image控件一样,当点住这个控件时,就可以对这个控件进行长.宽.高等调整,(只不过我在一个画布上,对画布上所画的矩形筐进行调整)
aquarius
資深會員


發表:3
回覆:347
積分:330
註冊:2003-05-21

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-11-11 16:49:21 IP:211.23.xxx.xxx 未訂閱
引言: 我看了都不符合我的要求,只有再麻烦您这位大哥了. 我要的就像delphi中放一个image控件一样,当点住这个控件时,就可以对这个控件进行长.宽.高等调整,(只不过我在一个画布上,对画布上所画的矩形筐进行调整)
這個問題有討論過了, 去看看吧!! http://forum.vclxx.org/topic.php?TOPIC_ID=1802&FORUM_ID=4&CAT_ID=2&Topic_Title=%A6b%B0%F5%A6%E6%AE%C9%B9%B3+IDE+%AE%C9%AF%E0%A5H%A9%EC%A6%B2%AA%BA%A4%E8%A6%A1%A7%EF%C5%DC%A4%B8%A5%F3%A4j%A4p%A4%CE%A6%EC%B8m&Forum_Title=VCL ...Aquarius
------
水瓶男的blog: http://791909.blogspot.com
ys168
初階會員


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

發送簡訊給我
#5 引用回覆 回覆 發表時間:2007-08-09 21:57:25 IP:59.117.xxx.xxx 訂閱
// Unit1 cpp    //--------------------------------------------------------------------------- #define NO_WIN32_LEAN_AND_MEAN  #include  #include #pragma hdrstop #include "GetRectU.h" #include "Unit2.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //當成功製作一新TrayIcon時的識別ID------------------------------------------- const int WM_TRAYID = WM_USER 1001; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- //新增或更新自訂的TrayIcon void __fastcall TForm1::AddorChangeIcon(int iconNum) { //在程式結束前,將此布林變數及整數變數的儲存位置固定住 static bool AlreadyAdded = false; static int IconAdded = -1; //第一次啟用本函式之後,即排除相同變數的重複執行 if (IconAdded == iconNum) return; //宣告及填入TrayIcon結構 NOTIFYICONDATA newIcon; newIcon.cbSize = sizeof(newIcon); newIcon.uID = WM_TRAYID;//自訂識別ID newIcon.hWnd = Handle; //自訂此TrayIcon的callback訊息 newIcon.uCallbackMessage = WM_TRAYICON; //將字串複製至「提示」中 lstrcpy(newIcon.szTip, "按右鍵:PopupMenu 選單。\n雙按左鍵:隱藏 / 顯示。"); //設定從ImageList1中取出的圖示 ImageList1->GetIcon(iconNum, TrayIcon); newIcon.hIcon = TrayIcon->Handle; //決定是新增或修改TrayIcon DWORD dwMessage; (AlreadyAdded)?(dwMessage = NIM_MODIFY):(dwMessage = NIM_ADD); //設定旗標--允許送出自訂訊息、自訂圖示、自訂提示 newIcon.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; //創造一新增或修改現有TrayIcon ::Shell_NotifyIcon(dwMessage, &newIcon); //經過第一次是新增TrayIcon,以後皆是更新修改 //此2值更新且儲存固定地址,以供下次執行本函式使用 AlreadyAdded = true; IconAdded = iconNum; } //------------------------------------------------------------------------------------ void __fastcall TForm1::WmNewTray(TMessage &Msg) { //專為捕捉TrayIcon自訂訊息 if(Msg.Msg == WM_TRAYICON) { switch(Msg.LParam) { //當滑鼠雙擊此TrayIcon時,即切換顯現或隱藏Form1視窗 case WM_LBUTTONDBLCLK: { if(::IsWindowVisible(Handle)) { ::ShowWindow(Handle,SW_HIDE); AddorChangeIcon(1); } else { ::ShowWindow(Handle,SW_SHOW); ::SetForegroundWindow(Handle);//將Form1提至最前面備用 AddorChangeIcon(0); } break; } case WM_RBUTTONUP://當滑鼠右鍵點按TrayIcon,則出現POP選單 { POINT p; ::GetCursorPos(&p);//取得螢幕座標 ::SetForegroundWindow(Handle);//將Form1提至最前面備用 PopupMenu1->Popup(p.x, p.y);//顯現POP選單 PostMessage(Handle, WM_NULL, 0,0);//清除未知訊息 break; } } } //若有其他訊息依預設處理 TForm::Dispatch(&Msg); } //--------------------------------------------------------------------------- void __fastcall TForm1::N1Click(TObject *Sender) { Close(); } //--------------------------------------------------------------------------- void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action) { //對等於現存的TrayIcon結構資料 NOTIFYICONDATA tray; tray.cbSize = sizeof(tray); tray.uID = WM_TRAYID;//自訂ID tray.hWnd = Handle; tray.hIcon = TrayIcon->Handle; //依此結構,即進行刪除此TrayIcon ::Shell_NotifyIcon(NIM_DELETE, &tray); delete TrayIcon;//刪除程式開始時新增的圖示元件 } //--------------------------------------------------------------------------- // 設定Form 透明度 void __fastcall TForm1::SetWinAttr(int idv) { long lStyle; lStyle=GetWindowLong(Handle, GWL_EXSTYLE ); lStyle |= 0x00080000; SetWindowLong(Handle, GWL_EXSTYLE, lStyle ); // idv 或第三個參數 1 全透明,設為 150,即半透明狀態,255為不透明 SetLayeredWindowAttributes(Handle, RGB(255,0,255),idv,3); ReleaseCapture(); Perform( WM_SYSCOMMAND, 0xf012, 0 ); Application->ProcessMessages(); } //--------------------------------------------------------------------------- void __fastcall TForm1::FormShow(TObject *Sender) { //新增一個圖示,用來擷取ImageList1中的圖像 TrayIcon = new Graphics::TIcon; SetWinAttr(0); AddorChangeIcon(1); Application->Minimize(); //將快捷工具列上的母視窗Project1隱藏 ::ShowWindow(Application->Handle, SW_HIDE); } //--------------------------------------------------------------------------- // 擷取區塊 void __fastcall TForm1::N4Click(TObject *Sender) { AddorChangeIcon(0); try{ Form2 = new TForm2(Application); Form2->ShowModal(); } catch(Exception &exception) { delete Form2; Application->ShowException(&exception); } ::ShowWindow(Handle,SW_HIDE); AddorChangeIcon(1); } //--------------------------------------------------------------------------- // 說明 void __fastcall TForm1::N6Click(TObject *Sender) { MessageDlg("擷取區塊︰ 可以在螢幕畫面按下滑鼠右鍵拉出虛線區域,來擷取區塊供儲存或至剪貼簿。\n\n可編輯虛線區域,以滑鼠點選移動虛線的四邊的小黑塊,皆可改變虛線區域大小。\n\n\n---------------------------------\n\n\以鍵盤可以更容易地微調虛線區域︰\n\n按四個方向鍵可隨意放大虛線區域。\n\n或按下Shift鍵 方向鍵可隨意移動虛線區域。\n\n或按下Ctrl鍵 Right Arrow Key Or Ctrl鍵 Down Arrow Key 皆可縮小區域。\n\n\n---------------------------------\n\n\複製全螢幕︰會以全螢幕為最大區域複製,按滑鼠左鍵,會跳出PopupMenu可選擇離開。\n\n最後選取好的區域做處理︰ 在虛線框內按滑鼠左鍵,會跳出PopupMenu選擇處理。\n\n一、『擷取區塊 to BMP 檔』,將選取儲存BMP檔,\n\n會以日期時間為檔名,如︰PM2007722_071625.BMP。\n\n儲存至您選擇的路徑。\n\n二、『擷取區塊 to JPG 檔』,將選取儲存JPG檔,\n\n如上的儲存方式。\n\n三、『複製到剪貼簿...』,可開啟您的繪圖軟體,做細微的處理。\n\n\按 SPACE 空白鍵︰可關閉or顯示虛線的小黑塊。\n\n 離開或結束︰ 關閉本程式。\n\n\ " , mtInformation , TMsgDlgButtons() << mbOK, 0); } //--------------------------------------------------------------------------- // 複製全螢幕 void __fastcall TForm1::N5Click(TObject *Sender) { AllScr=true; N4Click(Sender); AllScr=false; } //--------------------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender) { CreateShortCut("桌面抓圖","桌面擷取矩形區域"); } //--------------------------------------------------------------------------- void TForm1::CreateShortCut(String linkName,String hint) { IShellLink* pLink; IPersistFile* pPersistFile; LPMALLOC ShellMalloc; LPITEMIDLIST DesktopPidl; char buf[30]; char DesktopDir[MAX_PATH],dirp[MAX_PATH]; ::GetCurrentDirectory(MAX_PATH,dirp); // 取得現在的目錄路徑 if(FAILED(SHGetMalloc(&ShellMalloc))) return; if(FAILED(SHGetSpecialFolderLocation(NULL, CSIDL_DESKTOPDIRECTORY, &DesktopPidl))) return; if(!SHGetPathFromIDList(DesktopPidl, DesktopDir)) { ShellMalloc->Free(DesktopPidl); ShellMalloc->Release(); return; } ShellMalloc->Free(DesktopPidl); ShellMalloc->Release(); if(SUCCEEDED(CoInitialize(NULL))) { if(SUCCEEDED(CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void **) &pLink))) { pLink->SetPath(Application->ExeName.c_str()); pLink->SetWorkingDirectory(dirp); pLink->SetDescription(hint.c_str()); pLink->SetShowCmd(SW_SHOW); if(SUCCEEDED(pLink->QueryInterface(IID_IPersistFile, (void **)&pPersistFile))) { WideString strShortCutLocation(DesktopDir); sprintf(buf,"\\%s.lnk",linkName.c_str()); strShortCutLocation = buf; pPersistFile->Save(strShortCutLocation.c_bstr(), TRUE); pPersistFile->Release(); } pLink->Release(); } CoUninitialize(); } } //---------------------------------------------------------------------- // Unit1 .h //--------------------------------------------------------------------------- #ifndef GetRectUH #define GetRectUH //--------------------------------------------------------------------------- #include #include #include #include <Forms.hpp> #include //TrayIcon專屬標頭檔--------------------------------------------------------- #include #include #include //TrayIcon自訂訊息----------------------------------------------------------- const int WM_TRAYICON = WM_USER 1001; //--------------------------------------------------------------------------- class TForm1 : public TForm { __published: // IDE-managed Components TPopupMenu *PopupMenu1; TMenuItem *N1; TMenuItem *N3; TImageList *ImageList1; TMenuItem *N4; TMenuItem *N5; TMenuItem *N6; void __fastcall N1Click(TObject *Sender); void __fastcall FormClose(TObject *Sender, TCloseAction &Action); void __fastcall FormActivate(TObject *Sender); void __fastcall FormShow(TObject *Sender); void __fastcall N4Click(TObject *Sender); void __fastcall N6Click(TObject *Sender); void __fastcall N5Click(TObject *Sender); void __fastcall FormCreate(TObject *Sender); private: // User declarations Graphics::TIcon *TrayIcon; //新增或更新自訂的TrayIcon void __fastcall AddorChangeIcon(int iconNum); //捕捉TrayIcon自訂訊息 void __fastcall WmNewTray(TMessage &Msg); // void __fastcall WndProc(Messages::TMessage& Message); public: // User declarations bool AllScr; #pragma option push -vi- BEGIN_MESSAGE_MAP MESSAGE_HANDLER(WM_TRAYICON, TMessage, WmNewTray) END_MESSAGE_MAP(TForm) #pragma option pop __fastcall TForm1(TComponent* Owner); void __fastcall SetWinAttr(int idv); void CreateShortCut(String linkName,String hint); }; //--------------------------------------------------------------------------- extern PACKAGE TForm1 *Form1; //--------------------------------------------------------------------------- #endif //============================================================================= // Unit2 cpp //--------------------------------------------------------------------------- #define NO_WIN32_LEAN_AND_MEAN #include #include // 為了使用 GlobalFreePtr() #include #include #include #include #pragma hdrstop #include "Unit2.h" #include "GetRectU.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm2 *Form2; Graphics::TBitmap *bmp; POINT p; TPanel *pnl[4]; int ac; int itn,itb; bool amplify_fg; bool draw_fg; bool reac_fg; bool reduce; bool reduce2; bool Space_fg; bool __fastcall SetDirectory(AnsiString StartDir, AnsiString *selDir, AnsiString *dirName); //--------------------------------------------------------------------------- __fastcall TForm2::TForm2(TComponent* Owner) : TForm(Owner) { reac_fg=false; draw_fg=false; amplify_fg=false; reduce=false; reduce2=false; Space_fg=true; } //--------------------------------------------------------------------------- int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lpData) { if(uMsg == BFFM_INITIALIZED){ PCSTR prevDir = reinterpret_cast (lpData); if(DirectoryExists(prevDir)) SendMessage(hwnd, BFFM_SETSELECTION, static_cast (1L), lpData); } return 0; } //------------------------------------------------------------------------------------- bool __fastcall SetDirectory(AnsiString StartDir, AnsiString *selDir, AnsiString *dirName) { auto bool rc = true; BROWSEINFO bi; char PathStr[MAX_PATH]; char FolderName[MAX_PATH]; LPITEMIDLIST ItemID; memset(&bi, 0, sizeof(BROWSEINFO)); memset(PathStr, 0, MAX_PATH); bi.hwndOwner = Application->Handle; bi.pszDisplayName = FolderName; bi.lpszTitle = "選擇資料夾"; bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_DONTGOBELOWDOMAIN | BIF_NEWDIALOGSTYLE; bi.lpfn = reinterpret_cast (BrowseCallbackProc); bi.lParam = reinterpret_cast (StartDir.c_str()); CoInitialize(NULL); ItemID = SHBrowseForFolder(&bi); if(ItemID == NULL){ rc = false; }else{ SHGetPathFromIDList(ItemID, PathStr); } GlobalFreePtr(ItemID); CoUninitialize(); *selDir = PathStr; *dirName = FolderName; return rc; } //----------------------------------------------------------------------------------------- void __fastcall TForm2::FormActivate(TObject *Sender) { Form2->DoubleBuffered=true; } //--------------------------------------------------------------------------- void __fastcall TForm2::N1Click(TObject *Sender) { Form2->Close(); } //--------------------------------------------------------------------------- void __fastcall TForm2::FormCreate(TObject *Sender) { Form2->BorderStyle = bsNone; //禁止Form2再重繪Form2背景, //而可將桌面影像留住Form2背景中 Form2->Brush->Style = bsClear; //Form2放大至全螢幕 Form2->SetBounds(0, 0, Screen->Width, Screen->Height); } //--------------------------------------------------------------------------- void __fastcall TForm2::Image1MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { if(!reac_fg) { Screen->Cursor=crCross; IsMouseDown = true; start = TPoint(X, Y); newend = start; ReDraw(ac); } } //--------------------------------------------------------------------------- void __fastcall TForm2::Image1MouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { if (IsMouseDown) { draw_fg=true; X = (X>Image1->Width)?Image1->Width:X; Y = (Y>Image1->Height)?Image1->Height:Y; newend = TPoint(X, Y); ReDraw(ac); } } //--------------------------------------------------------------------------- void __fastcall TForm2::Image1MouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { if(!draw_fg && !Form1->AllScr) // 如果沒拉出區塊, 則跳離 { N2->Enabled=false; BMP1->Enabled=false; JPG1->Enabled=false; return; } else if(Form1->AllScr) reac_fg=true; if(!reac_fg) { Screen->Cursor=crDefault; IsMouseDown = false; reac_fg=true; ////////////////////////// for(int i = 0; i < 4; i ) { pnl[i] = new TPanel(this); pnl[i]->Parent=this; pnl[i]->Color=clBlack; pnl[i]->BevelInner=bvNone; pnl[i]->BevelOuter=bvNone; pnl[i]->BorderStyle=bsNone; // pnl[i]->ParentColor=true; pnl[i]->Width=7; pnl[i]->Height=7; pnl[i]->Tag=i; } pnl[0]->Left=start.x; // Left pnl[0]->Top=start.y ((newend.y-start.y)/2)-2; pnl[0]->Cursor=crSizeWE; pnl[0]->pnl_LeftMouseDown; pnl[0]->pnl_LeftMouseMove; pnl[0]->pnl_LeftMouseUp; pnl[1]->Left=start.x ((newend.x-start.x)/2)-2; // Top pnl[1]->Top =start.y; pnl[1]->Cursor=crSizeNS; pnl[1]->pnl_LeftMouseDown; pnl[1]->pnl_LeftMouseMove; pnl[1]->pnl_LeftMouseUp; pnl[2]->Left=newend.x-8; // Right pnl[2]->Top=start.y ((newend.y-start.y)/2)-2; pnl[2]->Cursor=crSizeWE; pnl[2]->pnl_LeftMouseDown; pnl[2]->pnl_LeftMouseMove; pnl[2]->pnl_LeftMouseUp; pnl[3]->Left=start.x ((newend.x-start.x)/2)-2; // Botoom pnl[3]->Top=newend.y-7; pnl[3]->Cursor=crSizeNS; pnl[3]->pnl_LeftMouseDown; pnl[3]->pnl_LeftMouseMove; pnl[3]->pnl_LeftMouseUp; } } //--------------------------------------------------------------------------- void __fastcall TForm2::ReDraw(int na) { Image1->Canvas->Draw(0, 0, bmp); Image1->Canvas->Pen->Style = psDashDotDot; Image1->Canvas->Brush->Style = bsClear; Image1->Canvas->Pen->Mode=pmXor; Image1->Canvas->Pen->Color = clWhite; if(reac_fg) // 移動 { switch(na) { case 0: Image1->Canvas->Rectangle(start.x, start.y,newend.x, newend.y); break; case 1: Image1->Canvas->Rectangle(start.x--, start.y,newend.x--, newend.y); // Left break; case 2: Image1->Canvas->Rectangle(start.x , start.y,newend.x , newend.y); // Right break; case 3: Image1->Canvas->Rectangle(start.x, start.y--,newend.x, newend.y--); // Top break; case 4: Image1->Canvas->Rectangle(start.x, start.y ,newend.x, newend.y ); // Botton break; } pnl[0]->Left=start.x; // Left pnl[0]->Top=start.y ((newend.y-start.y)/2)-2; pnl[2]->Left=newend.x-7; // Right pnl[2]->Top=start.y ((newend.y-start.y)/2)-2; pnl[1]->Left=start.x ((newend.x-start.x)/2)-2; // Top pnl[1]->Top =start.y; pnl[3]->Left=start.x ((newend.x-start.x)/2)-2; // Botoom pnl[3]->Top=newend.y-7; } else if(reduce) // 縮小 { switch(na) { case 1: Image1->Canvas->Rectangle(start.x, start.y,newend.x--, newend.y); // Right pnl[2]->Left=newend.x-7; pnl[2]->Top=start.y ((newend.y-start.y)/2)-2; pnl[1]->Left=start.x ((newend.x-start.x)/2)-2; pnl[1]->Top =start.y; pnl[3]->Left=start.x ((newend.x-start.x)/2)-2; // Botoom pnl[3]->Top=newend.y-7; break; case 2: Image1->Canvas->Rectangle(start.x, start.y,newend.x, newend.y--); // Botton pnl[3]->Left=start.x ((newend.x-start.x)/2)-2; // Botoom pnl[3]->Top=newend.y-7; pnl[0]->Left=start.x; pnl[0]->Top=start.y ((newend.y-start.y)/2)-2; pnl[2]->Left=newend.x-7; pnl[2]->Top=start.y ((newend.y-start.y)/2)-2; break; } } else { // 放大 switch(na) { case 0: Image1->Canvas->Rectangle(start.x, start.y,newend.x, newend.y); break; case 1: Image1->Canvas->Rectangle(start.x--, start.y,newend.x, newend.y); // Left pnl[0]->Left=start.x; pnl[0]->Top=start.y ((newend.y-start.y)/2)-2; pnl[1]->Left=start.x ((newend.x-start.x)/2)-2; pnl[1]->Top =start.y; pnl[3]->Left=start.x ((newend.x-start.x)/2)-2; // Botoom pnl[3]->Top=newend.y-7; break; case 2: Image1->Canvas->Rectangle(start.x, start.y,newend.x , newend.y); // Right pnl[2]->Left=newend.x-8; pnl[2]->Top=start.y ((newend.y-start.y)/2)-2; pnl[1]->Left=start.x ((newend.x-start.x)/2)-2; pnl[1]->Top =start.y; pnl[3]->Left=start.x ((newend.x-start.x)/2)-2; // Botoom pnl[3]->Top=newend.y-7; break; case 3: Image1->Canvas->Rectangle(start.x, start.y--,newend.x, newend.y); // Top pnl[1]->Left=start.x ((newend.x-start.x)/2)-2; pnl[1]->Top =start.y; pnl[0]->Left=start.x; pnl[0]->Top=start.y ((newend.y-start.y)/2)-2; pnl[2]->Left=newend.x-7; pnl[2]->Top=start.y ((newend.y-start.y)/2)-2; break; case 4: Image1->Canvas->Rectangle(start.x, start.y,newend.x, newend.y ); // Botton pnl[3]->Left=start.x ((newend.x-start.x)/2)-2; // Botoom pnl[3]->Top=newend.y-7; pnl[0]->Left=start.x; pnl[0]->Top=start.y ((newend.y-start.y)/2)-2; pnl[2]->Left=newend.x-7; pnl[2]->Top=start.y ((newend.y-start.y)/2)-2; break; } } } //---------------------------------------------------- void __fastcall TForm2::FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift) { if(Shift.Contains(ssShift)) // 移動 { reac_fg=true; switch(Key) { case VK_LEFT: ac=1; ReDraw(ac); Timer1->Enabled=true; break; case VK_RIGHT: ac=2; ReDraw(ac); Timer1->Enabled=true; break; case VK_UP: ac=3; ReDraw(ac); Timer1->Enabled=true; break; case VK_DOWN: ac=4; ReDraw(ac); Timer1->Enabled=true; break; } } else if(Shift.Contains(ssCtrl)) // 縮小 { reduce=true; reac_fg=false; switch(Key) { case VK_RIGHT: ac=1; ReDraw(ac); Timer1->Enabled=true; break; case VK_DOWN: ac=2; ReDraw(ac); Timer1->Enabled=true; break; } } else { // 放大 reac_fg=false; amplify_fg=true; switch(Key) { case VK_LEFT: ac=1; ReDraw(ac); Timer1->Enabled=true; break; case VK_RIGHT: ac=2; ReDraw(ac); Timer1->Enabled=true; break; case VK_UP: ac=3; ReDraw(ac); Timer1->Enabled=true; break; case VK_DOWN: ac=4; ReDraw(ac); Timer1->Enabled=true; break; case VK_SPACE: if(Space_fg) { Space_fg=false; for(int i=0;i<4;i ) pnl[i]->Visible=false; } else { Space_fg=true; for(int i=0;i<4;i ) pnl[i]->Visible=true; } break; } } } //--------------------------------------------------------------------------- void __fastcall TForm2::FormKeyUp(TObject *Sender, WORD &Key, TShiftState Shift) { Timer1->Enabled=false; if(reduce) { reduce=false; reac_fg=true; } if(amplify_fg) { reac_fg=true; } } //--------------------------------------------------------------------------- void __fastcall TForm2::Timer1Timer(TObject *Sender) { ReDraw(ac); } //--------------------------------------------------------------------------- void __fastcall TForm2::pnl_LeftMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { reac_fg=true; // 確認滑鼠是按住Label 上 if(::DragDetect(Application->Handle,Point(X,Y))) { IsMouseDown2 = true; p=Point(X,Y); } } //--------------------------------------------------------------------------- void __fastcall TForm2::pnl_LeftMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { IsMouseDown2=false; } //--------------------------------------------------------------------------- void __fastcall TForm2::pnl_LeftMouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { int nItem = ((TPanel *)Sender)->Tag; switch(nItem) { case 0: if (IsMouseDown2) // Left { start.x = start.x (X-p.x); itn=0; ReDraw2(itn); } break; case 1: if (IsMouseDown2) // Top { start.y = start.y (Y-p.y); itn=1; ReDraw2(itn); } break; case 2: if (IsMouseDown2) // Right { newend.x = newend.x (X-p.x); itn=2; ReDraw2(itn); } break; case 3: if (IsMouseDown2) // Bottom { newend.y = newend.y (Y-p.y); itn=3; ReDraw2(itn); } break; } } //--------------------------------------------------------------------------- void __fastcall TForm2::ReDraw2(int na) { Image1->Canvas->Draw(0, 0, bmp); Image1->Canvas->Pen->Style = psDashDotDot; Image1->Canvas->Brush->Style = bsClear; Image1->Canvas->Pen->Mode=pmXor; Image1->Canvas->Pen->Color = clWhite; if(IsMouseDown2) // 移動 { Image1->Canvas->Rectangle(start.x, start.y,newend.x, newend.y); pnl[0]->Left=start.x; // Left pnl[0]->Top=start.y ((newend.y-start.y)/2)-2; pnl[2]->Left=newend.x-7; // Right pnl[2]->Top=start.y ((newend.y-start.y)/2)-2; pnl[1]->Left=start.x ((newend.x-start.x)/2)-2; // Top pnl[1]->Top =start.y; pnl[3]->Left=start.x ((newend.x-start.x)/2)-2; // Botoom pnl[3]->Top=newend.y-7; } } //---------------------------------------------------------------------------- // 儲存為 BMP 檔 void __fastcall TForm2::BMP1Click(TObject *Sender) { char sbuf[128]; String S; AnsiString StartDirectory = "C:\\"; // 設定對話框起始目錄 AnsiString SelectedDirectory; // 儲存被選擇目錄的路徑字串 AnsiString DirectoryName; // 儲存被選擇目錄的名稱字串 S=""; if(Form1->AllScr) // 全螢幕 { if(SetDirectory(StartDirectory, &SelectedDirectory, &DirectoryName)) { S = FormatDateTime("AM/PMyyyymd_hhmmss", Now() ); sprintf(sbuf,"%s\\%s.BMP",SelectedDirectory,S); bmp->SaveToFile(sbuf); ShowMessage("儲存完畢: " AnsiString(sbuf)); } } else { Graphics::TBitmap *Bitmap2 = new Graphics::TBitmap; TRect r = Rect(start.x, start.y,newend.x, newend.y); //設定這暫時圖檔屬性 Bitmap2->Width=newend.x - start.x; Bitmap2->Height=newend.y - start.y; Bitmap2->PixelFormat=pf24bit; Bitmap2->Canvas->CopyRect(r,bmp->Canvas, r); //將全螢幕複製至Bitmap上 ::BitBlt(Bitmap2->Canvas->Handle,0,0, Bitmap2->Width,Bitmap2->Height, bmp->Canvas->Handle,start.x,start.y,SRCCOPY); if(SetDirectory(StartDirectory, &SelectedDirectory, &DirectoryName)) { S = FormatDateTime("AM/PMyyyymd_hhmmss", Now() ); sprintf(sbuf,"%s\\%s.BMP",SelectedDirectory,S); Bitmap2->SaveToFile(sbuf); ShowMessage("儲存完畢: " AnsiString(sbuf)); } delete Bitmap2; } Form2->Close(); } //--------------------------------------------------------------------------- void __fastcall TForm2::JPG1Click(TObject *Sender) { char sbuf[128]; String S; AnsiString StartDirectory = "C:\\"; // 設定對話框起始目錄 AnsiString SelectedDirectory; // 儲存被選擇目錄的路徑字串 AnsiString DirectoryName; // 儲存被選擇目錄的名稱字串 S=""; TJPEGImage *jpg = new TJPEGImage; jpg->PixelFormat=jf24Bit; jpg->CompressionQuality = 75; if(Form1->AllScr) { if(SetDirectory(StartDirectory, &SelectedDirectory, &DirectoryName)) { S = FormatDateTime("AM/PMyyyymd_hhmmss", Now() ); sprintf(sbuf,"%s\\%s.JPG",SelectedDirectory,S); jpg->Assign(bmp); jpg->SaveToFile(sbuf); ShowMessage("儲存完畢: " AnsiString(sbuf)); } } else { TRect r = Rect(start.x, start.y,newend.x, newend.y); Graphics::TBitmap *Bitmap=new Graphics::TBitmap; //設定這暫時圖檔屬性 Bitmap->Width=newend.x - start.x; Bitmap->Height=newend.y - start.y; Bitmap->PixelFormat=pf24bit; Bitmap->Canvas->CopyRect(r,bmp->Canvas, r); //將全螢幕複製至Bitmap上 ::BitBlt(Bitmap->Canvas->Handle,0,0, Bitmap->Width,Bitmap->Height, bmp->Canvas->Handle,start.x,start.y,SRCCOPY); if(SetDirectory(StartDirectory, &SelectedDirectory, &DirectoryName)) { S = FormatDateTime("AM/PMyyyymd_hhmmss", Now() ); sprintf(sbuf,"%s\\%s.JPG",SelectedDirectory,S); jpg->Assign(Bitmap); jpg->SaveToFile(sbuf); ShowMessage("儲存完畢: " AnsiString(sbuf)); } delete Bitmap; } delete jpg; Form2->Close(); } //--------------------------------------------------------------------------- void __fastcall TForm2::N2Click(TObject *Sender) { if(Form1->AllScr) { Clipboard()->Assign(bmp); ShowMessage("已完成傳至系統剪貼簿. . ."); } else { TRect r = Rect(start.x, start.y,newend.x, newend.y); Graphics::TBitmap *Bitmap3 = new Graphics::TBitmap; //設定這暫時圖檔屬性 Bitmap3->Width=newend.x - start.x; Bitmap3->Height=newend.y - start.y; Bitmap3->PixelFormat=pf24bit; Bitmap3->Canvas->CopyRect(r,bmp->Canvas, r); //將全螢幕複製至Bitmap上 ::BitBlt(Bitmap3->Canvas->Handle,0,0, Bitmap3->Width,Bitmap3->Height, bmp->Canvas->Handle,start.x,start.y,SRCCOPY); Clipboard()->Assign(Bitmap3); ShowMessage("已完成傳至系統剪貼簿. . ."); delete Bitmap3; } Form2->Close(); } //--------------------------------------------------------------------------- void __fastcall TForm2::FormClose(TObject *Sender, TCloseAction &Action) { delete bmp; for(int i=0;i<4;i ) delete pnl[i]; } //--------------------------------------------------------------------------- void __fastcall TForm2::FormShow(TObject *Sender) { IsMouseDown = false; //創造一暫時圖檔 Graphics::TBitmap *Bitmap=new Graphics::TBitmap; //設定這暫時圖檔屬性 Bitmap->Width=Screen->Width; Bitmap->Height=Screen->Height; Bitmap->PixelFormat=pf24bit; HDC NewDC=::GetWindowDC(0); //將全螢幕複製至Bitmap上 ::BitBlt(Bitmap->Canvas->Handle,0,0, Screen->Width,Screen->Height, NewDC,0,0,SRCCOPY); Image1->Picture->Assign(Bitmap); //釋放DC ReleaseDC(Form2->Handle,NewDC); bmp = new Graphics::TBitmap(); // 動態建立畫布 bmp->Width=Image1->Width; bmp->Height=Image1->Height; bmp->Assign(Bitmap); ac=0; ReDraw(ac); delete Bitmap; } //--------------------------------------------------------------------------- // Unit2 .h //--------------------------------------------------------------------------- #ifndef Unit2H #define Unit2H //--------------------------------------------------------------------------- #include #include #include #include <Forms.hpp> #include #include //--------------------------------------------------------------------------- class TForm2 : public TForm { __published: // IDE-managed Components TImage *Image1; TPopupMenu *PopupMenu1; TTimer *Timer1; TMenuItem *N1; TMenuItem *BMP1; TMenuItem *JPG1; TMenuItem *N2; TMenuItem *N3; void __fastcall FormActivate(TObject *Sender); void __fastcall N1Click(TObject *Sender); void __fastcall FormCreate(TObject *Sender); void __fastcall Image1MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y); void __fastcall Image1MouseMove(TObject *Sender, TShiftState Shift, int X, int Y); void __fastcall Image1MouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y); void __fastcall FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift); void __fastcall FormKeyUp(TObject *Sender, WORD &Key, TShiftState Shift); void __fastcall Timer1Timer(TObject *Sender); void __fastcall pnl_LeftMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y); void __fastcall pnl_LeftMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y); void __fastcall pnl_LeftMouseMove(TObject *Sender, TShiftState Shift, int X, int Y); void __fastcall BMP1Click(TObject *Sender); void __fastcall JPG1Click(TObject *Sender); void __fastcall N2Click(TObject *Sender); void __fastcall FormClose(TObject *Sender, TCloseAction &Action); void __fastcall FormShow(TObject *Sender); private: // User declarations bool IsMouseDown,IsMouseDown2; TPoint start; TPoint end; TPoint newend; public: // User declarations __fastcall TForm2(TComponent* Owner); void __fastcall ReDraw(int na); void __fastcall ReDraw2(int na); }; //--------------------------------------------------------------------------- extern PACKAGE TForm2 *Form2; //--------------------------------------------------------------------------- #endif
------
yangshuh
系統時間:2024-03-29 3:03:33
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!