Home » U++ Library support » TopWindow&PopUp, TrayIcon » Is it possible to show a console window in GUI_APP_MAIN?
Is it possible to show a console window in GUI_APP_MAIN? [message #18680] |
Thu, 16 October 2008 10:36 |
sevenjay
Messages: 30 Registered: October 2008 Location: Taiwan
|
Member |
|
|
Well.....I know maybe it's a stupid question.
Is it possible to show a console window in GUI_APP_MAIN?
In my application, I have a command need users input their password and they can see the log of the command.
To have users' trust, I don't want to send pw from GUI then catch log back from the command message.
On Linux the code example is like this:
function called in GUI_APP_MAIN
int function()
{
printf("this is a test program\n");
const char * send_argv[]={"sudo","ls","-al",NULL};
pid_t pid = fork();
switch(pid) {
case -1: //parent fork failed
return P2M_FORK_FAIL;
break;
case 0: //child process
if(-1==execvp(send_argv[0], send_argv)); //execvp("sudo",{"sudo","ls","-al",NULL})
return P2M_EXEC_FAIL;
break;
default: //parent process
wait(NULL);
return P2M_OK;
break;
}
}
But even printf() can not show a message...
If there is any idea, please tell me.
Thanks a lot!
|
|
|
Re: Is it possible to show a console window in GUI_APP_MAIN? [message #18688 is a reply to message #18680] |
Fri, 17 October 2008 07:52 |
pepe11
Messages: 16 Registered: June 2006 Location: Slovakia
|
Promising Member |
|
|
Hi,
Do you mean GUI + Console in one aplication ?In WIN is it possible. I use it for debuging in real time application(very old aplication). But i do not whether that is implemeted in U++.
#include <wincon.h>
void InitDebugPrintf(char *Format)
{
COORD Size;
InitializeCriticalSection( &Criticalsection );
ConsoleCreated = TRUE;
ConsoleCreated = AllocConsole();
ConsoleScreenBuffer = CreateConsoleScreenBuffer( GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL );
Size.X = 120;
Size.Y = 1024;
SetConsoleScreenBufferSize( ConsoleScreenBuffer, Size );
if( ConsoleScreenBuffer != NULL ) SetConsoleActiveScreenBuffer( ConsoleScreenBuffer );
SetConsoleTitle(Format);
}
void CancelDebugPrintf()
{
DeleteCriticalSection( &Criticalsection );
fclose(stream);
fclose(stream1);
CloseHandle( ConsoleScreenBuffer );
// FreeConsole();
}
void DebugPrintf( unsigned char Type, char *Format, ... )
{
char LocalBuffer[128];
int SizeWritten;
DWORD SizeToWriteToConsole;
va_list ap;
va_start( ap, Format );
if(( SizeWritten = _vsnprintf( LocalBuffer , sizeof( LocalBuffer ), Format, ap )) != -1 )
{
LocalBuffer[sizeof(LocalBuffer)-1] = '\0';
if( ConsoleCreated == FALSE ) InitDebugPrintf("PEPE I");
EnterCriticalSection( &Criticalsection );
if( ConsoleScreenBuffer != NULL )
{
SetConsoleTextAttribute(ConsoleScreenBuffer,FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
WriteConsole( ConsoleScreenBuffer, TEXT(LocalBuffer), SizeToWriteToConsole = SizeWritten, &SizeToWriteToConsole, NULL );
}
LeaveCriticalSection( &Criticalsection );
}
va_end( ap );
}
Pepe
|
|
|
|
|
Re: Is it possible to show a console window in GUI_APP_MAIN? [message #19006 is a reply to message #18731] |
Wed, 05 November 2008 06:35 |
sevenjay
Messages: 30 Registered: October 2008 Location: Taiwan
|
Member |
|
|
mr_ped wrote on Sat, 18 October 2008 21:36 | Maybe you can also check TheIDE internal console used to output compilation/search/run input/output when used together with "Debug/Run options../Standard output: Console".
This one works in the same way both under windows and linux and it's faster than ordinary shell (bash or cmd.exe).
I'm just not sure about input possibilities, and where to look for this one in the TheIDE sources.
|
Thanks for your idea.
The console will be in the TheIDE and can not input anything to itself.
Well.... I did it by using xterm in Linux. You can try "cmd /K dir" command if you want to do it In windows.
Here is the sample code:
int exec_xterm()
{
const char * temp_argv[100]={"xterm", "-sb", "-rightbar", "-hold", "-e", "sudo", "ls", NULL};
char * const * send_argv=(char * const * )temp_argv;//force convert type
pid_t pid = fork();//------------------------------------------------------
switch(pid) {
case -1: //parent fork failed
perror("parent fork failed");
return FORK_FAIL;
break;
case 0: //child process
if(-1==execvp(send_argv[0],send_argv));
{
perror("exec failed");
return EXEC_FAIL;
}
break;
default: //parent process
wait(NULL);
return OK;
break;
}
//-----------------------------------------------------------
}
Hope it may be helpful for someone...
[Updated on: Wed, 05 November 2008 06:38] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Sat Dec 07 21:59:25 CET 2024
Total time taken to generate the page: 0.03107 seconds
|