API CALLS

Share your advanced PureBasic knowledge/code with the community.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by ricardo.

Since must of us use API CALLS i suggest to share all the API calls that every one found, it could be very instructive and give big help to each other

Thanks

Ricardo
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by blueb.

Ricardo...I'm not sure what you mean.

All the WinAPI calls are available as a help file that works with PB.

e.g.

Code: Select all

Procedure.l ScreenWidth ()
   ProcedureReturn GetSystemMetrics_(#SM_CYSCREEN)
EndProcedure
The GetSystemMetrics command is a WinAPI call.
Note that you must use the '_' in PureBasic.

There is a Win32.hlp (~ 8 megs) file that can be downloaded from the Internet that is available from:
http://www.borland.com/devsupport/delphi/downloads/

(It's located at the bottom of a *very* long page of downloads)

Download this file, unzip it and place it in:
c:\PUREBASIC\Help

After this simply place your cursor on the GetSystemMetrics word and press the 'F1' (Help) key. The Win API help for that function will be displayed.

Hope that helps,
--Bob
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by ricardo.

Yes Bob, i know it and it did have this Win32, but maybe some of us don't know exactly how to use every API CALL, thats my point, when some of us learn how to use some specific API we can share this to others.

One example is the RichEdit Example that i made.
Other example:

Code: Select all

;This example GET/SET the priority
;read your WIN32.HELP for more info

hProcess = GetCurrentProcess_()
ret = GetPriorityClass_(hProcess)
MessageRequester("GetPriority",Str(ret),0)
SetPriorityClass_(hProcess, #REALTIME_PRIORITY_CLASS)
ret = GetPriorityClass_(hProcess)
MessageRequester("NewPriority",Str(ret),0)

And one question:


This fails because i need to send the address of SECURITY_ATTRIBUTES structure that are declared at win32,inc. How can i get the address of this structure?
I know where to find the code, im looking for the address in memory:

Code: Select all

Dim security.SECURITY_ATTRIBUTES(1)

Chwn = CreateConsoleScreenBuffer_(#GENERIC_READ,#FILE_SHARE_READ,SECURITY_ATTRIBUTES,#CONSOLE_TEXTMODE_BUFFER,0)
messagerequester("",str(Chwn),0); gives -1
Thanks
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

API CALLS

Post by BackupUser »

Restored from previous forum. Originally posted by ricardo.


EDIT MULTILINE:

Tthos code will create a Edit with Multiline attribute

Code: Select all

class$ = "Class1"                        ;this is the class of the PB forms
exe$ = "app"                             ;the name of your application
result = FindWindow_(class$,exe$)
hwn = CreateWindowEx_(#WS_EX_CLIENTEDGE ,"edit","EditMultile Example",#WS_CHILD | #WS_VISIBLE | #ES_MULTILINE |#ES_AUTOHSCROLL,40,40,200,250,result,1,0,0)

;------------------------------------------------------------------------------
In the other hand, im trying to change the attributes of the StringGadget with this lines, but something dosent works:

Code: Select all

clase$ = "Edit"   
name$ = "edit"
RESULTADO = FindWindowEx_(RESULTADO,0,clase$,name$)
CURSTYLE = GetWindowLong_(RESULTADO,#GWL_STYLE)
CURSTYLE = CURSTYLE|#WS_CHILD | #WS_VISIBLE | #ES_MULTILINE|#ES_AUTOHSCROL
SetWindowLong_(RESULTADO,#GWL_STYLE,CURSTYLE)
Any idea?

Regards,

Ricardo
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by ricardo.

Sorry, i miss some lines in the code, but this is not why the example dosent works. Here is complete

Code: Select all

class$ = "Class1"                        ;this is the class of the PB forms
exe$ = "app"                             ;the name of your application
result = FindWindow_(class$,exe$)

clase$ = "Edit"                          ;Edit class
name$ = "edit"                           ;name of the gadget
RESULTADO = FindWindowEx_(result,0,clase$,name$)
CURSTYLE = GetWindowLong_(RESULTADO,#GWL_STYLE)
CURSTYLE = CURSTYLE|#WS_CHILD | #WS_VISIBLE | #ES_MULTILINE|#ES_AUTOHSCROL
SetWindowLong_(RESULTADO,#GWL_STYLE,CURSTYLE)
Any idea?

Regards,

Ricardo
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by blueb.

Ricardo,
The WinAPI call FindWindow requires that use use pointers to get the resulting handle to the window.

Therefore:

Code: Select all

class.s = "Class1" ;this is the class of the PB forms
exe.s = "IconTray.exe" ;the name of your application
result = FindWindow_(*class,*exe)   
;NOTE: The parameters above MUST be string pointers.
MessageRequester("Handle of Window", str(result), 0) ; I used an actual file name here to be sure I got a good result.
clase.s = "Edit" ; Edit class
name.s = "edit" ;name of the gadget
RESULTADO = FindWindowEx_( result, 0, *clase, *name)
MessageRequester("Handle of Window", str(RESULTADO), 0)  ;Since the gadget 'name' is not specific....expect a ZERO resultado
CURSTYLE = GetWindowLong_(RESULTADO, #GWL_STYLE)
CURSTYLE = CURSTYLE  &  #WS_CHILD | #WS_VISIBLE | #ES_MULTILINE | #ES_AUTOHSCROLL
SetWindowLong_(RESULTADO, #GWL_STYLE, CURSTYLE )
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by ricardo.

Hi, Bob !!

Did it works in that way? im gonna test it Bob,
its a little strange, because i use FindWindow and FindWindowEx with succes so many times (in PureBasic) just with variables, no pointers.


Per example, you can use it to move, resize, hide,etc any control (gadget) during moving time with out pointers.

Good work my friend : )

Ricardo Arias
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by blueb.


Ricardo,
I'm only going by the WinAPI declarations Help screen that says.

HWND FindWindow(
LPCTSTR lpClassName //pointer to class name
LPCTSTR lpWindowname //pointer to window name
);


Maybe PB doesn't need to, I don't know.

Regards,
--Bob
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by ricardo.

Hi Friend : )

Well, i think that we are usiing some pointer when we write

class$ = "Edit"
then Class$ is a pointer to a NULL terminated string, its exactly the same to write
*class$ = "Edit"

I have tested with the * addittion and it dont works.

Im trying to change the attributes of the StrinGadget to make it multiline capable... if soem one can help us

Thanks Bob !!

Ricardo Arias
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Mr.Skunk.

Try this :

class$ = "Edit"

and then to modify

pokes(@class$,"the new string")

Hope it helps

Mr Skunk

Mr Skunk's PureBasic Web Page
http://www.skunknet.fr.st
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Franco.

Hi folks,
here you can download a Win API reference (specially for VB)

http://www.vbapi.com/apiguide.zip

There is no SEARCH function in this forum,
so I can't say if somebody mentioned it before.
API calls for Win2000 are included.
Hope this is helpful.




Have a nice day...
Franco
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Mr.Skunk.

HI

there is a search in that forum, look at the top of the page (just before FAQ)


Mr Skunk

Mr Skunk's PureBasic Web Page
http://www.skunknet.fr.st
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Franco.

Thanks Mr.Skunk to help a blind man over the street



Have a nice day...
Franco
Post Reply