好吧 好忙 还得整windows编程 好不容易整出的窗口
#include "StdAfx.h"
#include <windows.h>
TCHAR Title[32]=TEXT("迷宫"); //窗口的标题
TCHAR WinName[32]=TEXT("Simple"); //窗口的名称
ATOM RegisterWin(HINSTANCE);
BOOL CreatWin(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;
RegisterWin(hInstance);
if (!CreatWin(hInstance, nCmdShow))
{
return FALSE;
}
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
ATOM RegisterWin(HINSTANCE hInstance)
{
WNDCLASSEX wc;
wc.cbSize= sizeof(WNDCLASSEX);
wc.style= CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc= (WNDPROC)WndProc;
wc.cbClsExtra= 0;
wc.cbWndExtra= 0;
wc.hInstance= hInstance;
wc.hIcon= LoadIcon(hInstance, (LPCTSTR)IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = WinName;
wc.hIconSm = LoadIcon(wc.hInstance, (LPCTSTR)IDI_APPLICATION);
return RegisterClassEx(&wc);
}
//初始化窗口
BOOL CreatWin(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
//创建窗口
hWnd = CreateWindow( WinName,
Title,
WS_OVERLAPPEDWINDOW, //窗口式样
360,
100,
600,
480,
NULL,
NULL,
hInstance,
NULL);
if (!hWnd)
{
return FALSE;
}
ShowWindow(hWnd, nCmdShow); //显示窗口
UpdateWindow(hWnd);
//立即显示
return TRUE;
}
//窗口消息处理
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;
}
#include "StdAfx.h"
#include <windows.h>
TCHAR Title[32]=TEXT("迷宫"); //窗口的标题
TCHAR WinName[32]=TEXT("Simple"); //窗口的名称
ATOM RegisterWin(HINSTANCE);
BOOL CreatWin(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;
RegisterWin(hInstance);
if (!CreatWin(hInstance, nCmdShow))
{
return FALSE;
}
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
ATOM RegisterWin(HINSTANCE hInstance)
{
WNDCLASSEX wc;
wc.cbSize= sizeof(WNDCLASSEX);
wc.style= CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc= (WNDPROC)WndProc;
wc.cbClsExtra= 0;
wc.cbWndExtra= 0;
wc.hInstance= hInstance;
wc.hIcon= LoadIcon(hInstance, (LPCTSTR)IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = WinName;
wc.hIconSm = LoadIcon(wc.hInstance, (LPCTSTR)IDI_APPLICATION);
return RegisterClassEx(&wc);
}
//初始化窗口
BOOL CreatWin(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
//创建窗口
hWnd = CreateWindow( WinName,
Title,
WS_OVERLAPPEDWINDOW, //窗口式样
360,
100,
600,
480,
NULL,
NULL,
hInstance,
NULL);
if (!hWnd)
{
return FALSE;
}
ShowWindow(hWnd, nCmdShow); //显示窗口
UpdateWindow(hWnd);
//立即显示
return TRUE;
}
//窗口消息处理
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;
}