﻿<feed xmlns="http://www.w3.org/2005/Atom"><id>http://news.xb2.net/ot4xb.examples</id><title>ot4xb.examples (readonly)</title><link rel="alternate" href="http://news.xb2.net/ot4xb.examples" type="text/html" /><link rel="self" href="http://news.xb2.net/atom/ot4xb.examples" type="application/atom+xml" /><updated>2008-11-21T17:05:20Z</updated><generator uri="http://www.mssagepixels.com">MPNews</generator><entry><title type="text">Retrieving the computer name from the NETBIOS</title><link rel="alternate" href="http://news.xb2.net/ot4xb.examples/1/Retrieving+the+computer+name+from+the+NETBIOS.html" type="text/html" /><id>http://news.xb2.net/ot4xb.examples/1/Retrieving+the+computer+name+from+the+NETBIOS.html</id><published>2008-06-13T09:11:23Z</published><updated>2008-06-13T09:11:23Z</updated><author><name>Pablo Botella</name><email>pbn_NOSPAM_@pablob.com</email></author><content type="html">&lt;pre&gt;#include &amp;quot;ot4xb.ch&amp;quot;
// ---------------------------------------------------------------------------
function Main()
? cPrintf( &amp;quot;Computer Name : [%s]&amp;quot;, cGetComputerName() )
inkey(0)
return NIL
// ---------------------------------------------------------------------------
function cGetComputerName()
local cn := ChrR(0,256)
local cb := 255
@kernel32:GetComputerNameA(@cn,@cb)
return TrimZ(cn)
// ---------------------------------------------------------------------------&lt;/pre&gt;</content></entry><entry><title type="text">Retrieving a list of services with the status Active</title><link rel="alternate" href="http://news.xb2.net/ot4xb.examples/2/Retrieving+a+list+of+services+with+the+status+Active.html" type="text/html" /><id>http://news.xb2.net/ot4xb.examples/2/Retrieving+a+list+of+services+with+the+status+Active.html</id><published>2008-07-13T15:41:12Z</published><updated>2008-07-13T15:41:12Z</updated><author><name>Pablo Botella</name><email>pbn_NOSPAM_@pablob.com</email></author><content type="html">&lt;pre&gt;function aGetActiveServices()
local hSc :=  @advapi32:OpenSCManagerA(0,0,SC_MANAGER_ENUMERATE_SERVICE)
local lResult
local pData,cbData
local nRH      := 0  // Resume Handle
local cbNeeded := 0
local nSvcCnt  := 0
local lLoop    := .T.
local aSvc     := {}
local n,ns

if( hSc == 0 ) ; return {} ; end

cbData := 0x10000 ; pData  := _xgrab(cbData)

while lLoop
   nSvcCnt  := 0
   lResult := ( @advapi32:EnumServicesStatusExA( hSc,SC_ENUM_PROCESS_INFO,;
                nOr(SERVICE_DRIVER,SERVICE_WIN32),SERVICE_ACTIVE,pData,cbData,;
                @cbNeeded,@nSvcCnt,@nRH,0) != 0 )
                
   lLoop := (nFpGetLastError() == ERROR_MORE_DATA)
   if( lResult .or. lLoop )
      ns := 0
      for n := 1 to nSvcCnt
         aadd( aSvc , PeekDWord(pData,@ns, 11) )
         aSvc[-1][1] := PeekStr(aSvc[-1][1],,-1)
         aSvc[-1][2] := PeekStr(aSvc[-1][2],,-1)
      next
   end
   if lLoop .and. ( cbNeeded &amp;gt; cbData )
       _xfree( pData ); cbData := cbNeeded ; pData  := _xgrab(cbData)
   end
end
_xfree( pData )
@advapi32:CloseServiceHandle(hSc)
return aSvc&lt;/pre&gt;</content></entry><entry><title type="text">Generating random strings ( ot4xb build 1.5.2.79)</title><link rel="alternate" href="http://news.xb2.net/ot4xb.examples/3/Generating+random+strings+(+ot4xb+build+1.5.2.79).html" type="text/html" /><id>http://news.xb2.net/ot4xb.examples/3/Generating+random+strings+(+ot4xb+build+1.5.2.79).html</id><published>2008-09-12T20:52:31Z</published><updated>2008-09-12T20:52:31Z</updated><author><name>Pablo Botella</name><email>pb_no_spam_@_remove_all_betwen_underscores_xbwin.com</email></author><content type="html">&lt;pre&gt;Minimum ot4xb build 1.5.2.79
cGenRndStr() is introduced in ot4xb build 1.5.2.54 but was produced about 10% of duplicates
was fixed in 1.5.2.79
----------------------------------------------------------------------
I've run the test in my computer ( Intel Core Duo 3Ghz, 2Gb RAM)
with the following results
Elapsed Time: 3 Seconds
1000000 Items 0 Duplicates
----------------------------------------------------------------------

