Looking for books to learn C++ win32 programming ?

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 696 Views - Last Post: 21 August 2018 - 06:27 AM Rate Topic: -----

#1 sunshine33   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 129
  • Joined: 15-September 17

Looking for books to learn C++ win32 programming ?

Posted 19 August 2018 - 06:17 AM

What is the best book to learn C++ Win32 Programming ?



I have tried to program in some languages before , Then i thought about C win32 programming , Charles Petzold book was a nice one .

Is there any such good books for C++ ?

Why i keep changing from one programming languages to other is because i have lot of free time and i am also waiting for a few books of C# from amazon to arrive .

So i thought i would also try to learn C++ Win32 programming

:smile2:

This post has been edited by sunshine33: 19 August 2018 - 06:17 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Looking for books to learn C++ win32 programming ?

#2 Martyr2   User is offline

  • Programming Theoretician
  • member icon

Reputation: 5284
  • View blog
  • Posts: 14,105
  • Joined: 18-April 07

Re: Looking for books to learn C++ win32 programming ?

Posted 19 August 2018 - 09:12 AM

What about the book from the man who created C++ itself? Bjarne Stroutstrup...

https://www.amazon.c...h/dp/0321563840


Another recently seen document, which is a draft, seems pretty easy to digest and is interesting to go through...

http://python.cs.sou...ook/progcpp.pdf

But of course the Stroutstrup book is pretty much the definitive guide on the language.
Was This Post Helpful? 1
  • +
  • -

#3 sunshine33   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 129
  • Joined: 15-September 17

Re: Looking for books to learn C++ win32 programming ?

Posted 19 August 2018 - 10:12 AM

Thanks for the book suggestions ,
Does it have Windows programming in it ?
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 6406
  • View blog
  • Posts: 21,976
  • Joined: 05-May 12

Re: Looking for books to learn C++ win32 programming ?

Posted 19 August 2018 - 10:57 AM

The Windows Win32 API is primarily geared to work with the lowest common denominator which was C and Pascal at the time they were being designed/written. Since C APIs are accessible via C++, you would simply call them you would call any other libraries which has C facing interfaces like C standard library, OpenGL, OpenCV, ZipLib, etc.

Most C facing libraries nowadays also have C++ wrappers. For Windows, the most common C++ wrapper for the APIs is MFC, but I personally would not recommend going down that route because it carries high overhead, as well as, heavy "buy-in". By "buy-in", I mean that once you go with MFC, you need to go MFC (almost) all the way. Eg. you must inherit from the MFC classes; you must use MFC helper objects, etc.

ATL and WTL are better C++ wrappers for the Win32 APIs. Although most people associate COM programming with ATL, it also has Win32 API C++ wrappers. WTL was targeted primarily to just the Win32 API C++ wrappers without any COM. Both are intended to be lighter weight with less requirements to "buy-into" the framework. You could pick and choose pieces of it you want to use.

Looping back to your question regarding learning C++ and Windows Programming, most Windows Programming books teach you a C style of programming that may only occasionally make use of C++ features. Part of this is tradition because that is the way Windows programming has traditionally been taught and done. Another part of this is for clarity: The goal is to teach how to use the Windows API, and it really doesn't help to highlight the API if all you are going to do is to abstract it away using a C++ adapter/facade in front of the C APIs.
Was This Post Helpful? 1
  • +
  • -

#5 Martyr2   User is offline

  • Programming Theoretician
  • member icon

Reputation: 5284
  • View blog
  • Posts: 14,105
  • Joined: 18-April 07

Re: Looking for books to learn C++ win32 programming ?

Posted 19 August 2018 - 10:57 AM

It is a book on C++ which is platform agnostic. Yes, you can run the code on Windows, but itself is not directly targeting the windows OS. You will want to start with this book first before you go onto anything else. Win32 programming is just writing C++ that takes advantage of Windows specific functionality. You will need to learn to walk before you can run. :)
Was This Post Helpful? 1
  • +
  • -

#6 sunshine33   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 129
  • Joined: 15-September 17

Re: Looking for books to learn C++ win32 programming ?

Posted 20 August 2018 - 12:13 AM

Thanks for all the replies ,

So you need these API'S to make the GUI applications .OK

WinAPI is for C based GUI programs
MFC (Microsoft Foundation Class ) is for C++ based GUI programs



Then this is a good start ?

https://www.tutorial...m/mfc/index.htm
Was This Post Helpful? 0
  • +
  • -

#7 sunshine33   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 129
  • Joined: 15-September 17

Re: Looking for books to learn C++ win32 programming ?

Posted 20 August 2018 - 12:34 AM

After searching for this keyword , Microsoft Foundation Class , I found this book Programming Windows with MFC - Jeff Prosise

Looks good

:)
Was This Post Helpful? 0
  • +
  • -

