28
Jun 08

Delphi: Utils :: GetShellFolder

:: articles :: by Gilberto Saraiva

Folks,

Get some Shell Folder from Current User or All User ( System ):

 Delphi |  copy code |? 
01
uses Registry;
02
 
03
type
04
  TShellFolderType = (
05
    // User
06
    sftAppData, sftCookies, sftDesktop, sftFavorites,
07
    sftNetHood, sftPersonal, sftPrintHood, sftRecent, sftSendTo, sftStartMenu,
08
    sftTemplates, sftPrograms, sftStartup, sftLocalSettings, sftLocalAppData,
09
    sftCache, sftHistory, sftMyPictures, sftFonts, sftMyMusic, sftCDBurning,
10
    sftMyVideo, sftAdminTools,
11
    // System
12
    sftCommonAppData, sftCommonPrograms, sftCommonDocuments, sftCommonDesktop,
13
    sftCommonStartMenu, sftCommonPictures, sftCommonMusic, sftCommonVideo,
14
    sftCommonFavorites, sftCommonStartup, sftCommonTemplates,
15
    sftCommonAdminTools, sftCommonPersonal);
16
 
17
 
18
function GetShellFolder(AShellFolderType: TShellFolderType): string;
19
begin
20
  with TRegistry.Create do
21
  begin
22
    if AShellFolderType <= sftAdminTools then
23
      RootKey := HKEY_CURRENT_USER
24
    else
25
      RootKey := HKEY_LOCAL_MACHINE;
26
 
27
    OpenKey('\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders', True);
28
    case AShellFolderType of
29
      sftAppData       : Result := ReadString('AppData');
30
      sftCookies       : Result := ReadString('Cookies');
31
      sftDesktop       : Result := ReadString('Desktop');
32
      sftFavorites     : Result := ReadString('Favorites');
33
      sftNetHood       : Result := ReadString('NetHood');
34
      sftPersonal      : Result := ReadString('Personal');
35
      sftPrintHood     : Result := ReadString('PrintHood');
36
      sftRecent        : Result := ReadString('Recent');
37
      sftSendTo        : Result := ReadString('SendTo');
38
      sftStartMenu     : Result := ReadString('Start Menu');
39
      sftTemplates     : Result := ReadString('Templates');
40
      sftPrograms      : Result := ReadString('Programs');
41
      sftStartup       : Result := ReadString('Startup');
42
      sftLocalSettings : Result := ReadString('Local Settings');
43
      sftLocalAppData  : Result := ReadString('Local AppData');
44
      sftCache         : Result := ReadString('Cache');
45
      sftHistory       : Result := ReadString('History');
46
      sftMyPictures    : Result := ReadString('My Pictures');
47
      sftFonts         : Result := ReadString('Fonts');
48
      sftMyMusic       : Result := ReadString('My Music');
49
      sftCDBurning     : Result := ReadString('CD Burning');
50
      sftMyVideo       : Result := ReadString('My Video');
51
      sftAdminTools    : Result := ReadString('Administrative Tools');
52
 
53
      // System
54
      sftCommonAppData    : Result := ReadString('Common AppData');
55
      sftCommonPrograms   : Result := ReadString('Common Programs');
56
      sftCommonDocuments  : Result := ReadString('Common Documents');
57
      sftCommonDesktop    : Result := ReadString('Common Desktop');
58
      sftCommonStartMenu  : Result := ReadString('Common Start Menu');
59
      sftCommonPictures   : Result := ReadString('CommonPictures');
60
      sftCommonMusic      : Result := ReadString('CommonMusic');
61
      sftCommonVideo      : Result := ReadString('CommonVideo');
62
      sftCommonFavorites  : Result := ReadString('Common Favorites');
63
      sftCommonStartup    : Result := ReadString('Common Startup');
64
      sftCommonTemplates  : Result := ReadString('Common Templates');
65
      sftCommonAdminTools : Result := ReadString('Common Administrative Tools');
66
      sftCommonPersonal   : Result := ReadString('Personal');
67
    end;                                                     
68
  end;
69
end;