#include &amp;quot;ot4xb.ch&amp;quot;
#define MAX_LOOP  1000000
// ---------------------------------------------------------------------------
function Main()
local nSeconds := Seconds()
local pHt      := _HDICT_NEW(,MAX_LOOP)
local n
for n := 1 to MAX_LOOP
   _HDICT_SETPROP(pHt,cBin2Hex(cGenRndStr(8,.T.)), 0) 
   // cBin2Hex() is needed here as the hash table is case insensitive
next
? cPrintf(&amp;quot; Elapsed Time: %i Seconds&amp;quot;,Seconds() - nSeconds)
? cPrintf(&amp;quot; %i Items  %i Duplicates&amp;quot;,MAX_LOOP , MAX_LOOP - _HDICT_COUNT(pHt) )
inkey(0)
return NIL
// ---------------------------------------------------------------------------&lt;/pre&gt;</content></entry><entry><title type="text">Retrieving Drive Information</title><link rel="alternate" href="http://news.xb2.net/ot4xb.examples/4/Retrieving+Drive+Information.html" type="text/html" /><id>http://news.xb2.net/ot4xb.examples/4/Retrieving+Drive+Information.html</id><published>2008-09-26T19:45:24Z</published><updated>2008-09-26T19:45:24Z</updated><author><name>Pablo Botella</name><email>pb_no_spam_@_remove_all_betwen_underscores_xbwin.com</email></author><content type="html">&lt;pre&gt;function ShowDriveInfo(cRoot , cStr )
local oInfo  := GetDriveInfo(cRoot)

cStr += CRLF + PadC( &amp;quot;| &amp;quot; + cRoot + &amp;quot; |&amp;quot;,78,&amp;quot;-&amp;quot;)
if oInfo == NIL
   cStr += CRLF + &amp;quot;Error: Unable to retrieve the volume information.&amp;quot;
   cStr += CRLF + cPrintf( &amp;quot;Type of Drive:[%s]&amp;quot;,_n2dt_(nGetDriveType(cRoot)) )
else
   cStr += CRLF + cPrintf( &amp;quot;Label: [%s] Serial:[%lX]&amp;quot; ,  oInfo:cLabel , oInfo:nSerial )
   cStr += CRLF + cPrintf( &amp;quot;MaxFileNameLen:[%i] FileSystem:[%s] Type:[%s]&amp;quot;,;
                  oInfo:nMaxCompLen,oInfo:cFileSystem,_n2dt_(oInfo:nDriveType) )
end
return cStr&lt;/pre&gt;</content></entry><entry><title type="text">Forced Administrative Privileges</title><link rel="alternate" href="http://news.xb2.net/ot4xb.examples/5/Forced+Administrative+Privileges.html" type="text/html" /><id>http://news.xb2.net/ot4xb.examples/5/Forced+Administrative+Privileges.html</id><published>2008-09-30T19:25:27Z</published><updated>2008-09-30T19:25:27Z</updated><author><name>Pablo Botella</name><email>pb_no_spam_@_remove_all_betwen_underscores_xbwin.com</email></author><content type="html">&lt;pre&gt;This sample will check first if the current user have administrative privileges

if lIsUserAdmin()
   ? &amp;quot;Current user has administrative privileges&amp;quot;

If no sufficient privileges will show you a screen to get a user/pwd with admin privileges
will try to run the same exe with the provided user/pwd account
and close itself if succesfull

So you will get a new instance of the same exe but this time running with the privileges of the provided account.

function lLogonAsAdmin()    
local cUser      := Space(60)
local cPwd       := Space(60)
local aSI        := AFill(Array(17),0)
local aPI        := AFill(Array(4),0)
local cWApp      := cSzAnsi2Wide(AppName(.F.)) 
local result     := .F.
aSI[1] := 68       
if !lLogOnDialog(@cUser,@cPwd) ; return .F. ; end 

