1.判断焦点是否在当前应用程序
用GetActiveWindow()进行判断。
这个函数返回的为HWND型,即窗体句柄
可以和GetWindowText()配合进行。
利用GetActiveWidow()得到的HWND,用在GetWindowText(HWND,Buffer,MAX_PATH);中,之后ShowMessage(Buffer)看看是不是窗体的标题,如果是,则获得,否则,该窗体不具备焦点。
2.获得不含空格字符的Edit->Text?
Edit->Text.Trim();
3.怎样隐藏控制台程序的窗口
设置
#pragma comment( linker, "/subsystem:/"windows/" /entry:/"mainCRTStartup/"" ) // 设置入口地址
这样就ok了
4.程序刪除自己
int main(int argc, char *argv[])
{
HMODULE module = GetModuleHandle(0);
CHAR buf[MAX_PATH];
GetModuleFileName(module, buf, sizeof buf);
CloseHandle(HANDLE(4));
__asm {
lea eax, buf
push 0
push 0
push eax
push ExitProcess
push module
push DeleteFile
push UnmapViewOfFile
ret
}
return 0;
}
5.怎样用编程实现TRichEdit动态滚屏
编程时动态滚屏,比如让它的滚动条滚到中间71 %处
int TextLength=Memo1->Lines->Text.Length();//文本长度
int Pos=71;//需要到达的位置
Memo1->SelStart=TextLength*Pos/100;// 选择文本开始位置
6.更改系统时间
TSystemTime systemtime;
AnsiString NewTime;
NewTime="13:58:00";
DateTimeToSystemTime( Date()+StrToTime(NewTime),systemtime);
SetLocalTime(&systemtime);
7.请问要怎麽让TImage的背景有透明的效果呢?
在程序中一开始先对Image2做初始设定
Image2->Picture->Bitmap->Transparent = true;
Image2->Picture->Bitmap->TransparentColor = <指定一个透明色>;
Image2->Canvas->Brush->Color = <指定一个透明色>;
Image2->Canvas->Brush->Style = bsSolid;
Image2->Canvas->FillRect(Image2->BoundsRect);
8.清空收回站
if(SHEmptyRecycleBin(Application->Handle,NULL,SHERB_NOCONFIRMATION)==S_OK)
ShowMessage("清空回收站成功!");
else ShowMessage("清空回收站失败!");