C写windows窗体,(我原来一直以为C不能写gui界面,原来是我太菜了)

#include "windows.h" char szClassName[] = {"First Window"}; HWND hParent; // LRESULT 类型是一个32位值,指的是从窗口过程或者回调函数返回的32位值 。 CALLBACK指定此函数为回调函数 LRESULT CALLBACK WindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { switch(uMsg) { case WM_CLOSE: { DestroyWindow(hwnd); PostQuitMessage(0); } break; default: return DefWindowProc(hwnd, uMsg, wParam, lParam); } return 0; } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pszCmdLine, int cmdShow) { WNDCLASS stWndClass; MSG stMsg; RtlZeroMemory(&stWndClass, sizeof(stWndClass) + sizeof(stMsg)); //填充 WndClass结构 + MSG结构 stWndClass.style = CS_VREDRAW | CS_HREDRAW; stWndClass.lpfnWndProc = &WindowProc; stWndClass.hInstance = hInstance; stWndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); stWndClass.hCursor = LoadCursor(NULL, IDC_ARROW); stWndClass.hbrBackground =(HBRUSH)COLOR_WINDOW; stWndClass.lpszClassName = szClassName; //注册窗口类 RegisterClass(&stWndClass); //创建窗口 hParent = CreateWindowEx(0, szClassName, "我的第一个窗口程序 黑客防线", WS_OVERLAPPEDWINDOW, / CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); if(!hParent) return 0; //显示窗口 ShowWindow(hParent, SW_SHOWNORMAL); //刷新客户区 UpdateWindow(hParent); //消息循环 while(GetMessage(&stMsg, NULL, 0, 0) != 0) { TranslateMessage(&stMsg); DispatchMessage(&stMsg); } return stMsg.wParam; } void EntryPoint() { WinMain(GetModuleHandle(NULL), NULL, NULL, 0); ExitProcess(0); }

 

这个是调用windows的api完成的,感觉自己以前真幼稚,还以为C就局限于dos界面,悲剧

你可能感兴趣的:(C写windows窗体,(我原来一直以为C不能写gui界面,原来是我太菜了))