主题:请各位看看这个简单的API程序的一个错误 谢谢各位了
大家好 我刚刚开始学习API
这是第一个程序 始终有一个错误
希望各位帮帮我啊
谢谢啦
#include<windows.h>
LRESULT CALLBACK Myproc(HWND,UINT,WPARAM,LPARAM);
//HWND hwnd;
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
TCHAR AppName[]=TEXT("My First");
MSG msg;
extern HWND hwnd;
WNDCLASS myclass;
myclass.hCursor=LoadCursor(hInstance,IDC_ARROW);
myclass.cbClsExtra=0;
myclass.cbWndExtra=0;
myclass.hbrBackground=(HBRUSH)GetStockObject(GRAY_BRUSH);
myclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
myclass.hInstance=hInstance;
myclass.lpfnWndProc=Myproc;
myclass.lpszClassName=AppName;
myclass.lpszMenuName=NULL;
myclass.style=CS_HREDRAW|CS_VREDRAW;
if(!RegisterClass(&myclass))
{
MessageBox(hwnd,TEXT("faild register class"),NULL,MB_OK);
return 0;
}
hwnd=CreateWindow( AppName, //LPCTSTR lpClassName,
TEXT("haha"),//LPCTSTR lpWindowName,
WS_MAXIMIZEBOX, //DWORD dwStyle,
CW_USEDEFAULT,//int x,
CW_USEDEFAULT,//int y,
CW_USEDEFAULT,//int nWidth,
CW_USEDEFAULT,//int nHeight,
NULL,// HWND hWndParent,
NULL,//HMENU hMenu,
hInstance,//HINSTANCE hInstance,
NULL// LPVOID lpParam
);
ShowWindow(hwnd,SW_NORMAL);
UpdateWindow(hwnd);
while(GetMessage(&msg,hwnd,NULL,NULL))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK Myproc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
HDC hdc;
RECT rect;
PAINTSTRUCT ps;
hdc=BeginPaint(hwnd,&ps);
GetClientRect(hwnd,&rect);
switch(msg)
{
case WM_PAINT:
DrawText(hdc,TEXT("chenminxiami"), -1,&rect, DT_CENTER);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,msg,wParam,lParam);
}
>正在编译...
1>api.cpp
1>e:\vs2008\api应用程序\api\api\api.cpp(26) : warning C4700: 使用了未初始化的局部变量“hwnd”
1>正在链接...
1>LINK : fatal error LNK1168: 无法打开 E:\vs2008\API应用程序\API\Debug\API.exe 进行写入
1>生成日志保存在“file://e:\vs2008\API应用程序\API\API\Debug\BuildLog.htm”
1>API - 1 个错误,1 个警告
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 =
这是第一个程序 始终有一个错误
希望各位帮帮我啊
谢谢啦
#include<windows.h>
LRESULT CALLBACK Myproc(HWND,UINT,WPARAM,LPARAM);
//HWND hwnd;
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
TCHAR AppName[]=TEXT("My First");
MSG msg;
extern HWND hwnd;
WNDCLASS myclass;
myclass.hCursor=LoadCursor(hInstance,IDC_ARROW);
myclass.cbClsExtra=0;
myclass.cbWndExtra=0;
myclass.hbrBackground=(HBRUSH)GetStockObject(GRAY_BRUSH);
myclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
myclass.hInstance=hInstance;
myclass.lpfnWndProc=Myproc;
myclass.lpszClassName=AppName;
myclass.lpszMenuName=NULL;
myclass.style=CS_HREDRAW|CS_VREDRAW;
if(!RegisterClass(&myclass))
{
MessageBox(hwnd,TEXT("faild register class"),NULL,MB_OK);
return 0;
}
hwnd=CreateWindow( AppName, //LPCTSTR lpClassName,
TEXT("haha"),//LPCTSTR lpWindowName,
WS_MAXIMIZEBOX, //DWORD dwStyle,
CW_USEDEFAULT,//int x,
CW_USEDEFAULT,//int y,
CW_USEDEFAULT,//int nWidth,
CW_USEDEFAULT,//int nHeight,
NULL,// HWND hWndParent,
NULL,//HMENU hMenu,
hInstance,//HINSTANCE hInstance,
NULL// LPVOID lpParam
);
ShowWindow(hwnd,SW_NORMAL);
UpdateWindow(hwnd);
while(GetMessage(&msg,hwnd,NULL,NULL))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK Myproc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
HDC hdc;
RECT rect;
PAINTSTRUCT ps;
hdc=BeginPaint(hwnd,&ps);
GetClientRect(hwnd,&rect);
switch(msg)
{
case WM_PAINT:
DrawText(hdc,TEXT("chenminxiami"), -1,&rect, DT_CENTER);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,msg,wParam,lParam);
}
>正在编译...
1>api.cpp
1>e:\vs2008\api应用程序\api\api\api.cpp(26) : warning C4700: 使用了未初始化的局部变量“hwnd”
1>正在链接...
1>LINK : fatal error LNK1168: 无法打开 E:\vs2008\API应用程序\API\Debug\API.exe 进行写入
1>生成日志保存在“file://e:\vs2008\API应用程序\API\API\Debug\BuildLog.htm”
1>API - 1 个错误,1 个警告
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 =