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

推荐订阅源

N
News and Events Feed by Topic
T
The Exploit Database - CXSecurity.com
P
Palo Alto Networks Blog
T
Threat Research - Cisco Blogs
Cloudbric
Cloudbric
Recent Commits to openclaw:main
Recent Commits to openclaw:main
I
Intezer
Attack and Defense Labs
Attack and Defense Labs
P
Privacy International News Feed
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
L
Lohrmann on Cybersecurity
C
Cybersecurity and Infrastructure Security Agency CISA
V2EX - 技术
V2EX - 技术
AWS News Blog
AWS News Blog
O
OpenAI News
L
LINUX DO - 最新话题
N
News | PayPal Newsroom
PCI Perspectives
PCI Perspectives
www.infosecurity-magazine.com
www.infosecurity-magazine.com
T
Troy Hunt's Blog
Latest news
Latest news
D
Darknet – Hacking Tools, Hacker News & Cyber Security
A
Arctic Wolf
Spread Privacy
Spread Privacy
G
GRAHAM CLULEY
T
Tor Project blog
博客园_首页
Know Your Adversary
Know Your Adversary
有赞技术团队
有赞技术团队
S
Secure Thoughts
美团技术团队
Apple Machine Learning Research
Apple Machine Learning Research
爱范儿
爱范儿
T
Tailwind CSS Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
V
Visual Studio Blog
J
Java Code Geeks
Cisco Talos Blog
Cisco Talos Blog
Schneier on Security
Schneier on Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
S
Security Affairs
Jina AI
Jina AI
人人都是产品经理
人人都是产品经理
雷峰网
雷峰网
宝玉的分享
宝玉的分享
量子位
Last Week in AI
Last Week in AI
月光博客
月光博客
罗磊的独立博客
S
SegmentFault 最新的问题

博客园 - 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;
}