【Windows程序设计字体显示练习】设计一个窗口,在窗口中有5行文字,字体分别为楷体、黑体和自定义字体,字号由8到40线性增长,每一行的文字相继出现后又消失。

设计一个窗口,在窗口中有5行文字,字体分别为楷体、黑体和自定义字体,字号由8到40线性增长,每一行的文字相继出现后又消失,而且每一行文字的颜色由RGB(0,0,0)到RGB(255,255,255)线性增长。

#include<windows.h>
#include<tchar.h>

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
   
	WNDCLASSEX wcex;
	HWND hWnd;
	MSG msg;
	TCHAR szWindowClass[] = L"字体显示练习";
	TCHAR szTitle[] = L"字体显示练习";

	//----------------初始化窗口类--------------------
	wcex.cbSize = sizeof(WNDCLASSEX);
	wcex.style = 0;
	wcex.lpfnWndProc = WndProc;
	wcex.cbClsExtra = 0;
	wcex.cbWndExtra = 0;
	wcex.hInstance = hInstance;
	wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
	wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
	wcex.lpszMenuName = NULL;
	wcex.lpszClassName = szWindowClass;
	wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
	//-------------------窗口类的注册-----------------------------
	if (!RegisterClassEx(&wcex))   //如果注册失败则发出警告
	{
   
		MessageBox(NULL, L"窗口类注册失败!", L"窗口注册", NULL);
		return 1;
	}
	//---------------
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的Java程序,可以在窗口中加入字体样式设置菜单,并且支持选择宋体、楷体和草书三种字体: ```java import java.awt.*; import java.awt.event.*; import javax.swing.*; public class FontMenuExample extends JFrame implements ActionListener { private JTextArea textArea; private JMenuBar menuBar; private JMenu fontMenu; private JMenuItem songMenuItem, kaiMenuItem, caoMenuItem; public FontMenuExample() { super("Font Menu Example"); // Create a text area textArea = new JTextArea(); textArea.setEditable(true); textArea.setFont(new Font("宋体", Font.PLAIN, 16)); // Create a menu bar menuBar = new JMenuBar(); // Create a font menu fontMenu = new JMenu("字体"); songMenuItem = new JMenuItem("宋体"); kaiMenuItem = new JMenuItem("楷体"); caoMenuItem = new JMenuItem("草书"); songMenuItem.addActionListener(this); kaiMenuItem.addActionListener(this); caoMenuItem.addActionListener(this); fontMenu.add(songMenuItem); fontMenu.add(kaiMenuItem); fontMenu.add(caoMenuItem); // Add the font menu to the menu bar menuBar.add(fontMenu); // Set the menu bar for the frame setJMenuBar(menuBar); // Add the text area to the frame add(new JScrollPane(textArea)); // Set the size and visibility of the frame setSize(400, 300); setVisible(true); } public void actionPerformed(ActionEvent e) { if (e.getSource() == songMenuItem) { textArea.setFont(new Font("宋体", Font.PLAIN, 16)); } else if (e.getSource() == kaiMenuItem) { textArea.setFont(new Font("楷体", Font.PLAIN, 16)); } else if (e.getSource() == caoMenuItem) { textArea.setFont(new Font("草书", Font.PLAIN, 16)); } } public static void main(String[] args) { new FontMenuExample(); } } ``` 在这个程序中,我们首先创建了一个`JTextArea`对象作为文本区域,然后创建了一个`JMenuBar`对象作为菜单栏。接着,我们创建了一个`JMenu`对象作为字体菜单,并在其中添加了三个`JMenuItem`对象,分别对应宋体、楷体和草书三种字体。我们还实现了`ActionListener`接口,以便在用户选择不同的字体时能够响应事件并设置相应的字体。最后,我们将菜单栏添加到窗口上,将文本区域添加到窗口上,并设置窗口的大小和可见性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值