delphi各种用法

摘要:
有什么办法可以马上处理吗?答案是肯定的。我在网上搜索了很久……我用Delphi写了几行代码。添加自定义类型以判断系统类型,typeTOSVersion=;添加自定义函数过程函数GetOS:TOSVersion//获取系统类型以获取托盘句柄varOS:TOSVersionInfo;beginZeroMemory;操作系统。dwOSVersionInfoSize:=SizeOf;GetVersionEx;结果:=osUnknown;如果操作系统。dwPlatformId=VER_平台_ WIN32_ NT然后开始操作。dwMajorVersion3:Result:=osNT3;4: 结果:=osNT4;5: begincaseOS。dwMinorVersionof0:结果:=os2K;1: 结果:=osXP;2: 结果:=os2K3;终止终止终止endelseif and then Result:=os95elseif and then result:=os98elseif andthen Result:=osMEend;函数GetSysTrayWnd():HWND;//返回系统托盘的句柄,该句柄适用于所有Windows版本varOS:TOSVersion;beginOS:=GetOS;结果:=FindWindow;结果:=FindWindowEx;ifthenResult:=FindWindowEx;ifthenResult:=FindWindowEx;终止程序KillTrayIcons;varhwndTrayToolBar:HWND;r光线工具栏:t返回;x、 y:单词;beginowndTrayToolBar:=获取SysTrayWnd;窗户。GetClientRect;forx:=1或TrayToolBar.right-1dobeginforx:=1或TrayTToolBar。bottom-1dobeginSendMessage;终止终止结束;//调用KillTrayIcons程序将立即清除所有无用的托盘图标。经过我的测试,可以使用Delphi7+XP系统。Delphionst常量声明演示程序TForm1

调用外部程序,等待外部程序运行完成,相当于Showmodal功能,呵呵