28
Jun 08

Delphi: Utils :: WinSystem32Path

:: articles :: by Gilberto Saraiva

Folks,

Get Windows’s System32 Directory as Path ( \ at end)

 Delphi |  copy code |? 
01
var
02
  WinSystem32PathStr: string = '';
03
 
04
function WinSystem32Path: string;
05
begin
06
  if WinSystem32PathStr = '' then
07
  begin
08
    SetLength(Result, MAX_PATH);
09
    SetLength(Result, GetSystemDirectory(PChar(Result), MAX_PATH));
10
    WinSystem32PathStr := Result + '\';
11
  end;
12
  Result := WinSystem32PathStr;
13
end;



28
Jun 08

Delphi: Utils :: WindowsPath

:: articles :: by Gilberto Saraiva

Folks,

Get the Windows Directory as Path ( \ at end ):

 Delphi |  copy code |? 
01
var
02
  WindowsPathStr: string = '';
03
 
04
function WindowsPath: string;
05
begin
06
  if WindowsPathStr = '' then
07
  begin
08
    SetLength(Result, MAX_PATH);
09
    SetLength(Result, GetWindowsDirectory(PChar(Result), MAX_PATH));
10
    WindowsPathStr := Result + '\';
11
  end;
12
  Result := WindowsPathStr;
13
end;



28
Jun 08

Delphi: Utils :: GetShortcutCmd

:: articles :: by Gilberto Saraiva

Folks,

Get the program and command line of a shortcurt file (.LNK)

 Delphi |  copy code |? 
01
uses ActiveX, ComObj, ShlObj;
02
 
03
function GetShortcutCmd(AShortcutPath: string): string;
04
var
05
  ShellLink: IUnknown;
06
  Win32Data: TWin32FindData;
07
  Buff: array [0..MAX_PATH*2] of Char;
08
begin
09
  ShellLink := CreateComObject(CLSID_ShellLink);
10
  with (ShellLink as IShellLink), (ShellLink as IPersistFile) do
11
  begin
12
    Load(PWChar(WideString(AShortcutPath)), 0);
13
    GetPath(@Buff[0], MAX_PATH, Win32Data, SLGP_UNCPRIORITY);
14
    GetArguments(@Buff[MAX_PATH], MAX_PATH);
15
    Result := Trim(PChar(@Buff) + ' ' + PChar(@Buff[MAX_PATH]));
16
  end;
17
end;



28
Jun 08

Delphi: Utils :: GetHwndClass

:: articles :: by Gilberto Saraiva

Folks,

Get the Class Name of the Window Object ( Handle )

 Delphi |  copy code |? 
1
uses Windows;
2
 
3
function GetHwndClass(AHandle: HWND): string;
4
begin
5
  SetLength(Result, 255);
6
  GetClassName(AHandle, PChar(Result), 255);
7
  Result := StrPas(PChar(Result));
8
end;



28
Jun 08

Delphi: Utils :: GetHwndText

:: articles :: by Gilberto Saraiva

Folks,

The first of a serie of usefull functions, that I’ll provide here.

Get the Text ( Caption ) of a Windows Object ( Handle )

 Delphi |  copy code |? 
01
uses Windows;
02
 
03
 
04
function GetHwndText(AHandle: HWND): string;
05
var
06
  iLen: integer;
07
begin
08
  iLen := GetWindowTextLength(AHandle);
09
  SetLength(Result, iLen);
10
  GetWindowText(AHandle, PChar(Result), iLen + 1);
11
end;



25
Jun 08

Is the end of the world?

:: news :: by Gilberto Saraiva

Folks,

Is this video the first step to the end?


Hugs for all



24
Jun 08

Challenge: Delphi’s Windows

:: challenges :: by Gilberto Saraiva

Camaradas,

Ola e boa sorte!

O desafio das Janelas do Delphi

Linguagem/Tema

Delphi

Nível

Intermediário

