C++ win32 in VS 2005

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RandomPscho
    FFR Player
    • Jun 2006
    • 504

    #1

    C++ win32 in VS 2005

    Hello all

    I am trying to learn c++ for win32 apps in Visual Studio 2005. Still
    new to c++, but I can program decently in the console.

    I followed a tutorial here:

    but the code doesn't work in 2005. I got it to work by adding (LPCWSTR)
    before all the errors saying it couldn't convert. Now it runs, but it
    has Chinese text in the title, when it is supposed to say Random1Pscho
    :s

    Here is the code, just compile it in Visual Studio 2005 and run. I have
    no idea why it has chinese characters, can anybody here help? A

    Code:
    #include <windows.h>
    
    const char g_szClassName[] = "myWindowClass";
    const char name[] = "Random1Pscho";
    
    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
    lParam)
    {
        switch(msg)
        {
            case WM_CLOSE:
                DestroyWindow(hwnd);
            break;
            case WM_DESTROY:
                PostQuitMessage(0);
            break;
            default:
                return DefWindowProc(hwnd, msg, wParam, lParam);
        }
        return 0;
    
    }
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
        LPSTR lpCmdLine, int nCmdShow)
    {
        WNDCLASSEX wc;
        HWND hwnd;
        MSG Msg;
    
        wc.cbSize        = sizeof(WNDCLASSEX);
        wc.style         = 0;
        wc.lpfnWndProc   = WndProc;
        wc.cbClsExtra    = 0;
        wc.cbWndExtra    = 0;
        wc.hInstance     = hInstance;
        wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
        wc.hCursor       = LoadCursor(NULL, IDC_CROSS);
        wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+4);
        wc.lpszMenuName  = NULL;
        wc.lpszClassName = (LPCWSTR)g_szClassName;
        wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
    
        if(!RegisterClassEx(&wc))
        {
            MessageBox(NULL, (LPCWSTR)"Window Registration Failed!",
    (LPCWSTR)"Error!",
                MB_ICONEXCLAMATION | MB_OK);
            return 0;
        }
    
        hwnd = CreateWindowEx(
            WS_EX_CLIENTEDGE,
            (LPCWSTR)g_szClassName,
            (LPCWSTR)name,
            WS_OVERLAPPEDWINDOW,
            CW_USEDEFAULT, CW_USEDEFAULT, 350, 150,
            NULL, NULL, hInstance, NULL);
    
        if(hwnd == NULL)
        {
            MessageBox(NULL,(LPCWSTR)"Window Creation
    Failed!",(LPCWSTR)"Error!",
                MB_ICONEXCLAMATION | MB_OK);
            return 0;
        }
    
        ShowWindow(hwnd, nCmdShow);
        UpdateWindow(hwnd);
    
        while(GetMessage(&Msg, NULL, 0, 0) > 0)
        {
            TranslateMessage(&Msg);
            DispatchMessage(&Msg);
        }
        return (int)Msg.wParam;
    }
    THANKS A LOT!
  • Illysium
    FFR Player
    • Dec 2006
    • 38

    #2
    Re: C++ win32 in VS 2005

    Error with this line:

    wc.lpszClassName = (LPCWSTR)g_szClassName;
    41 C:\Documents and Settings\Owner\My Documents\Untitled1.cpp cannot convert `const WCHAR*' to `const CHAR*' in assignment

    Can't compile if it doesn't work *grin*

    ".. Leave it be .."
    If you have attempted Alchemy by clapping your hands or by drawing an array, copy and paste this in your signature.

    Comment

    • RandomPscho
      FFR Player
      • Jun 2006
      • 504

      #3
      Re: C++ win32 in VS 2005

      Are you sure your using visual studio 05? It compile for that, and only for that.

      I got the code working in both visual studio and dev-c++ (without the (LPCWSTR) typecasting) so I have been using dev-c++.

      Comment

      Working...