如何往右键菜单添加功能

Windows下右键菜单的功能很方便,添加

这里介绍 Windows终端的添加方法,同样的方法也可以于添加其它软件

1.按WIn+R打开运行框,输入

1
regedit

回车 进入注册表编辑器

2.在路径一栏输入

1
计算机\HKEY_CLASSES_ROOT\Directory\Background\shell\

或者依次点击进入也可以
3.右键点击shell,选择 新建 ,然后选择 ,命名为你想要的名字比如“终端”,成功后回到桌面右键发现有了叫做 “终端” 的选项。

注: 还可以在右边的界面中右键单击**(默认)后点击修改(M),修改 数值数据 为你想要的名字,不改的话默认是项**的名称

4.在 “终端” 下面新建一个项名字为 command ,将数据设置成

1
C:\Windows\System32\wt.exe

这时,桌面右键菜单的选项就可以用了。
这个和调用的文件路径有关,换句话说,如果要调用其它程序,修改到其相应的路径即可。

5、(这个不重要)添加图标:右键点击shell中你刚刚新建的这个 “终端”,选择 新建,然后选择 字符串值,将 名称设置为Icon。

同样的方法,将数据数据设置成图标文件的路径,即可修改成功

Qt的ui文件无法拖拽放置控件

问题:用Clion开发Qt时新建Qt Ui Class中产生的ui文件用QtDesigner打开后无法在QtDesigner中将控件拖入QMainWindow类窗口中。
原因:生成的ui文件中不包含有QWidget
方法:在ui文件中加入以下内容

1
2
3
4
5
6
7
8
<widget class="QWidget" name="centralwidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>

完整ui文件如下:

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
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<author/>
<comment/>
<exportmacro/>
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>

<widget class="QWidget" name="centralwidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>

</widget>
<pixmapfunction/>
<connections/>
</ui>

CLion在Run或Debug时中文乱码的解决

Clion 默认全局编码方式为 UTF-8,会导致中文乱码

官方 JetBrains 提供的解决方案是:
使用快捷键:shift+ctrl+alt+/ 然后选择第一个选项 Registry(注册表),找到蓝色的 run.processes.with.pty 将其 Value 的复选框去掉,即可正常显示中文。

结构体初始化的几种方法



1.先定义再初始化

1
2
3
4
5
6
7
8
struct obj_t {
const char *name;
int val;
};

obj_t obj;
obj.name = "ABC";
obj.val = 0;

2.定义的时候初始化

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// 写法1 按照顺序赋值
struct {
const char *name;
int val;
} obj_2 = {"ABD", 0};

// 写法2 单独对成员赋值
struct {
const char *name;
int val;
} obj_3 = {.name = "ABD", .val = 0};

// 写法3
struct obj_t {
const char *name;
int val;
};
obj_t obj_1 = {.name = "name", .val = 0};

3.结构体嵌套

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// 写法1
struct {
const char *name;
int val;
struct{
int a;
}obj;
} obj_4 = {"ABD", 0, 666};

// 写法2
struct {
const char *name;
int val;
struct{
int a;
}obj;
} obj_5 = {.name = "ABD", .val = 0, {.a = 666}};

4.结构体数组

1
2
3
4
struct {
const char *name;
int val;
} obj_6[2] = {[0] = {"name 0", 0}, [1]= {"name 1", 1}};

5.结构体嵌套数组

1
2
3
4
5
6
7
struct {
const char *name;
int val;
struct{
int a;
}obj;
} obj_7[2] = {[0] = {"name 0", 0, 0}, [1] = {"name 1"}};

1
2
3
4
5
6
7
8
9
10
11
12
struct obj_t {
const char *name;
int val;
struct {
int a;
} obj;
};

obj_t obj_8[2] = {
[0] = {"name 0", 0, 0},
[1] = {"name 1", 0, 0}
};

6.使用类型别名

1
2
3
4
5
6
typedef struct {
const char *name;
int val;
} obj_t;

obj_t obj_9;

7.成员函数

1
2
3
4
5
6
7
8
9
10
11
void fn() {
;
}

typedef struct {
const char *name;
int val;
void (*function)();
} obj_t;

obj_t obj_10 = {.function = fn};

编译时断言

这其实是使用C语言的宏来实现的非常有“创意”的一个功能。有些时候,特别是在进行内核编程时,在编译时就能够进行条件检查的断言,而不是在运行时进行,这非常有用。不幸的是,C99标准还不支持任何编译时的断言。

但是,我们可以利用预处理来生成代码,这些代码只有在某些条件成立时才会通过编译(最好是那种不做实际功能的命令)。有各种各样不同的方式都可以做到这一点,通常都是建立一个大小为负的数组或结构体。最常用的方式如下:

