﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-不说害怕</title><link>http://www.cppblog.com/zhupf/</link><description>生活不止苟与且， 还有诗和远方</description><language>zh-cn</language><lastBuildDate>Mon, 20 Apr 2026 04:46:19 GMT</lastBuildDate><pubDate>Mon, 20 Apr 2026 04:46:19 GMT</pubDate><ttl>60</ttl><item><title>GDI+中用TextureBrush来FillRectangle的问题</title><link>http://www.cppblog.com/zhupf/archive/2013/07/25/GDIP_TextureBrush.html</link><dc:creator>zhupf</dc:creator><author>zhupf</author><pubDate>Thu, 25 Jul 2013 09:28:00 GMT</pubDate><guid>http://www.cppblog.com/zhupf/archive/2013/07/25/GDIP_TextureBrush.html</guid><wfw:comment>http://www.cppblog.com/zhupf/comments/202114.html</wfw:comment><comments>http://www.cppblog.com/zhupf/archive/2013/07/25/GDIP_TextureBrush.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/zhupf/comments/commentRss/202114.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zhupf/services/trackbacks/202114.html</trackback:ping><description><![CDATA[在给对话框背景贴图的时候, 使用了九宫格的切图方式.<br />先平铺: 中, 上下左右, 4条边.<br />再单独绘制4个角 和标题 图片.<br />为了平铺方便. 使用了 TextureBrush来FillRectangle. 没有使用DrawImage.<br />原本是为了简单. 谁知TextureBrush怎么画都不对.&nbsp;<br /><div style="padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; width: 1171.09375px; word-break: break-all;">TextureBrush&nbsp;_Brush(&amp;_Image);<br />Rect&nbsp;_Rect(x,y,w,h);<br />_Gfx.FillRectangle(&amp;_Brush,_Rect);</div>除了在FillRectangle的左边在0,0的时候是正确的.其他都偏了, 很乱.<br />研究了一下.<br />原来TextureBrush在FillRectangle的时候在内部会从0,0位置开始平铺好, 然后再取一块_Rect矩形区域贴到你需要绘制的地方.<br />需要加一句才能正确绘制:&nbsp;<span style="color: #333333; font-family: Arial; line-height: 25.984375px; background-color: #ffffff;">TranslateTransform</span><br /><div style="padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; width: 1171.09375px; word-break: break-all;">TextureBrush&nbsp;_Brush(&amp;_Image);<br />Rect&nbsp;_Rect(x,y,w,h);<br /><span style="color: red;"><strong>_Brush.TranslateTransform(x,y);</strong></span><br />_Gfx.FillRectangle(&amp;_Brush,_Rect);</div><img src ="http://www.cppblog.com/zhupf/aggbug/202114.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zhupf/" target="_blank">zhupf</a> 2013-07-25 17:28 <a href="http://www.cppblog.com/zhupf/archive/2013/07/25/GDIP_TextureBrush.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>WinHttp支持HTTPS下载</title><link>http://www.cppblog.com/zhupf/archive/2013/07/02/201459.html</link><dc:creator>zhupf</dc:creator><author>zhupf</author><pubDate>Tue, 02 Jul 2013 06:44:00 GMT</pubDate><guid>http://www.cppblog.com/zhupf/archive/2013/07/02/201459.html</guid><wfw:comment>http://www.cppblog.com/zhupf/comments/201459.html</wfw:comment><comments>http://www.cppblog.com/zhupf/archive/2013/07/02/201459.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/zhupf/comments/commentRss/201459.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zhupf/services/trackbacks/201459.html</trackback:ping><description><![CDATA[<div></div><div>#include "windows.h"</div><div>#include "winhttp.h"</div><div>#include "wchar.h"</div><div>#pragma comment(lib,"Winhttp.lib")</div><div>// SSL (Secure Sockets Layer) example</div><div>// compile for console</div><div>void main()</div><div>{</div><div><span style="white-space:pre">	</span>HINTERNET hOpen = 0;</div><div><span style="white-space:pre">	</span>HINTERNET hConnect = 0;</div><div><span style="white-space:pre">	</span>HINTERNET hRequest = 0;</div><div><span style="white-space:pre">	</span>IStream *stream = NULL;</div><div><span style="white-space:pre">	</span>HRESULT hr;</div><div><span style="white-space:pre">	</span>while (1)</div><div><span style="white-space:pre">	</span>{</div><div><span style="white-space:pre">		</span>hOpen = WinHttpOpen(L"Aurora Console App", WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,</div><div><span style="white-space:pre">				</span>WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0);</div><div><span style="white-space:pre">		</span>if (!hOpen) {</div><div><span style="white-space:pre">			</span>wprintf(L"WinHttpOpen failed (0x%.8X)\n", GetLastError());</div><div><span style="white-space:pre">			</span>break;</div><div><span style="white-space:pre">		</span>}</div><div><span style="white-space:pre">		</span>hConnect = WinHttpConnect(hOpen, L"raw.github.com", INTERNET_DEFAULT_HTTPS_PORT, 0);</div><div><span style="white-space:pre">		</span>if (!hConnect) {</div><div><span style="white-space:pre">			</span>wprintf(L"WinHttpConnect failed (0x%.8X)\n", GetLastError());</div><div><span style="white-space:pre">			</span>break;</div><div><span style="white-space:pre">		</span>}</div><div><span style="white-space:pre">		</span>LPCWSTR types[2];</div><div><span style="white-space:pre">		</span>types[0] = L"text/html";</div><div><span style="white-space:pre">		</span>types[1] = 0;</div><div><span style="white-space:pre">		</span>// use flag WINHTTP_FLAG_SECURE to initiate SSL</div><div><span style="white-space:pre">		</span>hRequest = WinHttpOpenRequest(hConnect, L"GET", L"zpfzzz/test/master/README.md",</div><div><span style="white-space:pre">				</span>NULL, WINHTTP_NO_REFERER, &amp;types[0], WINHTTP_FLAG_SECURE);</div><div><span style="white-space:pre">		</span>if (!hRequest)</div><div><span style="white-space:pre">		</span>{</div><div><span style="white-space:pre">			</span>wprintf(L"WinHttpOpenRequest failed (0x%.8X)\n", GetLastError());</div><div><span style="white-space:pre">			</span>break;</div><div><span style="white-space:pre">		</span>}</div><div><span style="white-space:pre">		</span>if (!WinHttpSendRequest(hRequest, WINHTTP_NO_ADDITIONAL_HEADERS, 0, WINHTTP_NO_REQUEST_DATA, 0, 0, 0))</div><div><span style="white-space:pre">		</span>{</div><div><span style="white-space:pre">			</span>wprintf(L"WinHttpSendRequest failed (0x%.8X)\n", GetLastError());</div><div><span style="white-space:pre">			</span>break;</div><div><span style="white-space:pre">		</span>}</div><div><span style="white-space:pre">		</span>if (!WinHttpReceiveResponse(hRequest, 0))</div><div><span style="white-space:pre">		</span>{</div><div><span style="white-space:pre">			</span>wprintf(L"WinHttpReceiveResponse failed (0x%.8X)\n", GetLastError());</div><div><span style="white-space:pre">			</span>break;</div><div><span style="white-space:pre">		</span>}</div><div><span style="white-space:pre">		</span>// query remote file size, set haveContentLength on success and dwContentLength to the length</div><div><span style="white-space:pre">		</span>wchar_t szContentLength[32];</div><div><span style="white-space:pre">		</span>DWORD cch = 64;</div><div><span style="white-space:pre">		</span>DWORD dwHeaderIndex = WINHTTP_NO_HEADER_INDEX;</div><div><span style="white-space:pre">		</span>BOOL haveContentLength = WinHttpQueryHeaders(hRequest, WINHTTP_QUERY_CONTENT_LENGTH, NULL,</div><div><span style="white-space:pre">				</span>&amp;szContentLength, &amp;cch, &amp;dwHeaderIndex);</div><div><span style="white-space:pre">		</span>DWORD dwContentLength;</div><div><span style="white-space:pre">		</span>if (haveContentLength) dwContentLength = _wtoi(szContentLength);</div><div><span style="white-space:pre">		</span>// read the response into memory stream</div><div><span style="white-space:pre">		</span>hr = CreateStreamOnHGlobal(0, true, &amp;stream);</div><div><span style="white-space:pre">		</span>if (hr) {</div><div><span style="white-space:pre">			</span>wprintf(L"CreateStreamOnHGlobal failed (0x%.8X)\n", hr);</div><div><span style="white-space:pre">			</span>break;</div><div><span style="white-space:pre">		</span>}</div><div><span style="white-space:pre">		</span>// allocate buffer for streaming received data</div><div><span style="white-space:pre">		</span>char *p = new char[4096];</div><div><span style="white-space:pre">		</span>if (!p)</div><div><span style="white-space:pre">		</span>{</div><div><span style="white-space:pre">			</span>wprintf(L"failed to allocate buffer\n");</div><div><span style="white-space:pre">			</span>break;</div><div><span style="white-space:pre">		</span>}</div><div><span style="white-space:pre">		</span>// to receive all data, we need to enter a loop</div><div><span style="white-space:pre">		</span>DWORD dwReceivedTotal = 0;</div><div><span style="white-space:pre">		</span>while (WinHttpQueryDataAvailable(hRequest, &amp;cch) &amp;&amp; cch)</div><div><span style="white-space:pre">		</span>{</div><div><span style="white-space:pre">			</span>if (cch &gt; 4096) cch = 4096;</div><div><span style="white-space:pre">			</span>dwReceivedTotal += cch;</div><div><span style="white-space:pre">			</span>// display number of received bytes</div><div><span style="white-space:pre">			</span>if (haveContentLength)</div><div><span style="white-space:pre">			</span>{</div><div><span style="white-space:pre">				</span>wprintf(L"received %d of %d (%d%%)%c", dwReceivedTotal, dwContentLength,&nbsp;</div><div><span style="white-space:pre">					</span>dwReceivedTotal*100/dwContentLength, 13);</div><div><span style="white-space:pre">			</span>}</div><div><span style="white-space:pre">			</span>else {</div><div><span style="white-space:pre">				</span>wprintf(L"received %d (unknown length)%c", dwReceivedTotal, 10);</div><div><span style="white-space:pre">			</span>}</div><div><span style="white-space:pre">			</span>WinHttpReadData(hRequest, p, cch, &amp;cch);</div><div><span style="white-space:pre">			</span>// write into stream</div><div><span style="white-space:pre">			</span>hr = stream-&gt;Write(p, cch, NULL);</div><div><span style="white-space:pre">			</span>if (hr)</div><div><span style="white-space:pre">			</span>{</div><div><span style="white-space:pre">				</span>wprintf(L"failed to write data to stream (0x%.8X)\n", hr);</div><div><span style="white-space:pre">			</span>}</div><div><span style="white-space:pre">		</span>}</div><div><span style="white-space:pre">		</span>delete [] p;</div><div><span style="white-space:pre">		</span>wprintf(L"\n\nreceived all data.\n");</div><div><span style="white-space:pre">		</span>// terminate the sream with a NULL</div><div><span style="white-space:pre">		</span>p = NULL;</div><div><span style="white-space:pre">		</span>stream-&gt;Write(&amp;p, 1, NULL);</div><div><span style="white-space:pre">		</span>// get pointer to stream bytes</div><div><span style="white-space:pre">		</span>wprintf(L"getting HGLOBAL from stream...\n");</div><div><span style="white-space:pre">		</span>HGLOBAL hgl;</div><div><span style="white-space:pre">		</span>hr = GetHGlobalFromStream(stream, &amp;hgl);</div><div><span style="white-space:pre">		</span>if (hr) {</div><div><span style="white-space:pre">			</span>wprintf(L"GetHGlobalFromStream failed (0x%.8X)\n", hr);</div><div><span style="white-space:pre">			</span>break;</div><div><span style="white-space:pre">		</span>}</div><div><span style="white-space:pre">		</span>wprintf(L"locking memory...\n");</div><div><span style="white-space:pre">		</span>p = (char*)GlobalLock(hgl);</div><div><span style="white-space:pre">		</span>if (!p)</div><div><span style="white-space:pre">		</span>{</div><div><span style="white-space:pre">			</span>wprintf(L"GlobalLock failed (0x%.8X)\n", GetLastError());</div><div><span style="white-space:pre">			</span>break;</div><div><span style="white-space:pre">		</span>}</div><div><span style="white-space:pre">		</span>wprintf(L"displaying received data...\n");</div><div><span style="white-space:pre">		</span>// terminate the string at 1024 bytes (MessageBox lag)</div><div><span style="white-space:pre">		</span>//if (dwReceivedTotal &gt; 1024) dwReceivedTotal = 1024;</div><div><span style="white-space:pre">		</span>//*p[dwReceivedTotal] = 0;</div><div><span style="white-space:pre">		</span>MessageBoxA(0, p, "", 0);</div><div><span style="white-space:pre">		</span>GlobalUnlock(hgl);</div><div><span style="white-space:pre">		</span>break;</div><div><span style="white-space:pre">	</span>}</div><div><span style="white-space:pre">	</span>// delete stream and close handles</div><div><span style="white-space:pre">	</span>if (stream) stream-&gt;Release();</div><div><span style="white-space:pre">	</span>if (hRequest) WinHttpCloseHandle(hRequest);</div><div><span style="white-space:pre">	</span>if (hConnect) WinHttpCloseHandle(hConnect);</div><div><span style="white-space:pre">	</span>if (hOpen) WinHttpCloseHandle(hOpen);</div><div><span style="white-space:pre">	</span>system("pause");</div><div>}</div><div></div><img src ="http://www.cppblog.com/zhupf/aggbug/201459.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zhupf/" target="_blank">zhupf</a> 2013-07-02 14:44 <a href="http://www.cppblog.com/zhupf/archive/2013/07/02/201459.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>