#include <windows.h>
#include <stdio.h>LRESULT CALLBACK WinSunProc(
  HWND hwnd,      // handle to window
  UINT uMsg,      // message identifier
  WPARAM wParam,  // first message parameter
  LPARAM lParam   // second message parameter
);int WINAPI WinMain(
  HINSTANCE hInstance,      // handle to current instance
  HINSTANCE hPrevInstance,  // handle to previous instance
  LPSTR lpCmdLine,          // command line
  int nCmdShow              // show state
)
{
WNDCLASS wndcls;// WNDCLS
wndcls.cbClsExtra=0;
wndcls.cbWndExtra=0;
wndcls.hbrBackground=(HBRSH)GetStockObject(BLACK_BRUSH);
wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);
wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);
wndcls.hInstance=hInstance;
wndcls.lpfnWndProc=WinSunProc;
wndcls.lpszClassName="Weixin2003";
wndcls.lpszMenuName=UNLL;
wndcls.style=CS_HREDRW | CS_VREDRAW; // CS_VREDARW
RegisterClass(&wndcls);

HWND hwnd;
hwnd=CreateWindow("Winxin2003","北京科学技术培训中心",WS_OVERLAPPEDWINDOW,
0,0,600,400,NULL,NULL,hInstance,NULL);

ShowWindow(hWnd,SW_SHOWNORMAL);
UpdateWindow(hWnd); MSG msg;
while(GetMessage(&msg,NULL,0,0.))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}LRESULT CALLBACK WinSunProc(
  HWND hwnd,      // handle to window
  UINT uMsg,      // message identifier
  WPARAM wParam,  // first message parameter
  LPARAM lParam   // second message parameter
)
{
switch(uMsg)
{
case WM_CHAR:
char szChar[20];
sprintf(szChar,"char is %d",wParam);
MessageBox(hwnd,szChar,"weixin",0);
break;
case WM_LBUTTONDOWN:
MessageBox(HWND hWnd,"mouse clicked","weixin",0);
HDC hDC;
hDC=GetDC(HWND hWnd);
TextOut(HDC,0,50,"API函数的练习",strlen(API函数的练习));
ReleaseDC(HWND hWnd,HDC hDC);
break;
case WM_PAINT:
HDC hDC;
PAINTSTRUCT ps;
hDC=BeginPaint(HWND hWnd,&ps);
TextOut(HDC,0,0,"维新培训",strlen("维新培训"));
EndPaint(HWND hWnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBOX(hwnd,"是否真的结束?","weixin",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTOY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(HWND,uMsg,wParam,IParam);
}
return 0;
}

解决方案 »

  1.   

    发来错误提示
    --------------------Configuration: WinMain1 - Win32 Debug--------------------
    Compiling...
    WinMain1.cpp
    d:\program files\microsoft visual studio\vc98\include\winnls.h(514) : error C2018: unknown character '0x10'
    d:\program files\microsoft visual studio\vc98\include\objidl.h(9586) : error C2018: unknown character '0xed'
    d:\program files\microsoft visual studio\vc98\include\objidl.h(9586) : error C2061: syntax error : identifier 'IEnu'
    d:\vclesson\vclesson1\winmain1\winmain1.cpp(21) : error C2065: 'HBRSH' : undeclared identifier
    d:\vclesson\vclesson1\winmain1\winmain1.cpp(21) : error C2440: '=' : cannot convert from 'int' to 'struct HBRUSH__ *'
            Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
    d:\vclesson\vclesson1\winmain1\winmain1.cpp(21) : error C2146: syntax error : missing ';' before identifier 'GetStockObject'
    d:\vclesson\vclesson1\winmain1\winmain1.cpp(27) : error C2065: 'UNLL' : undeclared identifier
    d:\vclesson\vclesson1\winmain1\winmain1.cpp(27) : error C2440: '=' : cannot convert from 'int' to 'const char *'
            Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
    d:\vclesson\vclesson1\winmain1\winmain1.cpp(28) : error C2065: 'CS_HREDRW' : undeclared identifier
    d:\vclesson\vclesson1\winmain1\winmain1.cpp(35) : error C2065: 'hWnd' : undeclared identifier
    d:\vclesson\vclesson1\winmain1\winmain1.cpp(39) : warning C4244: 'argument' : conversion from 'const double' to 'unsigned int', possible loss of data
    d:\vclesson\vclesson1\winmain1\winmain1.cpp(62) : error C2275: 'HWND' : illegal use of this type as an expression
            d:\program files\microsoft visual studio\vc98\include\windef.h(195) : see declaration of 'HWND'
    d:\vclesson\vclesson1\winmain1\winmain1.cpp(62) : error C2146: syntax error : missing ')' before identifier 'hWnd'
    d:\vclesson\vclesson1\winmain1\winmain1.cpp(62) : error C2059: syntax error : ')'
    d:\vclesson\vclesson1\winmain1\winmain1.cpp(64) : error C2275: 'HWND' : illegal use of this type as an expression
            d:\program files\microsoft visual studio\vc98\include\windef.h(195) : see declaration of 'HWND'
    d:\vclesson\vclesson1\winmain1\winmain1.cpp(64) : error C2146: syntax error : missing ')' before identifier 'hWnd'
    d:\vclesson\vclesson1\winmain1\winmain1.cpp(64) : error C2059: syntax error : ')'
    d:\vclesson\vclesson1\winmain1\winmain1.cpp(65) : error C2275: 'HDC' : illegal use of this type as an expression
            d:\program files\microsoft visual studio\vc98\include\windef.h(239) : see declaration of 'HDC'
    d:\vclesson\vclesson1\winmain1\winmain1.cpp(65) : error C2018: unknown character '0xba'
    d:\vclesson\vclesson1\winmain1\winmain1.cpp(65) : error C2018: unknown character '0xaf'
    d:\vclesson\vclesson1\winmain1\winmain1.cpp(65) : error C2018: unknown character '0xca'
    d:\vclesson\vclesson1\winmain1\winmain1.cpp(65) : error C2018: unknown character '0xfd'
    d:\vclesson\vclesson1\winmain1\winmain1.cpp(65) : error C2018: unknown character '0xb5'
    d:\vclesson\vclesson1\winmain1\winmain1.cpp(65) : error C2018: unknown character '0xc4'
    d:\vclesson\vclesson1\winmain1\winmain1.cpp(65) : error C2018: unknown character '0xc1'
    d:\vclesson\vclesson1\winmain1\winmain1.cpp(65) : error C2018: unknown character '0xb7'
    d:\vclesson\vclesson1\winmain1\winmain1.cpp(65) : error C2018: unknown character '0xcf'
    d:\vclesson\vclesson1\winmain1\winmain1.cpp(65) : error C2018: unknown character '0xb0'
    d:\vclesson\vclesson1\winmain1\winmain1.cpp(65) : error C2065: 'API' : undeclared identifier
    d:\vclesson\vclesson1\winmain1\winmain1.cpp(66) : error C2275: 'HWND' : illegal use of this type as an expression
            d:\program files\microsoft visual studio\vc98\include\windef.h(195) : see declaration of 'HWND'
    d:\vclesson\vclesson1\winmain1\winmain1.cpp(66) : error C2146: syntax error : missing ')' before identifier 'hWnd'
    d:\vclesson\vclesson1\winmain1\winmain1.cpp(66) : error C2059: syntax error : ')'
    d:\vclesson\vclesson1\winmain1\winmain1.cpp(69) : error C2086: 'hDC' : redefinition
    d:\vclesson\vclesson1\winmain1\winmain1.cpp(71) : error C2275: 'HWND' : illegal use of this type as an expression
            d:\program files\microsoft visual studio\vc98\include\windef.h(195) : see declaration of 'HWND'
    d:\vclesson\vclesson1\winmain1\winmain1.cpp(71) : error C2146: syntax error : missing ')' before identifier 'hWnd'
    d:\vclesson\vclesson1\winmain1\winmain1.cpp(71) : error C2059: syntax error : ')'
    d:\vclesson\vclesson1\winmain1\winmain1.cpp(72) : error C2275: 'HDC' : illegal use of this type as an expression
            d:\program files\microsoft visual studio\vc98\include\windef.h(239) : see declaration of 'HDC'
    d:\vclesson\vclesson1\winmain1\winmain1.cpp(73) : error C2275: 'HWND' : illegal use of this type as an expression
            d:\program files\microsoft visual studio\vc98\include\windef.h(195) : see declaration of 'HWND'
    d:\vclesson\vclesson1\winmain1\winmain1.cpp(73) : error C2146: syntax error : missing ')' before identifier 'hWnd'
    d:\vclesson\vclesson1\winmain1\winmain1.cpp(73) : error C2059: syntax error : ')'
    d:\vclesson\vclesson1\winmain1\winmain1.cpp(76) : error C2065: 'MessageBOX' : undeclared identifier
    d:\vclesson\vclesson1\winmain1\winmain1.cpp(81) : error C2065: 'WM_DESTOY' : undeclared identifier
    d:\vclesson\vclesson1\winmain1\winmain1.cpp(81) : error C2051: case expression not constant
    d:\vclesson\vclesson1\winmain1\winmain1.cpp(85) : error C2275: 'HWND' : illegal use of this type as an expression
            d:\program files\microsoft visual studio\vc98\include\windef.h(195) : see declaration of 'HWND'
    d:\vclesson\vclesson1\winmain1\winmain1.cpp(85) : error C2065: 'IParam' : undeclared identifier
    Error executing cl.exe.WinMain1.exe - 44 error(s), 1 warning(s)
      

  2.   

    MessageBox(HWND hWnd,"mouse clicked","weixin",0); 
    HDC hDC; 
    hDC=GetDC(HWND hWnd); 
    TextOut(HDC,0,50,"API函数的练习",strlen(API函数的练习)); 
    ReleaseDC(HWND hWnd,HDC hDC); 
    break; 
    case WM_PAINT: 
    HDC hDC; 
    PAINTSTRUCT ps; 
    hDC=BeginPaint(HWND hWnd,&ps); 
    TextOut(HDC,0,0,"维新培训",strlen("维新培训")); 
    EndPaint(HWND hWnd,&ps); 
    这里面很多函数的参数(HWND hWnd)只需要hWnd,去掉HWND。其它的再仔细检查下。
      

  3.   

    好多都是大小写拼写问题  还有就是
    wndcls.lpszClassName="Weixin2003"; 
    hwnd=CreateWindow("Winxin2003","北京科学技术培训中心",WS_OVERLAPPEDWINDOW, 
    0,0,600,400,NULL,NULL,hInstance,NULL); 名字不一样  一条一条慢慢改吧
      

  4.   

    TextOut(HDC,0,50,"API函数的练习",strlen(API函数的练习));