构建最简单的WTL Hello World程序,基于:WTL91_5321_Final + VS2013 + WIN7
添加->新建项目
为了简单起见,我们删除一些button和对应的处理代码(一般我们只需要修改dialog对应的.h/.cpp代码)
MainDlg.h
// MainDlg.h : interface of the CMainDlg class
//
/////////////////////////////////////////////////////////////////////////////
#pragma once
class CMainDlg : public CDialogImpl
{
public:
enum { IDD = IDD_MAINDLG };
BEGIN\_MSG\_MAP(CMainDlg)
MESSAGE\_HANDLER(WM\_INITDIALOG, OnInitDialog)
COMMAND\_ID\_HANDLER(IDCANCEL, OnCancel)
END\_MSG\_MAP()
// Handler prototypes (uncomment arguments if needed):
// LRESULT MessageHandler(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
// LRESULT CommandHandler(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
// LRESULT NotifyHandler(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& /*bHandled*/)
LRESULT OnInitDialog(UINT /\*uMsg\*/, WPARAM /\*wParam\*/, LPARAM /\*lParam\*/, BOOL& /\*bHandled\*/);
LRESULT OnCancel(WORD /\*wNotifyCode\*/, WORD wID, HWND /\*hWndCtl\*/, BOOL& /\*bHandled\*/);
};
MainDlg.cpp
// MainDlg.cpp : implementation of the CMainDlg class
//
/////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "resource.h"
#include "MainDlg.h"
LRESULT CMainDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
// center the dialog on the screen
CenterWindow();
// set icons
HICON hIcon = AtlLoadIconImage(IDR\_MAINFRAME, LR\_DEFAULTCOLOR, ::GetSystemMetrics(SM\_CXICON), ::GetSystemMetrics(SM\_CYICON));
SetIcon(hIcon, TRUE);
HICON hIconSmall = AtlLoadIconImage(IDR\_MAINFRAME, LR\_DEFAULTCOLOR, ::GetSystemMetrics(SM\_CXSMICON), ::GetSystemMetrics(SM\_CYSMICON));
SetIcon(hIconSmall, FALSE);
return TRUE;
}
LRESULT CMainDlg::OnCancel(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
EndDialog(wID);
return 0;
}
最初的运行样子:
我们新建一个Static Text
我们可以直接在Caption属性修改成我们想要的文字
或者在OnInitDialog编码实现:
CWindow wnd = this->GetDlgItem(IDC_STATIC);
CStatic *pEdit = (CStatic*)&wnd;
pEdit->SetWindowText(_T("Hello World"));
更改字体:
CFont font;
font.CreatePointFont(16, TEXT("Arial"));
CWindow wnd = this->GetDlgItem(IDC\_STATIC);
CStatic \*pEdit = (CStatic\*)&wnd;
pEdit->SetFont(font);
pEdit->SetWindowText(\_T("Hello World"));
手机扫一扫
移动阅读更方便
你可能感兴趣的文章