The subject sums it up. I have searched thoroughly (as best as I know how) to figure out how to right justify the text in a @STATIC control. Any takers?
Yep,
use these codes instead of the codes coming from the dialog editor.
'Static styles
Const SS_NOTIFY=0x00000100
Const SS_LEFT = 0x0
Const SS_CENTER = 0x1
Const SS_RIGHT = 0x2
Const SS_NOPREFIX = 0x80 : ' Don't do " " character translation
Use SS_Notify if you want your static to recognize mouse clicks.
SS_NOPREFIX stops the static from doing certain things, all details are on MSDN
Personally I like the SS_NOPREFIX as it fills out the static with the background color stopping the bleed thru in statics you get when the text doesn't fill the static completely.
/Douglas
Quote from: Dogge on January 09, 2008, 01:08:57 AM
Yep,
use these codes instead of the codes coming from the dialog editor.
'Static styles
Const SS_NOTIFY=0x00000100
Const SS_LEFT = 0x0
Const SS_CENTER = 0x1
Const SS_RIGHT = 0x2
Const SS_NOPREFIX = 0x80 : ' Don't do " " character translation
Use SS_Notify if you want your static to recognize mouse clicks.
SS_NOPREFIX stops the static from doing certain things, all details are on MSDN
Personally I like the SS_NOPREFIX as it fills out the static with the background color stopping the bleed thru in statics you get when the text doesn't fill the static completely.
/Douglas
Thanks, Douglas, I have tried every combination I can think of, but the text (numbers) in the @STATIC control stubbornly refuses to budge from the left. Here is a simple set of code, maybe you can show me where what you wrote goes?
' Display , 11, 14, 70 Hours Left
SETFONT d2, "Times New Roman",28,700,40 ' Send updated data to screen
SETCONTROLTEXT(d2,40,STR$(num11HrsLeft/numSecs))
SETFONT d2, "Times New Roman",28,700,41
SETCONTROLTEXT(d2,41,STR$(num14HrsLeft/numSecs))
SETFONT d2, "Times New Roman",28,700,42
SETCONTROLTEXT(d2,42,STR$(num70HrsLeft/numSecs))
FYI - none of the SS_codes are working (at least in the way I have tried to use them. ;))
Thankks!
Try this code.
CONST STATIC_1 = 1
CONST STATIC_2 = 2
CONST STATIC_3 = 3
'Static styles
Const SS_NOTIFY=0x00000100
Const SS_LEFT = 0x0
Const SS_CENTER = 0x1
Const SS_RIGHT = 0x2
Const SS_NOPREFIX = 0x80 : ' Don't do " " character translation
DIALOG d1
CREATEDIALOG d1,0,0,300,202,0x80C80080,0,"static alignment",&d1_handler
CONTROL d1,@STATIC,"Left",60,20,166,40,ss_left|ss_noprefix,STATIC_1
CONTROL d1,@STATIC,"Centered",60,60,166,40,ss_center|ss_noprefix,STATIC_2
CONTROL d1,@STATIC,"Right",60,100,166,40,ss_right|ss_noprefix,STATIC_3
domodal d1
SUB d1_handler
int x
SELECT @MESSAGE
CASE @IDINITDIALOG
CENTERWINDOW d1
' fill statics just to show
for x=static_1 to static_3
setfont d1, "Arial", 28,700,0,x
next x
setcontrolcolor d1, static_1, rgb(0,0,0), rgb(255,0,0)
setcontrolcolor d1, static_2, rgb(0,0,0), rgb(0,255,0)
setcontrolcolor d1, static_3, rgb(0,0,0), rgb(0,0,255)
CASE @IDCLOSEWINDOW
CLOSEDIALOG d1,@IDOK
CASE @IDCONTROL
SELECT @CONTROLID
ENDSELECT
ENDSELECT
RETURN
ENDSUB
Quote from: Dogge on January 09, 2008, 03:16:23 AM
Try this code.
...
...
BEE-YOU-TEE-FUL !!!
Thanks you very much for taking the time to send me the program. Seeing it in context and in action really helps to get my arms around it! It also heps me see just what I need to study-up on! ;)
Or this.
Control MainWin,@Static,"",170,25,195,28,@CTEditRight,lblA
Control MainWin,@Static,"",170,25,195,28,@CTEditLeft,lblB
Control MainWin,@Static,"",170,25,195,28,@CTEditCenter,lblC
CodeTRUCKER
IMHO it isn't necessary to double post the exact same questions here AND on CodingMonkeys.
But again, that's just my opinion.
Larry
Quote from: mrainey on January 09, 2008, 07:03:32 AM
Or this.
Control MainWin,@Static,"",170,25,195,28,@CTEditRight,lblA
Control MainWin,@Static,"",170,25,195,28,@CTEditLeft,lblB
Control MainWin,@Static,"",170,25,195,28,@CTEditCenter,lblC
I tried this originally, but it did not seem to have effect? What I have learned from your example is it appears that the control ID does not have to be just numbers!
Quote from: Larry McCaughn on January 09, 2008, 11:57:45 AM
CodeTRUCKER
IMHO it isn't necessary to double post the exact same questions here AND on CodingMonkeys.
But again, that's just my opinion.
Larry
Noted and with 800+ posts in this forum I'd say your "HO" is worth paying it heed. Which would you say should be the primary forum to post in?
Quoteit appears that the control ID does not have to be just numbers
I create a Char variable with descriptive name for each control and assign it a unique number (the number assignments don't conflict with those for controls in other windows). The names are a huge help to me in keeping track of what's going on in my (control top-heavy) programs.
QuoteWhich would you say should be the primary forum to post in?
Since the man who WROTE EBasic(as well as IBasic STD, IBasic Pro, Aurora, and CBasic) runs this forum and ansers questions all the time I believe you get the best answers here.
Lots of times this is the only place you're going to get an answer.
Don't get me wrong, I am not badmouthing or belittling CodingMonkeys in any way, shape, or form.
And you are totally free to p[ost whatever you want any where you want.
I just offered my opinion and that is all it was.
Hope you enjoy EBasic as much as the rest of us here do.
Larry
What Mike was talking about with Control MainWin,@Static,"",170,25,195,28,@CTEditRight,lblA
Control MainWin,@Static,"",170,25,195,28,@CTEditLeft,lblB
Control MainWin,@Static,"",170,25,195,28,@CTEditCenter,lblC
is that prior to those lines in his code is 3 lines similar to this
const lblA = 213
const lblB = 13
const lblC = 2
The point being that the numbers you assign them must be unique for control ID numbers in your code.
Control ID are always numbers and you have a choice of using a "number" or a CONST that has been assigned a number.
Doing it this way allows you to give meaningful names in your code. Makes it easier to keep track of what you are looking at(as Mike stated).
Larry
Calvin,
Here's a little example of justification in a static text control. It doesn't do anything (but hey, it's free ;D). Larry's idea of using a const works too, and makes for less typing.
AutoDefine "Off"
Declare Extern BringWindowToTop(hwnd:Int),Int
SetID "WM_NCLButtonDown",161
SetID "HTCaption",2
Def TruckerWin:Window
Def lblTruckerOne:Char
Def lblTruckerTwo:Char
Def lblTruckerThree:Char
Def lblTruckerFour:Char
Def Black:Int
Def White:Int
Def DarkBlue:Int
'WINDOW CONTROL ASSIGNMENTS
lblTruckerOne = 1
lblTruckerTwo = 2
lblTruckerThree = 3
lblTruckerFour = 4
' COLOR DEFINITIONS
Black = RGB(0,0,0)
White = RGB(255,255,255)
DarkBlue = RGB(73,95,243)
' CREATE THE WINDOW OFF SCREEN
OpenWindow TruckerWin,-1000,-1000,400,300,@MinBox,0,"",&HandlerTruckerWin
SetWindowColor TruckerWin,DarkBlue
GoSub CreateTruckerControls
CenterWindow TruckerWin
BringWindowToTop(TruckerWin.hwnd)
' WAIT FOR WINDOW TO CLOSE
WaitUntil TruckerWin.hwnd = 0
' END THE PROGRAM
CloseWindow TruckerWin
End
Sub CreateTruckerControls
Def a:Int
Control TruckerWin,@Static,"",20,50,160,18,@CTEditLeft,lblTruckerOne
Control TruckerWin,@Static,"",20,150,160,18,@CTEditCenter,lblTruckerTwo
Control TruckerWin,@Static,"",220,50,160,18,@CTEditRight,lblTruckerThree
Control TruckerWin,@Static,"",220,150,160,18,@CTEditLeft,lblTruckerFour
For a = 1 to 4 : ' ALL CONTROLS
SetFont TruckerWin,"Tahoma",8,700,0,a
Next a
For a = lblTruckerOne to lblTruckerFour
SetControlColor TruckerWin,a,Black,White
Next a
SetControlText TruckerWin,lblTruckerOne,"One Left"
SetControlText TruckerWin,lblTruckerTwo,"Two Center"
SetControlText TruckerWin,lblTruckerThree,"Three Right"
SetControlText TruckerWin,lblTruckerFour,"Four Left Again"
Return
EndSub
Sub HandlerTruckerWin
Select @Class
' DRAG WINDOW
Case @IDLbuttonDn
If (#<Window>@HitWindow = TruckerWin)
BringWindowToTop(TruckerWin.hwnd)
SendMessage TruckerWin,@WM_NclButtonDown,@HTCaption,0
EndIf
' CLOSE WINDOW
Case @IDCloseWindow
CloseWindow TruckerWin
EndSelect
Return
EndSub
Nice, neat example Mike.
Larry
Hi,
Nice example.
I noticed the DECLAERE EXTERN BringWindowToTop(...
at the beginning of the program.
Where is this function defined?
It must be 'hiding' somewhere, because the sample compiles and runs.
????
Haim
It is a windows API function and should be delcared as an import. Luckily the linker is smart enough to pick up the address in the import library and call the function indirectly.
Paul.
Thanks,
that's why I found it strange...
Haim
Nobody asked, but I'll mention it anyway .. :)
Sometimes you have a textbox (I like that term better than @static) which is fairly small and you want the text to be centered vertically as well as horizontally.
In that case, use:
@cteditcenter | 0x200
when you set up the control style.
best wishes, :)
Graham
Graham, I didn't know about that one - will be very useful.
Ditto Mike
Thanks Graham
New to me too!
Thanks,
Haim
Graham,
You wouldn't know how to do that vertical justification with an Edit control, would you? :)
Hi Mike,
I don't know of a way to do it with an Edit control I'm afraid.
Edit Controls are pretty ugly things in my view, with limited facilities. So it might not be possible.
On the other hand, the impossible takes a little longer :) - I'll get back yo you ..
best wishes. :)
Graham
Just to say, I've managed to center text vertically using a bit of a trick .. :)
I've posted it in the Creative section, 'cos that's what I used to experiment with it.
best wishes, :)
Graham