How is the Win32 API used in C++ to minimize a window to the system tray? - c++

Pretty much a self-explanatory title. I'm writing an application in C++ with the Win32 API, and I'd like to know how to minimize to the system tray. I can find all kinds of articles online about minimizing to the system tray in C#, Python, even Visual Basic, I think, but for the life of me I can not find a single article on how to minimize something to the system tray in C++.
Any and all help or even redirection would be highly appreciated.
EDIT: Question answered. Once I knew about the Shell_NotifyIcon function, I was easily able to find this CodeProject article which is exactly what I needed.

All you need is the Shell_NotifyIcon function. You ought to be able to work it out from MSDN, but if you need more help I'm sure there are a million places on the web that give samples. Now that you know the name of the API, web search will fill in the gaps.

Related

Creating GUIs in Win32 C++

I'm developing my first Windows desktop application and I'm trying to figure out what the best approach would be to create the program's GUI.
I know, I know... I feel stupid for asking considering the amount of data on the subject on SO. However most answers seem outdated and I'm not sure if they fit my specific project. Also tutorials for Windows 8 'metro apps' are clogging my Google search results, which is NOT what I'm looking for.
I use Visual Studio. I've followed tutorials. I have basic knowledge of C and Java and extensive experience with PHP. I'm excited to learn C++, so I'm not looking for GUIs to create a GUI (like WinForms). I also don't care about managed code and portability for now, especially since I'm trying to avoid dependencies (i.e. users having to install .NET). As long as it runs smoothly on Vista and up, I'm happy.
The application
The software will teach basic physics to kids. I'd like to create a main area and a sidebar. The main area will feature a physics animation, say a bouncing ball, along with some Q&A. Users can zoom in to the animation to measure some stuff and answer the question. Users can track their progress in the sidebar. That's pretty much it.
What I've found so far
I'm getting a bit frustrated with MSDN. Most of their examples are given in four different languages (C#, C++, etc). I can't seem to get more than a bit of Hello World code from them.
I found a GDI API on MSDN and it seems like a good start for me. However I've read quite a few answers on SO saying creating layouts in pure C++ is really hard, that we're better of using frameworks like ATL and WTL. Since I'm also going to create (somewhat interactive) animations, I've wondered whether I should use gaming-targeted APIs like Direct2D.
Since all of this is new to me, and there are a lot of options, I don't know where to start for my particular application. Any tips would be greatly appreciated!
Using the raw Win32 API (no additional downloads or third-party helpers):
Here's a good primer (introduces dialog boxes, text boxes, buttons, etc): theForger's Win32 API Tutorial
And here's where you go from there (numeric up-downs, list boxes, combo boxes, tooltips, and more): Common Controls on MSDN. Most of these require you to #include <commctrl.h>.
I also found this to be a good resource that covered what the other two didn't: Win32 Developer - Window Assets
But the Win32 API doesn't seem like it does exactly what you want. A physics app for kids should have a more visual GUI than the API can provide. Good luck, though!
If you're ok with adding additional Frameworks, I'd suggest looking at Qt.
It allows to create the GUI from code only, has a good structure, and has an Interface for 2D drawing, if required.
If you are concerned about dependencies, you only have to include the Qt DLLs to your executables; no installation is required for the user.
To get started, see my (old) tutorial "Lessons in Windows API Programming".
But you really need a good book, such as edition 5 or earlier of Charles Petzold's classic "Programming Windows".
The problem with latest edition is that it's for C# and .NET, with Charles grabbing the tail of the "new way" at just the wrong timeā€¦
Disclaimer: I haven't checked the details of edition numbers.
Using the Windows API is the simplest, but producing advanced GUIs can take a very long time. Microsoft Foundation Class is a way to make the Windows API more user friendly and OOP. Does anyone have any experience with MFC?
Why not use some 2D C++ game engine, like HGE: http://hge.relishgames.com/overview.html.

Create a C++ program that processes incoming calls on a phone-line (land-line)

For some time now I've been tossing around what I think is am awesome idea: I want to write essentially a C++ phone server to handle all of my incoming calls on a land-line. I'll have a white-list (yay never having to worry about telemarketers ever again!), a black-list, and will be able to access my phone using my gaming headset, allowing me to make/answer calls while I'm gaming or whatever. In the future I'd also like to hook it up to a gui and make it have pop-ups and other cool features.
The problem is, I have no idea where to start. I'm familiar enough with C++, but have no idea how to go about doing anything with a phone-line. I can plug a phone-line into my computer, but I have no idea how to get my program to be able to use that connection. There's WinSock2 for being able to use my ethernet connection, is there something similar I'd be able to use to use the phone line? As it's using the same ethernet jack, I wonder if it's even possible to use WinSock2 to use the phone-line?
I saw this post, which wasn't particularly helpful: stackoverflow link , which points out Dual-tone multi-frequency signaling. I stumbled across this site: link, but isn't really going to help me get started.
So I was wondering, is there some sort of library out there that would allow me to tap into a phone-line that's connected to my computer? Is there a standard somewhere out there concerning phone-lines and what the different combinations of tone's mean? Can anyone here help get me started? I realize it's somewhat of a big undertaking, so any push in the right direction would be greatly appreciated. Thanks.
[Update:]
I found this question, which is a step in the right direction, but I'm not sure yet if it helps me (I need to go to bed, and will take a look at it in the morning). I did see mention of a Microsoft Telephony API though, I'll try doing more research on that tomorrow.
If working with MS products is not an absolute necessity, you might also consider taking a shot at Asterisk. This is an open-source PBX (in software) that allows development on Linux, Windows (emulated) and Mac. At the company where I work, we use it for implementing small-scale exchanges, about a 100 lines or so. It also interfaces well with VoIP and allows a whole host of protocols. I have developed scripts and programs in C++ that work on voice packets in real-time, and so far, my experience has been good. As for your stated use-case of blocking telemarketers etc., this would be a very good fit. Check out further details here.
After doing more research, having one link lead to another link, and coming up with new search terms, I stumbled across this site that looks like it could kick me off using the Windows Telephony API in C++: link. This link includes open source c++ samples showing how to do the basics of what this question asks, I'll just have to test to see if they actually still work.
This is only the beginning of my research, so I'll keep you posted on any other findings. If anyone else is knowledgeable in this area, please still feel free to drop me information on what I want to accomplish.