Regra(s)
  • A aplicação demo deve ser do tipo Console e ser toda escrita no dpr.
  • Você podera fazer uso das sequintes Units: SysUtils e Windows
  • OBS: qualquer coisa enviada desrespeitando as regras, não irei nem responder

    O Problema

    Em um teste de emprego para programador Delphi, você se depara com a seguinte solicitação:

    O teste consiste na criação de uma classe no padrão abaixo:

  • A classe: TWinBase = class(TObject)
  • A TWinBase deve criar uma janela do tipo ToolWindow na criação de um objeto dessa classe.
  • O Handle da janela criada deve ter escopo público, provido por uma propriedade ( property Handle: HWND …. )
  • Uma função na classe receberá os eventos da janela criada, esse procedimento deve ser virtual e de escopo público
  • A classe deve poder ser criada quantas vezes forem necessárias
  • Objetivo(s)

    Escrever a classe e todas as funções necessárias para que seu teste seja bem sucedido e você consiga ser aceito como funcionário.

    Referência(s)

    Base estrutural da TWinBase:

     Delphi |  copy code |? 
    01
    02
    type
    03
      TWinBase = class(TObject)
    04
      private
    05
        FHandle: HWND;
    06
      public
    07
        constructor Create;
    08
        destructor Destroy; override;
    09
        property Handle: HWND read FHandle write FHandle;
    10
        function WndProc(AHandle: HWND; AMsgCode: UINT; AWParam: WPARAM;
    11
          ALParam: LPARAM): Longint; virtual; stdcall;
    12
      end;
    13

    Windows APIs:

     Delphi |  copy code |? 
    01
    02
    function GetClassInfo(hInstance: HINST; lpClassName: PChar;
    03
      var lpWndClass: TWndClass): BOOL; stdcall;
    04
     
    05
    function RegisterClass(const lpWndClass: TWndClass): ATOM; stdcall;
    06
     
    07
    function UnregisterClass(lpClassName: PChar; hInstance: HINST): BOOL; stdcall;
    08
     
    09
    function CreateWindowEx(dwExStyle: DWORD; lpClassName: PChar;
    10
      lpWindowName: PChar; dwStyle: DWORD; X, Y, nWidth, nHeight: Integer;
    11
      hWndParent: HWND; hMenu: HMENU; hInstance: HINST; lpParam: Pointer): HWND;
    12
     
    13
    function DefWindowProc(hWnd: HWND; Msg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
    14

    Esse desafio se destina a todos que conhecem a linguagem Delphi e tem bom entendimento sobre as APIs de manipulação de Janelas.

    As dúvidas e questionamentos podem ser postados aqui!
    O primeiro que acertar, vou entrar em contato e disponibilizar um espaço aqui para que ele demonstre como fez.

    Abraços.



    24
    Jun 08

    Microsoft iPhone

    :: news :: by Gilberto Saraiva

    Folks,

    Posting fast at work time ^^


    Who want one???

    Hugs for all



    24
    Jun 08

    Challenge: Compass Rose

    :: challenges :: by Gilberto Saraiva

    Camaradas,

    Mais um desafio pro pessoal.

    O desafio da Rosa-dos-ventos

    Linguagem/Tema

    Qualquer uma. O importante e a resposta certa com a formatação certa.

    Nível

    Extremo

    Regra(s)
  • Não há regras
  • O Problema

    Diante de uma rosa-dos-ventos um grande pensador criou um pequeno poema, mas esse poema não é comum, ele esta encriptado por uma fórmula constante encima do tema. O autor só se preocupou em informar no final do texto uma pequena dica.

     plain |  copy code |? 
    01
    02
    mMdtëAriûPfwîDukáRiyñGbréDtkåVMhúxuvòHXsêüQhâOJzêçXoê
    
    03
    uúôIzuìBsiü gxïIzpçWriüPgwîDYpæWNdûPFaóIYpëàAVûõDaóèY
    
    04
    åVmcúOevíCtPàVlcafaqèXsmiQLcôiZqçXOeüQGbôIZqçXNeüñGxï
    
    05
    pçùNe÷ìBséäUláùNdöìBwnäYpbôIdaëBrsãTOføMDtëARiûTKaYpC
    
    06
    ARhMOFbbHYoåVQhúõJa\èCsêàQlcôyauìJsjüU jùNEuñ|enäULbô
    
    07
    uìBdiüPrwóEZpæáRiûñabóéYtëáRidõKfaòHxoå mcúOEvíHXoåVQ
    
    08
    ôJzòçXnüQgùulzñçXnL PgwïEuláSiüñG ïäUlhùJzòìBsjüQgxï
    
    09
    lâSje÷LcsêZqgsSjzòGbséZnæWRiûPFwî`UpæøIyñëBréûPfùóIH
    
    10
    WmszPføóoyoëA_hûOjaòHyoåVmhúOJvíCtjàRhyðFvmèTOføMCtër
    
    11
    ûOfrîDYkUVMdõKArèCTkIoMyðFWmãnSføMDtðARhûPCwós„oæWMhû
    
    12
    víãooåøQhúðFvíãXjàóHctêAswâTjaòpxoêAqlâSjzcLxoåX cõOE
    
    13
    ƒSnåVQgôJZqçCOjüELbïEVqìáWgsöLgùîDuecSidöPfwóHypæWmdö
    
    14
    aéYpéùNdyðFArèYP øMDtëBWmûPFaóIYpëWMdöPFwîD€oæøIyñFWn
    
    15
    etóIFpæWN,WLBsé PgùN[uñGWréûPgùNReìæWnäöKbôaZpçù]lûñG
    
    16
    äUlæôIzñçXnéüPgGîEuìáWnäöLbôéZpçáRizrdbrîDp~tNduìFwnä
    
    17
    bôIzpæ}niöPg…îDukæWNdñGBréZPNùNDuñGWnäUKbôIZpçWNe÷LGw
    
    18
    UláSIdöKFwîZ.gùNvuñëBräTLbùîouìæenéûKbôBDuëáWmdöKnaîD
    
    19
    áRidõKaríCToåVMcQJArèYOtøMDhðFVqrTKaóHYoëARhûOFvíDTfø
    
    20
    a^BRiûgGwîDUpæWNdöPFwóèOsæø‚hûKBrîãTkáøIyðæWm{ûPføîDy
    
    21
    WehúOjkíDtosVmcúOfvíCtjàRhyðFvmèCTjàQHxðqrhûO wòHYoåV
    
    22
    õtaríCTkàRHyaJAríCTjàQHyðFAqéúOføíCvëàRhmðJaòíCtêàQaõ
    
    23
    aòçXoå÷McxïAKlâTj sLcsêAqhúOZvòGxoå lcõNevíCXnäZPgùaE
    
    24
    BSjüQGbïEVlçSJzòHXoåZQgúOEvíCSjàQHxðJZqçXOe÷LCtêAQhúO
    
    25
    26
    Minha vida neste momento é a rosa com seus efeitos colaterais, guiando-me através dos seus cardeais.
    
    27
    Abaixo listo um número por direção:
    
    28
    142113242433124221414213144143124332242311421223322334112413123143311
    
    29

    Objetivo(s)

    Você deve enviar o poema assim que descobrir como faze-lo.

    Referência(s)

    Rosa dos Ventos

    1. E: Leste
    2. O: Oeste
    3. N: Norte
    4. S: Sul
    5. NE: Nordeste
    6. NO: Noroeste
    7. SE: Sudeste
    8. SO: Sudoeste
    9. ENE: Lés-nordeste
    10. ESE: Lés-sudeste
    11. SSE: Sul-sudeste
    12. NNE: Nor-nordeste
    13. NNO/NNW: Nor-noroeste
    14. SSO/SSW: Sul-sudoeste
    15. OSO/WSW: Oés-sudoeste
    16. ONO/WNW: Oés-noroeste

    Wiki: http://pt.wikipedia.org/wiki/Rosa-dos-ventos

    Esse desafio se destina a todos que possuem grande entendimento em lógica e criação de algoritmos específicos.

    As dúvidas e questionamentos podem ser postados aqui!
    O primeiro que acertar, vou entrar em contato e disponibilizar um espaço aqui para que ele demonstre como fez.

    Abraços.