一、函数原型
HMODULE GetModuleHandle( LPCTSTR lpModuleName // module name );
二、函数介绍
1、返回值
HMODULE,如执行成功成功,则返回模块句柄。零表示失败。获取错误信息,请调用GetLastError。
Continue reading
一、函数原型
HMODULE GetModuleHandle( LPCTSTR lpModuleName // module name );
二、函数介绍
1、返回值
HMODULE,如执行成功成功,则返回模块句柄。零表示失败。获取错误信息,请调用GetLastError。
Continue reading
#include <Windows.h> #include <tchar.h> // 窗口处理函数 LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_DESTROY: PostQuitMessage(0); // 发送WM_QUIT消息,结束程序 break; } return DefWindowProc(hWnd, uMsg, wParam, lParam); // 系统默认窗口处理函数 } INT WINAPI _tWinMain( _In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPTSTR lpCmdLine, _In_ INT nShowCmd) { WNDCLASS wc; HWND hWnd; MSG msg; // 注册窗口类 ZeroMemory(&wc, sizeof(wc)); wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = TEXT("BasicWindow"); RegisterClass(&wc); // 创建窗口 hWnd = CreateWindow(TEXT("BasicWindow"), TEXT("BasicWindow"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); // 显示窗口 ShowWindow(hWnd, nShowCmd); UpdateWindow(hWnd); // 消息循环 while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; }
一、窗口处理函数
LRESULT CALLBACK WindowProc( HWND hwnd, // handle to window UINT uMsg, // message identifier WPARAM wParam, // first message parameter LPARAM lParam // second message parameter );
二、窗口类
typedef struct _WNDCLASS { UINT style; WNDPROC lpfnWndProc; int cbClsExtra; int cbWndExtra; HINSTANCE hInstance; HICON hIcon; HCURSOR hCursor; HBRUSH hbrBackground; LPCTSTR lpszMenuName; LPCTSTR lpszClassName; } WNDCLASS, *PWNDCLASS; ATOM RegisterClass( CONST WNDCLASS *lpWndClass // class data );
一、FindFirstFile和FindNextFile函数
HANDLE FindFirstFile( LPCTSTR lpFileName, // file name LPWIN32_FIND_DATA lpFindFileData // data buffer ); BOOL FindNextFile( HANDLE hFindFile, // search handle LPWIN32_FIND_DATA lpFindFileData // data buffer ); typedef struct _WIN32_FIND_DATA { DWORD dwFileAttributes; FILETIME ftCreationTime; FILETIME ftLastAccessTime; FILETIME ftLastWriteTime; DWORD nFileSizeHigh; DWORD nFileSizeLow; DWORD dwReserved0; DWORD dwReserved1; TCHAR cFileName[ MAX_PATH ]; TCHAR cAlternateFileName[ 14 ]; } WIN32_FIND_DATA, *PWIN32_FIND_DATA;
现在来说,支持C++11标准的C++语言均支持正则表达式。下面是简单的正则表达式示例,it定位到第一个位置,end_it是空迭代器,起到尾后迭代器的作用。同时,for循环中的it递增运算通过regex_search来推进迭代器,最终完成遍历任务。
#include <regex> #include <iostream> int main(void) { std::string data = "<Person><Item><ID>100001</ID><NAME>CHN</NMAE><AGE>5500</AGE></Item>" "<Item><ID>100002</ID><NAME>USA</NMAE><AGE>300</AGE></Item></Person>"; std::regex re("<Item><ID>(.*?)</ID><NAME>(.*?)</NMAE><AGE>(.*?)</AGE></Item>"); for (std::sregex_iterator it(data.begin(), data.end(), re), end_it; it != end_it; it++) { std::cout << it->str(1) << "\t" << it->str(2) << "\t" << it->str(3) << std::endl; } return 0; }
#include <Windows.h> #include <tchar.h> INT WINAPI _tWinMain( _In_ HINSTANCE hInstance, // handle to current instance _In_opt_ HINSTANCE hPrevInstance, // handle to previous instance _In_ LPTSTR lpCmdLine, // command line _In_ INT nShowCmd) // show state { MessageBox(NULL, TEXT("Windows Aplication"), TEXT("HELLO WORLD"), MB_OK); return 0; }
Qt程序设计之QPainter类没有实现画箭头功能,比较遗憾。下面就自己实现一个,记录一下,方便以后查阅。
一、函数如下:
void drawArrow(QPointF p1, QPointF p2, QPainter &painter, int lineWidth = 3, int arrowLength = 20);
正则表达式(Regular Expression)描述了一种字符串匹配的模式(Pattern),可以用来检查一个串是否含有某种子串、将匹配的子串替换或者从某个串中取出符合某个条件的子串等。
#include <QRegularExpression> int main(void) { QString data = "<Person><Item><ID>100001</ID><NAME>CHN</NMAE><AGE>5500</AGE></Item>" "<Item><ID>100002</ID><NAME>USA</NMAE><AGE>300</AGE></Item></Person>"; QRegularExpression re("<Item><ID>(.*?)</ID><NAME>(.*?)</NMAE><AGE>(.*?)</AGE></Item>"); QRegularExpressionMatchIterator it = re.globalMatch(data); while (it.hasNext()) { QRegularExpressionMatch match = it.next(); qDebug() << match.captured(1).toUtf8().data() << match.captured(2).toUtf8().data() << match.captured(3).toUtf8().data(); } return 0; }
UUID是通用唯一识别码(Universally Unique Identifier)的缩写,是一种软件建构的标准,亦为开放软件基金会组织在分布式计算环境领域的一部分。UUID是基于当前时间、计数器(counter)和硬件标识(通常为无线网卡的MAC地址)等数据计算生成的。
Continue reading
Qt程序设计之Unicode编码字符串转中文问题,就是要替换掉前面的“\\u”,再将4位16进制数转成QChar类型,问题基本解决。下面就用Qt自带的正则表达式解决,方法如下:
QString Unicode2CN(QString data) { QRegularExpression re("\\\\u([0-9a-fA-F]{4})"); QRegularExpressionMatchIterator it = re.globalMatch(data); while(it.hasNext()) { QRegularExpressionMatch match = it.next(); data.replace(match.captured(0), QChar(match.captured(1).toUShort(NULL, 16))); } return data; }