更改默认的窗口的字体在Win32窗口项目 [英] change the default window font in a win32 windows project

查看:704
本文介绍了更改默认的窗口的字体在Win32窗口项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建使用C和Win32 API的一个GUI应用程序。我想知道我们如何可以改变主窗口的默认字体thaoma。我从.NET正在添加的背景。在.NET中,如果我们改变父控件的字体然后自动的子控件继承字体....
是否有类似的离开它还是我们需要手动设置每个控件的字体......

I am creating a GUI application using C and Win32 api. I would like to know how we can change the default font of the Main window to thaoma. I am comming from .NET background. In .NET if we change the font of parent control then automatically the child controls inherits that font.... Is there away similar to it or do we need to manually set the font of each control.....

考虑以下code ...

Consider the following code...

#include <windows.h>

#define ID_EDIT 1
#define ID_BUTTON 2

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{

  static HWND hwndEdit;
  static HWND hwndButton;
  static int len;
  static TCHAR text[30];


  switch(msg)
  {
    case WM_CREATE:
    hwndEdit = CreateWindow(TEXT("Edit"), NULL, WS_CHILD | WS_VISIBLE | WS_BORDER,
                50, 50, 150, 20, hwnd, (HMENU) ID_EDIT,
                NULL, NULL);

    hwndButton = CreateWindow(
        TEXT("button"), TEXT("Set Title"),       
        WS_VISIBLE | WS_CHILD,  
        50, 100, 80, 25,        
        hwnd, (HMENU) ID_BUTTON, NULL, NULL);      

    break;


    case WM_DESTROY:
        PostQuitMessage(0);
    break;
  }
  return DefWindowProc(hwnd, msg, wParam, lParam);
}

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
            LPSTR lpCmdLine, int nCmdShow )
{
  MSG  msg ;    
  WNDCLASS wc = {0};
  wc.lpszClassName = TEXT( "Edit Control" );
  wc.hInstance     = hInstance ;
  wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
  wc.lpfnWndProc   = WndProc ;
  wc.hCursor       = LoadCursor(0,IDC_ARROW);


  RegisterClass(&wc);
  CreateWindow( wc.lpszClassName, TEXT("Edit control"),
                WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                220, 220, 280, 200, 0, 0, hInstance, 0);  

  while( GetMessage(&msg, NULL, 0, 0)) {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
  }
  return (int) msg.wParam;
}

我如何更改按钮的字体,文本框,在上面的程序。

How can i change the font of button, textbox in the above program..

请帮我在这里.......,让我知道的一般过程遵循,而在Win32 API的编码....

Please help me here.......and let me know the general process followed while coding in win32 api....

在此先感谢..

推荐答案

您可以通过发送它的 WM_SETFONT 消息设置窗口的字体:

You can set the font of a window by sending it the WM_SETFONT message:

HWND myButton = CreateWindowEx(/* ... */);
HFONT myFont  = /* ... load font from somewhere ... */

/* Change the button font. */
SendMessage(myButton, WM_SETFONT, WPARAM(myFont), TRUE);

此方法给你一个控制通过控制控制哪些字体你使用,但是你只需要每个窗口做一次。

This approach gives you a control-by-control control over which fonts you're using, but you only need to do it once per window.

这篇关于更改默认的窗口的字体在Win32窗口项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