Friday, June 25, 2004

The phucked fonetical alfabet

Here is something a friend of mine Mr T. did, the purpose of this phonetical alphabet is to cause maximum confusion.


A -> Aisle
B -> Bee
C -> Cereal
D -> Djibouti
E -> Eye
F -> Filter
G -> Gnome
H -> Hour
I -> I or Isle
J -> Juan
K -> Know
L -> Llanelli
M -> Mnemonic
N -> No
O -> Our
P -> Philtre
Q -> Qatar
R -> Right
S -> Sea or Serial
T -> Tsunami
U -> Urn
V -> Vondel
W -> Write
X -> Xhosa
Y -> Yvonne
Z -> Zeal




Can you imagine if a tech support person uses this alphabet to check one of those WinXP product keys!

Friday, June 18, 2004

Same friend, only one reading this blog asked for more...

I was going to say skin a cat but that would make him winch, so I am saying it any way because it is a saying...
The second way to get all Winforms in your app...
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


procedure TWinForm.Button4_Click(sender: System.Object; e: System.EventArgs);
const
AllBindingFlags : BindingFlags = BindingFlags.Instance or BindingFlags.Static or
BindingFlags.Public or BindingFlags.NonPublic or
BindingFlags.FlattenHierarchy;
var
MSCorlibModule : Module;
HandleBucketType : System.Type;
hashBucketField : FieldInfo;
hashBuckets : System.Array;
HandleBucket : TObject;
HandleField : FieldInfo;
WinHandle : IntPtr;
FoundControl : Control;
i : integer;
begin
MSCorlibModule := Self.GetType.BaseType.Module;
if not Assigned(MSCorlibModule) then Exit;

hashBucketField := Typeof(NativeWindow).GetField('hashBuckets',AllBindingFlags);
//if there are no hash buckets we might as well end it here.
if not Assigned(hashBucketField) then Exit;
hashBuckets := System.Array(hashBucketField.GetValue(nil));
if not Assigned(hashBuckets) then Exit;

HandleBucketType := MSCorlibModule.GetType('System.Windows.Forms.NativeWindow+HandleBucket');
if not Assigned(HandleBucketType) then Exit;

HandleField := HandleBucketType.GetField('handle',AllBindingFlags);
if not Assigned(HandleField) then Exit;

for i := 0 to hashBuckets.Length - 1 do
begin
HandleBucket := hashBuckets.GetValue(i);
if Assigned(HandleBucket) then
begin
WinHandle := IntPtr(HandleField.GetValue(HandleBucket));
if (WinHandle.ToInt32 <> 0) then
begin
FoundControl := Control.FromHandle(WinHandle);
if FoundControl is System.Windows.Forms.Form then
MessageBox.Show(FoundControl.Text);
end;
end;
end;
end;

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Delphi code again...

A friend who asked me...

How can I get a list of all the Winforms in my .net application... hmmm I thought this should be easy... I should have known Brian (Long) would not have asked the question if it was easy... as he is pure evil that way. Making me think, as my wife will concur this is a big task in itself!.... I undertook to use the CLR rather than using Interop... Well Brian here is one Solution:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


procedure TWinForm.Button2_Click(sender: System.Object; e: System.EventArgs);


const
AllBindingFlags : BindingFlags = BindingFlags.Instance or BindingFlags.Static or
BindingFlags.Public or BindingFlags.NonPublic or
BindingFlags.FlattenHierarchy;

CtorParams : array [0..1] of System.Type = (TypeOf(Control),TypeOf(boolean));

type
TIntptrArrayType = array of IntPtr;

var
MSCorlibModule : Module;
FusionType : System.Type;
FldInfo : FieldInfo;
ThreadWindowsCtor : ConstructorInfo;
ThreadWindowsObject : TObject;
ThreadWindowsParams : array [0..1] of TObject;
ThreadWindowCount, i : integer;
WindowsArr : TIntptrArrayType;
TempControl : Control;
begin
//We could "MSCorlibAssembly := Assembly.Load('mscorlib');" again BUT this is
//easier... there are numerous ways to skin this cat.
MSCorlibModule := Self.GetType.BaseType.Module;
if not Assigned(MSCorlibModule) then Exit;
FusionType := MSCorlibModule.GetType('System.Windows.Forms.Application+ThreadWindows');
if not Assigned(FusionType) then Exit;
ThreadWindowsCtor := FusionType.GetConstructor(AllBindingFlags, nil,
CallingConventions.HasThis,CtorParams, nil);
if not Assigned(ThreadWindowsCtor) then Exit;

ThreadWindowsParams[0] := nil; //Look for all controls on the thread
ThreadWindowsParams[1] := TObject(false); //False ONLY get winforms

// Create the ThreadWindows Object
ThreadWindowsObject := ThreadWindowsCtor.Invoke(ThreadWindowsParams);
if not Assigned(ThreadWindowsObject) then Exit;

//Get the number of windows on the thread
FldInfo := FusionType.GetField('windowCount',AllBindingFlags);
ThreadWindowCount := integer(FldInfo.GetValue(ThreadWindowsObject));
if ThreadWindowCount <= 0 then Exit;

//Get an window handles
FldInfo := FusionType.GetField('windows',AllBindingFlags);
if not Assigned(FldInfo) then Exit;
WindowsArr := TIntptrArrayType(FldInfo.GetValue(ThreadWindowsObject));
if not Assigned(WindowsArr) then Exit;
for i := 0 to ThreadWindowCount -1 do
begin
TempControl := Control.FromHandle(WindowsArr[i]);
if Assigned(TempControl) then
//Get the caption of each control
MessageBox.Show(TempControl.Text);
end;
end;

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Yes, people that is Pascal or Delphi if you prefer... written in a C-ish fashion.