16
Jul 08
::
news :: by Gilberto Saraiva
Folks,
Sometimes we need a challenge to get some deceptions and see our human condition.
If you lose its normal, only one can win, if not congratzzz you are the one.
What side you choose?
Today I received the google codejam e-mail saing that the qualification round is today, in 9hr.
I don’t feel prepared for a challenge today…
My head still looking for some usefull creations for ParallelJobs library and the work don’t let me play with it.
On the mean time I’ll see what I can do on a short time.
news — No comments
10
Jul 08
::
news :: by Gilberto Saraiva
Camaradas,
Já que o usei o Hino Brasileiro no texto demonstrativo do Caster, vou postar um possível resultado aqui:
Hino Brasileiro:

>_ Castered! _<
Abraços
news — No comments
08
Jul 08
::
news :: by Gilberto Saraiva
Folks,
Today I challenge myself, about 5 or 6 hours to create Caster, the clone of Wordle, but its works only for Win32 plataform with some advantages.
The challenge idea comes when I remeber this site: http://wordle.net/
A creation by Jonathan Feinberg.
I finished my challenge with this result:

Download it here: Caster (706 KB) - 146 hits
Project page: Caster: Desktop Wordle Clone
Any troubles or suggestion, post here.
news — No comments
05
Jul 08
::
news :: by Gilberto Saraiva
Folks,
A long time ago I founded this site: Jooce.com. A really good one that provide a Virtual Desktop for everybody who wants one, for free.
Let me show what you can have using it:
2 Virtual Desktops for each account: Private and Public.
Unlimited upload/download size and quote.
Contact list with possibility of groups creation.
Share files with your contacts instantly regardless of the size.
Public desktop only for your contacts
Flex application, beautiful design, layout and animations.
Easy to use
The biggest FAQ list I’ve seen: http://asset.jooce.com/faq/faq.html
With this motivation I started the projects JooceBox on DevPartners (In Brazilian Portuguese)
Download it here:
For Delphi developers you can get follow the course:
SVN: http://skpc.dyndns.org:11520/svn/DevPartners/JooceBox/
Trac: http://skpc.dyndns.org:11500/trac/DevPartners/JooceBox/
So create your account and be happy.
news — 2 comments
05
Jul 08
::
news :: by Gilberto Saraiva
Camaradas,
Ontem iniciei o ParallelJobs no DevPartners.
Mas o que é o ParallelJobs?
O ParallelJobs vai ser uma library para Delphi que consiste em disponibilizar facilitadores para criação de processos paralelos nas aplicações diversas.
A library ainda está no começo, mas já tem um aplicativo teste que vai servir para exemplificar algumas maneiras de utilização e criação de processos parallelos.
Acompanhe o fórum para maiores informações:
http://devpartners.projects.pro.br/forum/?board=8.0
Vou manter ele em inglês, mas isso não impede a comunicação em português de quem quiser contribuir.
façam bom uso e colaborem se puderem,
Abraços.
news — No comments
03
Jul 08
::
articles :: by Gilberto Saraiva
Folks,
A light for everybody. First of all, I’ll use two other usefull functions I posted on this site:
GetHwndClass
GetHwndText
And now the magic:
| 01 | uses Windows, TLHelp32; |
| 02 | |
| 03 | type |
| 04 | TWalkOnHandlesCallback = function(AHwnd, AParentHWnd: HWND; |
| 05 | AClass, AText: string; AFlag: Integer): boolean of object; |
| 06 | |
| 07 | function WalkOnHandles(AParent: HWND; AFlag: integer; |
| 08 | ACallback: TWalkOnHandlesCallback): Integer; |
| 09 | var |
| 10 | CurrHWnd: HWND; |
| 11 | begin |
| 12 | Result := 0; |
| 13 | CurrHWnd := GetTopWindow(AParent); |
| 14 | while CurrHWnd <> 0 do |
| 15 | begin |
| 16 | Result := Result + 1; |
| 17 | if Assigned(ACallback) then |
| 18 | if not ACallback(CurrHWnd, AParent, |
| 19 | GetHwndClass(CurrHWnd), GetHwndText(CurrHWnd), AFlag) then |
| 20 | Break; |
| 21 | CurrHWnd := GetNextWindow(CurrHWnd, GW_HWNDNEXT); |
| 22 | end; |
| 23 | end; |
| 24 | |
| 25 | function WalkOnHandlesOfExe(AExeName: string; AFlag: integer; |
| 26 | ACallback: TWalkOnHandlesCallback): Integer; |
| 27 | var |
| 28 | PID, CheckPID: DWord; |
| 29 | hSnapShot: THandle; |
| 30 | ProcessEntry: TProcessEntry32; |
| 31 | CurrHWnd: HWND; |
| 32 | begin |
| 33 | Result := 0; |
| 34 | PID := 0; |
| 35 | hSnapShot := CreateToolhelp32Snapshot((TH32CS_SNAPALL), 0); |
| 36 | ProcessEntry.dwSize := SizeOf(TProcessEntry32); |
| 37 | Process32First(hSnapShot, ProcessEntry); |
| 38 | repeat |
| 39 | if ProcessEntry.szExeFile = AExeName then |
| 40 | begin |
| 41 | PID := ProcessEntry.th32ProcessID; |
| 42 | Break; |
| 43 | end; |
| 44 | until Process32Next(hSnapShot, ProcessEntry) = false; |
| 45 | CloseHandle(hSnapShot); |
| 46 | |
| 47 | if PID > 0 then |
| 48 | begin |
| 49 | CurrHWnd := GetTopWindow(GetDesktopWindow); |
| 50 | while CurrHWnd <> 0 do |
| 51 | begin |
| 52 | Result := Result + 1; |
| 53 | GetWindowThreadProcessID(CurrHWnd, @CheckPID); |
| 54 | if CheckPID = PID then |
| 55 | if Assigned(ACallback) then |
| 56 | if not ACallback(CurrHWnd, 0, |
| 57 | GetHwndClass(CurrHWnd), GetHwndText(CurrHWnd), AFlag) then |
| 58 | Break; |
| 59 | CurrHWnd := GetNextWindow(CurrHWnd, GW_HWNDNEXT); |
| 60 | end; |
| 61 | end; |
| 62 | end; |
Now let me explain what this big code do.
This code its only a light, a simple idea, about how you can navigate through the Windows Objects (Handle) from everywhere.
A simple example:
Create a TMemo named mmoLog
Link OnCreate of the Main Form
Create a the callback on the Main Form class
| 01 | |
| 02 | TForm1 = class(TForm) |
| 03 | mmoLog: TMemo; |
| 04 | procedure FormCreate(Sender: TObject); |
| 05 | private |
| 06 | { Private declarations } |
| 07 | public |
| 08 | function WalkCall(AHwnd, AParentHWnd: HWND; |
| 09 | AClass, AText: string; AFlag: Integer): boolean; |
| 10 | end; |
| 11 | |
The rest of the code:
| 01 | |
| 02 | procedure TForm1.FormCreate(Sender: TObject); |
| 03 | begin |
| 04 | WalkOnHandlesOfExe('delphi32.exe', 0, WalkCall); |
| 05 | end; |
| 06 | |
| 07 | function TForm1.WalkCall(AHwnd, AParentHWnd: HWND; AClass, |
| 08 | AText: string; AFlag: Integer): boolean; |
| 09 | begin |
| 10 | Result := True; |
| 11 | mmoLog.Lines.Add(stringofChar(' ', AFlag) + Format('%d: [ %s ] %s', [AHwnd, AClass, AText])); |
| 12 | WalkOnHandles(AHwnd, AFlag + 2, WalkCall); |
| 13 | end; |
| 14 | |
This example will list all Windows Objects on the Delphi application and will result a idented log on the mmoLog.
Simple uhm?
WalkOnHandles
Walk on all handles by the Z-order of the specified Parent.
WalkOnHandlesOfExe
Walk on all handles by the Z-order that have DesktopWindow as parent and the Application as owner.
articles — 3 comments
03
Jul 08
::
articles :: by Gilberto Saraiva
Folks,
For evebody who wants to control how the application’s threads and processes will consume the CPU I wrote this function to provide an easy way to do this.
| 01 | uses Windows; |
| 02 | |
| 03 | type |
| 04 | TWorkOnProcessorUseMode = (cpuNum, cpuPerc, cpuIndex); |
| 05 | |
| 06 | procedure WorkOnProcessor(AUse: Cardinal; AMode: TWorkOnProcessorUseMode); |
| 07 | var |
| 08 | Mask: integer; |
| 09 | lpSystemInfo: TSystemInfo; |
| 10 | |
| 11 | function ToMask(m: integer): integer; |
| 12 | var |
| 13 | i: integer; |
| 14 | begin |
| 15 | Result := 0; |
| 16 | for i := 0 to m - 1 do |
| 17 | Result := Result + (1 shl i); |
| 18 | end; |
| 19 | begin |
| 20 | GetSystemInfo(lpSystemInfo); |
| 21 | with lpSystemInfo do |
| 22 | begin |
| 23 | case AMode of |
| 24 | cpuNum: begin |
| 25 | if AUse > dwNumberOfProcessors then |
| 26 | AUse := dwNumberOfProcessors; |
| 27 | end; |
| 28 | cpuPerc: begin |
| 29 | if AUse > 100 then AUse := 100; |
| 30 | AUse := Round(dwNumberOfProcessors / 100 * AUse); |
| 31 | end; |
| 32 | end; |
| 33 | if AMode <> cpuIndex then |
| 34 | begin |
| 35 | Mask := ToMask(dwNumberOfProcessors); |
| 36 | Mask := Mask xor ToMask(dwNumberOfProcessors - AUse); |
| 37 | end else |
| 38 | Mask := (1 shl (AUse - 1)); |
| 39 | SetProcessAffinityMask(GetCurrentProcess, Mask); |
| 40 | end; |
| 41 | end; |
You’ll have three ways to put your application running only on the processor(s) you want.
cpuNum mode:
With this mode you’ll be able to specify the number of processors you want to use. The logical structure will count from the first processor.
cpuPerc mode:
With this mode you’ll be able to specify a percentage to use of all processors on the machine. If the machine have four processors and you specify 50 (50%) on the first param, your application will use 2 cores. If 2 cores and 50% will use 1 core.
cpuIndex mode:
With this mode you’ll be able to specify the processor you want to use. If you have 4 cores and you want to use only the third core, specify 3 on the first param and your application will use only the 3º core and no one more.
A little detail:
Your application starts without a setting about what processor will be used and all threads and processes created before the use of the function above can be not modified and so the process can keep on an unspecified core.
The best way to use this function is declaring it on the DPR and using it before Application.Initialize;
Ex:
| 1 | // on the .DPR of the project |
| 2 | begin |
| 3 | WorkOnProcessor(50, cpuPerc); |
| 4 | Application.Initialize; |
| 5 | Application.CreateForm(TForm1, Form1); |
| 6 | Application.Run; |
| 7 | end. |
articles — No comments
03
Jul 08
::
articles :: by Gilberto Saraiva
Folks,
This code below implement a singleton structure for the aplication, and that need to be implemented on the DPR file of the project:
| 01 | uses Windows; |
| 02 | |
| 03 | function AppSingleton(ACheckPath: boolean = false): boolean; |
| 04 | var |
| 05 | s: string; |
| 06 | i, iLast: Cardinal; |
| 07 | begin |
| 08 | s := ParamStr(0); |
| 09 | iLast := 1; |
| 10 | case Integer(ACheckPath) of |
| 11 | 0: for i := 1 to Length(s) do if s[i] = '\' then iLast := i; |
| 12 | 1: for i := 1 to Length(s) do if s[i] in [':','\','.',' '] then s[i] := '_'; |
| 13 | end; |
| 14 | Result := (CreateMutex(nil, true, PChar(Cardinal(@s) + (iLast - 1))) <> 0) and |
| 15 | (GetLastError = 0); |
| 16 | end; |
I use the CreateMutex API that works as a semaphore, if open, the application is unique, if closed the application is already running.
I wrote a condition to check the full path of the application for the Mutex call, so if you want to check the full path use the funciotn with param as True, the default is False and the check will be only on the application exe name.
A little detail about checking the functionality of this function:
Under debug mode the checkout on full path mode will fail and more then one application can be raised. This problem is because the relationship of the application with other program, so the CreateMutex API understand the Process ID is diferent from others.
articles — No comments
01
Jul 08
::
articles :: by Gilberto Saraiva
Camaradas,
Já é velha essa dica, mas pra quem não conhece vale a pena informar:
Se você tem um e-mail, ex:
eu_tenho_gmail@gmail.com
Você pode orientar os emissores no cadastro em algum site ou feed da seguinte forma:
eu_tenho_gmail+gsaraiva_feed@gmail.com
Assim quando você receber o e-mail do feed, ele conterá alem do assunto de quem lhe enviou a palavra “gsaraiva_feed”.
Faça um teste, envie para você mesmo um e-mail com o assunto:
GMAIL
Mas no seu endereço de e-mail antes do @ adicione: “+TESTE”
Envie e aguarde o recebimento.
Interessante não é?
Ajuda bastante na hora de fazer filtros na caixa de entrada.
Abraços
articles — No comments