Thread: learning windows

  1. #16
    Registered User
    Join Date
    Mar 2003
    Posts
    580
    To directly answer your question, learing windows programming is a bit different than learning game programming. Game programming is largely about learning mathematics and algorithms, and learning windows programming is purely about memorizing what each function in the windows api does.

    In order to learn the windows api you typically have to have a strong learning curve and the ability to memorize.


    My own spin on the issue:
    Learning windows programming, while useful, is probably not too important to hark on if your goal is to program games. In a way, learning game programming is somewhat easier, because once you really understand a mathematical equation or algorithm, you never forget it. The opposite is true for windows api programming, because if you are not consistently working with windows api it is quite easy to forget how to use it.

    I personally only have experience up until making filemenus and generating windows that you can draw graphics to, and even then I can't do it off of the top of my head, I need to look at other people's code, a book, or stuff I've already implemented.

    An easier route is to just use visual basic for things like 'settings applications' (an application that must be run before your actual game starts which asks what settings, eg screen resolution, you want. The application then writes this data to a text file, and then your actual game application reads this data in and the actual game executes).
    Last edited by Darkness; 01-31-2005 at 09:29 AM.
    See you in 13

  2. #17
    Self-Taught Noob
    Join Date
    Jan 2005
    Location
    Ohio
    Posts
    38
    ive been working on a console game in C++ off and on for a while and havnt really ran into much problem. but i want to further my expierence to add pictures to the game and maybe add some mouse support. i figured i would be easier to learn windows to do such things.

    Also what is the difference between windows programming and Visual C++.
    No one died when Clinton lied.

    Compiler: Borland C++ Builder
    OS: Windows XP

  3. #18
    Registered User
    Join Date
    Mar 2003
    Posts
    580
    If I were you I'd search the Window's programming FAQ for that answer.
    Last edited by Darkness; 01-31-2005 at 11:19 AM.
    See you in 13

  4. #19
    Trolley boy JackGL's Avatar
    Join Date
    Jan 2005
    Location
    UK
    Posts
    15
    Quote Originally Posted by GamingMarvel
    Also what is the difference between windows programming and Visual C++.
    Visual C++ is an IDE, which is a development environment that you can code in and create applications.

    Alternatives include DevCPP, CodeWarrior...etc.

    You don't have to use Visual C++ to write Windows programs, and you don't have to be Windows programming to use Visual C++.

    Windows programming is using C++ and the Windows API to create applications and things that use windows, menus, message boxes...etc.

  5. #20
    Self-Taught Noob
    Join Date
    Jan 2005
    Location
    Ohio
    Posts
    38
    thanks

    so if i understood you correctky if i already no same C++ itll be easier to learn VC++ than windows
    No one died when Clinton lied.

    Compiler: Borland C++ Builder
    OS: Windows XP

  6. #21
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    VC++ is not an API like the win32 API, VC++ is a tool to create programs using C++. Basicly it is an editor, debugger, compiler and linker together.

  7. #22
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905
    Quote Originally Posted by GamingMarvel
    so if i understood you correctky if i already no same C++ itll be easier to learn VC++ than windows


    Umm...VC++ is an IDE...it's not a language/API. The win32 API is basically just a set of functions and libraries that can sit on top of your code and allow you to create win32 windows. VC++ was made using the win32 API (I believe I remember reading somewhere that some of the first versions of VC++ were compiled with VC++, heh).

    But yah, I remember first learning win32 that I was doing it right around the time that I was trying to learn OpenGL and I wanted to understand what was going on when I created the window that OpenGL rendered to. I personally started off from winprog.org's tutorials, however, when I first went there the tutorials were way over my head, but I kept going back about once a week on a minimum and over time it eventually started to make sense. The win32 API, as Darkness said, is just a lot of memorizing, but thankfully there's MSDN for most cases of things.

    -edit-
    gah, Shakti beat me,

  8. #23
    Self-Taught Noob
    Join Date
    Jan 2005
    Location
    Ohio
    Posts
    38
    you lost me i think

    so visual C++ and Windows isnt programming it's just extra code you put into your console program to give them the windows look?
    No one died when Clinton lied.

    Compiler: Borland C++ Builder
    OS: Windows XP

  9. #24
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    nononono, Windows API is a set a functions that helps you give the windowslook to programs. Visual C++ is just a tool that will help you when you are programming.

  10. #25
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    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.
    Last edited by VirtualAce; 02-01-2005 at 10:13 AM.

  11. #26
    ~viaxd() viaxd's Avatar
    Join Date
    Aug 2003
    Posts
    246
    OMG, that's just sick...linux programming is way more fun.
    :wq

  12. #27
    Registered User
    Join Date
    Mar 2003
    Posts
    580
    what he posted is mfc.

    This whole thing is getting horribly confused.

    Windows API - an interface to the functions implemented in the windows DLLs

    MFC (Microsoft Foundation Classes) - a bunch of classes which is supposed to make access to the Windows API easier, but makes life hell

    -You can use the windows API in basically any language
    -it's far easier to write windows applications using visual basic than it is with C/C++
    See you in 13

  13. #28
    Self-Taught Noob
    Join Date
    Jan 2005
    Location
    Ohio
    Posts
    38
    now you really lost me

    so VC++ is a program to make other programs andWindows is functions put into your already made code?

    i might have to teach myself a little VB by the sounds of it.
    No one died when Clinton lied.

    Compiler: Borland C++ Builder
    OS: Windows XP

  14. #29
    Attack hamster fuh's Avatar
    Join Date
    Dec 2002
    Posts
    176
    VC++ is a development enviroment, like Borland C++ builder.

    Windows is a library that helps you make graphical applications (although it is not graphicly oriented). Example of Windows code:
    Code:
    //Creating the window: SECTION 1
        hwnd = CreateWindowEx (
               0,                   /* Extended possibilites for variation */
               szClassName,         /* Classname */
               "HomemadePaint",     /* Title Text */
               WS_POPUPWINDOW | WS_CAPTION | WS_MINIMIZEBOX, /* how the window looks*/
               0,       /* Windows decides the position */
               0,       /* where the window ends up on the screen */
               350,                 /* The programs width */
               350,                 /* and height in pixels */
               HWND_DESKTOP,        /* The window is a child-window to desktop */
               NULL,                /* No menu */
               hThisInstance,       /* Program Instance handler */
               NULL                 /* No Window Creation data */
               );
    
    
    //The message loop: SECTION 2
        /* Run the message loop. It will run until GetMessage() returns 0 */
        while (GetMessage (&messages, NULL, 0, 0))
        {
            /* Translate virtual-key messages into character messages */
            TranslateMessage(&messages);
            /* Send message to WindowProcedure */
            DispatchMessage(&messages);
        }
    
    
    
    //The window procedure: SECTION 3
    LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {            
            HDC hDC;
            PAINTSTRUCT ps;       
        switch (message)                  /* handle the messages */
        {
            case WM_CREATE:
                 break;
            case WM_COMMAND:
            switch(LOWORD(wParam))
            {
                case ID_FILE_EXIT:
                    PostMessage(hwnd, WM_CLOSE, 0, 0);
                break;
    
                default:
                MessageBox(NULL, "Feature not yet implemented", "Action not supported", MB_OK);
    
                break;     
            }
        break;
    
            case WM_PAINT:
                hDC=GetDC(hwnd);
                Paint(hDC);  //My funtion
                ReleaseDC(hwnd, hDC);
                break;
            case WM_CLOSE:
                 PostQuitMessage(0);
                 break;
    You can see Windows code isn't very pretty. What this does is:
    Section 1: This part creates the window and specifies the, well, specifications

    Section 2: I just pulled this up, so it isn't a good example, but this is the message loop. It should check for errors, but I'm too lazy to show you how

    Section 3: This handles the messages. Somewhere in the DispatchMessage function called in section 2 something lurks that calls WindowProcedure and passes it the message, along with wParam and lParam, which give you alot of the information needed to handle events. The big switch statement handles the messages. It determines whether the message is one of about 500 constants and if it is one that the program supports, it handles it. The WM_COMMAND message comes when you click on somthing in a File, Edit, Help, View, Tools, etc. menu. The loword of the wParam tells what you click on. In this example I check if it is File->Exit and if it is, I kill the program. If it is not one the program handles I post a message box that has "Feature not yet implemented" on it. If the message is that the Window requires a repaint, I prepare the hDC (handle to a Device Context) for painting and call my paint function and pass it hDC. After that is done I release hDC. If the Xish thing in the top right corner of the window (image attached) is pressed, it too kills the program.

    Well, section 3 got a little lengthy and barely even touched the subject of WindowProcedure. This is just a touch of what Windows programming is, though. Learning Windows programming really does require a good book or tutorial.

    Hope that helps,
    fuh
    Last edited by fuh; 02-02-2005 at 04:08 PM. Reason: Forgot image of X-ish thing! Oh no!
    Stupid things pop singers say

    "I get to go to lots of overseas places, like Canada."
    - Britney Spears

    "I love what you've done with the place!"
    -Jessica Simpson upon meeting the Secretary of Interior during tour of the White House

  15. #30
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    MCF is easy and quick. Just don't examine each line (yet).

    You don't have to peer inside things like 'sprint()' to use them.

    Soon enough, as you push the limits of what MFC can do, you will discover what the code does.

    You don't need to know this just yet.......

    >>DDX_Control(pDX, IDC_EDITVERT, m_editVert);
    this 'links' the control IDC_EDITVERT to a member variable m_editVert.
    It has to run after the dialog has been created, because all the HWNDs (ect) are 'allocated' then, but before the dialog is shown on screen.


    fuh you could try.....

    Code:
    PAINTSTRUCT  PaintDetails;
    case WM_PAINT:
                // ask windows what it want to paint and to validate that area (remove paint msg)
                BeginPaint(hwnd ,&PaintDetails);
                Paint(PaintDetails.hdc);  //yourfuntion
                EndPaint(hwnd, &PaintDetails);// let windows handle the clean-up
                break;
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. LoadFromFile() causes Windows 98 to freeze?
    By MidnightlyCoder in forum Windows Programming
    Replies: 8
    Last Post: 03-17-2006, 02:23 PM
  2. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM
  3. Manipulating the Windows Clipboard
    By Johno in forum Windows Programming
    Replies: 2
    Last Post: 10-01-2002, 09:37 AM
  4. Looking for good beginner tutorials in learning windows api
    By Unregistered in forum Windows Programming
    Replies: 2
    Last Post: 10-30-2001, 06:42 AM