October 29, 2025, 01:55:43 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


DrawText snippet

Started by RitchieF, March 09, 2010, 11:07:05 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

RitchieF

Hi all,

found a code snippet at the link in the snippet and tried to convert to EB. But with my limited knowlegde I don't succeed.

'This code snippet shows how to draw a rotated text on a form.
'
'Written by Nir Sofer
'
'http://nirsoft.mirrorz.com
$include "windows.inc"

DEF hdc as INT
DEF lf As LOGFONT
   
DIALOG d1

CREATEDIALOG d1,0,0,600,350,@CAPTION|@SYSMENU|@BORDER,0,"Drawtext Test",&dialoghandler

DOMODAL d1
releasehdc d1,hdc
END
   
WAITUNTIL d1 = 0

SUB dialoghandler
SELECT @MESSAGE
    CASE @IDINITDIALOG
        CENTERWINDOW d1
Form_Paint()
    CASE @IDCLOSEWINDOW
        CLOSEDIALOG d1,@IDOK
ENDSELECT

ENDSUB

SUB GetFont(hdc As INT, Angle As uint)
    'Get the current HFONT handle
hFont = _GetCurrentObject(hdc, OBJ_FONT)
    'Retrieve the LOGFONT structure from the font handle.
    _GetObject (hFont, Len(lf), lf)
    'Change the font angle
    lf.lfEscapement = Int(Angle * 10)
    lf.lfOrientation = lf.lfEscapement
    'Create a new font
    GetFont = _CreateFontIndirect(lf)
EndSUB

SUB Form_Paint
STOP
DEF TextToDraw As String
    DEF X As INT
    DEF Y As INT
    DEF Angle As Double

'We must use a TrueType font, otherwise the text won't be rotated.
SETFONT d1, "Arial", 12, 700, @SFITALIC | 0x00FF0000
hdc = GETHDC(d1)
'GetFont(hdc,30)
TextToDraw = "http://nirsoft.cjb.net"
   
    X = 00: Y = 0
    'You can change the Angle value from 0 and up to 360 degrees in steps of 0.1 degrees.
    Angle = 0
    'Draw the text in 3 colors in order to create 3D effect.
    DrawText (hdc, TextToDraw, X-1, Y-1, Angle, RGB(0, 0, 255))
    DrawText (hdc, TextToDraw, X+1, Y+1, Angle, RGB(0, 0, 0))
    DrawText (hdc, TextToDraw, X, Y, Angle, RGB(0, 0, 192))
ENDSUB

Sub DrawText(hdc As INT, Text As String, X As INT, Y As INT, Angle As Double, _COLOR As double)
    Dim hFont As uint
    Dim hPrevFont As uint
   
    _SetTextColor (hdc, _COLOR)
    'Create a font for the rotated text
    hfont = SendMessage(d1, WM_GETFONT,0,0, hdc)

    'Select the font into the DC
    hPrevFont = _SelectObject(hdc, hFont)
    'Draw the text
    _TextOut (hdc, X, Y, Text, Len(Text))
    'Select back the previous font
    _SelectObject (hdc, hPrevFont)
    'destroy the font object.
    _DeleteObject (hFont)
End Sub


where do I make somethig ( or all ) wrong ?

Thanks for any help

Richard

LarryMc

Juggled things around a little.
Might not be the cleanest way to do it but it works.


$include "windows.inc"

DEF hdc as INT
DEF lf As LOGFONT
uint GFont   
DIALOG d1

CREATEDIALOG d1,0,0,600,350,@CAPTION|@SYSMENU|@BORDER,0,"Drawtext Test",&dialoghandler

DOMODAL d1

END
   
WAITUNTIL d1 = 0

SUB dialoghandler
SELECT @MESSAGE
CASE @IDINITDIALOG
CENTERWINDOW d1
SETFONT d1, "Arial", 12, 700, @SFITALIC | 0x00FF0000
case WM_SETFONT
GFont = @wParam
case @IDPAINT
Form_Paint()
releasehdc d1,hdc
CASE @IDCLOSEWINDOW
CLOSEDIALOG d1,@IDOK
ENDSELECT

ENDSUB

SUB GetFont(hdc As INT, Angle As uint)
    'Get the current HFONT handle
hFont = _GetCurrentObject(hdc, OBJ_FONT)
    'Retrieve the LOGFONT structure from the font handle.
    _GetObject (hFont, Len(lf), lf)
    'Change the font angle
    lf.lfEscapement =Int(Angle * 10)
    lf.lfOrientation = lf.lfEscapement
    'Create a new font
    GFont = _CreateFontIndirect(lf)
EndSUB