1
2
3
4
5
6
7
8
9
/* Force a compilation error if condition is false, but also produce a result
* (of value 0 and type size_t), so it can be used e.g. in a structure
* initializer (or wherever else comma expressions aren't permitted). */
/* Linux calls these BUILD_BUG_ON_ZERO/_NULL, which is rather misleading.
*/
#define STATIC_ZERO_ASSERT(condition) (sizeof(struct { int:-!(condition); }) )
#define STATIC_NULL_ASSERT(condition) ((void *)STATIC_ZERO_ASSERT(condition) )
/* Force a compilation error if condition is false */
#define STATIC_ASSERT(condition) ((void)STATIC_ZERO_ASSERT(condition))

如果(condition)计算结果为一个非零值(即C中的真值),即! (condition)为零值,那么代码将能顺利地编译,并生成一个大小为零的结构体。如果(condition)结果为0(在C真为假),那么在试图生成一个负大小的结构体时,就会产生编译错误。

它的使用非常简单,如果任何某假设条件能够静态地检查,那么它就可以在编译时断言。例如,在上面提到的标志列表中,标志集合的类型为uint32_t,所以,我们可以做以下断言:

1
STATIC_ASSERT(Total <= 32)

它扩展为:

1
(void)sizeof(struct { int:-!(Total <= 32) })

现在,假设Total<=32。那么-!(Total <= 32)等于0,所以这行代码相当于:

1
(void)sizeof(struct { int: 0 })

这是一个合法的C代码。现在假设标志不止32个,那么-!(Total <= 32)等于-1,所以这时代码就相当于:

1
(void)sizeof(struct { int: -1 } )

因为位宽为负,所以可以确定,如果标志的数量超过了我们指派的空间,那么编译将会失败。

C语言__attribute__的使用

一、介绍

GNU C 的一大特色就是__attribute__ 机制。attribute 可以设置函数属性(Function Attribute )、变量属性(Variable Attribute )和类型属性(Type Attribute )。

attribute 书写特征是:attribute 前后都有两个下划线,并切后面会紧跟一对原括弧,括弧里面是相应的__attribute__ 参数。

attribute 语法格式为:attribute ((attribute-list))

关键字__attribute__ 也可以对结构体(struct )或共用体(union )进行属性设置。大致有六个参数值可以被设定,即:aligned, packed, transparent_union, unused, deprecated 和 may_alias 。

在使用__attribute__ 参数时,你也可以在参数的前后都加上“__” (两个下划线),例如,使用__aligned__而不是aligned ,这样,你就可以在相应的头文件里使用它而不用关心头文件里是否有重名的宏定义。

二、attribute 的参数介绍

1、aligned

指定对象的对齐格式(以字节为单位),如:

1
2
3
4
5
6
7
8
struct S {

short b[3];

} __attribute__ ((aligned (8)));


typedef int int32_t __attribute__ ((aligned (8)));

该声明将强制编译器确保(尽它所能)变量类 型为struct S 或者int32_t 的变量在分配空间时采用8字节对齐方式。

如上所述,你可以手动指定对齐的格式,同样,你也可以使用默认的对齐方式。如果aligned 后面不紧跟一个指定的数字值,那么编译器将依据你的目标机器情况使用最大最有益的对齐方式。例如:

1
2
3
4
5
struct S {

short b[3];

} __attribute__ ((aligned));

这里,如果sizeof (short )的大小为2byte,那么,S 的大小就为6 。取一个2 的次方值,使得该值大于等于6 ,则该值为8 ,所以编译器将设置S 类型的对齐方式为8 字节。

aligned 属性使被设置的对象占用更多的空间,相反的,使用packed 可以减小对象占用的空间。

需要注意的是,attribute 属性的效力与你的连接器也有关,如果你的连接器最大只支持16 字节对齐,那么你此时定义32 字节对齐也是无济于事的。

2、packed

​ 使用该属性对struct 或者union 类型进行定义,设定其类型的每一个变量的内存约束。就是告诉编译器取消结构在编译过程中的优化对齐(使用1字节对齐),按照实际占用字节数进行对齐,是GCC特有的语法。这个功能是跟操作系统没关系,跟编译器有关,gcc编译器不是紧凑模式的,我在windows下,用vc的编译器也不是紧凑的,用tc的编译器就是紧凑的。

​ 下面的例子中,packed_struct 类型的变量数组中的值将会紧紧的靠在一起,但内部的成员变量s 不会被“pack” ,如果希望内部的成员变量也被packed 的话,unpacked-struct 也需要使用packed 进行相应的约束。

