一.实现目的
为了更好的学习QT中的窗口、句柄等概念,先对Windows编程进行了大体了解,通过一个简单文本编辑器的实现,来加深对这些基本概念的理解。
二. 基本功能
- 支持拷贝粘贴
- 支持文件保存(保存路径支持中文,注意:保存文件时要写清楚文件后缀.txt)
- 自动提示已输入字数
- 保存成功会有提示
三.具体实现
//! C/C++语言Windows程序设计 -> 简易文本编辑器 -> 演示
#include <windows.h>
#include <winldap.h>
#include <stdio.h>
#include <stdlib.h>
//! 各控件所使用的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 clas