久没写文章了,是因为我的WCF学习因为够用了所以暂停了,而且最近忙着做毕业设计,和在毕业前垂死的挣扎一下让我自己成为一名新手C++ Coder。
我今天不是来写什么教程的,我是来晒图晒代码的。
我这两天晚上都在研究怎么使用Windows API来弹出一个窗体,今晚终于搞定了。
#include <Windows.h> LRESULT CALLBACK WindowProc( _In_ HWND hwnd, _In_ UINT uMsg, _In_ WPARAM wParam, _In_ LPARAM lParam ); int CALLBACK WinMain( _In_ HINSTANCE hInstance, _In_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nCmdShow ) { WCHAR* cls_Name = L"helloworld"; // 设计窗口类 WNDCLASS wc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hCursor = LoadCursor(hInstance, IDC_ARROW);; wc.hIcon = LoadIcon(hInstance, IDI_APPLICATION);; wc.lpszMenuName = NULL; wc.style = CS_HREDRAW | CS_VREDRAW; wc.hbrBackground = (HBRUSH)COLOR_WINDOW; wc.lpfnWndProc = WindowProc; wc.lpszClassName = cls_Name; wc.hInstance = hInstance; //注册窗口 RegisterClass(&wc); //生成窗体,返回句柄 HWND hwnd = CreateWindow( cls_Name, L"Helloworld,Top of c#", WS_OVERLAPPEDWINDOW, 38, 20, 480, 250, NULL, NULL, hInstance, NULL); if (hwnd == NULL) { return 0; } //显示窗口 ShowWindow(hwnd, SW_SHOW); //刷新窗口 UpdateWindow(hwnd); //传递消息 MSG msg; while (GetMessage(&msg, hwnd, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return 0; } LRESULT CALLBACK WindowProc( _In_ HWND hwnd, _In_ UINT uMsg, _In_ WPARAM wParam, _In_ LPARAM lParam ) { return DefWindowProc(hwnd, uMsg, wParam, lParam); }
大家加油,再接再厉!