'Field Scraping' in Windows

I want to develop an auditing application for certain Windows applications. I want to grab the text from MessageBoxes, Windows, Forms, Selections etc and ideally I would like to program in C++.
I've looked into Windows UI Automation as a possible solution, but am slightly put off as it says it will need to know parts of the underlying data structures which I can't get at. Alternatively, I've looked around and Neo's SafeKeys says that it protects against 'field scraping', but upon searching for it I can't find any information on how it is done. Could someone with experience with this please enlighten me? I'm aware you can scrape websites and the like, but I wish to scrape applications instead.
Any help would be greatly appreciated.
Look into using the accessibility layer, MSAA
I presume they are talking about doing a lot of EnumChildWindows() and GetWindowText().
A simple way of doing this without going near any data structures is to use Abbyy's OCR SDK http://www.abbyy.com/ocr_sdk/ to emulate in an application what their amazing Screenshot reader does. http://www.abbyy.com/screenshot_reader/ . With this technology, nothing you can read on the screen is safe from being captured as text, though it makes a mess of the odd character occasionally.

MSHTML MFC Tutorial

I know this has been asked twice before but both had no proper replies and are dated so in case someone has found something in these days, I'm asking again!.
Any one knows any good tutorial for MSHTML or some open source project which can be read to understand how various operations can be done in MSHTML - MFC?
Thanks
Your question makes it difficult to know exactly what you are trying to do, but the main MFC class that you need to use is CHtmlView. The MSDN has the definitive sources of information about it:
CHtmlView class
Creating a Web
Browser-Style MFC Application
Using MFC to Host a WebBrowser Control
If you find those links a bit terse, then this page contains some slightly friendlier articles:
Advanced CHtmlView Hosting
However, I would also ask whether you are definitely 100% sure that you want to use MFC?
The reason I ask is because I've worked for a number of years on an open-source project that hosts the Microsoft WebBrowser control and we saw significant performance improvements when we stripped out MFC from the project. The MFC abstractions weren't really buying us anything over the COM interfaces that are exposed by the control. Stripping out the MFC also made our code much simpler.
The project is open source, so if you want to see the code for yourself, you can get more information here. It is specifically the LibRender project that hosts the WebBrowser control. If you want to see it running, you should build the SWViewer solution.
The one place I like to visit for MFC is Newcomer's site There are some useful tutorials and demos of various things there. Although its more of a general MFC site, so maybe you can find what you are looking for there.

searching for winapi functions

I'm learning programing windows applications with C++. Now I'm reading about messages and I'm playing with the spy++.
What function spy++ use in order to mark/highlight the window under mouse cursor?
Also, can you give me some tips about using MSDN? I'm my opinion is not user friendly at all.
I'm learning programming by myself and i can't get some real life experience tips as those which are learning at college or in teams.
ty
Not sure exactly what your problem with MSDN is ... I tend to go to e.g. Win32 and COM development and look around for a suitable category in the listing to the left, then click down from there. Or just enter function names and search if I already know what I'm looking for but want the reference documentation. On the other hand, I'm not much of a Win32 developer.
I think spy++ is just inverting the colors directly on the window/screen DC (You could use InvertRect() for example) On Windows 2000 and later, it is probably better to use a translucent layered window if you actually wanted to implement this window highlight since some graphic corruption can occur when messing with other windows behind their back.
Writing a Windows application with just the windows API is possible, but you'll end up writing huge amounts of boilerplate code just to create simple things. This is why people normally use libraries built on top of it to make things easier - MFC for example.
The MSDN article Creating Win32 Applications provides a good explanation of the ins-and-outs of a Windows application using the Win32 API. Bare in mind though that you could build the same application in minutes using MFC.
I agree that MSDN is not the most user friendly source of information for a beginner. In my opinion it works much better as a reference.
My advice would be to focus on building some test applications using MFC (assuming you are tied to C++ as a language). Try looking at the codeproject MFC sections for example, and perhaps even buy a book to help get you started. This does of course require Visual Studio, but you can download the free express edition here