编译C++的时候出现error C2143:缺少“;”(在“}”之前)

附带源代码如下:
void CDoc_viewView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
if(nChar == VK_RETURN) //如果按下回车键
{
m_strDisplay.Empty();
m_nLine++;
}
else if(m_strDisplay.GetLength() < 64) //当前行字符数小于64
m_strDisplay += (char)nChar;
CClientDC dc(this);
TEXTMETRIC tm;
dc.GetTextMetrics(&tm);
int nLineHeight = tm.tmHeight + tm.tmExternalLeading;
dc.TextOut(0, m_nLine * nLineHeight, m_strDisplay);
CView::OnChar(nChar, nRepCnt, nFlags);

//CView::OnChar(nChar, nRepCnt, nFlags);
}
其中错误在第八行的“}”之前

#include <windows.h>

#pragma comment(lib, "Winmm.lib") //漏掉库文件
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR szCmdLine,int iCmdShow)
{

char szAppName[]="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)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
if(!RegisterClass(&wndclass))
{
MessageBox(NULL,"This program requires Windows NT!",szAppName,MB_ICONERROR);
return 0;
}
hwnd = CreateWindow(szAppName,
"The Hello Program",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);

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)//WndProc w小写了。
{
HDC hdc;
PAINTSTRUCT ps;
RECT rect;

switch(message)
{
case WM_CREATE:
PlaySound("hellowin.wav",NULL,SND_FILENAME | SND_ASYNC);
return 0;

case WM_PAINT:
hdc = BeginPaint(hwnd,&ps);
GetClientRect(hwnd,&rect);
DrawText(hdc,TEXT("Hello,Windows98!"),-1,&rect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
EndPaint(hwnd,&ps);
return 0;

case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,message,wParam,lParam);
}
你的串号我已经记下,采纳后我会帮你制作
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-11-23
这样的话 m_strDisplay.Empty();
m_nLine++;
看看这两个定义没!还有就是 那个点 用的对不!本回答被网友采纳
第2个回答  2010-11-25
#include <windows.h>

#pragma comment(lib, "Winmm.lib") //漏掉库文件
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR szCmdLine,int iCmdShow)
{

char szAppName[]="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)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
if(!RegisterClass(&wndclass))
{
MessageBox(NULL,"This program requires Windows NT!",szAppName,MB_ICONERROR);
return 0;
}
hwnd = CreateWindow(szAppName,
"The Hello Program",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);

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)//WndProc w小写了。
{
HDC hdc;
PAINTSTRUCT ps;
RECT rect;

switch(message)
{
case WM_CREATE:
PlaySound("hellowin.wav",NULL,SND_FILENAME | SND_ASYNC);
return 0;

case WM_PAINT:
hdc = BeginPaint(hwnd,&ps);
GetClientRect(hwnd,&rect);
DrawText(hdc,TEXT("Hello,Windows98!"),-1,&rect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
EndPaint(hwnd,&ps);
return 0;

case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,message,wParam,lParam);
}
相似回答