#include<windows.h>
#include<stdio.h>
LRESULT CALLBACK WinSunProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
); int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPWSTR lpCmdLine,
int nShowCmd )
{
WNDCLASS wndclas;
wndclas.cbClsExtra=0;
wndclas.cbWndExtra=0;
wndclas.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wndclas.hCursor=LoadCursor(NULL,IDC_CROSS);
wndclas.hIcon=LoadIcon(NULL,IDI_ERROR);
wndclas.hInstance=hInstance;
wndclas.lpfnWndProc=WinSunProc;
wndclas.lpszClassName="weixin2003";
wndclas.lpszMenuName=NULL;
wndclas.style=CS_VREDRAW|CS_HREDRAW;
RegisterClass(&wndclas); HWND hwnd;
hwnd=CreateWindow("weixin2003","计算机中心!",
WS_OVERLAPPEDWINDOW,0,0,400,
600,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,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
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,"mouse clicked","weixin",0);
HDC hdc;
hdc=GetDC(hwnd);
TextOut(hdc,0,50,"yingying",strlen("yingying"));
ReleaseDC(hwnd,hdc);
break;
case WM_PAINT:
HDC hDC;
PAINTSTRUCT ps;
hdc=BeginPaint(hwnd,&ps);
TextOut(hDC,0,50,"woaini",strlen("woaini"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"break is yes or no!","weixin",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
} return 0;
};
//一个简单的vc程序 错误很奇怪!WinMian出错!请
//大家帮帮忙!!
#include<stdio.h>
LRESULT CALLBACK WinSunProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
); int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPWSTR lpCmdLine,
int nShowCmd )
{
WNDCLASS wndclas;
wndclas.cbClsExtra=0;
wndclas.cbWndExtra=0;
wndclas.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wndclas.hCursor=LoadCursor(NULL,IDC_CROSS);
wndclas.hIcon=LoadIcon(NULL,IDI_ERROR);
wndclas.hInstance=hInstance;
wndclas.lpfnWndProc=WinSunProc;
wndclas.lpszClassName="weixin2003";
wndclas.lpszMenuName=NULL;
wndclas.style=CS_VREDRAW|CS_HREDRAW;
RegisterClass(&wndclas); HWND hwnd;
hwnd=CreateWindow("weixin2003","计算机中心!",
WS_OVERLAPPEDWINDOW,0,0,400,
600,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,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
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,"mouse clicked","weixin",0);
HDC hdc;
hdc=GetDC(hwnd);
TextOut(hdc,0,50,"yingying",strlen("yingying"));
ReleaseDC(hwnd,hdc);
break;
case WM_PAINT:
HDC hDC;
PAINTSTRUCT ps;
hdc=BeginPaint(hwnd,&ps);
TextOut(hDC,0,50,"woaini",strlen("woaini"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"break is yes or no!","weixin",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
} return 0;
};
//一个简单的vc程序 错误很奇怪!WinMian出错!请
//大家帮帮忙!!
解决方案 »
- 程序运行后没反应过了N久弹出内存不足对话框
- 请教一个关于MDI的问题
- vc++中输入1970年1月1日或之前的时间后,运行就出错,具体如何解决。请高手明示
- 同志们啊,怎么打印EDIT里面的一大段文字啊???
- 想用vc做个简单的摄像头显示程序,请问有什么书可以参考?步骤如何?
- 多个实例的问题,回答正确必给分
- 大家编数据库是用向导多还是手写多啊?我的在程序中连接数据库老出问题!
- 怎样将数码相机的图片导入计算机中?
- 各位大虾救我
- 我用的VC编辑器是中文创天的,但是不论是在做MDI或但文档程序时通过向导做的,生成EXE文件时都有错,错误如下:
- 问大家一个问题。进来的我都感激!很急!
- mfc下对话框的外观改变问题??
HDC hDC;
PAINTSTRUCT ps;
hdc=BeginPaint(hwnd,&ps);
TextOut(hDC,0,50,"woaini",strlen("woaini"));
EndPaint(hwnd,&ps);
break;首先你这里的hDC错了.hdc=BeginPaint(hwnd,&ps);自己看清楚吧.而且相信还有其他地方有错.洗澡了.
sprintf(szChar,"char is d%",wParam);
这里应该是:
sprintf(szChar,"char is %d",wParam);
WM_PAINT里面hDC大小写错误。
Compiling...
vc1.cpp
D:\study\vc\vc1.cpp(16) : error C2731: 'WinMain' : function cannot be overloaded
D:\study\vc\vc1.cpp(11) : see declaration of 'WinMain'
执行 cl.exe 时出错.vc1.obj - 1 error(s), 0 warning(s)
int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // pointer to command line
int nCmdShow // show state of window
)这个格式是完全不能够该得。
你将你的第三个参数的类型改为LPSTR 试一试。
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/vc1.exe : fatal error LNK1120: 1 unresolved externals
执行 link.exe 时出错.vc1.exe - 1 error(s), 0 warning(s)