PDA

View Full Version : console_attach description?



oli
06-12-2009, 23:29
Hi,

tried to find out what console_attach does, but there is no info in the on/offline help and I didn't find any information in the forum.
If added iinto code, it has no effect.

Lionheart008
07-12-2009, 18:31
same question here, dear oli.

but you can get some results ;) look at the end of tb script example. the description for manual help will follow I am sure, if eros or anybody else read this one.


Uses "Console"

dim sx, sy as number
dim cx, cy as number
Dim ta,tz As Number

' Save some info
sx = Console_GetSizeX()
sy = Console_GetSizeY()
cx = Console_GetCursorX()
cy = Console_GetCursorY()
ta = Console_GetTextAttribute()
tz = Rnd(10,255)

Console_SetTextAttribute(Console_ForegroundRGB(1,1,1,1))

Console_WriteLine(" CONSOLE INFO")
Console_WriteLine("----------------")

Console_SetTextAttribute(ta)

Console_WriteLine("Title : " + Console_GetTitle())

Console_WriteLine("Size :" + str$(sx) + "x" + ltrim$(str$(sy)) + " (" + ltrim$(str$(sx*sy*2)) + " bytes)")

Console_WriteLine("Origin in :" + str$(cx) + "," + ltrim$(str$(cy)))

Console_WriteLine("Text attribute :" + str$(ta))

Console_Attach(tz)

Console_WriteLine "console_attach exists but what's purpose good for? :) " + tz

Console_SetCursorPosition(30, 23)
Console_WriteLine("Press any key to exit.")
Console_WaitKey


frank

oli
08-12-2009, 13:48
Hm, in thinBasic history I found for version 1.0.9.1 mention of a Windows API call:
http://msdn.microsoft.com/en-us/library/ms681952(VS.85).aspx - Attaches the calling process to the console of the specified process.

Also FreeConsole and AllocConsole are mentioned in MSDN so I guess that's it.
Would be interested in some working example - I guess the parameter is some parent process ID,
but where do I get such process ID and what is the purpose of attaching?

I ask because I'm working on some kind of "extended" cmdline or Dos box, which will have some additional commands (prefixed with ! for example).
The problem is if you type CD C:\something and in the next line want to delete some file in that folder the environment is not preserved - for each
execution I call something like:
OS_Shell($cmdline, %OS_WNDSTYLE_NORMAL, %OS_SHELL_SYNC)
And my idea is to use this console_attach to somehow preserve the enviroment.
Or does anyone have a better idea how to solve this env problem?

Bye,
Oli

oli
08-12-2009, 14:00
Hm, in thinBasic history I found for version 1.0.9.1 mention of a Windows API call:
http://msdn.microsoft.com/en-us/library/ms681952(VS.85).aspx - Attaches the calling process to the console of the specified process.

Also FreeConsole and AllocConsole are mentioned in MSDN so I guess that's it.
Would be interested in some working example - I guess the parameter is some parent process ID,
but where do I get such process ID and what is the purpose of attaching?

I ask because I'm working on some kind of "extended" cmdline or Dos box, which will have some additional commands (prefixed with ! for example).
The problem is if you type CD C:\something and in the next line want to delete some file in that folder the environment is not preserved - for each
execution I call something like:
OS_Shell($cmdline, %OS_WNDSTYLE_NORMAL, %OS_SHELL_SYNC)
And my idea is to use this console_attach to somehow preserve the enviroment.
Or does anyone have a better idea how to solve this env problem?

Bye,
Oli


Actually I found now following http://www.codeguru.com/forum/showthread.php?t=293668:
"AttachConsole gives the ability for a GUI application to write to the console window of the console from which it was started."

So this will not really help me solving my environment problem :(

Bye,
Oli

Lionheart008
08-12-2009, 18:04
hello.

perhaps this example can help. although I am not sure what the result should be for "Console_attach" or "console_alloc" here's a way how I have understood what your intention for finding infos with links may be. send a message from ui module to console.


'---------------------------------
'- test example 1 for oli by frank
'---------------------------------

Uses "console", "ui"
%messageWorkout = 1
%ButtonCopy = 1002
%ButtonClose = 1003

Dim hDlg As Long
Dim x,y,z As Long


Function TBMain() As Long
Dim myconsole As Long
Dim getStdHandle(2) As String

Dialog NEW hDlg, "myConsole_test",-1,-1, 330, 203, _
%WS_POPUP Or _
%WS_VISIBLE Or _
%WS_CLIPCHILDREN Or _
%WS_CAPTION Or _
%WS_SYSMENU Or _
%WS_MINIMIZEBOX, _
0 To hDlg

Control ADD BUTTON, hDlg, %ButtonClose, "Click to kill", 160, 50, 60, 24
Control ADD BUTTON, hDlg, %ButtonCopy, "TextInfos_Send!", 40,90,80,44 Call cbSendDialog

Console_Attach(x)
Console_Alloc 'no parameters, 0=failure, nonzero=success
myConsole = GetStdHandle (%messageWorkout)

Dialog SHOW MODAL hDlg Call cbDialog

End Function

CallBack Function cbSendDialog() As Long
Static i As Long
Local txt As ASCIIZ*256
Local Out As String
Local myConsole As String
Local WriteConsole As Long

Select Case CBMSG
Case %WM_COMMAND
If CBWPARAM = %ButtonCopy Then
Incr i
txt = "TestLine " + Str$(i) + $CRLF
Console_Write myConsole, txt, Len(txt), Out, 0
End If

Case %WM_DESTROY
MsgBox 0, "Window is to be destroyed."
End Select

End Function

CallBack Function cbDialog() As Long

Select Case CBMSG
Case %WM_COMMAND
If CBWPARAM = %ButtonClose Then Dialog End CBHNDL

Case %WM_DESTROY
MsgBox 0, "Window is to be destroyed."

End Select

End Function


write a message to eros and ask for these both console commands so you will get detailled infos, I am sure ;)

maybe I could help for the first step in your direction. But I am not sure.

servus, frank

oli
08-12-2009, 21:59
Hi Frank,

thank you for the example - I'm quite new to thinBasic and the example showed me some use of thinBasic I wasn't aware of :D

Unfortunately we didn't yet figure out what the console_attach and console_alloc do - In your example if I comment out both commands it still works :o
I'll really have to ask Eros :)

Anyway it looks I'll solve the "environment" problem in a different way for now as it looks like console_attach is not what I need.

Bye,
Oli