分类分类
关注+2011-01-14作者:不详
问: 用vc++6.0怎么写Windows简单窗口代码啊,求各位大虾发一下代码啊,还有是要用一个c++文件还是要一个win3工程呢
答:新建工程里选win32 APPLICATION 一个简单的win32程序即可
你不写代码 当然会没东西。。 你想看的话可以建立一个经典的hello world
方案二:
只用两个函数,够简单了吧! #include <Windows.h> LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; switch( msg ) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: 在此添加任意绘图代码... EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, msg, wParam, lParam); } return 0; } INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT ) { // Register the window class WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L, GetModuleHandle(NULL), NULL, NULL, (HBRUSH)(COLOR_WINDOW+1), NULL, "Tutorial", NULL }; wc.hCursor=LoadCursor(0,IDC_ARROW); RegisterClassEx( &wc ); // Create the application's window HWND hWnd = CreateWindow( "Tutorial", "Tutorial 01", WS_OVERLAPPEDWINDOW, 100, 100, 600, 500, NULL, NULL, wc.hInstance, NULL ); ShowWindow( hWnd, SW_SHOWDEFAULT ); UpdateWindow( hWnd ); MSG msg; ZeroMemory(&msg,sizeof(msg)); HACCEL hAccelTable; hAccelTable = LoadAccelerators(wc.hInstance, NULL);//(LPCTSTR)IDC_SAMPLEWIN // 主消息循环: while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } UnregisterClass( "Tutorial", wc.hInstance ); return 0; }
相关文章
更多+相同厂商
热门推荐
点击查看更多
点击查看更多
点击查看更多
说两句网友评论