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

);

 

你可能感兴趣的:(null,application,Class,button,border,menu)