gtk user control自绘控件

ubuntu下gtk库是默认已安装的,开发部署很方便,以下是我写的自绘控件例子:


EuhatChildWnd.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#pragma once
 
struct _cairo_surface;
struct _GtkWidget;
 
class EuhatChildWnd
{
public:
	EuhatChildWnd(int width, int height);
	~EuhatChildWnd();
 
	void clear();
	void drawBrush(struct _GtkWidget *widget, double x, double y);
 
	struct _GtkWidget *drawingArea_;
	struct _cairo_surface *surface_;
 
	double xFrom_;
	double yFrom_;
};

阅读更多gtk user control自绘控件

编译时打印宏变量内容

1
2
3
4
5
6
7
8
9
#define PRINT_MACRO_HELPER(_x) #_x
#define PRINT_MACRO(_x) #_x " = " PRINT_MACRO_HELPER(_x)
 
#define DEFINED_PI 3.14
#define DEFINED_NULL
#pragma message(PRINT_MACRO(DEFINED_PI))
#pragma message(PRINT_MACRO(DEFINED_NULL))
#pragma message(PRINT_MACRO(UNDEFINED))
//#error print stop here.

refer to: https://blog.csdn.net/xshbx/article/details/7981564

从cmdline解析出参数token

将命令行字符串解析成argv中的一个个token,上源码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include <string>
#include <vector>
#include <sstream>
 
using namespace std;
 
wstring copySpanStr(const wchar_t* start, const wchar_t* end)
{
	wchar_t* buf = (wchar_t*)malloc((end - start + 1) * sizeof(wchar_t));
	wchar_t* pTo = buf;
	for (const wchar_t* p = start; p != end; p++)
	{
		if (*p == L'\\' && p + 1 != end)
		{
			p++;
			*pTo++ = *p;
		}
		else
			*pTo++ = *p;
	}
	*pTo = 0;
	wstring out = buf;
	free(buf);
	return out;
}
 
int getParams(const wchar_t* str, vector<wstring>& out)
{
	int isInQMark = 0;
	int isInSpace = 1;
	const wchar_t* tokenStart = str;
	for (const wchar_t* p = str; *p != 0; p++)
	{
		if (*p == L'"')
		{
			if (!isInQMark)
			{
				isInQMark = 1;
				tokenStart = p + 1;
			}
			else
			{
				isInQMark = 0;
				out.push_back(copySpanStr(tokenStart, p));
			}
		}
		else if (*p == L'\\')
		{
			if (*(p + 1) != 0)
				p++;
		}
		else if (*p == L' ')
		{
			if (!isInQMark)
			{
				if (!isInSpace)
				{
					isInSpace = 1;
					if (tokenStart != p)
					{
						out.push_back(copySpanStr(tokenStart, p));
						tokenStart = p;
					}
				}
				else
				{
 
				}
			}
		}
		else
		{
			if (!isInQMark)
			{
				if (!isInSpace)
				{
 
				}
				else
				{
					isInSpace = 0;
					tokenStart = p;
				}
			}
		}
	}
	return out.size();
}
 
wstring strReplaceCh2Str(const wchar_t* in, wchar_t fromCh, const wchar_t* toStr)
{
	const wchar_t* p = in;
	wstringstream ss;
	const wchar_t* pToStr;
	for (; *p != 0; p++)
	{
		if (*p == fromCh)
		{
			for (pToStr = toStr; *pToStr != 0; pToStr++)
			{
				ss << *pToStr;
			}
		}
		else
			ss << *p;
	}
	return ss.str();
}
 
int main()
{
	wstring path = strReplaceCh2Str(L"c:\\aa.txt", L'\\', L"\\\\");
	wstring msg = strReplaceCh2Str(L"\"优孩\"是EuhatExpert的中文名。", L'\"', L"\\\"");
 
	wstring cmd = L"EuhatExample.exe subCmd \"" + path + L"\" \"" + msg + L"\"";
 
	vector<wstring> params;
	getParams(cmd.c_str(), params);
	return 0;
}

dll中的全局类实例什么时候初始化

如果外部工程ExeB调了动态库DllA中的函数,当ExeB运行时,DllA中的全局类实例一定会初始化,但不一定非得在ExeB中调DllA中的函数后DllA中的全局类实例才会初始化,比如在DllA中代码如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class DllA01()
{
public:
	DllA01()
	{
		MessageBoxA(NULL, "init", NULL, 0);
	}
	~DllA01()
	{
		MessageBoxA(NULL, "fini", NULL, 0);
	}
	void test(void)
	{
		MessageBoxA(NULL, "test", NULL, 0);
	}
};
__declspec(dllexport) DllA01 gA01;
extern "C" __declspec(dllexport) void dllA01Test(void)
{
	MessageBoxA(NULL, "dllA01Test", NULL, 0);
}

在ExeB中加入

1
2
3
4
#pragma comment(lib, "DllA.lib")
#pragma comment(linker, "/include:__imp__dllA01Test")
//#pragma comment(linker, "/include:__imp_?gA01@@3VDllA01@@A")
//#pragma comment(linker, "/ENTRY:foo")

GetHDSerial编译不通过

源码参见https://www.codeleading.com/article/62852336906/
提示

1
2
3
4
error C2065: “STORAGE_PROPERTY_QUERY”: 未声明的标识符
error C2065: “StorageDeviceProperty”: 未声明的标识符
error C2065: “PropertyStandardQuery”: 未声明的标识符
error C2065: “IOCTL_STORAGE_QUERY_PROPERTY”: 未声明的标识符

按F1在msdn上查到的可能结果为

1
#include <Ntddstor.h>

但加了还是编译不通过,其实正确的是只要加入

1
#include <WinIoCtl.h>

refer to: https://stackoverflow.com/questions/4420632/i-dont-know-what-problem-it-is-error-error-c2065-storage-property-query

Qt备忘录

安装完qt-vs-tools-msvc2013-2.0.0.vsix后,重启vs2013,工程项目右键菜单上qt功能选项为灰色无效,怎么办?
打开.vcxproj修改

1
<Keyword>Win32Proj</Keyword>

1
<Keyword>Qt4VSv1.0</Keyword>

再重启vs,在工程上右键菜单上点击“Convert Project to Qt VS Tools Project”。
refer to: https://blog.csdn.net/ermzdy2/article/details/99692954

生成要翻译的语言文件

1
2
lupdate hello.pro -ts zh_hans.ts
lrelease zh_hans.ts -qm zh_hans.qm

refer to: https://blog.csdn.net/aaa123524457/article/details/80582978

窗口上画矩形

1
2
3
4
5
6
7
void DlgTst01::paintEvent(QPaintEvent *e)
{
    QPainter painter(this);
    painter.setBrush(Qt::red);
    painter.setPen(Qt::red);
    painter.drawRect(QRect(0, 0, this->width(), this->height()));
}

refer to: http://www.myexception.cn/qt/1119616.html

嵌入子对话框

1
setWindowFlags(Qt::CustomizeWindowHint|Qt::FramelessWindowHint);