vc CreateWindow创建窗口控件及设置字体

vc CreateWindow创建窗口控件及设置字体

 HWND hBtn, hEdit, hText, hCombBox;
 hBtn = CreateWindow(   //按钮创建
  "button",
  "创建的按钮",
  WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_CENTER|BS_VCENTER,
  100,100,90,28,
  m_hWnd,
  NULL,
  AfxGetInstanceHandle(),
  0);

 hEdit = CreateWindow(   //edit控件
  "edit",
  "create",
  WS_VISIBLE|WS_CHILD|WS_BORDER/*|DT_CENTER*/|DT_VCENTER,
  100,70,100,25,
  m_hWnd,
  NULL,
  NULL,
  NULL);

HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
::SendMessage(hEdit,WM_SETFONT,(WPARAM)hFont,1);  //设置控件字体
::SendMessage(hBtn,WM_SETFONT,(WPARAM)hFont,1);

 hCombBox = CreateWindow(
  "combobox",
  "1",
  WS_CHILD|WS_VISIBLE|WS_BORDER|CBS_AUTOHSCROLL|CBS_DROPDOWNLIST,
  220, 100, 100, 25,
  m_hWnd,
  NULL,
  NULL,
  NULL);

1、字体字号的问题解决方案是:
创建一个自己想要的字体,我直接获取的
HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT); 

然后给Edit发消息
SendMessage(mhAgreementHand,WM_SETFONT,(WPARAM)hNewFont,1);


2、背景色的问题,直接在父窗口的WM_CTLCOLORSTATIC消息里返回一个黑画刷就好了
HBRUSH hbr = (HBRUSH)GetStockObject(BLACK_BRUSH);
return (LRESULT)hbr;

 

函数体

HWND CreateWindow(

    LPCTSTR lpClassName, // pointer to registered class name

    LPCTSTR lpWindowName, // pointer to window name

    DWORD dwStyle, // window style

    int x, // horizontal position of window

    int y, // vertical position of window

    int nWidth, // window width

    int nHeight, // window height

    HWND hWndParent, // handle to parent or owner window

    HMENU hMenu, // handle to menu or child-window identifier

    HANDLE hInstance, // handle to application instance

    LPVOID lpParam // pointer to window-creation data

);

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值