|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
// WinCreat.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
HINSTANCE g_hInstance=0;//接受实例句柄
LRESULT CALLBACK WnProc(HWND hWnd,UINT nMsg,WPARAM wParam,LPARAM IParam)//主窗口处理函数
{
switch(nMsg)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hWnd,nMsg,wParam,IParam);
}
//注册窗口类
BOOL Register(LPSTR IpClassName,WNDPROC wndproc)
{
WNDCLASSEX wce={0};
wce.cbSize=sizeof(wce);
wce.cbClsExtra=0;//窗口类附加缓冲区大小
wce.cbWndExtra=0;//窗口附加缓冲区大小
wce.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);//窗口背景颜色
wce.hCursor=NULL;//鼠标光标
wce.hIcon=NULL;//大图标
wce.hIconSm=NULL;//小图标
wce.hInstance=g_hInstance;
wce.lpfnWndProc =wndproc;
wce.lpszClassName=IpClassName;
wce.lpszMenuName=NULL;//菜单
wce.style=CS_HREDRAW|CS_VREDRAW;
ATOM nAtom = RegisterClassEx(&wce);//注册窗口
if(nAtom==0)
{
return FALSE;
}
return TRUE;
}
//创建主窗口
HWND CreateMain(LPSTR lpClassName,LPSTR lpWndName)
{
HWND hWnd=CreateWindowEx(0,lpClassName,lpWndName,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,g_hInstance,NULL);
return hWnd;
}
//显示窗口
void Display(HWND hWnd)
{
ShowWindow(hWnd,SW_SHOW);
UpdateWindow(hWnd);
}
//消息循环
void Message()
{
MSG nMsg={0};
while(GetMessage(&nMsg,NULL,0,0))
TranslateMessage(&nMsg);
DispatchMessage(&nMsg);
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
g_hInstance=hInstance;
if(!Register("Main",WnProc))
{
MessageBox(NULL,"注册失败","Error",MB_OK);
return 0;
}
HWND hWnd=CreateMain("Main","Windows");
Display(hWnd);
Message();
return 0;
}
各位老师给看下为什么我的这个程序,关闭按钮不能点击,窗口也不能移动,谢谢各位老师了!!
|
|