Where to start?

Hi, I am trying to learn how to use c++ to write windows applications.
I am familiar with C++ console application programming (Finished a good book and 3 semesters of comp. science in college) and i think next logical step is windows programming. I tried to find a good book and i read in about 10000000 forums that I have to start with the book called "Charles Petzold, Programming Windows". The book is ok, i spend a little time reading first 4 chapters, its super confusing but it start making some sence now. but the problem is that the book is written for C and not C++. I just wonder if its ok or there is a better book that will use C++.

1 more question, alot of functions are accepting Tchar strings, Just wonder if its possible to use just strings. I got tired of writing TEXT ("something here")

thanks.
There is _T() macro which do exactly the same thing as TEXT().
I try to explain the issues between C and C++ coding idioms and Windows programming here ...

http://www.jose.it-berater.org/smfforum/index.php?topic=3389.0

You can code without the TCHAR macros if you like, but many here consider it to be poor practice. I'm ambivalent about the issue myself. Couple years back though I decided to only use the TCHAR macros, and I've stuck with that. The various development environments enter the picture though. Code::Blocks (at leat the version I use) allows one to easily code without the macros. In other words, one can do this no problem ...

1
2
char szTitle[] = "My Program";
HWND hMain=CreateWindowEx(0,szTitle, szTitle, .....)


Or even ...

 
HWND hMain=CreateWindowEx(0,"button", "My Button #1", .....)


However, with Microsoft's Visual Studio, that will get you into trouble quite quickly. Not bad trouble, but trouble nonetheless. To make it work in Visual Studio, which defaults to wide character strings, you need to tell it through the project properties window that you want to use the multi-byte character set instead of wide character. Once you've done that - no problems.

The reason I decided finally after many years of fighting this issue to go with strictly the TCHAR macros, is that I code for both desktop Windows applications, and Windows CE. Windows CE doesn't use the single byte character set (at least not much). In cases where I wanted to port desktop code to Windows CE I would have to go through the miserable process of re-doing a lot of source code. But if I do everything using the macros, my code is portable. So that's why I use them. It is a big pain, but its the cost of doing business in C or C++.

Almost forgot! The other thing you can do if you really hate the tchar.h macros, is just use the wchar_t data type and the strictly W versions of the Windows Api functions. For example, ...

1
2
3
wchar_t szBuffer[] = L"My Name Is Fred";
wprintf(L"Who???   %s\n",szBuffer);
wprintf(L"Number Of wchar_ts In szBuffer = %d\n",wcslen(szBuffer));
Last edited on
I am using Ivor Horton’s Beginning Visual C++ 2010, and have found it to be very useful.
Topic archived. No new replies allowed.