Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Hide Console Window

1 view
Skip to first unread message

xfa...@googlemail.com

unread,
Oct 4, 2006, 4:38:50 AM10/4/06
to
I have a requirement to create a simple window switching program, which
switches between 2 windows when the specified hotkey is pressed. I have
managed to accomplish this fairly easilly although I want to hide the
console window that is shown when my application is run.

Here is my code:

#include <windows.h>
#include <winuser.h>

const char g_szClassName[] = "myWindowClass";

int SwitchWindow(HWND currentHwnd)
{
HWND msnHwnd = FindWindow(NULL, "this is a test.txt - Notepad");
HWND npHwnd = FindWindow(NULL, "work.txt - Notepad");

if(currentHwnd == msnHwnd) {
ShowWindow(npHwnd,SW_RESTORE);
SetForegroundWindow(npHwnd);
}
else if(currentHwnd == npHwnd) {
ShowWindow(msnHwnd,SW_RESTORE);
SetForegroundWindow(msnHwnd);
}
return 0;

}

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
lParam)
{
switch(msg) {
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_HOTKEY:
SwitchWindow(GetForegroundWindow());
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;

}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR
lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
HWND hwnd;
MSG Msg;

wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = NULL;
wc.lpszClassName = g_szClassName;
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

RegisterClassEx(&wc);

hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, g_szClassName, "The title
of my window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 150,
150, NULL, NULL, hInstance, NULL);

//ShowWindow(hwnd, SW_HIDE);
//UpdateWindow(hwnd);

RegisterHotKey(hwnd,999,0,VK_F3);

while(GetMessage(&Msg, NULL, 0, 0) > 0) {
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;

Sten Westerback (MVP SDK)

unread,
Oct 4, 2006, 5:05:19 AM10/4/06
to

<xfa...@googlemail.com> wrote in message
news:1159951130.3...@c28g2000cwb.googlegroups.com...

What CONSOLE window? Unless you have hidden some wrapper from main() your
application is a GUI one (WinMain()) and thus no window is shown unless you
show one yourself.
If you have a main() calling WinMain() or has changed the linker options,
then switch to GUI instead of Console in the settings.

If you mean your own GUI window then i can't see what's difficult in hiding
it -- just call ShowWindow(hwnd, SW_HIDE).

Describe your problem in more detail and we may be able to help.

- Sten


xfa...@googlemail.com

unread,
Oct 4, 2006, 6:55:46 AM10/4/06
to
Thanks for your help I had not set "Do not create a console window" in
the Linker settings in Dev-C++

0 new messages