bcb里面一些小代码..

王朝other·作者佚名  2006-01-10
窄屏简体版  字體: |||超大  

有不少代码是在csdn上网友发的帖子里面搜集的,看到的.先贴一点.

1.

2进制文件读写

fp=fopen("d:\\documents\\ttt.txt","rb");

if (fp != NULL) {

fseek(fp, 0, SEEK_END); //移到文件末尾

int nSize = ftell(fp); //取得文件长度

fseek(fp, 0, SEEK_SET); //移到文件开头

while(nSize-- > 0)

{

c = fgetc(fp);

hexstr+=AnsiString(IntToHex(c,2));

}

fclose(fp);

}

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

2.Memo后面添加字符函数

void AppendToMemo(TMemo* Memo, LPCSTR text)

{

int nPos, nNum;

if (Memo==NULL || text==NULL) return;

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

3.设置edit居中

DWORD ExStyleLeft;

DWORD ExStyleRight;

DWORD ExStyleCenter;

ExStyleLeft = GetWindowLong(Edit1->Handle, GWL_STYLE);

ExStyleRight = ExStyleLeft | ES_RIGHT;

ExStyleCenter = ExStyleLeft | ES_CENTER;

SetWindowLong(Edit1->Handle, GWL_STYLE, ExStyleLeft); //居左

SetWindowLong(Edit1->Handle, GWL_STYLE, ExStyleCenter); //居中

SetWindowLong(Edit1->Handle, GWL_STYLE, ExStyleRight); //居右

Edit1->Invalidate();

nNum = Memo->Perform(EM_GETLINECOUNT, 0, 0); //memeo第几行

nPos = Memo->Perform(EM_LINEINDEX, nNum, 0); //满行后的字符数,如果此行数没满,为npos为0

if (nPos < 0)

{nPos = Memo->Perform(EM_LINEINDEX, nNum-1, 0); //前面所有行数的字符

}

nNum = Memo->Perform(EM_LINELENGTH, nPos, 0); //新添加的字符数目 。

Memo->Perform(EM_SETSEL, nPos+nNum, nPos+nNum); // 设置新的位置

Memo->Perform(EM_REPLACESEL, 0, (long)text); //添加字符

}

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

struct WINLIST

{

HANDLE hWnd;

char cWinBuf[256];

} ;

void CloseSpedia(void);

TForm1 *Form1;

struct WINLIST gWinList[256];

int giCountWin,j;

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

4.枚举窗口enumwindows

bool CALLBACK EnumWindowsProc( HWND hWnd, LPARAM lParam )

{

char buffer[256];

GetWindowText(hWnd, buffer, 256);

if ( strlen(buffer) )

{

if (giCountWin < 256)

{

gWinList[ giCountWin].hWnd = hWnd;

strcpy(gWinList[ giCountWin].cWinBuf,buffer);

giCountWin ++;

}

}

return TRUE;

}

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

bool CALLBACK EnumChildProc( HWND hWnd, LPARAM lParam )

{

char buffer[256];

GetWindowText(hWnd, buffer, 256);

if ( strlen(buffer) )

{

if (giCountWin < 256)

{

gWinList[ giCountWin].hWnd = hWnd;

strcpy(gWinList[ giCountWin].cWinBuf,buffer);

giCountWin ++;

}

}

return TRUE;

}

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

void CloseSpedia(void)//

{

bool geth=false;

HANDLE gethWnd1=0,gethWnd2=0;

giCountWin = 0;

EnumWindows( (WNDENUMPROC)EnumWindowsProc,0);

for ( j = 0; j<giCountWin; j++)

{

Form1->ListBox1->Items->Add(gWinList[j].cWinBuf);

if ( strcmp(gWinList[j].cWinBuf,"金山毒霸 - 控制中心") == 0 )

{

if(!geth){gethWnd1=gWinList[j].hWnd;geth=true;}

else gethWnd2=gWinList[j].hWnd;

ShowWindow(gWinList[j].hWnd,SW_MAXIMIZE); //重新打开窗口

if ( strcmp(gWinList[j].cWinBuf,"未命名 - 画图") == 0 )

{

PostMessage( gWinList[j].hWnd,WM_CLOSE,0,0); //Close the window

// break;

}

}

giCountWin = 0;

EnumChildWindows( gethWnd1 , (WNDENUMPROC)EnumChildProc , 0 ) ;

ShowMessage(IntToStr(giCountWin).c_str());

for ( j = 0; j<giCountWin; j++)

{

Form1->ListBox1->Items->Add(gWinList[j].cWinBuf);

if ( strcmp(gWinList[j].cWinBuf,"斗地主") == 0 )

{

// gethWnd=gWinList[j].hWnd

// ShowWindow(gWinList[j].hWnd,SW_MAXIMIZE); //重新打开窗口

ShowMessage("qqgame");

}

}

giCountWin = 0;

EnumChildWindows( gethWnd2 , (WNDENUMPROC)EnumChildProc , 0 ) ;

ShowMessage(IntToStr(giCountWin).c_str());

for ( j = 0; j<giCountWin; j++)

{

Form1->ListBox1->Items->Add(gWinList[j].cWinBuf);

if ( strcmp(gWinList[j].cWinBuf,"金山毒霸 - 控制中心") == 0 )

{

gethWnd=gWinList[j].hWnd

ShowMessage(gWinList[j].cWinBuf);

}

}

}

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

5.遍历窗口所有具有color属性,改为red.

PPropInfo PropInfo;

for(int i=0;i<=ComponentCount;i++)

PropInfo=GetPropInfo((TTypeInfo*)Components[i]->ClassInfo(),"Color");

if(PropInfo)

SetOrdProp(Components[i],PropInfo,clRed);

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航