Thread: windows and c++

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    1

    windows and c++

    Hello,

    I am a complete idiot in programming. I was using cprogramming.com, but was wondering if someone could tell me how you learn how to do things for windows apps (eg. internet explorer, ZoneAlarm), as when I do the tutorials on cprogramming.com, everything is always in a dos window.

    Thanks,
    Jeff

  2. #2
    Registered User Dante Shamest's Avatar
    Join Date
    Apr 2003
    Posts
    970

  3. #3
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    >>> I am a complete idiot in programming

    It is because the tutorials you are using are trying to address this point. They are programming tutorials, not Win32 API tutorials. If you cannot program, believe me, you can't program the Win32 API. You will need to be able to reasonably fluent with your language before you try otherwise, you will just get confused and be back here asking why "X" doesn't work, when you are simply doing it wrong.

    Walk before you run, learn the alphabet before you start on poetry, the language, before the applications.

    This is just about the simplest Windows program you can write.

    Code:
    #include <windows.h>
    
    LRESULT CALLBACK WindowFunc(HWND, UINT, WPARAM, LPARAM);
    
    int WINAPI WinMain(HINSTANCE hThisInst, HINSTANCE hPrevInst, 
                       LPSTR Args, int WinMode)
    {
        HWND hWnd;
        MSG Message;
        WNDCLASSEX WinClass;
        
        WinClass.cbSize = sizeof(WNDCLASSEX);   
        WinClass.hInstance = hThisInst;
        WinClass.lpszClassName = "Window";
        WinClass.lpfnWndProc = WindowFunc; 
        WinClass.style = 0;     
        WinClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
        WinClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
        WinClass.hCursor = LoadCursor(NULL, IDC_ARROW);
        WinClass.lpszMenuName = NULL; 
        WinClass.cbClsExtra = 0; 
        WinClass.cbWndExtra = 0;
        WinClass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH); 
        
        if(!RegisterClassEx(&WinClass)) return 0;
        
        hWnd = CreateWindow("Window", 
                            "Window",
                            WS_OVERLAPPEDWINDOW, 
                            CW_USEDEFAULT,
                            CW_USEDEFAULT, 
                            CW_USEDEFAULT, 
                            CW_USEDEFAULT,
                            HWND_DESKTOP,
                            NULL,
                            hThisInst,
                            NULL);
        
        ShowWindow(hWnd, 
                   WinMode);
        UpdateWindow(hWnd);
    
        while(GetMessage(&Message,
                         NULL,
                         0,
                         0))
        {
            TranslateMessage(&Message); 
            DispatchMessage(&Message);
        }
        return Message.wParam;
    }
    
    LRESULT CALLBACK WindowFunc(HWND hWnd,UINT Message,WPARAM wParam,LPARAM lParam)
    {
        PAINTSTRUCT PaintStruct;
        HDC hDC;
    
        switch(Message)
        {
        case WM_PAINT:
            hDC = BeginPaint(hWnd,
                             &PaintStruct);
    
            TextOut(hDC,
                    10,
                    10,
                    "Hello Windows",
                    14);
    
            EndPaint(hWnd,
                     &PaintStruct);
            break;
    
        case WM_DESTROY:
            PostQuitMessage(0);
            break;
    
        default:
            return DefWindowProc(hWnd,
                                 Message,
                                 wParam,
                                 lParam);
        }
        return 0;
    }
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  4. #4
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    [pointless]
    Hmm, you could completely cut out the window procedure, change WNDCLASSEX to WNDCLASS and initialize it to [0] (except with curly braces instead of square ones) and cut out half the filling-in, use WS_VISIBLE instead of ShowWindow(), and cut out UpdateWindow(). That comes to less than 1/2 the code Actually, you could cut out the entire thing and just stick a MessageBox(), then return!
    [/pointless]

    JefWic:
    >>I am a complete idiot in programming.
    Then I agree with adrianxw, you probably shouldn't try Windows programming, unless, you're just being excessively modest
    Last edited by Hunter2; 03-17-2004 at 07:35 PM.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  5. #5
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Shorter:
    Code:
    #include <windows.h>
    INT WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, INT)
    {
      MessageBox(NULL, "I am teh 1337!!!", "Message!", MB_OK);
    }
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  6. #6
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Thanks for implementing my suggestion in code Magos
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  7. #7
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    The reason my tutorial code is the way it is is because it tries to explain the reason behind things as well as the simple mechanics. The programs are written with beginners in mind who aim to go on to produce more then just the very basic "Hello World" program.

    The full tutorial develops this program over several pages, I just clipped and posted the end result.

    It then goes on to demonstrate why it is rubbish, and suggests the next tutorial - (back buffering)!
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

Popular pages Recent additions subscribe to a feed