[ucgui] 对话框7——按钮触发与模式窗口

 

>_<" 模式窗口,只有结束该窗口时才能聚焦到其他的窗口上~

  1 //////////////////////////////////////////////////////////////////////

  2 //全局函数

  3 //////////////////////////////////////////////////////////////////////

  4 static void _cbDialog0(WM_MESSAGE * pMsg);

  5 static void _cbDialog1(WM_MESSAGE * pMsg);

  6 static void _cbDialog2(WM_MESSAGE * pMsg);

  7 //////////////////////////////////////////////////////////////////////

  8 //变量

  9 //////////////////////////////////////////////////////////////////////

 10 WM_HWIN hWin_p,hWin_c_AdjZero,hWin_c_AdjValue;

 11 //////////////////////////////////////////////////////////////////////

 12 //宏定义

 13 //窗口0:是主界面窗口

 14 //窗口1:是调零窗口

 15 //窗口2:是校准窗口

 16 //命名规则:P表示父窗口,C表示子窗口;

 17 //当存在同一级的相同控件时要在后面加上各自的名字区分

 18 //ID_控件类型_父窗口还是子窗口_一级区分_二级区分...

 19 //////////////////////////////////////////////////////////////////////

 20 #define ID_FRAMEWIN_P              (GUI_ID_USER + 0x0E)

 21 #define ID_BUTTON_P_AdjZero       (GUI_ID_USER + 0x18)

 22 #define ID_BUTTON_P_AdjValue       (GUI_ID_USER + 0x19)

 23 

 24 #define ID_FRAMEWIN_C_AdjZero   (GUI_ID_USER + 0x21)

 25 #define ID_BUTTON_C_AdjZero       (GUI_ID_USER + 0x22)

 26 #define ID_TEXT_C_AdjZero       (GUI_ID_USER + 0x25)

 27 #define ID_MULTIEDIT_C_AdjZero  (GUI_ID_USER + 0x26)

 28 

 29 #define ID_FRAMEWIN_C_AdjValue  (GUI_ID_USER + 0x27)

 30 #define ID_BUTTON_C_AdjValue      (GUI_ID_USER + 0x28)

 31 #define ID_MULTIEDIT_C_AdjValue (GUI_ID_USER + 0x29)

 32 #define ID_SLIDER_C_AdjValue      (GUI_ID_USER + 0x30)

 33 #define ID_TEXT_C_AdjValue      (GUI_ID_USER + 0x31)

 34 #define ID_EDIT_C_AdjValue      (GUI_ID_USER + 0x35)

 35 //////////////////////////////////////////////////////////////////////

 36 //资源列表

 37 //窗口0:是主界面窗口

 38 //窗口1:是调零窗口

 39 //窗口2:是校准窗口

 40 //////////////////////////////////////////////////////////////////////

 41 static const GUI_WIDGET_CREATE_INFO _aDialogCreate0[] = {

 42   { FRAMEWIN_CreateIndirect, "Framewin",ID_FRAMEWIN_P , 0, -1, 800, 480, 0, 0 },

 43   { BUTTON_CreateIndirect, "ZERO", ID_BUTTON_P_AdjZero, 725, 344, 60, 55, 0, 0 },

 44   { BUTTON_CreateIndirect, "VALUE",ID_BUTTON_P_AdjValue, 725, 404, 60, 55, 0, 0},

 45 };

 46 static const GUI_WIDGET_CREATE_INFO _aDialogCreate1[] = {

 47   { FRAMEWIN_CreateIndirect, "Adjust Zero",ID_FRAMEWIN_C_AdjZero, 250, 155, 225, 193, 0, 0},

 48   { BUTTON_CreateIndirect, "Button",ID_BUTTON_C_AdjZero, 153, 16, 50, 45, 0, 0},

 49   { TEXT_CreateIndirect, "Text",ID_TEXT_C_AdjZero, 29, 28, 102, 28, 0, 100},

 50   { MULTIEDIT_CreateIndirect, "Multiedit",ID_MULTIEDIT_C_AdjZero, 4, 88, 207, 81, 0, 0},

 51 };

 52 static const GUI_WIDGET_CREATE_INFO _aDialogCreate2[] = {

 53   { FRAMEWIN_CreateIndirect, "Adjust Value",ID_FRAMEWIN_C_AdjValue, 250, 154, 225, 193, 0, 0},

 54   { BUTTON_CreateIndirect, "Button",ID_BUTTON_C_AdjValue, 172, 8, 40, 39, 0, 0},

 55   { MULTIEDIT_CreateIndirect, "Multiedit",ID_MULTIEDIT_C_AdjValue, 4, 88, 207, 81, 0, 0},

 56   { SLIDER_CreateIndirect, "Slider",ID_SLIDER_C_AdjValue, 2, 61, 178, 20, 0, 0},

 57   { TEXT_CreateIndirect, "Text",ID_TEXT_C_AdjValue, 10, 20, 80, 20, 0, 100},

 58   { EDIT_CreateIndirect, "Edit",ID_EDIT_C_AdjValue, 184, 60, 26, 20, 0, 100},

 59 };

 60 //////////////////////////////////////////////////////////////////////

 61 //回调函数

 62 //窗口0:是主界面窗口

 63 //窗口1:是调零窗口

 64 //窗口2:是校准窗口

 65 //////////////////////////////////////////////////////////////////////

 66 static void _cbDialog0(WM_MESSAGE * pMsg) {

 67   WM_HWIN hItem;

 68   int Id, NCode;

 69   // USER START (Optionally insert additional variables)

 70   // USER END

 71 

 72   switch (pMsg->MsgId) {

 73   case WM_INIT_DIALOG://初始化建立2个非阻塞的基于主窗口的子窗口

 74       break;

 75   case WM_NOTIFY_PARENT:

 76     Id    = WM_GetId(pMsg->hWinSrc);

 77     NCode = pMsg->Data.v;

 78     switch(Id) {

 79     case ID_BUTTON_P_AdjZero: // Notifications sent by 'SET'

 80       switch(NCode) {

 81       case WM_NOTIFICATION_CLICKED:

 82         break;

 83       case WM_NOTIFICATION_RELEASED:

 84           hWin_c_AdjZero=GUI_CreateDialogBox(_aDialogCreate1, GUI_COUNTOF(_aDialogCreate1),&_cbDialog1, 0, 0, 0);

 85         //模式化并聚焦窗口

 86         WM_MakeModal(hWin_c_AdjZero);/*此函数使窗口在“模态”模式下作业。这意味着指针设备输入

 87                                         将仅发送到“模态”窗口,或者如果输入位置在模态窗口的矩形内则仅发送到其子窗口。*/

 88         WM_SetFocus(hWin_c_AdjZero);    //将输入焦点设置到指定窗口

 89         WM_InvalidateWindow(hWin_c_AdjZero);//使窗口无效

 90         break;

 91       }

 92       break;

 93     case ID_BUTTON_P_AdjValue: // Notifications sent by 'CHECK'

 94       switch(NCode) {

 95       case WM_NOTIFICATION_RELEASED:

 96         //模式化并聚焦窗口

 97           hWin_c_AdjValue=GUI_CreateDialogBox(_aDialogCreate2, GUI_COUNTOF(_aDialogCreate2),&_cbDialog2, 0, 0, 0);

 98         WM_MakeModal(hWin_c_AdjValue);/*此函数使窗口在“模态”模式下作业。这意味着指针设备输入

 99                                         将仅发送到“模态”窗口,或者如果输入位置在模态窗口的矩形内则仅发送到其子窗口。*/

100         WM_SetFocus(hWin_c_AdjValue);    //将输入焦点设置到指定窗口

101         WM_InvalidateWindow(hWin_c_AdjValue);//使窗口无效

102         break;

103       }

104       break;

105     }

106     break;

107   default:

108     WM_DefaultProc(pMsg);

109     break;

110   }

111 }