1
2
3
4
5
6
7
8
9
10
11
12
struct unpacked_struct
{
char c;
int i;
};

struct packed_struct
{
char c;
int i;
struct unpacked_struct s;
}__attribute__ ((__packed__));

如:

1
2
3
4
5
6
7
8
9
10
11
12
struct unpacked_struct
{
char c;
int i;
};

struct packed_struct
{
char c;
int i;
struct unpacked_struct s;
}__attribute__ ((__packed__));

下面的例子中使用__attribute__ 属性定义了一些结构体及其变量,并给出了输出结果和对结果的分析。代码为:

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
struct p
{
int a;
char b;
short c;

}__attribute__((aligned(4))) pp;

struct m
{
char a;
int b;
short c;
}__attribute__((aligned(4))) mm;

struct o
{
int a;
char b;
short c;
}oo;

struct x
{
int a;
char b;
struct p px;
short c;
}__attribute__((aligned(8))) xx;

int main()
{
printf("sizeof(int)=%d,sizeof(short)=%d.sizeof(char)=%d\n",sizeof(int)
,sizeof(short),sizeof(char));
printf("pp=%d,mm=%d \n", sizeof(pp),sizeof(mm));
printf("oo=%d,xx=%d \n", sizeof(oo),sizeof(xx));
return 0;
}

输出结果:

sizeof(int)=4,sizeof(short)=2.sizeof(char)=1

pp=8,mm=12

oo=8,xx=24

分析:都是字节对齐的原理,可以去看这儿:字节对齐

3、at

绝对定位,可以把变量或函数绝对定位到Flash中,或者定位到RAM。

1)、定位到flash中,一般用于固化的信息,如出厂设置的参数,上位机配置的参数,ID卡的ID号,flash标记等等

1
2
3
4
const u16 gFlashDefValue[512] __attribute__((at(0x0800F000))) = {0x1111,0x1111,0x1111,0x0111,0x0111,0x0111};//定位在flash中,其他flash补充为00


const u16 gflashdata__attribute__((at(0x0800F000))) = 0xFFFF;

2)、定位到RAM中,一般用于数据量比较大的缓存,如串口的接收缓存,再就是某个位置的特定变量

1
u8 USART2_RX_BUF[USART2_REC_LEN] __attribute__ ((at(0X20001000)));//接收缓冲,最大USART_REC_LEN个字节,起始地址为0X20001000.

注意:

1)、绝对定位不能在函数中定义,局部变量是定义在栈区的,栈区由MDK自动分配、释放,不能定义为绝对地址,只能放在函数外定义。

2)、定义的长度不能超过栈或Flash的大小,否则,造成栈、Flash溢出。

4、section

​ 提到section,就得说RO RI ZI了,在ARM编译器编译之后,代码被划分为不同的段,RO Section(ReadOnly)中存放代码段和常量,RW Section(ReadWrite)中存放可读写静态变量和全局变量,ZI Section(ZeroInit)是存放在RW段中初始化为0的变量。
​ 于是本文的大体意思就清晰了,attribute((section(“section_name”))),其作用是将作用的函数或数据放入指定名为”section_name”对应的段中。

1)、编译时为变量指定段:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
__attribute__((section("name")))
RealView Compilation Tools for µVision Compiler Reference Guide Version 4.0

Home > Compiler-specific Features > Variable attributes > __attribute__((section("name")))

4.5.6. __attribute__((section("name")))
Normally, the ARM compiler places the objects it generates in sections like data and bss. However, you might require additional data sections or you might want a variable to appear in a special section, for example, to map to special hardware. The section attribute specifies that a variable must be placed in a particular data section. If you use the section attribute, read-only variables are placed in RO data sections, read-write variables are placed in RW data sections unless you use the zero_init attribute. In this case, the variable is placed in a ZI section.

Note
This variable attribute is a GNU compiler extension supported by the ARM compiler.

