Visual C++ is something dreamed up by the guys at Microsoft that said, hey...why type all that crap in and actually program?
Instead we can make totally assinine tools like ClassWizard, WizardBar and twelve thousand digit GUID's inside of include files so no one in their right mind could read the thing.
Essentially in MFC programming under MSVC, which is what I think the whole IDE is geared towards is using their class wizard to create classes, variables, etc. and also to link them in with your visual components. It's like Visual Basic ...you create the dialog resource, bitmaps, menus, etc. and then the class wizard will link the interface to actual code.
Really it's a pain in the arse as I'm finding out and you rarely if ever type anything into the code.
Do yourself a favor and learn Direct3D or OpenGL. They are way easier than obfuscated MFC or Windows GUI.
I could program an entire renderer in about 3 days and yet I haven't been able to code my world editor for the renderer in about two weeks under MFC. I agree with Darkness...Windows programming is more about finding out which function does what and why, and you are relegated to looking said function up in the obfuscated convoluted Windows SDK help files. I think they were written to confuse....honestly. They really suck. No wonder so many books have been written to explain the thing.
If I sound a bit cynical, I am. GUI sucks. But I have to do it for editors and tools. Now off to figure out why my friggin CDialog isn't working right.....
Here is 'Visual C++' at its best.
Code:
#if !defined(AFX_GRIDSIZEDIALOG_H__276C72B5_16B4_4E7D_AECF_73E188AB2146__INCLUDED_)
#define AFX_GRIDSIZEDIALOG_H__276C72B5_16B4_4E7D_AECF_73E188AB2146__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// GridSizeDialog.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CGridSizeDialog dialog
class CGridSizeDialog : public CDialog
{
// Construction
public:
virtual BOOL OnInitDialog();
CGridSizeDialog(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CGridSizeDialog)
enum { IDD = IDD_GRIDSIZE };
CEdit m_editVert;
CEdit m_editHoriz;
CButton m_btnOk;
CButton m_btnCancel;
CSpinButtonCtrl m_spinVert;
CSpinButtonCtrl m_spinHoriz;
UINT m_iHorizSpacing;
UINT m_iVertSpacing;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CGridSizeDialog)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
void GetHVSpacing(UINT *iHrz,UINT *iVrt)
{
iHrz=&m_iHorizSpacing;
iVrt=&m_iVertSpacing;
}
// Generated message map functions
//{{AFX_MSG(CGridSizeDialog)
afx_msg void OnDeltaposSpinhoriz(NMHDR* pNMHDR, LRESULT* pResult);
virtual void OnOK();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_GRIDSIZEDIALOG_H__276C72B5_16B4_4E7D_AECF_73E188AB2146__INCLUDED_)
Code:
// GridSizeDialog.cpp : implementation file
//
#include "stdafx.h"
#include "ZeldaMapEdit.h"
#include "GridSizeDialog.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CGridSizeDialog dialog
CGridSizeDialog::CGridSizeDialog(CWnd* pParent /*=NULL*/)
: CDialog(CGridSizeDialog::IDD, pParent)
{
//{{AFX_DATA_INIT(CGridSizeDialog)
m_iHorizSpacing = 0;
m_iVertSpacing = 0;
//}}AFX_DATA_INIT
}
BOOL CGridSizeDialog::OnInitDialog(void)
{
CDialog::OnInitDialog();
//char txt[5];
//sprintf(txt,"%d",m_iHorizSpacing);
//m_editHoriz.SetWindowText(txt);
//m_editVert.SetWindowText(txt);
m_spinHoriz.SetRange(0,64);
m_spinVert.SetRange(0,64);
//m_spinHoriz.SetBuddy(m_editHoriz.GetActiveWindow());
//m_spinVert.SetBuddy(m_editVert.GetActiveWindow());
return true;
}
void CGridSizeDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CGridSizeDialog)
DDX_Control(pDX, IDC_EDITVERT, m_editVert);
DDX_Control(pDX, IDC_EDITHORIZ, m_editHoriz);
DDX_Control(pDX, IDOK, m_btnOk);
DDX_Control(pDX, IDCANCEL, m_btnCancel);
DDX_Control(pDX, IDC_SPINVERT, m_spinVert);
DDX_Control(pDX, IDC_SPINHORIZ, m_spinHoriz);
DDX_Text(pDX, IDC_EDITHORIZ, m_iHorizSpacing);
DDV_MinMaxUInt(pDX, m_iHorizSpacing, 0, 64);
DDX_Text(pDX, IDC_EDITVERT, m_iVertSpacing);
DDV_MinMaxUInt(pDX, m_iVertSpacing, 0, 64);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CGridSizeDialog, CDialog)
//{{AFX_MSG_MAP(CGridSizeDialog)
ON_NOTIFY(UDN_DELTAPOS, IDC_SPINHORIZ, OnDeltaposSpinhoriz)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CGridSizeDialog message handlers
void CGridSizeDialog::OnDeltaposSpinhoriz(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
*pResult = 0;
}
void CGridSizeDialog::OnOK()
{
// TODO: Add extra validation here
//char temp[3];
//m_editHoriz.GetWindowText(temp,3);
//::MessageBox(0,temp,0,0);
//m_iHorizSpacing=atoi(temp);
//m_editVert.GetWindowText(temp,3);
//m_iVertSpacing=atoi(temp);
m_editHoriz.UpdateData(true);
m_editVert.UpdateData(true);
CDialog::OnOK();
}
Don't ask me what half that crap is....cuz I don't know - I only wrote like 7 lines of it. The rest of the garbly gook was put in there by class wizard. But that's what you need to get MFC working.......so no way I'm gonna type all that crap in.
Whatever happened to good old constructors and oh....functions written by the programmer?
And isn't it nice to know that your compiler that you trust and use also has coded into it secret constructs like the one's you see in that code that enable it to be compatible with lame class wizard? Makes me feel all warm and fuzzy inside.
Last I recall // meant a comment in C. But no...that's not good enough. MS wants to use //{{ which I have no idea what that does. Obviously there's more to the MSVC parser than meets the eye.