Tag Archive: winapi

get environment variables

In “Global Map” einfügen:
————————-

MODULE('Windows.DLL')
  GetEnvironmentVariableA (*CSTRING, *CSTRING, ULONG),ULONG,PASCAL,RAW
END
GetEnv (STRING),STRING

In “Programm Precedures” einfügen:
———————————-

GetEnv PROCEDURE(str)
cres CSTRING(201)
cstr CSTRING(201)
len LONG
  CODE
  cstr = clip(str)
  len = GetEnvironmentVariableA (cstr, cres, size(cres)-1)
  return clip(cres)

Dann kann man bequem so einiges auslesen. Z.Bp. GetEnv(“OS”) oder “COMPUTERNAME”, “USERNAME”, “TEMP”.
Ich benutze dies vor allen Dingen im den “Global Properties” in INI-File in use = “Other” und dann !GetEnv(‘USERPROFILE’) & ‘\Anwendungsdaten\xxx.ini’
(xxx für den Programm-Namen) Damit hat jeder User am Rechner seine eigene Settings für das Programm.

Viel Erfolg
Michael Ziegler

get application icon

Module('WINAPI')
  FindExecutable(LONG,LONG,LONG),LONG,PASCAL,RAW,Name('FindExecutableA')
END
....

DATA
l:Executable         CSTRING(255)
l:FileName           CSTRING(255)

CODE
  ...
  l:FileName = 'test.txt'
  ret# = FindExecutable(address(l:FileName),0 , address(l:Executable))
  if l:Executable then
    ?Image1{Prop:Text} = l:Executable & '[]'
  else
    ?Image1{Prop:Text} = ICON:Hand  ! no icon found
  end
 ...

time since last reboot

Try GetTickCount: – You can use this to tell how long the computer has been running – From there you can calculate when the last reboot happened.

http://msdn.microsoft.com/library/en-us/sysinfo/base/gettickcount.asp

GetTickCount(),Long,PASCAL,proc,NAME('GetTickCount'),Dll(dll_mode)

local               group, pre(loc)
UpTime                long
UpDays                long
UpHours               long
UpMins                long
                    end


    loc:UpTime = GetTickCount()
    loc:UpDays = (((loc:UpTime / 1000) / 60) / 60) / 24
    loc:UpHours = (((loc:UpTime / 1000) / 60) / 60) % 24
    loc:UpMins = (((loc:UpTime / 1000) / 60) % 60)

Can display something like this:

 ' Up_Time = ' & loc:UpDays & 'd ' & loc:UpHours & 'h ' & format(loc:UpMins, @N02) & 'm'

Cheers
Jono Woodhouse

use the entire screen

Globall embed: Inside The Global Map

Module('User32.dll')
    SetWindowPos(LONG,LONG,SIGNED,SIGNED,SIGNED,SIGNED,LONG),BOOL,PASCAL
    GetWindowLong(LONG,SIGNED),LONG,PASCAL,NAME('GetWindowLongA')
    SetWindowLong(LONG,SIGNED,LONG),LONG,PASCAL,NAME('SetWindowLongA')
End

In INIT of the frame right after opening the window:

OrgStyle# = GetWindowLong(0{PROP:Handle},-16)
OrgStyle# = BXOR(OrgStyle#,0C00000H)
NewStyle# = SetWindowLong(0{PROP:Handle},-16,OrgStyle#)
r# = SetWindowPos(0{PROP:Handle},0,0,,,24h)

To find Max values i guess you can first do a 0{PROP:Maximized} = True and use the API GetWindowPos to read the Window size. Dont use
GetPosition(0,X,Y,W,H) because if you uses toolbars the WindowSize is redused. Using GetWindowPos will give you the correct size.


Ole-Morten Heien

——————————————————————————
Question:

> With a standard Clarion application (app frame, etc), how do I get a
> procedure to use the entire screen, not just the app window?
>
> This is for a POS application which I want to appear as a normal
> Windows application, EXCEPT when it it running as a cash register.
> The cash register procedure should use the entire screen.
>
> Can’t seem to find the right combination of settings, or whatever.

get logical drives