cUser := cSzAnsi2Wide(cUser)
cPwd  := cSzAnsi2Wide(cPwd)

result := ( @AdvApi32:CreateProcessWithLogonW(cUser,cSzAnsi2Wide(&amp;quot;.&amp;quot;),cPwd,1,cWApp,0,0,0,0,aSI,@aPI) != 0 )
if result 
   if aPI[1] != 0 ; @kernel32:CloseHandle(aPI[1]) ; end
   if aPI[2] != 0 ; @kernel32:CloseHandle(aPI[2]) ; end     
end
return result&lt;/pre&gt;</content></entry><entry><title type="text">Taskbar Icon</title><link rel="alternate" href="http://news.xb2.net/ot4xb.examples/6/Taskbar+Icon.html" type="text/html" /><id>http://news.xb2.net/ot4xb.examples/6/Taskbar+Icon.html</id><published>2008-10-08T11:40:24Z</published><updated>2008-10-08T11:40:24Z</updated><author><name>Pablo Botella</name><email>pb_no_spam_@_remove_all_betwen_underscores_xbwin.com</email></author><content type="html">&lt;pre&gt;#include &amp;quot;ot4xb.ch&amp;quot;
// ---------------------------------------------------------------------------
#define IDI_APPLICATION     32512
#define IDI_HAND            32513
#define IDI_QUESTION        32514
#define IDI_EXCLAMATION     32515
#define IDI_ASTERISK        32516
#define IDI_WINLOGO         32517
// ---------------------------------------------------------------------------
#define NIIF_NONE       0x00000000
#define NIIF_INFO       0x00000001
#define NIIF_WARNING    0x00000002
#define NIIF_ERROR      0x00000003
// ---------------------------------------------------------------------------
proc dbesys ; return
// ---------------------------------------------------------------------------
proc main()
local nKey := 0
local oTbi := TNotifyIcon():New(0,IDI_EXCLAMATION, &amp;quot;Using a system icon&amp;quot;)
local oCrt := SetAppWindow()

oTbi:bOnContextMenu  := {|| QOut(&amp;quot;OnContextMenu&amp;quot;)}
oTbi:bOnLDblClick    := {|| QOut(&amp;quot;OnLDblClick  &amp;quot;)}
oTbi:bOnLClick       := {|| QOut(&amp;quot;OnLClick     &amp;quot;)}
oTbi:bOnMouseMove    := {|| QOut(&amp;quot;OnMouseMove  &amp;quot;)}


? &amp;quot;Press a key to show icon from system in the taskbar ... &amp;quot; ; Inkey(0)
oTbi:Show()
oTbi:ShowInfo(,&amp;quot;From System&amp;quot;,1)

? &amp;quot;Press a key to show icon from file in the taskbar ... &amp;quot; ; Inkey(0)
oTbi:Modify(&amp;quot;0.ico&amp;quot;,NIL,&amp;quot;Using a Icon From File&amp;quot;)
oTbi:ShowInfo(,&amp;quot;From File&amp;quot;,2)

? &amp;quot;Press a key to show icon from EXE resource in the taskbar ... &amp;quot; ; Inkey(0)
oTbi:Modify(NIL,2,&amp;quot;Using a Icon From Resource in EXE&amp;quot;)
oTbi:ShowInfo(,&amp;quot;From resource in EXE&amp;quot;,3)

? &amp;quot;Press a key to show icon from DLL resource in the taskbar ... &amp;quot; ; Inkey(0)
oTbi:Modify(&amp;quot;test.dll&amp;quot;,3,&amp;quot;Using a Icon From resource in DLL&amp;quot;)
if oTbi:ShowInfo(,&amp;quot;From resource in DLL&amp;quot;,1)
   ? &amp;quot;Press a key to hide the ballon ... &amp;quot; ; inkey(0)
   oTbi:HideInfo()
end
? &amp;quot;Press a key to start the icon animation&amp;quot; ; Inkey(0)
oTbi:StartAnimation({{,1,&amp;quot;&amp;quot;},{,2},{,3},{,4},{,5},{,6},{,7},{,8},{,9},{,10}}, 200 )

? &amp;quot;Press a key to stop the icon animation&amp;quot; ; Inkey(0)
oTbi:StopAnimation()

? &amp;quot;Press ESC to close ... &amp;quot; ; while (nKey := Inkey(0)) != 27 ; end
oTbi:Destroy()
return&lt;/pre&gt;</content></entry></feed>