新手学习窗口,请不吝赐教
这是创建窗口的简单代码,编译能通过,但为什么不能运行呢?请各位帮看看,谢谢了,新手,望不吝赐教。#include<windows.h>
#include<string.h>
#include<stdlib.h>
//using namespace windows;
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
BOOL InitWindowsClass(HINSTANCE hInstance);
BOOL InitWindows(HINSTANCE hInstance,int nCmdShow);
//以下初始化窗口类
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInst,LPSTR IpszCmdLine,int nCmdShow)
{
MSG msg;
if(!InitWindowsClass(hInstance))
return FALSE;
if(!InitWindows(hInstance,nCmdShow))
return FALSE;
//创建窗口
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
//窗口函数
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lparam)
{
switch(message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,message,wParam,lparam);
}
return 0;
}
BOOL InitWindows(HINSTANCE hInstance,int nCmdShow)
{
HWND hwnd;
hwnd=CreateWindow("窗口",
"My_Windows",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
if(!hwnd) return FALSE;
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
return TRUE;
}
BOOL InitWindowsClass(HINSTANCE hInstance)
{
WNDCLASS wc;
wc.style = 0;
wc.lpfnWndProc = (WNDPROC)WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(hInstance,IDI_APPLICATION);
wc.hCursor = LoadCursor(hInstance, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH+3);//(COLOR_WINDOW+1);
wc.lpszMenuName = NULL;
wc.lpszClassName ="窗口";
return RegisterClass(&wc);
}