function GetDesktopHwnd(): HWND; var hWin: HWND; bufClassName: array[0..255] of Char; begin //取得窗体的HWND hWin := FindWindow('Progman', nil); //取得窗体的下一个HWND hWin := GetWindow(hWin, GW_CHILD); GetClassName(hWin, bufClassName, 255); while Trim(bufClassName) <> 'SHELLDLL_DefView' do begin if hWin <> 0 then begin hWin := GetNextWindow(hWin, GW_HWNDNEXT); GetClassName(hWin, bufClassName, 255); end else begin Result := hWin; Exit; end; end; hWin := GetWindow(hWin, GW_CHILD); GetClassName(hWin, bufClassName, 255); while Trim(bufClassName) <> 'SysListView32' do begin if hWin <> 0 then begin hWin := GetNextWindow(hWin, GW_HWNDNEXT); GetClassName(hWin, bufClassName, 255); end else begin Result := hWin; Exit; end; end; OutputDebugString(PChar(IntToStr(hWin))); Result := hWin; end;
procedure SetDesktopSmallIcon(); var hWin: HWND; WinStyle: Integer; begin hWin := GetDesktopHwnd; if hWin <> 0 then begin WinStyle := GetWindowLong(hWin, GWL_STYLE); SetWindowLong(hWin, GWL_STYLE, (WinStyle xor $0002)); end; end;