日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > c/c++ >内容正文

c/c++

C++ Builder技巧集锦

發(fā)布時(shí)間:2025/7/25 c/c++ 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C++ Builder技巧集锦 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
C++ Builder技巧集錦 1 /* 2 調(diào)用DOS程序時(shí)不顯示窗口 3 使 用 ShellExecute調(diào) 用 DOS程 序 時(shí) 可 以 不 顯 示 窗 口 , 如 :*/ 4 ShellExecute(0, "open", "c:\\tools\\arj.exe", "a c:\\p.arj c:\\*.bat c:\\*.sys", NULL, SW_HIDE);   5 /*產(chǎn)生隨機(jī)數(shù)代碼*/ 6 int SecVal; 7 AnsiString Hour,Minute,Second; 8 int RandomVal; 9 Hour=Now().FormatString("hh"); 10 Minute=Now().FormatString("nn"); 11 Second=Now().FormatString("ss"); 12 SecVal=StrToInt(Hour)*3600+StrToInt(Minute)*60+StrToInt(Second); 13 for(int i=1;i<=SecVal;i++) 14 { 15 RandomVal=random(1000); 16 } 17 Form1->Caption=IntToStr(RandomVal); 18 /*得到文件版本的函數(shù)*/ 19 AnsiString __fastcall TMainForm::returnversion( void ) 20 { 21 int ii; 22 unsigned int jj = sizeof( VS_FIXEDFILEINFO ); 23 char *pp, pp2[100]; 24 AnsiString ss; 25 VS_FIXEDFILEINFO *aa; 26 void **pp1 = (void **)&aa; 27 pp2[0] = 0; 28 ss = "()"; 29 ii = GetFileVersionInfoSize( Application->ExeName.c_str(), NULL ); 30 if( ii != 0 ) { 31 pp = new char[ii]; 32 if( GetFileVersionInfo( Application->ExeName.c_str(), 33 0, ii, pp ) ) { 34 if( VerQueryValue( pp, "\\", pp1, &jj ) ){ 35 ss = " V"; 36 ss += IntToStr( HIWORD(aa->dwFileVersionMS) )+"."; 37 ss += IntToStr( LOWORD(aa->dwFileVersionMS) )+"."; 38 ss += IntToStr( HIWORD(aa->dwFileVersionLS) )+"(build:"; 39 ss += IntToStr( LOWORD(aa->dwFileVersionLS) )+")"; 40 } 41 } 42 delete pp; 43 } 44 return ss; 45 } 46 /* 47 得到正在運(yùn)行的WINDOWS版本 48 WINDOWS版本多的很,你想這么多總是會(huì)存在著不兼容性,所以看看清它是什么有時(shí)會(huì)很重要! 49 加入下要的代碼吧:*/ 50 void __fastcall TForm1::FormCreate(TObject *Sender) 51 { 52 OSVERSIONINFO info ; 53 info.dwOSVersionInfoSize = sizeof (info) ; 54 GetVersionEx (&info) ; 55 switch (info.dwPlatformId) 56 { 57 case VER_PLATFORM_WIN32s: 58 Label1->Caption = "System: Windows Win 32s" ; 59 break ; 60 case VER_PLATFORM_WIN32_WINDOWS: 61 Label1->Caption = "System: Windows 95" ; 62 break ; 63 case VER_PLATFORM_WIN32_NT: 64 Label1->Caption = "System: Windows NT" ; 65 break ; 66 default: 67 Label1->Caption = "System: Unknown" ; 68 break ; 69 } 70 Label2->Caption = String ("Version: ") 71 + String ((int) info.dwMajorVersion) + "." + String((int)info.dwMinorVersion) ; 72 Label3->Caption = String ("Build: ") + String ((int) (info.dwBuildNumber & 0xFFFF)) ; 73 Label4->Caption = String ("System Info: '") + info.szCSDVersion + "'" ; 74 } 75 76 /* 77 讓TRichEdit自動(dòng)滾動(dòng) 78 我們用TIMER加上對(duì)WINDOWS發(fā)消息就可以實(shí)現(xiàn)了! 79 */ 80 void __fastcall TForm1::Timer1Timer(TObject *Sender) 81 { 82 SendMessage(RichEdit1->Handle, EM_SCROLL, SB_LINEDOWN, 0); 83 } 84 85 /* 86 除了一行一行的向下滾還可以有什么效果呢?看看下面! 87 */ 88 SB_LINEDOWN 向下一行 89 SB_LINEUP 向上一行 90 SB_PAGEDOWN 向下一頁(yè) 91 SB_PAGEUP 向上一頁(yè) 92 93 /* 94 改一下就行了。 95 如何加入主頁(yè)鏈接 96 你是不是有注意在一些軟件中有一個(gè)htpp://www.XXX.com/一點(diǎn)就會(huì)在瀏覽器中自動(dòng)打開這個(gè)主頁(yè)。我們要如何實(shí)現(xiàn)這一步呢?簡(jiǎn)單的很看看下面! 97 在窗體上加入一個(gè)LABEL; 98 定義Label的CAPTION為“加密金剛鎖主頁(yè)”; 99 加入下面代碼: 100 */ 101 void __fastcall TForm2::Label1Click(TObject *Sender) 102 { 103 ShellExecute(Handle,"open","http/www.encrypter.net",0,0,SW_SHOW); 104 } 105 106 /* 107 好了,你可以點(diǎn)了,當(dāng)然你出入一些特效如Cursor變成手形就更好了! 108 如何檢測(cè)本機(jī)是否與Internet連接 109 */ 110 HRASCONN TMainForm::CheckForConnections() 111 { 112 char buff[256]; 113 RASCONN rc; 114 rc.dwSize = sizeof(RASCONN); 115 DWORD numConns; 116 DWORD size = rc.dwSize; 117 // Enumerate the connections. 118 DWORD res = fRasEnumConnections(&rc, &size, &numConns); 119 if (!res && numConns == 0) 120 // No connections, return 0. 121 return 0; 122 if (res) { 123 // Error. Report it. 124 fRasGetErrorString(res, buff, sizeof(buff)); 125 Memo1->Lines->Add(buff); 126 } else { 127 // Get the connection status. 128 RASCONNSTATUS status; 129 status.dwSize = sizeof(status); 130 res = fRasGetConnectStatus(rc.hrasconn, &status); 131 if (res) { 132 // Error. Report it. 133 fRasGetErrorString(res, buff, sizeof(buff)); 134 Memo1->Lines->Add(buff); 135 return 0; 136 } else { 137 // Found connection, show details. 138 if (status.rasconnstate == RASCS_Connected) { 139 Memo1->Lines->Add("Existing connection found:"); 140 Memo1->Lines->Add(" Device type: " + 141 String(rc.szDeviceType)); 142 Memo1->Lines->Add(" Device name: " + 143 String(rc.szDeviceName)); 144 Memo1->Lines->Add(" Connected to: " + 145 String(rc.szEntryName)); 146 return rc.hrasconn; 147 } else { 148 // A connection was detected but its 149 // status is RASCS_Disconnected. 150 Memo1->Lines->Add("Connection Error"); 151 return 0; 152 } 153 } 154 } 155 return 0; 156 } 157 158 /* 159 如何顯示和不顯示鼠標(biāo) 160 在超級(jí)解霸中我們以發(fā)現(xiàn),在播放的時(shí)候MOUSE會(huì)自動(dòng)消失,這樣的效果有時(shí)真的有用,它是如何實(shí)現(xiàn)的。 161 在WINDOWS中API函數(shù)ShowCursor(bool bShow);是這個(gè)程序的主角。當(dāng)bShow為true,Mouse出現(xiàn),為false,MOUSE消失。下面我們來(lái)做一個(gè)單擊窗體MOUSE消失,再擊又出來(lái)的效果。 162 */ 163 void __fastcall TForm1::FormClick(TObject *Sender) 164 { 165 if(i==1) 166 ShowCursor(false); 167 if(-i==1) 168 ShowCursor(true); 169 i=-i; 170 } 171 172 /* 173 你可以跟據(jù)需要來(lái)做出各種效果! 174 如何顯示透明圖片 175 GIF是可以透明的,但是只能支持256色,BMP不支持透明但可以支持真彩,有沒有方法可以實(shí)現(xiàn)BMP的透明呢?答案是肯定的。 176 我們點(diǎn)一個(gè)BUTTON是出現(xiàn)透明的圖片畫在FORM上的效果! 177 */ 178 void __fastcall TForm1::Button1Click(TObject *Sender) 179 { 180 Graphics::TBitmap *pBitmap=new Graphics::TBitmap(); 181 pBitmap->LoadFromFile("test.bmp");//圖片文件 182 pBitmap->Transparent = true; //設(shè)置透明屬性為真 183 pBitmap->TransparentColor=clBlack;//設(shè)置透明色為黑色 184 pBitmap->TransparentMode = tmAuto; 185 Form1->Canvas->Draw(0,0,pBitmap); 186 delete pBitmap; 187 } 188 189 /* 190 如何自己寫代碼遍歷文件夾? 191 比如 遍歷C:\winnt\ 下的所有文件夾,并把所有文件夾的名字寫入到C:\folder.txt中去 192 */ 193 void __fastcall TForm1::Button1Click(TObject *Sender) 194 { 195 TSearchRec sr; 196 TStringList* sss=new TStringList(); 197 if (FindFirst("c:\\winnt", iAttributes, sr) == 0) 198 { 199 do 200 { 201 if ((sr.Attr & iAttributes) == sr.Attr) 202 { 203 sss->Add(sr.Name); 204 } 205 } while (FindNext(sr) == 0); 206 FindClose(sr); 207 } 208 sss->SaveToFile("c:\\folder.txt"); 209 } 210 211 /* 212 鎖定鼠標(biāo) 213 以下是鎖定在Form中的例子,如果你想鎖定你規(guī)定的區(qū)域,改變 R 即可。 214 譬如 215 */ 216 R = Rect(0,0,GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN)); 217 218 /* 219 鎖定在Form中: 220 */ 221 TRect R; 222 R = BoundsRect; 223 ClipCursor(&R); 224 225 /* 226 解鎖 227 */ 228 TRect R; 229 R = Rect(0,0,GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN)); 230 ClipCursor(&R); 231 232 /* 233 拖動(dòng)一個(gè)無(wú)標(biāo)題欄的窗體 234 在前面我們剛說了如何做一個(gè)不規(guī)則的窗體,這時(shí)我們會(huì)有一個(gè)新問題,不規(guī)則的窗體我們不能讓標(biāo)題欄還在上面,這樣多不好看,那沒有有標(biāo)題欄我們?nèi)绾蝸?lái)拖動(dòng)這個(gè)窗體呢?下面我們先看看分析吧! 235 */ 236 Windows分客戶區(qū)和非客戶區(qū)(標(biāo)題欄、菜單、窗口框),我們只要在點(diǎn)下客戶區(qū)時(shí)發(fā)出在非客戶區(qū)標(biāo)題欄的消息就能達(dá)到目的了。看看是如何做到的。 237 void __fastcall TForm1::CreateParams(TCreateParams &Params) 238 { 239 TForm::CreateParams(Params); 240 Params.Style &= ~WS_CAPTION; 241 } 242 void __fastcall TForm1::WMNCHitTest(TMessage &Msg) 243 { 244 if (GetAsyncKeyState(VK_LBUTTON)<0) 245 Msg.Result = HTCAPTION; 246 else 247 Msg.Result = HTCLIENT; 248 } 249 250 /* 251 獲取進(jìn)程句柄后如何和窗口句柄相聯(lián)系? 252 按鈕按下調(diào)用函數(shù)CreateProcess(strFileName,NULL,NULL,NULL,FALSE,0,NULL,&StartupInfo,&ProcessInfo); 253 */ 254 //ProcessInfo是一個(gè)全局變量,據(jù)此可獲取進(jìn)程句柄,進(jìn)程ID,線程ID等 255 256 /* 257 進(jìn)程啟動(dòng)完畢,然后調(diào)用函數(shù)EnumWindows(EnumWindowsProc,0) 258 */ 259 //EnumWindowsProc是回調(diào)函數(shù) 260 261 /* 262 回調(diào)函數(shù)EnumWindowsProc為: 263 */ 264 BOOL CALLBACK EnumWindowsProc(HWND hwnd,LPARAM lparam) 265 { 266 CString strPrompt; 267 DWORD ProcId; 268 DWORD ThreadId; 269 ThreadId=GetWindowThreadProcessId(hwnd,&ProcId) 270 if(ProcId==ProcessInfo.dwProcessId) 271 { 272 HWND targetWin; 273 targetWin=hwnd; 274 while(true) 275 { 276 HWND hTemp; 277 hTemp=GetParent(targetWin); 278 if(hTemp==NULL) 279 break; 280 else 281 targetWin=hTemp; 282 } 283 char szTemp[255]; 284 sprintf(szTemp,"%x",ProcId); 285 CString strTemp=szTemp; 286 GetWindowText(targetWin,strTemp.GetBuffer(255),255); 287 return FALSE; 288 } 289 else 290 return true; 291 } 292 293 /* 294 最小化和恢復(fù)程序的方法 295 1) 296 */ 297 // To minimize, pass SC_MINIMIZE as the WPARAM 298 SendMessage(Application->Handle, WM_SYSCOMMAND, SC_MINIMIZE, 0); 299 // To restore, pass SC_RESTORE as the WPARAM 300 SendMessage(Application->Handle, WM_SYSCOMMAND, SC_RESTORE, 0); 301 2) 302 // To minimize, pass SW_MINIMIZE to ShowWindow 303 ShowWindow(Application->Handle, SW_MINIMIZE); 304 // To restore, pass SW_RESTORE to ShowWindow 305 ShowWindow(Application->Handle, SW_RESTORE); 306 3) 307 // To minimize the app, call Minimize 308 Application->Minimize(); 309 // To restore the app, call Restore 310 Application->Restore(); 311 312 /* 313 個(gè)人看法,第一組方法最為靈活,可能用處比較的大,如果網(wǎng)友象再最小化窗口是搞出一些動(dòng)畫效果,那么用第二組函數(shù),第三組沒有什么特別的地方。 314 關(guān)閉外部應(yīng)用程序 315 先利用FindWindow函數(shù)找出要關(guān)閉的應(yīng)用程序的主窗口名字,然后發(fā)送一個(gè)消息即可。 316 實(shí)例如下: 317 */ 318 HWnd HWndCalculator; 319 HWndCalculator = Winprocs->FindWindow(nil, "計(jì)算器"); // close the exist Calculator 320 if (HWndCalculator) 321 SendMessage(HWndCalculator, WM_CLOSE, 0, 0);

?

posted on 2013-08-25 22:35 kernel_main 閱讀(...) 評(píng)論(...) 編輯 收藏

轉(zhuǎn)載于:https://www.cnblogs.com/kernel0815/p/3281615.html

總結(jié)

以上是生活随笔為你收集整理的C++ Builder技巧集锦的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。