|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <windows.h>
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
ATOM MyRegisterClass(HINSTANCE hInstance);
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpszCmdLine,
int nCmdShow)
{
HWND hwnd;//窗口句柄
MSG msg;//消息
MyRegisterClass(hInstance);
//3.创建窗口
hwnd = CreateWindow(
TEXT("MyWndClass"),
TEXT("Hello SDK Application"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,//父窗口句柄
NULL,//窗口菜单句柄
hInstance,
NULL);
//4.显示和更新窗口
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
//5.消息循环
while(GetMessage(&msg,NULL,0,0)){
TranslateMessage(&msg);
DispatchMessage(&msg);//转发到窗口过程
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd,
UINT message,
WPARAM wParam,
LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;//DC句柄
RECT rect;
//对各种消息进行处理
switch(message)
{
case WM_SIZE:
//重画 Paint
return 0;
case WM_LBUTTONDOWN:
//MessageBox(hwnd,TEXT("Mouse Clicked!"),TEXT("消息"),MB_OK);
//PostQuitMessage(0);
return 0;
case WM_PAINT: //绘制消息
hdc = BeginPaint(hwnd,&ps);
GetClientRect(hwnd,&rect);
//Ellipse(hdc,0,0,200,100);
DrawText(hdc,TEXT("Hello, Windows!"),-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);
}
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = (WNDPROC)WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = NULL;
wc.lpszClassName = TEXT("MyWndClass");
RegisterClassEx(&wc);
}
本意是想把原来程序中的注册窗口类写到主函数之外,在VC6.0与vs2008中编译成功,连接成功,就是不显示窗口,求解
|
|