473,511 Members | 16,830 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5998

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
11455
by: adrien | last post by:
Hi, (also posted in netscape.public.mozilla.browser) i use netscape 7 and want to hide the scrollbars of the window when something happens. I tried this: window.scrollbars.visible=false...
2
404
by: Jason Han | last post by:
I have a .NET Windows application which launches another .NET console application using Start() method in the Process class. I set the StartInfo.CreateNoWindow to true. But on Windows98, the...
3
10400
by: dricks dr | last post by:
Hi, I'm using the AxWebBrowser Control from microsoft in a C# application. It works fine, but i have many problems to hide the javascript error windows that appear when u visit a website with......
9
19416
by: DaveF | last post by:
Can you hide a vb.net console window?
1
3077
by: Terry Olsen | last post by:
I would like to hide a console window on startup so that the user can't close it. is this possible? If so, how would I also show it when I want to view it? *** Sent via Developersdex...
0
1365
by: Helge Lenuweit | last post by:
Hello, I am trying to put together an application that (1) shows Console.WriteLine() output when launched from within a console window (that is, from the command prompt) but that (2) **does not...
1
6902
by: JupeMarsInc | last post by:
Hi, I'm using a simple console application project in VC++ (not a window one). my question is, how can I hide the console window,prevent it from popping up when i run my program? Thank you
2
11432
luke14free
by: luke14free | last post by:
Hello guys, I've been searching for a method to hide the console (as c/c++ user would say) under windows, but i found nothing really helpful. What I found is: 1) I need to rename file as pyw. But...
1
2889
by: Kevin McKinley | last post by:
When I use py2exe to convert Python script to executable Windows programs I always have a black console pop up behind my program. If i run the script before i convert it with py2exe it don't have...
0
7242
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7423
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7081
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5668
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3225
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3213
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1576
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
447
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.