468,512 Members | 1,519 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,512 developers. It's quick & easy.

Hide Console Window

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;
}

Oct 3 '06 #1
2 5489

xf*****@googlemail.com wrote in message
<11**********************@k70g2000cwa.googlegroups .com>...
>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.
In wxWidgets it's:

MyWindow.Show(false);

..... BUT, that is also Off Topic in this NG!!

C++ has no 'window' or 'console'. Try one of the microslut NGs, like:

comp.os.ms-windows.programmer.win32

[ I'll bet you get an answer in under 10 minutes there. ]

--
Bob R
POVrookie
Oct 3 '06 #2

xf*****@googlemail.com wrote:
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.
try here: comp.os.ms-windows.programmer.win32

Oct 4 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by adrien | last post: by
3 posts views Thread by dricks dr | last post: by
1 post views Thread by Terry Olsen | last post: by
reply views Thread by Helge Lenuweit | last post: by
1 post views Thread by Kevin McKinley | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.