为了更好的学习QT中的窗口、句柄等概念,先对Windows编程进行了大体了解,通过一个简单文本编辑器的实现,来加深对这些基本概念的理解。
二.具体实现//! C/C++语言Windows程序设计 -> 简易文本编辑器 -> 演示 #include#include #include #include //! 各控件所使用的ID #define ID_EDITBOX 1 //< 文本编辑框控件 #define ID_TXTPATH 2 //< 路径编辑框控件 #define ID_SAVEBTN 3 //< 保存文件按钮 #define ID_CLSBTN 4 //< 清空编辑区按钮 #define ID_GROUP 5 //< 组合框 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); int CreateChildWindow(HWND, HWND*, LPARAM); //< 创建将使用到的子窗口控件 int SavaInputContent(TCHAR*, TCHAR*); //< 保存输入的文字到文件 char* UnicodeToUtf8(const wchar_t* unicode); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { static TCHAR szAppName[] = TEXT("demo"); HWND hwnd; MSG msg; WNDCLASS wndclass; wndclass.style = CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc = WndProc; wndclass.hInstance = hInstance; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hbrBackground = CreateSolidBrush(RGB(236, 233, 216)); wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); wndclass.lpszClassName = szAppName; wndclass.lpszMenuName = NULL; if(!RegisterClass(&wndclass)) { MessageBox(NULL, TEXT("Unable to register the window class!"), TEXT("error"), MB_OK | MB_ICONERROR); return 0; } hwnd = CreateWindow(szAppName, TEXT("Simple text editor -> demo"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); ShowWindow(hwnd, iCmdShow); UpdateWindow(hwnd); while(GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; }



