Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > C/C++: Для новичков > WinAPI в Visual Studio 2008


Автор: Frazelli 9.2.2009, 19:38
При компиляции в Visual Studio 2008

Код

#include "windows.h"
#include "windowsx.h"

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR , int)
{
    char szTitle[] = "Title";
    char szClassName[] = "Window";
    MSG msg;
    WNDCLASS wc;
    ZeroMemory(&wc, sizeof(wc));
    wc.style=wc.cbClsExtra=wc.cbWndExtra=0;
    wc.lpfnWndProc=WndProc;
    wc.hInstance=hInst;
    wc.hCursor=LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground=GetStockBrush(LTGRAY_BRUSH);
    wc.lpszMenuName=NULL;
    wc.lpszClassName=szClassName;          //ERROR
    RegisterClass(&wc);

    HWND hwnd=CreateWindow(szClassName, szTitle,                   //ERROR
                                           WS_OVERLAPPEDWINDOW | WS_VISIBLE,
        CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
        0, 0, hInst, NULL);
    ShowWindow(hwnd, SW_SHOWNORMAL);
    while (GetMessage(&msg, NULL, 0, 0))
        DispatchMessage(&msg);
    return 0;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
    case WM_DESTROY:
        {
            PostQuitMessage(0);
            return 0;
        }
    default:
        return DefWindowProc(hwnd, msg, wParam, lParam);
    }
}




выводит 2 ошибки:

d:\prog\cpp\l8\main.cpp(19) : error C2440: '=' : cannot convert from 'char [7]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
d:\prog\cpp\l8\main.cpp(25) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'char [7]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

Раньше компилировал в VC 6, проблем не было.
Как это можно исправить в Visual Studio 2008?

Автор: bsa 9.2.2009, 20:01
отключи в настройках проекта Unicode. Или вместо char используй wchar_t:
Код
    wchar_t szTitle[] = L"Title";
    wchar_t szClassName[] = L"Window";

Автор: Frazelli 9.2.2009, 20:09
 smile 

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)