开发者

Changing window procedure for console window

开发者 https://www.devze.com 2023-02-04 19:38 出处:网络
I want to make console window with a functional tray icon. I figured out that most probably it is necessary to replace initial console\'s window procedure so I will be able to control all messages inc

I want to make console window with a functional tray icon. I figured out that most probably it is necessary to replace initial console's window procedure so I will be able to control all messages including notify area events. But SetWindowLong() function returns 0, and GetLastError() tells tha开发者_StackOverflowt access is denied.

hwndFound = GetConsoleWindow();
SetWindowLong(hwndFound, GWL_WNDPROC, (long)WndProc);

What could it be, or maybe there is some other way to control tray icon manipulations?


If all you want to do is create a notification icon for a console application, there's nothing that says your Shell_NotifyIcon call has to point to the console window. Create an invisible dummy window with your own window class and procedure instead. Note that you'll probably have to do this from a secondary thread in order to run its message loop. (The console window is special, as it's hosted outside your process by conhost.exe/csrss.exe.)


No, you just need a window. Best thing is to startup a thread so you can pump a message loop and receive the icon notifications. Create a little hidden window that you can use for the Shell_NotifyIcon() call.


Which version of Windows are you using? I know that prior to Vista, console windows are treated specially, and can't be manipulated in many of the standard ways. This article by Raymond Chen might shed some further light.

0

精彩评论

暂无评论...
验证码 换一张
取 消