- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
HTH,
Gerry T.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
HTH,
Gerry T.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hmm, Steve, AFAIK GetForegroundWindow returns the handle of window belonging to any process, not just the calling (console) process -- I don't see how it could be reliably used in the context you mention?
Jugoslav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yeah, GetForegroundWindow returns whatever window happens to be in the foreground. Typically that would be the console app you're running, but not necessarily. I tend to use that in my own code in place of NULL, as it seems to have better results (especially with code that could be called from QuickWin.)
I'm just a dabbler here, so don't take my comments with any great weight.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
:
:
extern void SetCtrlHandler(HANDLE hConOut);
:
INT iret;
BOOL statConsole;
HWND hwnd;
HANDLE hStdOut;
CHAR ConsoleTitle[128];
DWORD dwCharsRead;
:
:
statConsole = SetConsoleTitle("My App Log");
dwCharsRead = GetConsoleTitle(ConsoleTitle, sizeof(ConsoleTitle));
hwnd = FindWindow(NULL,ConsoleTitle);
uses this hwind and not hInstance to
// post messages for the console
PostMessage(hwnd,...);
// customize its event handler
SetCtrlHandler(hwnd);
// customize its startup position
iret=SetWindowPos(hwnd,NULL,0,0,0,0,SWP_NOSIZE | SWP_NOZORDER);
//Show or hide the console
statConsole = ShowWindow(hwnd,SW_NORMAL);
//statConsole = ShowWindow(hwnd,SW_HIDE);
BOOL WINAPI handler(DWORD dwCtrlType)
{
// CHAR szTemp[64];
//The handler masks all console events via return(TRUE)
switch(dwCtrlType)
{
case CTRL_C_EVENT:
//strcpy(szTemp, "CTRL_C_EVENT");
break;
case CTRL_BREAK_EVENT:
//strcpy(szTemp, "CTRL_BREAK_EVENT");
break;
case CTRL_CLOSE_EVENT:
//strcpy(szTemp, "CTRL_CLOSE_EVENT");
Sleep(10000);
break;
case CTRL_LOGOFF_EVENT:
//strcpy(szTemp, "CTRL_LOGOFF_EVENT");
return(FALSE);
break;
case CTRL_SHUTDOWN_EVENT:
//strcpy(szTemp, "CTRL_SHUTDOWN_EVENT");
return(FALSE);
break;
default:
//strcpy(szTemp, "Unknown event");
break;
}
/_cputs(strcat(szTemp, " detected "));
return(TRUE);
}
void SetCtrlHandler(HANDLE hConOut)
{
BOOL status;
// Set custom handler for process
status = SetConsoleCtrlHandler(handler, TRUE);
//_cputs("Handler set ");
return;
}
Jugo, how do you insert smileys in messages?
Steve, I have no idea why writing a console handler in CVF is problematic but I vaguely recall some discussion on this issue. Can it be done in IVF?
Ciao,
Gerry T.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
1. HINSTANCE = HMODULE
being the base address at which a module is loaded. Handy for finding a console's HINSTANCE.
2. HANDLE = HWND
ie, generic and window handles are identical.
However, with STRICT type checking in VC++ .NET ( >98% ISO compliant according to the propaganda folks at MS), a distinction between HINSTANCE and HMODULE is to be maintained and WHND is to be used in preference to HANDLE.
HTH,
Gerry T.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Part 1) is true. Part 2) is not.
Your sample is (appears to be, didn't check carefully) correct, but it never uses a HANDLE? It usesconsole window HWND --as I said, such techniques are discouraged -- I'm not sure what would ShowWindow(SW_HIDE) do if you run it from full-screen console session.
But no, HANDLE and HWND are not interchangeable in any context that I know of. The former is usually used in context of a stream (file, pipe, console etc.) handle, while the latter is used in context of windows -- and you did not mix them in your sample.
STRICT C++ define enforces that every "atomic" handle type is typedef-ed to a named structure (winnt.h):
#ifdef STRICT
typedef void *HANDLE;
#define DECLARE_HANDLE(name) struct name##__ { int unused; }; typedef struct name##__ *name
HANDLE is actualy typedef for void*. Windef.h actually defines various handle types:
DECLARE_HANDLE(HINSTANCE);
typedef HINSTANCE HMODULE; /* HMODULEs can be used in place of HINSTANCEs */
...
DECLARE_HANDLE (HWND);
as you can see, HMODULE and HINSTANCE are typedef-ed as pointer to same structure (struct HINSTANCE__*), while HWND is typedef-ed to (struct HWND__*), while HANDLE is (void*) -- and these are not interchangeable under C++ without explicit cast.
Jugoslav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
They're both right.
>Your sample is (appears to be, didn't check carefully) >correct,
It is assuredly correct.
> but it never uses a HANDLE?
It does, look more carefully.
>It uses console window HWND
As per part 2.
>-- as I said, such techniques are discouraged --
Says who? MSDN, VC++7 say otherwise and that's who I go by and so ought you.
>I'm not sure what would ShowWindow(SW_HIDE) do if you run
>it from full-screen console session.
I'm not sure that ShowWindow(SW_HIDE) does much but
ShowWindow(hwnd,SW_HIDE) does exactly what it's supposed to do: it hides the console.
>But no, HANDLE and HWND are not interchangeable in any >context that I know of.
Well now you do.
>The former is usually used in context of a stream (file,
>pipe, console etc.) handle, while the latter is used in
>context of windows -- and you did not mix them in your
>sample.
Did too, :-). Look more carefully.
This topic has gone beyond the point of usefulness. So lets agree to differ.
HTH,
Gerry T.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
| It does, look more carefully.
| Says who? MSDN, VC++7 say otherwise and that's who I go by
| and so ought you.
| I'm not sure that ShowWindow(SW_HIDE) does much but
| ShowWindow(hwnd,SW_HIDE) does exactly what it's supposed to do:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Engaging in pedantic and bloviating dialogs on the inners of Windows is of no interest to me and makes no useful contribution to forum discussion.
Ciao,
Gerry T.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page