Я создал это простое приложение для Windows:
#include <windows.h>
#include <stdio.h>
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
int idmes = MessageBox (NULL, TEXT ("Hello!"), TEXT ("HelloMsg"), MB_ABORTRETRYIGNORE) ;
static TCHAR szAppName[] = TEXT ("HelloWin") ;
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) (COLOR_BACKGROUND+11) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("This program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindow (szAppName, // window class name
TEXT ("Programma di emiliano"), // window caption
WS_OVERLAPPEDWINDOW, // window style
CW_USEDEFAULT, // initial x position
CW_USEDEFAULT, // initial y position
CW_USEDEFAULT, // initial x size
CW_USEDEFAULT, // initial y size
NULL, // parent window handle
NULL, // window menu handle
hInstance, // program instance handle
NULL) ; // creation parameters
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc ;
PAINTSTRUCT ps ;
RECT rect ;
static short xChar, yChar ;
TEXTMETRIC tm ;
char szBuffer[80];
int i ;
switch (message)
{
case WM_CREATE:
MessageBox (NULL, TEXT ("Ciao caro!"), TEXT ("Salve bellezza"), 0) ;
hdc = GetDC (hwnd) ;
GetTextMetrics (hdc, &tm) ;
xChar = tm.tmAveCharWidth ;
yChar = tm.tmHeight + tm.tmExternalLeading ;
ReleaseDC (hwnd, hdc) ;
return 0 ;
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;
int iLength;
for (i = 0 ; i < 10 ; i++)
{ iLength = wsprintf( szBuffer, "The number is %d.", i );
TextOut (ps.hdc, xChar, yChar * (1 + i), szBuffer, 5) ;
}
EndPaint (hwnd, &ps) ;
return 0 ;
case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
, но я получаю эту ошибку:
------ Build started: Project: primo, Configuration: Debug Win32 ------
Build started 16/01/2011 03:10:02.
InitializeBuildStatus:
Creating "Debug\primo.unsuccessfulbuild" because "AlwaysCreate" was specified.
ClCompile:
All outputs are up-to-date.
primo.cpp
c:\users\larry\documents\visual studio 2010\projects\primo\primo\primo.cpp(79): warning C4244: '=' : conversion from 'LONG' to 'short', possible loss of data
c:\users\larry\documents\visual studio 2010\projects\primo\primo\primo.cpp(80): warning C4244: '=' : conversion from 'LONG' to 'short', possible loss of data
c:\users\larry\documents\visual studio 2010\projects\primo\primo\primo.cpp(90): error C2664: 'wsprintfW' : cannot convert parameter 1 from 'char [80]' to 'LPWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Build FAILED.
Time Elapsed 00:00:02.34
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Почему?