delphi代码
1.function WinExecAndWait32(FileName: string; Visibility: Boolean): integer;   
2.var  
3.  zAppName: array[0..512] of char; //存放应用程序名  
4.  StartupInfo: TStartupInfo;   
5.  ProcessInfo: TProcessInformation;   
6.  exitCode: Dword;   
7.  aVisibility: integer;   
8.begin  
9.  StrPCopy(zAppName, FileName);   
10.  FillChar(StartupInfo, Sizeof(StartupInfo), #0);   
11.  //给StartupInfo结构体赋值  
12.  StartupInfo.cb := Sizeof(StartupInfo);   
13.  StartupInfo.dwFlags := STARTF_USESHOWWINDOW;   
14.  if Visibility then  
15.    aVisibility := 1  
16.  else  
17.    aVisibility := 0;   
18.  
19.  StartupInfo.wShowWindow := aVisibility;   
20.  //调用CreateProcess 创建进程,执行指定的可执行文件  
21.  if not CreateProcess(nil, zAppName, nil, nil, false  
22.    , Create_NEW_CONSOLE or NORMAL_PRIORITY_CLASS   
23.    , nil, nil, StartupInfo, ProcessInfo) then  
24.    Result := -1  
25.  else  
26.  begin  
27.    //等待可执行文件退出  
28.    WaitforSingleObject(ProcessInfo.hProcess, INFINITE);   
29.    //得到进程终止状态码  
30.    GetExitCodeProcess(ProcessInfo.hProcess, exitCode);   
31.    result := Exitcode;   
32.  end;   
33.end;  

Delphi瞬间消除无用托盘图标(刷新托盘)  

用TerminateProcess把一个进程结束后有个问题,就是如果该程序在托盘有图标的话,这个图标并不会在它被结束时也消失。当然你用鼠标从上面移过可以解决这个问题,但本人在用自己的刷新辅助软件“疯狂刷新”的时候,每5分钟结束一次,一天下来如果不动电脑,就会在托盘区生成NNN个死图标,即使你拚命去点,也要点半天才能全部消除。有没有办法一下子搞定它呢?答案是肯定的,在网上搜了很久……用Delphi编写几行代码搞定。


添加自定义类型,用作判断系统类型,
type
    TOSVersion = (osUnknown, os95, os98, osME, osNT3, osNT4, os2K, osXP, os2K3);


添加自定义函数过程

function GetOS: TOSVersion; //获得系统类型,用来取得托盘句柄
var
    OS: TOSVersionInfo;
begin
    ZeroMemory(@OS, SizeOf(OS));
    OS.dwOSVersionInfoSize := SizeOf(OS);
    GetVersionEx(OS);
    Result := osUnknown;
    if OS.dwPlatformId = VER_PLATFORM_WIN32_NT then begin
        case OS.dwMajorVersion of
            3: Result := osNT3;
            4: Result := osNT4;
            5: begin
                    case OS.dwMinorVersion of
                        0: Result := os2K;
                        1: Result := osXP;
                        2: Result := os2K3;
                    end;
                end;
        end;
    end
    else if (OS.dwMajorVersion = 4) and (OS.dwMinorVersion = 0) then
        Result := os95
    else if (OS.dwMajorVersion = 4) and (OS.dwMinorVersion = 10) then
        Result := os98
    else if (OS.dwMajorVersion = 4) and (OS.dwMinorVersion = 90) then
        Result := osME
end;


function GetSysTrayWnd(): HWND; //返回系统托盘的句柄,适合于Windows各版本
var OS: TOSVersion;
begin
    OS := GetOS;
    Result := FindWindow('Shell_TrayWnd', nil);
    Result := FindWindowEx(Result, 0, 'TrayNotifyWnd', nil);
    if (OS in [osXP, os2K3]) then
        Result := FindWindowEx(Result, 0, 'SysPager', nil);
    if (OS in [os2K, osXP, os2K3]) then
        Result := FindWindowEx(Result, 0, 'ToolbarWindow32', nil);
end;


procedure KillTrayIcons (Sender: TObject);
var
    hwndTrayToolBar: HWND;
    rTrayToolBar: tRect;
    x, y: Word;
begin
    hwndTrayToolBar := GetSysTrayWnd;
    Windows.GetClientRect(hwndTrayToolBar, rTrayToolBar);
    for x := 1 to rTrayToolBar.right - 1 do begin
        for y := 1 to rTrayToolBar.bottom - 1 do begin
            SendMessage(hwndTrayToolBar, WM_MOUSEMOVE, 0, MAKELPARAM(x, y));
        end;
    end;
end;


//调用 KillTrayIcons(self) 过程就可以瞬间清除所有无用的托盘图标了。

经过本人测试,Delphi7+XP系统下确实可以用。

delphi const常量声明演示

procedure TForm1.Button1Click(Sender: TObject);
const
 xh:integer=6;  //用const定义一个常量,并赋予整形值6
 var x:string;   //用var定义一个变量,类型为字符串
begin
x:=inttostr(xh);  //吧整形xh 值赋给 x
showmessage (inttostr(xh));
result.Text:=x;      //在文本框输出x内容
end;

end.

Delphi有标题窗口最大化全屏解决方案

 //2ccc

在 WM_SYSCOMMAND 消息事件中,加入如下代码:
    inherited;
    if Message.CmdType and $FFF0 = SC_MAXIMIZE then
    begin
      //注意 Top的值是1
SetWindowPos(Handle,HWND_TOPMOST,0,1,Screen.Width,Screen.Height,SW_NOZORDER);
      Self.Top := 0;
    end;
当然也可以在 WM_SIZE 消息事件中,加入如下代码:
    if Message.SizeType = SIZE_MAXIMIZED then
    begin
       //注意 Top的值是1
SetWindowPos(Handle,HWND_TOPMOST,0,1,Screen.Width,Screen.Height,SW_NOZORDER);
       Self.Top := 0;
    end;

免责声明:文章转载自《delphi各种用法》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇windows常用命令【原创】HBase集群变更zookeeper问题下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

关于C++里set_intersection(取集合交集)、set_union(取集合并集)、set_difference(取集合差集)等函数的使用总结

文章转载自https://blog.csdn.net/zangker/article/details/22984803 set里面有set_intersection(取集合交集)、set_union(取集合并集)、set_difference(取集合差集)、set_symmetric_difference(取集合对称差集)等函数。其中,关于函数的五个参数问...

Delphi GlobalAlloc、GlobalLock、GlobalUnlock、GlobalFree 函数

GlobalAlloc 函数 分配一块内存,该函数会返回分配的内存句柄。 GlobalLock 函数 锁定内存块,该函数接受一个内存句柄作为参数,然后返回一个指向被锁定的内存块的指针。 您可以用该指针来读写内存。 GlobalUnlock 函数 解锁先前被锁定的内存,该函数使得指向内存块的指针无效。 GlobalFree 函数 释放内存块。您必须传给该函数...

[转载]Shell删除各种注释的脚本

转自:http://www.cppblog.com/zhangyq/archive/2010/10/08/127915.html 1.txt内容:file content  aabbcc<<<comment part 1abcdefghilkdifdfdfmmmmmmmmeeeeeeeeeeeeee  comment part 2>...

教程-Delphi 调用控制面板设置功能

应用程序运行时,有时需要对系统环境有特殊要求。例如,在Delphi数据库应用程序中可能需要进行BDE(Borland Database Engine)或ODBC数据源名称(DSN:Data Source Name)的设置;在网络应用程序中可能需要进行网络配置设置、Modem属性设置或用户拨号连接的帐号和密码的设置并保存在系统中;在CTI(Computer-...

Delphi用Socket API实现路由追踪

Windows自带的Tracert是向远程主机发送ICMP包进行追踪,但是目前很多主机关闭了ICMP答复,这个工具不太好使了~~~~~原理咱知道,正规的Trace不就是发送TTL依次递增的UDP包吗?什么网关和路由敢随意丢弃我们的UDP包而...unit YRecords;interfaceusesWindows;constPACKET_SIZE = 32...

[delphi]极域学生端解除键盘鼠标锁定退出全屏广播-强制窗口化-源代码

v2.0 2015-07-11 更新了V2.0 版本 发布在吾爱破解论坛 欢迎下载使用 http://www.52pojie.cn/thread-382769-1-1.html -------------------------------------------------------------------------- v1.0 2013-06-23...