为什么不能运行??说是 dc 重复定义
--------------------Configuration: aaabbb - Win32 Debug--------------------
Compiling...
aaabbb.cpp
c:\program files\microsoft visual studio\myprojects\aaabbb\aaabbb.cpp(69) : error C2086: 'hdc' : redefinition
Error executing cl.exe.
aaabbb.exe - 1 error(s), 0 warning(s)
我把hdc 换成其他名字还是不行
程序如下
#include <windows.h>
#include <stdio.h>
LRESULT CALLBACK qc(
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.cbClsExtra=0;
wndcls.cbWndExtra=0;
wndcls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);
wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);
wndcls.hInstance=hInstance;
wndcls.lpfnWndProc=qc;
wndcls.lpszClassName="qinchuan";
wndcls.lpszMenuName=NULL;
wndcls.style=CS_HREDRAW|CS_HREDRAW;
RegisterClass(&wndcls);
HWND hwnd;
hwnd=CreateWindow("qinchuan","window name",WS_OVERLAPPEDWINDOW,0,0,600,800,NULL,NULL,hInstance,0);
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
MSG msg;
while(GetMessage(&msg,hwnd,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
switch(uMsg)
{
case WM_LBUTTONDOWN:
MessageBox(hwnd,"lbuttondown","caption",MB_OK);
HDC hdc;
hdc=GetDC(hwnd);
TextOut(hdc,0,400,"输出一串文字",strlen("输出一串文字"));
ReleaseDC(hwnd,hdc);
break;
case WM_CHAR:
char szchar[20];
sprintf(szchar,"char is %d",wParam);
MessageBox(hwnd,szchar,"caption",MB_YESNO);
break;
case WM_PAINT:
HDC hdc;
PAINTSTRUCT ps;
hdc=BeginPaint(hwnd,&ps);
TextOut(hdc,0,400,"输出一串文字",strlen("输出一串文字"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"是否关闭","qinchuan",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}