SUB Form_Paint
STOP
DEF TextToDraw As String
    DEF X As INT
    DEF Y As INT
    DEF Angle As Double

'We must use a TrueType font, otherwise the text won't be rotated.

hdc = GETHDC(d1)
GetFont(hdc,30)
TextToDraw = "http://nirsoft.cjb.net"
   
    X = 100: Y = 100
    'Select the font into the DC
    hPrevFont = _SelectObject(hdc, GFont)
    'Draw the text in 3 colors in order to create 3D effect.
    DrawText (hdc, TextToDraw, X-1, Y-1, Angle, RGB(0, 0, 255))
    DrawText (hdc, TextToDraw, X+1, Y+1, Angle, RGB(0, 0, 0))
    DrawText (hdc, TextToDraw, X, Y, Angle, RGB(0, 0, 192))
    'destroy the font object.
    _DeleteObject (GFont)
ENDSUB

Sub DrawText(hdc As INT, Text As String, X As INT, Y As INT, Angle As Double, _COLOR As double)
    Dim hFont As uint
    Dim hPrevFont As uint
   
    _SetTextColor (hdc, _COLOR)

    'Draw the text
move d1,x,y
    _TextOut (hdc, X, Y, Text, Len(Text))
    'Select back the previous font
    _SelectObject (hdc, hPrevFont)

End Sub


LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

RitchieF

Thanks Larry !

Are there generally valid rules for non-pro programmers that can be used for converting VB to EB ?

I.E. :

1. if there are functions defined in the VB-source code first have a look into the file windows.inc if there is a function with the same name and the same count of parameters

If so you don't have to define them again but add an underscore as first character of the function name

2. if there are variables defined (especially udt type ) or constants have a look into windows.inc too if they are defined there already

If so you don't have to define them again . You might get an error of double definition

3. Which type of variable in EB must be used for which type of variable in VB ?
   i.e.
  the variable type " long " in VB is equal to which one in EB and so on

Could we open a thread covering this rules ?

Richard

LarryMc

I never used VB so I'm of no help.

I do know that you can solve a lot of problems by using Sapero's
$include "windowssdk.inc"
in your programs.

It will take care of a lot of the function/constant issues.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

RitchieF

Just thought it could be helpful for people like me as hobby programmer.

But btw you are touching another issue : EB comes with a lot of include files. How do I know which inc-file I must or can include to a project ?

Thanks

Richard

pistol350

It only depends on what kind of programming you do in your project.
If you code everything yourself or you want to use already written code (not te reinvent the wheel) ;)

For instance, if you use API functions related to "window" class, or contants or types, ... you will probably need to include the "windows.inc" file not to have to declare all the functions directly in your source file.
If you use "udp" functions, you will probably need to include the "udp.inc" file in your source and so on...

I hope i was clear enough.
Regards,

Peter B.

ckoehn

You can also download sapero's header files here http://www.sendspace.com/file/a7d7ui.  It is a big install but then if you don't know for sure which files you need all you need to do is $INCLUDE "windowssdk.inc" and it will include almost all API calls.


LarryMc

Quote from: RitchieF on March 10, 2010, 07:52:27 AM
Just thought it could be helpful for people like me as hobby programmer.
hey, I'm just a hobby programmer also. ;)

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

RitchieF

@ pistol350:
yes thats clear enough. So I must just figure out which function is defined in which inc file ?

@ckoehn :
a big inc file doesn't also mean a big exe-file , right ?

@ Larry McCaughn:

I think you have a bit more time to work with EB  ;)

Richard

LarryMc

Quote from: RitchieF on March 11, 2010, 07:25:55 AM
@ pistol350:
yes thats clear enough. So I must just figure out which function is defined in which inc file ?
If you use Sapero's windowssdk.inc then that becomes pretty much a non-issue

Quote from: RitchieF on March 11, 2010, 07:25:55 AM
@ckoehn :
a big inc file doesn't also mean a big exe-file , right ?
Right

Quote from: RitchieF on March 11, 2010, 07:25:55 AM
@ Larry McCaughn:
I think you have a bit more time to work with EB  ;)
Being disabled does have SOME advantages. ;D

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

RitchieF

Okay friends,

so now I installed sapero's header files , changed $INCLUDE "windows.inc" to $INCLUDE "windowssdk.inc", removed the underscores and compiled the code above.

An error message comes up :

File: winuser.inc (3833) duplicate declaration - int


Looking at winuser.inc I can find 2 declarations of DrawText

one at line 3830 and one at line 3833.

But I can't simply rem out one of both, right?

Richard

LarryMc

yes

But I never ran in to that problem.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

RitchieF

my code snippet has a sub called DrawText  ;). I renamed it and now it works-

Thanks anyway

Richard