112 

113 static void _cbDialog1(WM_MESSAGE * pMsg) {

114   WM_HWIN hItem;

115   int Id, NCode;

116 

117   switch (pMsg->MsgId) {

118   case WM_INIT_DIALOG:

119     //

120     // Initialization of 'Button'

121     //

122     hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_C_AdjZero);

123     BUTTON_SetText(hItem, "OK");

124     //

125     // Initialization of 'Text'

126     //

127     hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_C_AdjZero);

128     TEXT_SetText(hItem, "Adjustment Zero");

129     //

130     // Initialization of 'Multiedit'

131     //

132     hItem = WM_GetDialogItem(pMsg->hWin, ID_MULTIEDIT_C_AdjZero);

133     MULTIEDIT_SetText(hItem, "     make the machine zero load,and then click the OK button!");

134     MULTIEDIT_SetReadOnly(hItem,1);

135     MULTIEDIT_SetWrapWord(hItem);      

136     // USER START (Optionally insert additional code for further widget initialization)

137     // USER END

138     break;

139   case WM_NOTIFY_PARENT:

140     Id    = WM_GetId(pMsg->hWinSrc);

141     NCode = pMsg->Data.v;

142     switch(Id) {

143     case ID_BUTTON_C_AdjZero: // Notifications sent by 'Button'

144       switch(NCode) {

145       case WM_NOTIFICATION_RELEASED:    //释放按钮相应

146         GUI_EndDialog(hWin_c_AdjZero,0);

147         break;

148       }

149       break;

150     case ID_MULTIEDIT_C_AdjZero: // Notifications sent by 'Multiedit'

151       switch(NCode) {

152       case WM_NOTIFICATION_CLICKED:

153         break;

154       case WM_NOTIFICATION_RELEASED:

155         break;

156       case WM_NOTIFICATION_VALUE_CHANGED:

157         break;

158       }

159       break;

160     }

