惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

A
Arctic Wolf
博客园 - 聂微东
F
Fortinet All Blogs
云风的 BLOG
云风的 BLOG
小众软件
小众软件
V
Visual Studio Blog
博客园 - 三生石上(FineUI控件)
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Apple Machine Learning Research
Apple Machine Learning Research
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The Cloudflare Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The GitHub Blog
The GitHub Blog
Y
Y Combinator Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园_首页
L
LangChain Blog
A
About on SuperTechFans
阮一峰的网络日志
阮一峰的网络日志
I
Intezer
T
The Blog of Author Tim Ferriss
Security Latest
Security Latest
C
CXSECURITY Database RSS Feed - CXSecurity.com
Know Your Adversary
Know Your Adversary
Simon Willison's Weblog
Simon Willison's Weblog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Palo Alto Networks Blog
Scott Helme
Scott Helme
S
Secure Thoughts
Spread Privacy
Spread Privacy
T
Threat Research - Cisco Blogs
Attack and Defense Labs
Attack and Defense Labs
P
Privacy & Cybersecurity Law Blog
O
OpenAI News
H
Heimdal Security Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Help Net Security
Help Net Security
C
Cyber Attacks, Cyber Crime and Cyber Security
Blog — PlanetScale
Blog — PlanetScale
GbyAI
GbyAI
G
Google Developers Blog
博客园 - Franky
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
K
Kaspersky official blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
T
Tor Project blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
T
Tenable Blog
Google Online Security Blog
Google Online Security Blog
PCI Perspectives
PCI Perspectives

博客园 - answer

SQL查询重复记录 如何使用两台 NETGEAR 无线路由器进行无线中继(WDS) [转]取当前日期是在一年中的第几周 [转]写在UserControl销毁之时 给List排序( list sort) [转]检查本地DNS服务器是否正常工作及解决方法 SQLITE入门至精通 [转]WM手机,关于如何让手机一直运行下去,而不进入待机 [转]string表达式运算 [转]HTC G11 ROOT获取权限教程 [转]WebForm 与 winform 路径获取 [转]win7 系统装SQLServer2000 成功。 Mobile Development: Disable Windows Mobile 6.5 Start and Close Button [转]Windows Mobile: Hide StartButton in WinMo 6.5.x Windows CE 电源管理(转贴) [转]分享8个超棒的免费高质量图标搜索引擎 [转]Win7系统下VS2005_2008不识别WinCE5 SDK [转]windows 7 下ASP.net 本地配置 ( IIS 7) [转]SQLite存取二进制数据
[转]SelectObject() 装载字体 VC EVC
answer · 2011-02-21 · via 博客园 - answer

用API 在创建的窗口上写字的时候发现一个问题,FONT   的句柄必须声明为全局变量,否则在选入字体的时候会返回失败。
VC 和EVC在创建字体的方法有点不大一样。VC版如下:

LRESULT CALLBACK    WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
{ HDC hdc=NULL;
PAINTSTRUCT ps;
RECT rt;
HBRUSH hbrBkgnd;
static HPEN hpenDot;     // handle of dotted pen
static HFONT hFont;
LOGFONT lf;

switch(message){
case WM_CREATE:
        hpenDot = CreatePen(PS_DOT, 2, #ff0000); //创建虚线画笔

   hFont=CreateFont(                            // Create Font
    15,                      // nHeight
    0,                         // nWidth
    0,                         // nEscapement
    0,                         // nOrientation
    FW_NORMAL,                 // nWeight
    FALSE,                     // bItalic
    FALSE,                     // bUnderline
    0,                         // cStrikeOut
    ANSI_CHARSET,              // nCharSet
    OUT_DEFAULT_PRECIS,        // nOutPrecision
    CLIP_DEFAULT_PRECIS,       // nClipPrecision
    DEFAULT_QUALITY,           // nQuality
    DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
    _T("Arial"));              // lpszFacename

        break;
case WM_COMMAND:
       break; // do nothing
case WM_PAINT:
       SetWindowText(hWnd,"Text test");
       hdc = BeginPaint(hWnd, &ps);
       if(NULL==SelectObject(hdc,hFont))
           MessageBox(NULL,"fail font","debug",0);   
       if(NULL==SelectObject(hdc,hpenDot))
           MessageBox(NULL,"fail pen","debug",0);
       GetClientRect(hWnd, &rt);
       _stprintf(szMsg,"((%d,%d),(%d,%d))",rt.left,rt.top,rt.right,rt.bottom);
       //SetBkColor(hdc,#ff0000);
      // DrawText(hdc, szMsg, strlen(szMsg), &rt, DT_CENTER);
       TextOut(hdc,10,10,szMsg,strlen(szMsg));
       Rectangle(hdc,100, 100, 550,250);
       EndPaint(hWnd, &ps);
       UpdateWindow(ghWnd);
       break;
case WM_CLOSE:
         PostQuitMessage(0);
        break;
default:
      return DefWindowProc(hWnd,message,wParam,lParam);
}
return DefWindowProc(hWnd,message,wParam,lParam);
}

EVC 版:

LRESULT CALLBACK DlgProc_Panel(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
static HDC     hdc;
static PAINTSTRUCT   ps;
    static RECT     rt;
    static HBRUSH    hBrush;
static COLORREF    wColor=#000000;
static int     nDrawTimes=0;
static HFONT    hFont;
static LOGFONT          m_logfnt;
TCHAR lfFaceName[32]= TEXT("Times New Roman");
m_logfnt.lfCharSet=DEFAULT_CHARSET;
m_logfnt.lfClipPrecision=CLIP_DEFAULT_PRECIS;
m_logfnt.lfEscapement=0;
m_logfnt.lfHeight=80;
m_logfnt.lfItalic=false;
m_logfnt.lfOrientation=0;
m_logfnt.lfPitchAndFamily=FF_SWISS;
m_logfnt.lfQuality=DEFAULT_QUALITY;
m_logfnt.lfStrikeOut=false;
m_logfnt.lfUnderline=true;
m_logfnt.lfWeight=800;
m_logfnt.lfWidth=20;
m_logfnt.lfOutPrecision=OUT_DEFAULT_PRECIS;


switch (message)
{
case WM_INITDIALOG:
   hFont=CreateFontIndirect(&m_logfnt);
   nDrawTimes=0;
   wColor=#ff0000;
   MoveWindowFullScreen(hDlg);
   break;
case WM_PAINT:
   hdc = BeginPaint(hDlg, &ps);
   GetClientRect(hDlg, &rt);
   hBrush=CreateSolidBrush(wColor);
   FillRect(hdc,&rt,hBrush);
   //TextOut(hdc, rt.left+10, rt.top+100, "Test", 4);
   SelectObject(hdc,hFont);
   SetTextColor(hdc,#0000ff);
   rt.top += rt.bottom/2;
   DrawText(hdc,TEXT("Test\n"),-1,&rt,DT_CENTER);
   DeleteObject(hBrush);
   EndPaint(hDlg, &ps);
   break;
case WM_LBUTTONDOWN:
case WM_KEYUP:
   InvalidateRect(hDlg,&rt,TRUE);
   EndDialog(hDlg,TRUE);
   break;
}
    return FALSE;
}