#8 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 6406
  • View blog
  • Posts: 21,976
  • Joined: 05-May 12

Re: Looking for books to learn C++ win32 programming ?

Posted 20 August 2018 - 06:08 AM

If you are just learning C++, MFC is not a great example of a well designed C++ library. It was born during the age where C++ was essentially C with classes. To make matters worse, modern C++ abhors the use of macros. MFC revels in its use of macros. Additionally, MFC was designed back in the days when large, deep class hierarchies was thought to be good design (as well as ease the users of the Borland OWL over into MFC). We have since learned that composition is better than inheritance. It was also designed before the the popularity of STL and so does not interface well with the now accepted Standard C++ Library.

I highly suggest learning C++ at the console level first, and then pick up MFC so that you don't get infected with it's poor design ideas.
Was This Post Helpful? 1
  • +
  • -

#9 Thomas1965   User is online

  • D.I.C Regular

Reputation: 106
  • View blog
  • Posts: 394
  • Joined: 09-September 16

Re: Looking for books to learn C++ win32 programming ?

Posted 20 August 2018 - 08:19 AM

Quote

i have decided to learn c# for the rest of my life

You seem to have changed your mind very quickly.
Why don't you stick with C#, it's much easier to learn than C++ ?

This post has been edited by Thomas1965: 20 August 2018 - 08:19 AM

Was This Post Helpful? 1
  • +
  • -

#10 sunshine33   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 129
  • Joined: 15-September 17

Re: Looking for books to learn C++ win32 programming ?

Posted 20 August 2018 - 08:28 AM

Thanks for the reply .

So C++ makes use of ,

Microsoft Foundation class ( MFC )
Standard Template Library ( STL )

to make GUI programs .


An example of Microsoft Foundation class

Quote

Hello.cpp



#include <afxwin.h>
#include "Hello.h"
CMyApp myApp;
/////////////////////////////////////////////////////////////////////////
// CMyApp member functions
BOOL CMyApp::InitInstance ()
{
    m_pMainWnd = new CMainWindow;
 
   m_pMainWnd->ShowWindow (m_nCmdShow);
    m_pMainWnd->UpdateWindow ();
    return TRUE;
}
/////////////////////////////////////////////////////////////////////////
// CMainWindow message map and member functions
BEGIN_MESSAGE_MAP (CMainWindow, CFrameWnd)
    ON_WM_PAINT ()
END_MESSAGE_MAP ()
CMainWindow::CMainWindow ()
{
    Create (NULL, _T ("The Hello Application"));
}
void CMainWindow::OnPaint ()
{
    CPaintDC dc (this);
    
    CRect rect;
    GetClientRect (&rect);
    dc.DrawText (_T ("Hello, MFC"), -1, &rect,
        DT_SINGLELINE ¦ DT_CENTER ¦ DT_VCENTER);
}



Quote

Hello.h


class CMyApp : public CWinApp
{
public:
    virtual BOOL InitInstance ();
};
class CMainWindow : public CFrameWnd
{
public:
    CMainWindow ();
protected:
    afx_msg void OnPaint ();
    DECLARE_MESSAGE_MAP ()
};





An example of Standard Template Library

int main() 
{	
int input;	
vector<int> ivec;

	
// input	
while (cin >> input )		
ivec.push_back(input);

	
// sorting
sort(ivec.begin(), ivec.end());	


// output
vector<int>::iterator it;	
for ( it = ivec.begin();	      
it != ivec.end(); ++it ) 
{			
cout << *it << " ";	
}	
cout << endl;

	
return 0;

}




View PostThomas1965, on 20 August 2018 - 08:19 AM, said:

Quote

i have decided to learn c# for the rest of my life

You seem to have changed your mind very quickly.
Why don't you stick with C#, it's much easier to learn than C++ ?



Thanks for the reply ,

I am waiting for a book of C# from amazon to arrive
I thought i would do some research about C++ too in the meanwhile

:)

This post has been edited by sunshine33: 20 August 2018 - 12:59 PM

Was This Post Helpful? 0
  • +
  • -

#11 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 6406
  • View blog
  • Posts: 21,976
  • Joined: 05-May 12

Re: Looking for books to learn C++ win32 programming ?

Posted 20 August 2018 - 04:57 PM

STL knows nothing about GUIs. Your example above is a console program.

C++ also knows nothing about GUIs. It is more like some GUI frameworks are written in C++ and/or meant to be used by C++ programs.
Was This Post Helpful? 1
  • +
  • -

#12 sunshine33   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 129
  • Joined: 15-September 17

Re: Looking for books to learn C++ win32 programming ?

Posted 21 August 2018 - 01:24 AM

Thanks for all the help Skydiver ,
I finally found what i was looking for .


Quote

addition.cpp


// Fig. 2.12: addition.cpp
// Addition program with MFC dialog box
#include <afxwin.h>
#include "addition_ids.h"
#include "CAdditionDialog.h"