161     break;

162   default:

163     WM_DefaultProc(pMsg);

164     break;

165   }

166 }

167 

168 static void _cbDialog2(WM_MESSAGE * pMsg) {

169   WM_HWIN hItem;

170   int Id, NCode;

171 

172   switch (pMsg->MsgId) {

173   case WM_INIT_DIALOG:

174     //

175     // Initialization of 'Button'

176     //

177     hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_C_AdjValue);

178     BUTTON_SetText(hItem, "OK");

179     //

180     // Initialization of 'Multiedit'

181     //

182     hItem = WM_GetDialogItem(pMsg->hWin, ID_MULTIEDIT_C_AdjValue);

183     MULTIEDIT_SetText(hItem, "     make the machine load above half measuring range ,and then slide the slider to meet the current percentage, last click the OK button!");

184     MULTIEDIT_SetReadOnly(hItem,1);

185     MULTIEDIT_SetWrapWord(hItem);    

186     //

187     // Initialization of 'Text'

188     //

189     hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_C_AdjValue);

190     TEXT_SetText(hItem, "Adjust Value");

191     //

192     // Initialization of 'Edit'

193     //

194     hItem = WM_GetDialogItem(pMsg->hWin, ID_EDIT_C_AdjValue);

195     EDIT_SetText(hItem, "123");

196 

197     break;

198   case WM_NOTIFY_PARENT:

199     Id    = WM_GetId(pMsg->hWinSrc);

200     NCode = pMsg->Data.v;

201     switch(Id) {

202     case ID_BUTTON_C_AdjValue: // Notifications sent by 'Button'

203       switch(NCode) {

204       case WM_NOTIFICATION_RELEASED://释放按钮时相应

205           GUI_EndDialog(hWin_c_AdjValue,0);

206         break;

207       }

208       break;

209     case ID_MULTIEDIT_C_AdjValue: // Notifications sent by 'Multiedit'

210       switch(NCode) {

211       case WM_NOTIFICATION_CLICKED:

212         break;

213       case WM_NOTIFICATION_RELEASED:

214         break;

215       case WM_NOTIFICATION_VALUE_CHANGED:

216         break;

217       }

218       break;

219     case ID_SLIDER_C_AdjValue: // Notifications sent by 'Slider'

220       switch(NCode) {

221       case WM_NOTIFICATION_CLICKED:

222         break;

223       case WM_NOTIFICATION_RELEASED:

224         break;

225       case WM_NOTIFICATION_VALUE_CHANGED:

226         break;

227       }

228       break;

229     case ID_EDIT_C_AdjValue: // Notifications sent by 'Edit'

230       switch(NCode) {

231       case WM_NOTIFICATION_CLICKED:

232         break;

233       case WM_NOTIFICATION_RELEASED:

234         break;

235       case WM_NOTIFICATION_VALUE_CHANGED:

236         break;

237       }

238       break;

239     }

240     break;

241   default:

242     WM_DefaultProc(pMsg);

243     break;

244   }

245 }

246 

247 //////////////////////////////////////////////////////////////////////

248 //主函数

249 //////////////////////////////////////////////////////////////////////

250 void Fun(void) {

251     GUI_Init();                    //ucgui初始化 

252     GUI_ExecDialogBox(_aDialogCreate0, GUI_COUNTOF(_aDialogCreate0),&_cbDialog0, 0, 0, 0);

253 }

 

你可能感兴趣的:(GUI)