#include <windows.h> TCHAR szTitle[32]="";//"小雅的劝学网"; //窗口的标题 TCHAR szWindowClass[32]="Simple"; //窗口的名称 ATOM MyRegisterClass(HINSTANCE); BOOL InitInstance(HINSTANCE, int); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { MSG msg; MyRegisterClass(hInstance); //注册窗口类 if (!InitInstance (hInstance, nCmdShow)) //初始化窗口 { return FALSE; } while (GetMessage(&msg, NULL, 0, 0)) //消息循环 { TranslateMessage(&msg); //消息解释 DispatchMessage(&msg); //消息发送 } //注意:不能用“return 0;”,因为有非正常退出的可能性 return (int)msg.wParam; } //注册窗口类 ATOM MyRegisterClass(HINSTANCE hInstance) { WNDCLASSEX wc; //定义一个窗口类,其实是一个结构体 wc.cbSize = sizeof(WNDCLASSEX); //结构体的字节长度 wc.style = CS_HREDRAW ¦ CS_VREDRAW; //窗口式样 wc.lpfnWndProc = (WNDPROC)WndProc; //窗口处理函数 wc.cbClsExtra = 0; //分配给窗口类结构之后的额外字节数,一般为0 wc.cbWndExtra = 0; //分配给窗口实例之后的额外字节数,一般为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 = szWindowClass; //窗口名 wc.hIconSm = LoadIcon(wc.hInstance, (LPCTSTR)IDI_APPLICATION); return RegisterClassEx(&wc); } //初始化窗口 BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { HWND hWnd; //创建窗口 hWnd = CreateWindow( szWindowClass, //窗口名 szTitle, //窗口标题 WS_CHILD ¦WS_VISIBLE, //窗口式样 100, //窗口左上角的x坐标 100, //窗口左上角的y坐标 50, //窗口的宽度 50, //窗口的高度 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; } 不过这样不行啊。。编译出错。。。 C:\Documents and Settings\sky\桌面\sd\t1.c In function `InitInstance': 61 C:\Documents and Settings\sky\桌面\sd\t1.c `brvbarWS_VISIBLE' undeclared (first use in this function) (Each undeclared identifier is reported only once for each function it appears in.) 我环境是 XP+ DEV-c++ |