// clicked the "Add" button
afx_msg void CAdditionDialog::OnAdd()
{
   const TEXT_SIZE = 16;
   char szText[ TEXT_SIZE + 1 ]; // buffer for conversions

   // get addresses of Edit Box Controls 

   CEdit *pTotal = ( CEdit * ) ( GetDlgItem( IDC_TOTAL ) );
   CEdit *pNum   = ( CEdit * ) ( GetDlgItem( IDC_NUMBER ) );

   pNum->GetWindowText( szText, TEXT_SIZE ); // get Number
   m_nTotal += atoi( szText );      // add binary value
   
   itoa( m_nTotal, szText, 10 );    // convert total to text

   pTotal->SetWindowText( szText ); // display total
   pNum->SetWindowText( "" );       // clear input
   pNum->SetFocus();                // next input to Number
}

// clicked the "Clear" button
afx_msg void CAdditionDialog::OnClear()
{
   CEdit *pTotal = ( CEdit * ) ( GetDlgItem( IDC_TOTAL ) );
   CEdit *pNum   = ( CEdit * ) ( GetDlgItem( IDC_NUMBER ) );

   m_nTotal = 0;                // clear the total
   pTotal->SetWindowText( "" ); // clear the edit box
   pNum->SetFocus();            // next input to Number
}

BEGIN_MESSAGE_MAP( CAdditionDialog, CDialog )
   ON_COMMAND( IDC_ADD, OnAdd )
   ON_COMMAND( IDC_CLEAR, OnClear )
END_MESSAGE_MAP()

// dialog-based application 
class CAdditionApp : public CWinApp {
public:
   BOOL InitInstance()
   {
      CAdditionDialog additionDialog;
      additionDialog.DoModal();  // run dialog
      return FALSE;              // finished
   }

} addition;




Quote

addition_ids.h


// Fig 2.12: addition_ids.h
// Define Message Numbers

#define IDC_NUMBER 2000
#define IDC_ADD    2001
#define IDC_TOTAL  2002
#define IDC_CLEAR  2003




Quote

CAdditionalDialog.h


// Fig. 2.12: CAdditionDialog.h
// Addition program with MFC dialog box

class CAdditionDialog : public CDialog {
public:
   CAdditionDialog()
      : CDialog( "Addition" ), m_nTotal( 0 ) {}

   afx_msg void OnAdd();         // clicked the "Add" button
   afx_msg void OnClear();       // clicked the "Clear" button

private:
   int m_nTotal;                 // sum of numbers

   DECLARE_MESSAGE_MAP()
};




Quote

addition.rc


// Fig. 2.12: Addition.rc
// resource script for addition example
#include "afxres.h"
#include "addition_ids.h"

Addition DIALOG  50, 50, 130, 130
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU

CAPTION "Addition Dialog Box"
{
    LTEXT         "Enter a number:", IDC_STATIC, 30, 20, 50, 8
    EDITTEXT      IDC_NUMBER, 30, 30, 72, 16, ES_NUMBER

    DEFPUSHBUTTON "Add", IDC_ADD, 50, 50, 30, 15

    LTEXT         "Total:", IDC_STATIC, 30, 70, 20, 8
    EDITTEXT      IDC_TOTAL, 30, 80, 70, 16, 
                  ES_READONLY | NOT WS_TABSTOP

    PUSHBUTTON    "Clear", IDC_CLEAR, 50, 100, 30, 15, 
                  NOT WS_TABSTOP
}



Is that final piece of the code part of the original program or a separate one ?
Was This Post Helpful? 0
  • +
  • -

#13 Thomas1965   User is online

  • D.I.C Regular

Reputation: 106
  • View blog
  • Posts: 394
  • Joined: 09-September 16

Re: Looking for books to learn C++ win32 programming ?

Posted 21 August 2018 - 03:47 AM

The last part is a resource script and it's part of the program.
It defines the actual dialog(UI)
Was This Post Helpful? 1
  • +
  • -

#14 sunshine33   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 129
  • Joined: 15-September 17

Re: Looking for books to learn C++ win32 programming ?

Posted 21 August 2018 - 04:19 AM

Thanks .
I am going to prepare some proper notes for C++ learning

:)
Was This Post Helpful? 0
  • +
  • -

#15 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 6406
  • View blog
  • Posts: 21,976
  • Joined: 05-May 12

Re: Looking for books to learn C++ win32 programming ?

Posted 21 August 2018 - 05:21 AM

The MFC code in post #10 is a real Windows program. The MFC code in post #12 is a "hack". The first one actually registers a window class, setups controls, and runs a message loop to handle events. This is how a traditional Windows program works. The second one uses the default dialog class, uses a dialog template in the resource script to setup controls, and uses the dialog's message loop to handle events.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2