PDA

View Full Version : New Data Link Library



peter
19-11-2013, 10:22
Hi Eros,


New Dll to test. Runs with ThinBasic 1.9.11.0 without intricacies.
But one mysterious thing happens with an Api declaration.


It is TextOut, the screen coordinates of this function are not correctly shown.
And SetBkColor does not work as expected !


Uses "ui"
#INCLUDE "abc.inc"


DWord hdc, hwnd
hwnd= Canvas_Window("ThinBasic",xMiddle(320),yMiddle(240),320,240)
Canvas_Attach(hwnd,0,%TRUE)
hdc = Canvas_GetDC()


SetHandleDC hdc
SetFont 12,24,%FW_BOLD,""
SetColorKey Rgb(255,255,255)


Dim a(8) As Byte
Long mem, h, x, z, b1, b2
String s


s="PETER"


b1 = LoadIcon "icon/acorn.ico"
b2 = LoadBmp "bmp/panorama.bmp",30
mem= NewMemory (20)


h= OpenFile "abc_test.txt"
WriteByte h,s,5
CloseFile h

h= OpenFile "abc_test.txt"
ReadByte h,s,5
CloseFile h


bPoke mem,0,80
bPoke mem,1,69
bPoke mem,2,84
bPoke mem,3,69
bPoke mem,4,82

a(1) = bPeek mem,0
a(2) = bPeek mem,1
a(3) = bPeek mem,2
a(4) = bPeek mem,3
a(5) = bPeek mem,4


PlayWav "scream"

While IsWindow(hwnd)
If GetAsyncKeyState(27) Then Exit While
Canvas_Clear(Rgb(0,0,255))

For x=1 To 5
Say(x*16-16,80,Chr$(a(x)),Rgb(255,255,255))
Next


Say(100,20," BANANA", Rgb(255,255,0))
DrawIcon b1,100,110,128,128,0
DrawBmp b2,135,50,50,50,z

z +=1
If z=30 Then z=0
Canvas_Redraw
SetFps (60)
Wend


KillMemory(mem)
FreeGraphic
Canvas_Window End


'Does not work here! Coordinates show a wrong behaviour.
Function Say(ix As Long, iy As Long, txt As String, col As Long) As Long
SetBkMode hdc,1
SetBkColor hdc, 255*256 'green, but doesn't work!
SetTextColor hdc, col
TextOut hdc,ix,iy,txt,Len(txt)
End Function

ErosOlmi
19-11-2013, 18:11
Peter,

I will have a look this evening when home.

Ciao
Eros

ErosOlmi
19-11-2013, 23:09
Peter,

your ABC.DLL is working fine here: no GPF of any case like I had in the past.

Regarding the problem on TextOut I was reading Microsoft documentation at http://msdn.microsoft.com/en-us/library/windows/desktop/dd145133(v=vs.85).aspx and in Remarks session there is the following: "By default, the current position is not used or updated by this function". So this let me think you need to position the cursor before using it. Something like the following:


Function Say(ix As Long, iy As Long, txt As String, col As Long) As Long
'SetBkMode hdc, 1
'SetBkColor hdc, col'255*256 'green, but doesn't work!
'SetTextColor hdc, col
'MoveToEx hdc, ix, iy, 0
Canvas_SetPos ix, iy
Canvas_Color( col, -2)
TextOut hdc, 0, 0, txt, Len(txt)
End Function




Let me know.
Ciao
Eros

peter
20-11-2013, 00:05
Thank you Eros,

This works fine for me and helps me at the moment.
There is a DrawText Function, inside the abc.dll, what shows the same behaviour.


I will make some experiments with the TextOut Windows Api.
May be that I take the Api DrawText.


Anyway, good job by you.


Here is a tiny AlphaBlending test.



Uses "ui"
#INCLUDE "abc.inc"


DWord hdc, hwnd
hwnd = Canvas_Window("ThinBasic",xMiddle(640),yMiddle(480),640,480)
Canvas_Attach(hwnd,0,%TRUE)
hdc = Canvas_GetDC()
SetHandleDC hdc
SetFont 24,24,%FW_BOLD,""


Long a1, i=1
Single x
a1= LoadBmp "bmp/bild1.bmp",1


While IsWindow(hwnd) And KeyDown(27)=0
Canvas_Clear Rgb(255,255,255)
AlphaBlend a1,0,0,640,480,x


If i=1 And x <255 Then
x += 0.8
Else
i=2
End If


If i=2 And x >0 Then
x -= 0.8
Else
i=1
End If

SetText 80,10,"FADE IN & FADE OUT",255*256

Canvas_Redraw
Wend
FreeGraphic
Canvas_Window End


Sub SetText(ix As Long, iy As Long, txt As String, col As Long)
Canvas_SetPos ix, iy
Canvas_Color( col, -2)
TextOut hdc, 0, 0, txt, Len(txt)
End Sub