我用STM32F767驱动7寸触摸屏。
主程序太大了,我想整理一下,就把按钮初始化部分单写到一个文件里。
有写了个头文件。
C源文件如下:
#include "sys.h"
#include "delay.h"
#include "usart.h"
#include "led.h"
#include "key.h"
#include "sdram.h"
#include "tftlcd.h"
#include "ltdc.h"
#include "mpu.h"
#include "timer.h"
#include "usmart.h"
#include "malloc.h"
#include "touch.h"
#include "GUI.h"
#include "WM.h"
#include "GUIDEMO.h"
#include "edit.h"
#include "dropdown.h"
#include "DIALOG.h"
#include "emwin.h"
#include <stdlib.h>
#include <string.h>
#ifndef GUI_FLASH
#define GUI_FLASH
#endif
extern GUI_FLASH const GUI_FONT GUI_Fontst211;
extern GUI_FLASH const GUI_FONT GUI_FontST37AA2;
extern GUI_FLASH const GUI_FONT GUI_Fontyh62;
extern WM_HWIN hWin,hWin1,hWin2,hWin3;
extern BUTTON_Handle hButton1,hButton2,hButton3,hButton4,hButton5,hButton6;
extern BUTTON_Handle hButton7,hButton8,hButton9,hButton10,hButton11;
extern BUTTON_Handle hButton12,hButton13,hButton14,hButton15;
extern BUTTON_Handle hButton16,hButton17,hButton18,hButton19;
extern const GUI_WIDGET_CREATE_INFO _aDialogCreate[];
//按钮初始化
void BUTTON_Init(void)
{
hButton1 = WM_GetDialogItem(hWin, GUI_ID_BUTTON1); //获取按钮句柄
hButton2 = WM_GetDialogItem(hWin, GUI_ID_BUTTON2); //获取按钮句柄
hButton3 = WM_GetDialogItem(hWin, GUI_ID_BUTTON3); //获取按钮句柄
hButton4 = WM_GetDialogItem(hWin, GUI_ID_BUTTON4); //获取按钮句柄
hButton5 = WM_GetDialogItem(hWin, GUI_ID_BUTTON5); //获取按钮句柄
BUTTON_SetBkColor(hButton1,0,GUI_WHITE); //设置按钮颜色
BUTTON_SetBkColor(hButton2,0,GUI_WHITE); //设置按钮颜色
BUTTON_SetBkColor(hButton3,0,GUI_WHITE); //设置按钮颜色
BUTTON_SetBkColor(hButton4,0,GUI_WHITE); //设置按钮颜色
BUTTON_SetBkColor(hButton5,0,GUI_WHITE); //设置按钮颜色
BUTTON_SetFont(hButton1,&GUI_FontST37AA2); //设置按钮字体
BUTTON_SetFont(hButton2,&GUI_FontST37AA2); //设置按钮字体
BUTTON_SetFont(hButton3,&GUI_FontST37AA2); //设置按钮字体
BUTTON_SetFont(hButton4,&GUI_FontST37AA2); //设置按钮字体
BUTTON_SetFont(hButton5,&GUI_FontST37AA2); //设置按钮字体
BUTTON_SetText(hButton1, "设置"); //按钮文本显示
BUTTON_SetText(hButton2, "标定"); //按钮文本显示
BUTTON_SetText(hButton3, "查询");
//BUTTON_SetText(hButton4,"鍔涘€兼瀹?);
BUTTON_SetText(hButton4,"力值检定");
BUTTON_SetText(hButton5, "帮助"); //按钮文本显示
//WM_EnableWindow(hButton1);
//WM_DisableWindow(hButton4);
BUTTON_SetTextColor(hButton4,0,GUI_GRAY_E7);
}
void Sub_Button(void)
{
hButton6 = WM_GetDialogItem(hWin1, GUI_ID_BUTTON6); //获取按钮句柄
hButton7 = WM_GetDialogItem(hWin1, GUI_ID_BUTTON7); //获取按钮句柄
hButton8 = WM_GetDialogItem(hWin1, GUI_ID_BUTTON8); //获取按钮句柄
BUTTON_SetBkColor(hButton6,0,GUI_WHITE); //设置按钮颜色
BUTTON_SetBkColor(hButton7,0,GUI_WHITE); //设置按钮颜色
BUTTON_SetBkColor(hButton8,0,GUI_WHITE); //设置按钮颜色
BUTTON_SetFont(hButton6,&GUI_Fontst211); //设置按钮字体
BUTTON_SetFont(hButton7,&GUI_Fontst211); //设置按钮字体
BUTTON_SetFont(hButton8,&GUI_Fontst211); //设置按钮字体
BUTTON_SetText(hButton6, "试验日期"); //按钮文本显示
BUTTON_SetText(hButton7, "试验类型"); //按钮文本显示
BUTTON_SetText(hButton8, "试验编号");
hButton9 = WM_GetDialogItem(hWin1, GUI_ID_BUTTON9); //获取按钮句柄
BUTTON_SetBkColor(hButton9,0,GUI_WHITE); //设置按钮颜色
BUTTON_SetFont(hButton9,&GUI_Fontst211); //设置按钮字体
BUTTON_SetText(hButton9, "查询"); //按钮文本显示
hButton10 = WM_GetDialogItem(hWin1, GUI_ID_BUTTON10); //获取按钮句柄
BUTTON_SetBkColor(hButton10,0,GUI_WHITE); //设置按钮颜色
BUTTON_SetFont(hButton10,&GUI_Fontst211); //设置按钮字体
BUTTON_SetText(hButton10, "删除"); //按钮文本显示
hButton11 = WM_GetDialogItem(hWin1, GUI_ID_BUTTON11); //获取按钮句柄
BUTTON_SetBkColor(hButton11,0,GUI_WHITE); //设置按钮颜色
BUTTON_SetFont(hButton11,&GUI_Fontst211); //设置按钮字体
BUTTON_SetText(hButton11, "试验日期"); //按钮文本显示
hButton12 = WM_GetDialogItem(hWin1, GUI_ID_BUTTON12); //获取按钮句柄
BUTTON_SetBkColor(hButton12,0,GUI_WHITE); //设置按钮颜色
BUTTON_SetFont(hButton12,&GUI_Fontst211); //设置按钮字体
BUTTON_SetText(hButton12, "试验编号"); //按钮文本显示
hButton13 = WM_GetDialogItem(hWin1, GUI_ID_BUTTON13); //获取按钮句柄
BUTTON_SetBkColor(hButton13,0,GUI_WHITE); //设置按钮颜色
BUTTON_SetFont(hButton13,&GUI_Fontst211); //设置按钮字体
BUTTON_SetText(hButton13, "试件形状"); //按钮文本显示
hButton14 = WM_GetDialogItem(hWin1, GUI_ID_BUTTON14); //获取按钮句柄
BUTTON_SetBkColor(hButton14,0,GUI_WHITE); //设置按钮颜色
BUTTON_SetFont(hButton14,&GUI_Fontst211); //设置按钮字体
BUTTON_SetText(hButton14, "试件尺寸"); //按钮文本显示
hButton15 = WM_GetDialogItem(hWin1, GUI_ID_BUTTON15); //获取按钮句柄
BUTTON_SetBkColor(hButton15,0,GUI_WHITE); //设置按钮颜色
BUTTON_SetFont(hButton15,&GUI_Fontst211); //设置按钮字体
BUTTON_SetText(hButton15, "标距(mm)"); //按钮文本显示
hButton16 = WM_GetDialogItem(hWin1, GUI_ID_BUTTON16); //获取按钮句柄
BUTTON_SetBkColor(hButton16,0,GUI_WHITE); //设置按钮颜色
BUTTON_SetFont(hButton16,&GUI_Fontyh62); //设置按钮字体
BUTTON_SetText(hButton16, "关闭"); //按钮文本显示
}
头文件如下:
#ifndef __EMWIN_H /* Make sure we only include it once */
#define __EMWIN_H
#include "GUI.h"
void BUTTON_Init(void);
void Sub_Button(void);
#endif
主程序里包含了头文件。原来都在一个文件里的时候,显示的好好的。
分开写之后,按钮上的字体就显示不出来了。高手指教,怎么回事?谢谢!
|
|