Skip to content

Instantly share code, notes, and snippets.

View l2m2's full-sized avatar

l2m2

View GitHub Profile
@l2m2
l2m2 / x.cpp
Created April 1, 2022 05:53
将阿拉伯数字转换成中文数字
/**
* 将阿拉伯数字转换成中文数字,仅支持到万
*/
inline static std::string toChineseString(unsigned int n)
{
std::string result;
std::vector<std::string> units{ "", "", "", "" };
std::vector<std::string> nums{ "", "", "", "", "", "", "", "", "", "" };
@l2m2
l2m2 / x.cpp
Last active January 14, 2022 06:22
执行命令,获取输出
// https://stackoverflow.com/questions/478898/how-do-i-execute-a-command-and-get-the-output-of-the-command-within-c-using-po
std::string exec(const char* cmd)
{
std::array<char, 128> buffer;
std::string result;
std::unique_ptr<FILE, decltype(&_pclose)> pipe(_popen(cmd, "r"), _pclose);
if (!pipe) {
throw std::runtime_error("popen() failed!");
}
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
@l2m2
l2m2 / main.cpp
Last active October 26, 2021 05:56
获取当前进程的窗口句柄
struct _TempHandleData {
unsigned long processId;
HWND windowHandle;
};
BOOL isMainWindow(HWND handle)
{
return ::GetWindow(handle, GW_OWNER) == (HWND)0 && ::IsWindowVisible(handle);
}
@l2m2
l2m2 / check_ppt.vbs
Created October 11, 2021 06:36
检查PowerPoint组件是否可用
Set objPPT = CreateObject("PowerPoint.Application")
If IsNull(objPPT) Then
MsgBox("Create PowerPoint.Application Failed.")
Else
MsgBox("Create PowerPoint.Application OK.")
objPPT.Quit
End If
@l2m2
l2m2 / conversion.cpp
Created September 29, 2021 01:33 — forked from pezy/conversion.cpp
Encoding Conversion In C++
// Convert a wide Unicode string to an UTF8 string
std::string utf8_encode(const std::wstring &wstr)
{
int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL);
std::string strTo(size_needed, 0);
WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &strTo[0], size_needed, NULL, NULL);
return strTo;
}
// Convert an UTF8 string to a wide Unicode String
@l2m2
l2m2 / numberedit.cpp
Last active September 7, 2021 01:54
Duilib-基于CEditUI实现可限制输入范围的数字编辑框
class NumberEditUI : public CEditUI {
public:
NumberEditUI() : CEditUI()
{
this->OnNotify += DuiLib::MakeDelegate(this, &NumberEditUI::OnTextChanged);
}
protected:
virtual void SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue) override
{
if (_tcsicmp(pstrName, _T("min")) == 0) {
@l2m2
l2m2 / main.cpp
Created August 25, 2021 02:54
挂起进程
#include <iostream>
#include <stdio.h>
#include <Windows.h>
#include <TlHelp32.h>
void suspend(DWORD processId)
{
HANDLE hThreadSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
THREADENTRY32 threadEntry;
@l2m2
l2m2 / ping_test.cpp
Created December 8, 2020 02:20
Qt测试IP是否可达
#include <QCoreApplication>
#include <QtCore>
bool ping_test(const QString &ip) {
QStringList parameters;
#ifdef Q_OS_WIN
parameters << "-n" << "1";
#else
parameters << "-c 1";
#endif
import os, glob, re
module = 'xxx'
fixup = r"""
/*!
* \class {cls}
* \inmodule {module}
*/
update utclabm_formula_control_info
set group_id = t2.group_id
from utclabm_formula_control_info t1
inner join ( select group_id, line_id from utclabm_station where status = 'active' ) t2
on t1.line_id = t2.line_id