!------------------------------------------------------------------------------------------
! inside the global map
!------------------------------------------------------------------------------------------
Module('WINAPI')
   GetLogicalDrives(),ULONG,PASCAL
   GetLogicalDriveStrings(LONG,*CSTRING),LONG,PASCAL,RAW,NAME('GetLogicalDriveStringsA')
   GetDriveType(*CSTRING),UNSIGNED,PASCAL,RAW,NAME('GetDriveTypeA')
END

!------------------------------------------------------------------------------------------
! DATA
!------------------------------------------------------------------------------------------
qDrive               QUEUE,PRE(qDrive)
Drive                CSTRING(5)
qDrive:Desciption    CSTRING(40)
Type                 BYTE
                     END
l:DrivesCString      CSTRING(200)
l:DrivesLen          LONG

!------------------------------------------------------------------------------------------
! CODE
!------------------------------------------------------------------------------------------
   l:DrivesDWORD   = GetLogicalDrives()
   l:DrivesLen     = 200
   l:DrivesCString = '<0>{200}'
   l:DrivesString  = ''
   clear(qDrive)
   free(qDrive)
   ret# = GetLogicalDriveStrings(l:DrivesLen,l:DrivesCString)
   loop i# = 1 to 200
     if val(l:DrivesCString[i#]) > 20 then
       qDrive:Drive = qDrive:Drive & l:DrivesCString[i#]
     else
       if qDrive:Drive then
         qDrive:Type = GetDriveType(qDrive:Drive)
         case qDrive:Type
           of 0;  qDrive:Desciption = 'The drive type cannot be determined.'
           of 1;  qDrive:Desciption = 'The root directory does not exist.'
           of 2;  qDrive:Desciption = 'removable drive'
           of 3;  qDrive:Desciption = 'fixed drive'
           of 4;  qDrive:Desciption = 'network drive'
           of 5;  qDrive:Desciption = 'CDROM drive'
           of 6;  qDrive:Desciption = 'ramdisk'
         end
         add(qDrive)
         clear(qDrive)
       end
     end
   end

play wav file

! inside the global map
Module('WINAPI')
   SndPlaySound(*LPCSTR,UNSIGNED),BOOL,PROC,PASCAL,RAW,NAME('SndPlaySoundA')
END

! data
l:SoundFile cstring(255)

! code
  l:SoundFile = 'test.wav'
  SndPlaySound(l:SoundFile,1)  ! play sound and return
  SndPlaySound(l:SoundFile,0)  ! play sound and wait

get computername and user

! inside the global Map
Module('WINAPI')
   GetComputerName(*CSTRING,*ULONG),SIGNED,RAW,PASCAL,NAME('GetComputerNameA')
   WNetGetUser(ULONG,*CSTRING,*ULONG),LONG,RAW,PASCAL,NAME('WNetGetUserA')
END

! data
WIN:Computername CSTRING(32)
WIN:Computerlen  ULONG
WIN:User         CSTRING(32)
WIN:Userlen      ULONG
WIN:Net          ULONG

! code
  WIN:Computerlen = 32
  WIN:Userlen     = 32
  ret# = GetComputerName(WIN:ComputerName,WIN:Computerlen)  ! get the computername
  ret# = WNetGetUser(WIN:Net,WIN:User,WIN:Userlen)          ! get the current user

enumerate windows printers

!--------------------------------------------------------------------------------------------
! Ralf Schoeffler http://www.schoeffler.biz mailto:info@schoeffler.biz
!-----------------------------snipp ---------------------------------------------------------
! inside the global map

MODULE('WINAPI')

EnumPrintersA(ULONG,*CSTRING,ULONG,*BYTE,ULONG,*ULONG,*ULONG),BOOL,PASCAL,RAW
END

!--------------------------------------------------------------------------------------------
!DATA
flag         ULONG
pname        CSTRING(255)
level        ULONG
cbBuf        ULONG
cbBuffer     STRING(65536)
pcbNeed      ULONG
pcRetrun     ULONG
pPrinterEnum BYTE OVER(cbBuffer)
ret          LONG
zeiger       LONG,DIM(16384) OVER(cbBuffer)
tstr         STRING(250)
tbyte        BYTE
pPrinter     Queue
Name           STRING(32)
Port           STRING(60)
SPrinter       BYTE
END


!--------------------------------------------------------------------------------------------
!CODE
flag      = 2                    ! PRINTER_ENUM_LOCAL
pname     = ''                   ! Cstring(255)
level     = 2                    ! Printer_Info_2
cbBuf     = 65536                ! Size of cbpBuffer
pcbNeed   = 0                    ! Structur as bytes
pcRetrun  = 0                    ! count of printers
ret       =
EnumPrintersA(flag,pname,level,pPrinterEnum,cbBuf,pcbNeed,pcRetrun)
loop p# = 0 to pcRetrun - 1
   clear(pPrinter)
   !-------------------------------------------------------------------------------------------
   ! printername
   !-------------------------------------------------------------------------------------------
   tstr = ''
   loop i# = 0 to 32
     peek(zeiger[2+(p#*21)]+i#, tbyte)
     if tbyte = 0 then break end
     tstr[i#+1] = chr(tbyte)
   end
   pPrinter:Name = tstr
   !-------------------------------------------------------------------------------------------
   ! Standard Printer
   !-------------------------------------------------------------------------------------------
   if clip(pPrinter:Name) = clip(PRINTER{PROPPRINT:Device}) then
     pPrinter:SPrinter = 1
   end
   !-------------------------------------------------------------------------------------------
   ! Printerport
   !-------------------------------------------------------------------------------------------
   tstr = ''
   loop i#=0 to 32
     peek(zeiger[4+(p#*21)]+i#,tbyte)
     if tbyte=0 then break end
     tstr[i#+1]=chr(tbyte)
   end
   pPrinter:Port = tstr
   pPrinters = pPrinter
   add(pPrinters)
end !loop
!-----------------------------snipp ---------------------------------------------------------

use winsock

This article only contains the equates and prototypes for the winsock api calls. The equates are at the top of the article, and the prototypes are at the bottom.

Courtesy of Bill Knopf, LEADS Software Group.

Equates for Winsock:

!---------------------- WINSOCK EQUATES ----------------------
SOCK_STREAM     EQUATE(1)
SOCK_DGRAM      EQUATE(2)

INVALID_SOCKET  EQUATE(-1)
SOL_SOCKET      EQUATE(0000ffffh)
IPPROTO_TCP     EQUATE(6)
SOCKET_ERROR    EQUATE(-1)

AF_INET         EQUATE(2)               !TCP/IP Address Type
AF_IPX          EQUATE(6)               !IPX/SPX Address Type
INADDR_ANY      EQUATE(0)
INADDR_BROADCAST EQUATE(-1)             !Broadcast Address

SO_DEBUG        EQUATE(0001h)
SO_ACCEPTCONN   EQUATE(0002h)
SO_REUSEADDR    EQUATE(0004h)
SO_DONTROUTE    EQUATE(0010h)
SO_BROADCAST    EQUATE(0020h)
SO_USELOOPBACK  EQUATE(0040h)
SO_LINGER       EQUATE(0080h)
SO_OOBINLINE    EQUATE(0100h)
SO_SNDBUF       EQUATE(1001h)
SO_RCVBUF       EQUATE(1002h)
SO_SNDLOWAT     EQUATE(1003h)
SO_RCVLOWAT     EQUATE(1004h)
SO_SNDTIMEO     EQUATE(1005h)
SO_RCVTIMEO     EQUATE(1006h)
SO_ERROR        EQUATE(1007h)
SO_TYPE         EQUATE(1008h)

TCP_NODELAY     EQUATE(0001h)

SOMAXCONN       EQUATE(5)

MSG_OOB         EQUATE(1h)
MSG_PEEK        EQUATE(2h)
MSG_DONTROUTE   EQUATE(4h)
MSG_MAXIOVLEN   EQUATE(16)

MAXGETHOSTSTRUCT EQUATE(1024)

FD_READ      EQUATE(01h)
FD_WRITE     EQUATE(02h)
FD_OOB       EQUATE(04h)
FD_ACCEPT    EQUATE(08h)
FD_CONNECT   EQUATE(10h)
FD_CLOSE     EQUATE(20h)

WSABASEERR              EQUATE(10000)

WSAEINTR                EQUATE(WSABASEERR+4)
WSAEBADF                EQUATE(WSABASEERR+9)
WSAEACCES               EQUATE(WSABASEERR+13)
WSAEFAULT               EQUATE(WSABASEERR+14)
WSAEINVAL               EQUATE(WSABASEERR+22)
WSAEMFILE               EQUATE(WSABASEERR+24)

WSAEWOULDBLOCK          EQUATE(WSABASEERR+35)
WSAEINPROGRESS          EQUATE(WSABASEERR+36)
WSAEALREADY             EQUATE(WSABASEERR+37)
WSAENOTSOCK             EQUATE(WSABASEERR+38)
WSAEDESTADDRREQ         EQUATE(WSABASEERR+39)
WSAEMSGSIZE             EQUATE(WSABASEERR+40)
WSAEPROTOTYPE           EQUATE(WSABASEERR+41)
WSAENOPROTOOPT          EQUATE(WSABASEERR+42)
WSAEPROTONOSUPPORT      EQUATE(WSABASEERR+43)
WSAESOCKTNOSUPPORT      EQUATE(WSABASEERR+44)
WSAEOPNOTSUPP           EQUATE(WSABASEERR+45)
WSAEPFNOSUPPORT         EQUATE(WSABASEERR+46)
WSAEAFNOSUPPORT         EQUATE(WSABASEERR+47)
WSAEADDRINUSE           EQUATE(WSABASEERR+48)
WSAEADDRNOTAVAIL        EQUATE(WSABASEERR+49)
WSAENETDOWN             EQUATE(WSABASEERR+50)
WSAENETUNREACH          EQUATE(WSABASEERR+51)
WSAENETRESET            EQUATE(WSABASEERR+52)
WSAECONNABORTED         EQUATE(WSABASEERR+53)
WSAECONNRESET           EQUATE(WSABASEERR+54)
WSAENOBUFS              EQUATE(WSABASEERR+55)
WSAEISCONN              EQUATE(WSABASEERR+56)
WSAENOTCONN             EQUATE(WSABASEERR+57)
WSAESHUTDOWN            EQUATE(WSABASEERR+58)
WSAETOOMANYREFS         EQUATE(WSABASEERR+59)
WSAETIMEDOUT            EQUATE(WSABASEERR+60)
WSAECONNREFUSED         EQUATE(WSABASEERR+61)
WSAELOOP                EQUATE(WSABASEERR+62)
WSAENAMETOOLONG         EQUATE(WSABASEERR+63)
WSAEHOSTDOWN            EQUATE(WSABASEERR+64)
WSAEHOSTUNREACH         EQUATE(WSABASEERR+65)
WSAENOTEMPTY            EQUATE(WSABASEERR+66)
WSAEPROCLIM             EQUATE(WSABASEERR+67)
WSAEUSERS               EQUATE(WSABASEERR+68)
WSAEDQUOT               EQUATE(WSABASEERR+69)
WSAESTALE               EQUATE(WSABASEERR+70)
WSAEREMOTE              EQUATE(WSABASEERR+71)

WSASYSNOTREADY          EQUATE(WSABASEERR+91)
WSAVERNOTSUPPORTED      EQUATE(WSABASEERR+92)
WSANOTINITIALISED       EQUATE(WSABASEERR+93)
WSANOSOCKETS            EQUATE(WSABASEERR+94)

WSAHOST_NOT_FOUND       EQUATE(WSABASEERR+1001)
HOST_NOT_FOUND          EQUATE(WSAHOST_NOT_FOUND)
WSATRY_AGAIN            EQUATE(WSABASEERR+1002)
TRY_AGAIN               EQUATE(WSATRY_AGAIN)
WSANO_RECOVERY          EQUATE(WSABASEERR+1003)
NO_RECOVERY             EQUATE(WSANO_RECOVERY)
WSANO_DATA              EQUATE(WSABASEERR+1004)
NO_DATA                 EQUATE(WSANO_DATA)

WSANO_ADDRESS           EQUATE(WSANO_DATA)
NO_ADDRESS              EQUATE(WSANO_ADDRESS)


SOCKET          EQUATE(UNSIGNED)

WSAData         GROUP,TYPE
wVersion          SHORT
wHighVersion      SHORT
szDescription     CSTRING(256)
szSystemStatus    CSTRING(128)
iMaxSockets       USHORT
iMaxUdpDg         USHORT
lpVendorInfo      CSTRING(30)
                END

in_addr   GROUP,TYPE
S_addr        ULONG
S_un_b        GROUP,OVER(S_addr)
s_b1            BYTE
s_b2            BYTE
s_b3            BYTE
s_b4            BYTE
              END

S_un_w        GROUP,OVER(S_addr)
s_w1            USHORT
s_w2            USHORT
              END
          END

hostent  GROUP,TYPE
h_name      CSTRING(35)
h_aliases   CSTRING(35)
h_addrtype  SHORT
h_length    SHORT
h_IPStr     CSTRING(20)
         END

servent  GROUP,TYPE
s_name     CSTRING(15)
s_alias    CSTRING(20)
s_port     SHORT
s_proto    CSTRING(3)
         END

sockaddr       GROUP,TYPE
family           SHORT
port             USHORT
addr             ULONG          !LIKE(in_addr)
zero             CSTRING(16)
               END

sockproto    GROUP,TYPE
sp_family      USHORT
sp_protocol    USHORT
             END

linger       GROUP,TYPE
l_onoff        USHORT
l_linger       USHORT
             END


!-------------------- WINSOCK PROTOTYPES ---------------------

 MODULE('WINSOCK.DLL')
   WSAStartup(UNSIGNED,LONG),SIGNED,PASCAL,NAME('WSASTARTUP'),DLL(dll_mode)
   WSACleanup(),SIGNED,PASCAL,NAME('WSACLEANUP'),DLL(dll_mode)
   htons(USHORT),USHORT,PASCAL,NAME('HTONS'),DLL(dll_mode)
   ntohs(USHORT),USHORT,PASCAL,NAME('NTOHS'),DLL(dll_mode)
   htonl(ULONG),ULONG,PASCAL,NAME('HTONL'),DLL(dll_mode)
   ntohl(ULONG),ULONG,PASCAL,NAME('NTOHL'),DLL(dll_mode)
   inet_addr(*CSTRING),ULONG,PASCAL,RAW,NAME('INET_ADDR'),DLL(dll_mode)
   inet_ntoa(ULONG),CSTRING,PASCAL,RAW,NAME('INET_NTOA'),DLL(dll_mode)
   getservbyname(*CSTRING,*CSTRING),LONG,RAW,PASCAL,NAME('GETSERVBYNAME'),DLL(dll_mode)
   getservbyport(SIGNED,*CSTRING),LONG,RAW,PASCAL,NAME('GETSERVBYPORT'),DLL(dll_mode)
   gethostname(*CSTRING,SIGNED),SIGNED,RAW,PASCAL,NAME('GETHOSTNAME'),DLL(dll_mode),PROC
   gethostbyname(*CSTRING),LONG,PASCAL,RAW,NAME('GETHOSTBYNAME'),DLL(dll_mode)
   WSAGetLastError(),SIGNED,RAW,PASCAL,NAME('WSAGETLASTERROR'),DLL(dll_mode)
   ssocket(SIGNED,SIGNED,SIGNED),UNSIGNED,PASCAL,NAME('SOCKET'),DLL(dll_mode)
   closesocket(UNSIGNED),SIGNED,PASCAL,NAME('CLOSESOCKET'),DLL(dll_mode)
   sbind(UNSIGNED,LONG,SIGNED),SIGNED,RAW,PASCAL,NAME('BIND'),DLL(dll_mode)
   getsockname(UNSIGNED,*sockaddr,*SIGNED),SIGNED,RAW,PASCAL,NAME('GETSOCKNAME'),DLL(dll_mode)
   getpeername(UNSIGNED,*sockaddr,*SIGNED),SIGNED,RAW,PASCAL, NAME('GETPEERNAME'),DLL(dll_mode)
   getsockopt(UNSIGNED,SIGNED,SIGNED,*CSTRING,*SIGNED),SIGNED,RAW,PASCAL,NAME('GETSOCKOPT'),DLL(dll_mode)
   setsockopt(UNSIGNED,SIGNED,SIGNED,LONG,SIGNED),SIGNED,RAW,PASCAL,NAME('SETSOCKOPT'),DLL(dll_mode)
   sshutdown(UNSIGNED,SIGNED),SIGNED,PASCAL,NAME('SHUTDOWN'),DLL(dll_mode)
   ioctlsocket(UNSIGNED,LONG,*ULONG),SIGNED,RAW,PASCAL,NAME('IOCTLSOCKET'),DLL(dll_mode)
   listen(UNSIGNED,SIGNED),SIGNED,PASCAL,NAME('LISTEN'),DLL(dll_mode)
   saccept(UNSIGNED,*sockaddr,*SIGNED),UNSIGNED,RAW,PASCAL,NAME('ACCEPT'),DLL(dll_mode)
   connect(UNSIGNED,*sockaddr,SIGNED),SIGNED,RAW,PASCAL,NAME('CONNECT'),DLL(dll_mode)
   ssend(UNSIGNED,LONG,SIGNED,SIGNED),SIGNED,RAW,PASCAL,NAME('SEND')
   recv(UNSIGNED,LONG,SIGNED,SIGNED),SIGNED,RAW,PASCAL, NAME('RECV'),DLL(dll_mode)
   sendto(UNSIGNED,LONG,SIGNED,SIGNED,LONG,SIGNED),SIGNED,RAW,PASCAL,NAME('SENDTO'),DLL(dll_mode)
   recvfrom(UNSIGNED,LONG,SIGNED,SIGNED,LONG,LONG),SIGNED,RAW,PASCAL,NAME('RECVFROM'),DLL(dll_mode)
   WSAAsyncgethostbyname(HANDLE,UNSIGNED,*CSTRING,*CSTRING,SIGNED), HANDLE,RAW,PASCAL,NAME('WSAASYNCGETHOSTBYNAME'),DLL(dll_mode)
   WSAAsyncgethostbyaddr(HANDLE,UNSIGNED,*CSTRING,SIGNED,SIGNED,*CSTRING,SIGNED),HANDLE,RAW,PASCAL,NAME('WSAASYNCGETHOSTBYADDR'),DLL(dll_mode)
   WSAAsyncSelect(UNSIGNED,HANDLE,UNSIGNED,LONG),SIGNED,PASCAL,NAME('WSAASYNCSELECT'),DLL(dll_mode)
 END

play mp3 file

This is what i do :
—–

After global includes:
Include('Winequ.clw')

In Global Map:
Module('Window's API')

MciGetErrorString(ULONG,*CSTRING,USHORT),SHORT,PASCAL,RAW,PROC,NAME('MciGetErrorStringA')

MciSendString(*CSTRING,*CSTRING,USHORT,USHORT),ULONG,PASCAL,RAW,PROC,NAME('MciSendStringA')
End

In Global Datas :
MciChaineRequise   Cstring(128)
MciValeurRetourne  Cstring(128)
MciNumeroErreur    Long
MciChaineErreur    Cstring(128)
FichierJoue        String(255)

Embed Accepted 'Play':
FichierJoue = 'C:\TestMp3\MyFile.Mp3'
MciChaineRequise = 'open mpegvideo!' & Clip(FichierJoue) &' alias Mp3' ; Do JouerMci
MciChaineRequise = 'play Mp3' ; Do JouerMci

Embed Accepted 'Stop' :
MciChaineRequise = 'stop Mp3'  ; Do JouerMci
MciChaineRequise = 'close Mp3' ; Do JouerMci

Procedure Routine:
JouerMci Routine
  Clear(MciValeurRetourne)
  Clear(MciNumeroErreur)
  Clear(MciChaineErreur)
  MciSendString(MciChaineRequise,MciValeurRetourne,128,0)
  MciGetErrorString(MciNumeroErreur,MciChaineErreur,128)

—-
For info, use this before play another file :
MciChaineRequise = ‘status Mp3 mode’ ; Do JouerMci

HTH. Eric