Example
/* in RO section */
const int descriptor[3] __attribute__ ((section ("descr"))) = { 1,2,3 };
/* in RW section */
long long rw[10] __attribute__ ((section ("RW")));
/* in ZI section *
long long altstack[10] __attribute__ ((section ("STACK"), zero_init));/

2)、编译时为函数指定段

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
__attribute__((section("name")))
RealView Compilation Tools for µVision Compiler Reference Guide Version 4.0

Home > Compiler-specific Features > Function attributes > __attribute__((section("name")))

4.3.13. __attribute__((section("name")))
The section function attribute enables you to place code in different sections of the image.

Note
This function attribute is a GNU compiler extension that is supported by the ARM compiler.

Example
In the following example, Function_Attributes_section_0 is placed into the RO section new_section rather than .text.

void Function_Attributes_section_0 (void) __attribute__ ((section ("new_section")));
void Function_Attributes_section_0 (void)
{
static int aStatic =0;
aStatic++;
}
In the following example, section function attribute overrides the #pragma arm section setting.

#pragma arm section code="foo"
int f2()
{
return 1;
} // into the 'foo' area

__attribute__ ((section ("bar"))) int f3()
{
return 1;
} // into the 'bar' area

int f4()
{
return 1;
} // into the 'foo' area
#pragma arm section

5、多个属性,组合使用

1
u8 FileAddr[100] __attribute__ ((section ("FILE_RAM"), zero_init,aligned(4)));

如何用AD一键打板0元薅华秋4层板羊毛?

01 一键下单免费打样

免费获取****百万AD元器件库

想要实现团队在线协同设计

想完成设计后系统自动进行DFM检查

想直接在AD里一键下单

0元免费打板??

从设计到生产,AD软件一键搞定!

为回馈广大用户,Altium邀您体验得极一键下单免费打样活动,只需****0元,即可把华秋高品质四层板带回家!用户通过DigiPCBA或在AD的AMF面板即可实现一键下单体验!

图片

▲ AD用户在AMF面板中

可找到该“四层板免费打样”活动

02 0元体验

★ 将您要打板的PCB或Gerber文件在DigiPCBA打包上传即可一键下单!

★ 华秋制造,不计成本,高品质四层板,免费!0元体验!每月两次!

Tips:直接在AD软件里,通过AMF面板询价、做DFM检查、一键生成Gerber/NC Drill文件并下单。这个超级超级方便哦,强烈建议各位AD用户点击一试!!

03 参与条件

★ DigiPCBA注册用户

点此注册DigiPCBA

★ Altium Designer用户(需安装AD21以上版本)

点此下载最新安装包

04 活动细则

★ 用户可通过AD的AMF面板完成PCB下单。

★ 或通过DigiPCBA云端平台完成PCB下单。

★ 每月可免费打样2次!

★ 工艺要求:

_ 高品质四层板,常规工艺
板厚: 1.0/1.6mm
铜厚: 外层1oz,内层0.5oz
线宽线距: ≥5mil
孔径: ≥0.2mm
长宽: 3~10cm以内
数量: 5片以内
交期: 48小时
注: 特殊工艺(如半孔或孔环较小等)不参加此活动

05 如何操作

\1. 确认使用AD21以上版本并已安装AMF插件(AD22以上版本都会默认安装)。

\2. AMF面板会对当前PCB进行分析并完成询价。请确认满足活动条件(询价结果为0元)后再点击右上方的“下订单”按键。

Tips关键字:单片数量为5,板厚必须为1.0/1.6mm。

图片

\3. 建议选择“包含PCB源文件到生产包”选项。这样系统会将原始设计文件一并上传到DigiPCBA订单,以便后续查看(注意:这里还并未将生产包发送到板厂)。

图片

\4. 点击“下订单”按键后系统会自动生成Gerber, NCDrill等文件并打包上传到DigiPCBA,并与订单关联。后台自动打开浏览器跳转到DigiPCBA网页(如没有登录,请先登录DigiPCBA)。

\5. 请正确填写收货地址并选择快递方式。(这里仍会显示快递费用,待华秋审核通过后,费用会自动减免)

图片

\6. 可以点击“修改订单”继续修改下单数量或工艺参数;如点击“发送到板厂”,则会将订单正式发送到板厂,等待审核。如之前已包含“源文件”,可在此处设定是否将“源文件”也发送给板厂(默认不勾选,只发送Gerber)。

图片

图片

\7. 等待板厂审核,如存在工艺问题,板厂会主动与您取得联系。

8. 如您已经关注了DigiPCBA公众号且将同一微信绑定了DigiPCBA账号,可以收到实时的消息推送。

\9. 请确认审核后价格为0元再点击“支付”。(注意:这里可能出现审核后不满足0元购的条件,还请您谅解)

图片

\10. 支付完成后,您可以在DigiPCBA网站查看订单生产及物流状态。等待收货吧 图片

更多关于操作一键下单的内容,请参阅《得极的一键下单你试过了吗?

图片

06 注意事项

★ 最终订单是否满足优惠条件,以板厂审核为准。

★ 总结一下关键操作:AD中询价创建订单 -> DigiPCBA网站发送订单 -> 等待审核 -> 支付

★ 在使用中如有任何问题,您可发送邮件至support@mail.digipcba.com咨询。