Board index » cppbuilder » Re: form inside a dll loaded by a console application

Re: form inside a dll loaded by a console application


2006-12-28 08:35:36 PM
cppbuilder85
Hi!
John van de Geyn wrote:
Quote
What is it your actualy trying to achieve? Sounds like you have a Console
application that uses a function in a DLL to I assume needs to get some user
information. Is this correct?
well let's say that the exchange of info is supposed to be
bidirectional! The GUI is supposed to pass user info to the console
application, and display its informations back to the user!
Quote
It might be easier and more reliable to just use a temp file to exchange
information(using say the HANDLE of the application you spawn as a
filename).
Too slow! and rude! :)
Although I have also used TCPIP succesfully in the past for
Quote
exchanging info between applications. I'm just wondering when the program
is used on networked machines with tight security settings that ports might
not be available.

Well that will be only a matter for network administrators :) ... and
this solution will also allow to have a remote GUI communicating with
the console application!
Thank U!
Regards!
Stefano B.
 
 

Re:Re: form inside a dll loaded by a console application

I cannot find the old app where I played with both a console and GUI windows
in an app.
However there is a window associated with the console. You cannot subclass
it but you can do some things with it. For example, here's a 'quicky' that
moves it around.
. Ed
-----------------------
// can be built from the command line with
// bcc32 -WCR filename
#include <windows.h>
class Console
{
public:
Console();
~Console() {}
operator HWND () const { return console_hwnd; }
private:
Console(const Console &);
Console operator = (const Console &);
HWND console_hwnd;
static char new_title[];
}; // end class Console
char Console::new_title[] = " ZAB}{NEW TITLE][ABC";
Console::Console()
{
char orig_title[1024];
// make sure the new title is unique
*new_title = ' ';
for (char c = '!';
FindWindow(NULL, new_title) && (c <= '`');
++c)
{
*new_title = c;
}
GetConsoleTitle(orig_title, sizeof(orig_title));
if (SetConsoleTitle(new_title))
{
Sleep(10); // Give Win9x/WinME time to update the title
console_hwnd = FindWindow(NULL, new_title);
SetConsoleTitle(orig_title);
}
else
{
console_hwnd = NULL;
}
} // end Console::Console
void ShowWindowMovement(HWND hwnd)
{
RECT rect;
GetWindowRect(hwnd, &rect);
int top = rect.top;
int high = rect.bottom - top;
int wide = rect.right - rect.left;
for (int i = 0, x = rect.left - 20;
i < 4;
++i, x += 5)
{
MoveWindow(hwnd, x, top, wide, high, TRUE);
Sleep(1000);
}
} // end ShowWindowMovement
int main()
{
Console cons_info;
ShowWindowMovement(cons_info);
return 0;
}
-----------------------
Quote
Remy Lebeau wrote in message
news: XXXX@XXXXX.COM ...
 

Re:Re: form inside a dll loaded by a console application

"Ed Mulroy" < XXXX@XXXXX.COM >wrote in message
Quote
However there is a window associated with the console. You cannot
subclass it but you can do some things with it. For example, here's a
'quicky' that moves it around.
As far as I know, MoveWindow() does not use the message queue. It sends the
appropriate window messages directly to the window procedure as if they were
sent with SendMessage(). So of course your example would work without a
queue being present in the console application's code.
Gambit
 

{smallsort}

Re:Re: form inside a dll loaded by a console application

Ed Mulroy wrote:
Quote
I have opened a GUI window in a console mode application. Unfortunately I
did it a while ago and it was a Win32 and not VCL application.
As I remember the console seemed to have its own message loop. I do not
remember how I handled that and will look around to see if I can out find
what I did.
I used DialogBox() which has it's own internal message loop, and
doesn't return until the window closes.
Perhaps you did too.
 

Re:Re: form inside a dll loaded by a console application

Possibly but I don't remember for sure and cannot find the program in which
I did it.
Even if I had, I remain secure in the statement that one can put up a
functioning non-dialog GUI window in a console app.
. Ed
Quote
Bob Gonder" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

I used DialogBox() which has it's own internal message loop,
and doesn't return until the window closes.
Perhaps you did too.
 

Re:Re: form inside a dll loaded by a console application

"Ed Mulroy" < XXXX@XXXXX.COM >wrote in message
Quote
Even if I had, I remain secure in the statement that one can put
up a functioning non-dialog GUI window in a console app.
I never said it couldn't be done. A console app is a Win32 app, so it
has full access to the Win32 API and can create and display its own
GUI windows. But a console app does not have any message loop by
default. It must be implemented manually in the user's own code.
Gambit
 

Re:Re: form inside a dll loaded by a console application

Quote
I never said it couldn't be done...
Note that my message was a response to what Bob Gonder's message. It was
not intended as an argument against what you said.
Quote
...a console app does not have any message loop by
default. It must be implemented manually in the user's
own code.
Agreed. A message loop also must be implemented manually in a GUI program
(other than a dialog-box only one) so that is as expected.
. Ed
Quote
Remy Lebeau wrote in message
news:45955986$ XXXX@XXXXX.COM ...

>Even if I had, I remain secure in the statement that one can put
>up a functioning non-dialog GUI window in a console app.

I never said it couldn't be done. A console app is a Win32 app, so it
has full access to the Win32 API and can create and display its own
GUI windows. But a console app does not have any message loop by
default. It must be implemented manually in the user's own code.
 

Re:Re: form inside a dll loaded by a console application

In the attachments group there is a message titled GUI window in console
app.
It is a not very well written demo of something like we are talking about.
No dialogs, just a Win32 app using a normal window. For those like me who
prefer the command line for small demos, a make file is included.
While throwing this together I found out why you need to use PeekMessage
instead of GetMessage. A GetMessage loop demands at least one message after
showing the window (even a mouse move will do it). Peekmessage does not.
It also demos using a shared variable as a flag with which the console can
cause the thread to end.
. Ed
Quote
Bob Gonder wrote in message
news: XXXX@XXXXX.COM ...

>I have opened a GUI window in a console mode application.
>Unfortunately I did it a while ago and it was a Win32 and not
>VCL application.

>As I remember the console seemed to have its own message
>loop. I do not remember how I handled that and will look
>around to see if I can out find what I did.

I used DialogBox() which has it's own internal message loop,
and doesn't return until the window closes.
Perhaps you did too.