Momentics创建Photon图形程序

Photon microGui是qnx原生的UI图形工具。Qnx下开发Photon 一般是使用phAB来创建,使用默认的Momentics IDE也可以创建Photon图形程序。

首先需要创建一个c/c++工程,然后添加Photon的库,如图:

添加了库之后,就可以写photon的helloworld程序了。

 1 #include <Ph.h>
 2 #include <Pt.h>
 3 
 4 int onBtnClick( PtWidget_t *widget, void *data, PtCallbackInfo_t *cbinfo)
 5 {
 6     std::cout << "onBtnClick!" << std::endl;
 7 }
 8 
 9 int main(int argc, char *argv[]) {
10     std::cout << "Welcome to the QNX MNH Test!" << std::endl;
11 
12     Pt_widget *window;
13     PtArg_t args[20];
14     int i = 0;
15     Ph_dim winSize;
16     winSize.h = 500;
17     winSize.w = 500;
18 
19     PtSetArg( &args[i++], Pt_ARG_WINDOW_TITLE, "Hello", 0);
20     PtSetArg( &args[i++], Pt_ARG_DIM, &winSize, 0);
21     //PtSetArg( &args[i++], Ph_WM_RENDER_BORDER, false, 0);
22 
23     if( NULL == ( window = PtAppInit( NULL, &argc, argv, i, args ) ) )
24     {
25         perror( "PtAppInit()" );
26         return 1;
27     }
28     window->border_width = 0;
29 
30     i = 0;
31     PtArg_t argDrawWidget[10];
32     PtSetArg( &args[i++], Pt_ARG_DIM, &winSize, 0);
33     Pt_widget *pDraw = PtCreateWidget(PtRaw, window, i, argDrawWidget);
34 
35     PtAddCallback( pDraw, Pt_CB_ACTIVATE, onBtnClick, NULL );
36     PtRealizeWidget(pDraw);
37 
38     PtRealizeWidget(window);
39     PtMainLoop();
40     return EXIT_SUCCESS;
41 }
首先要初始化PtAppInit,中间是使用PtCreateWidget创建控件以及PtAddCallback添加事件监听,并调用PtRealizeWidget使能并显示所有控件,最后调用PtMainLoop进入消息循环。
这样一个简单的Photon图形程序就完成了,编译完成后就可以拿去跑了。

Photon microGui虽然小,但是控件还是很完整的,

另外,photon还支持自定义控件。用它基本可以满足qnx下开发图形程序的需求。

原文地址:https://www.cnblogs.com/littlemeng/p/photon.html