亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? bitmaps.html

?? This tutorial attempts to get you started developing with the Win32 API as quickly and clearly as po
?? HTML
字號:
<HTML><LINK HREF="style.css" REL="STYLESHEET" TYPE="text/css"><HEAD><TITLE>Bitmaps, Device Contexts and BitBlt</TITLE></HEAD><BODY><FONT SIZE="-1">[ <A HREF="./index.html">contents</A>| <A HREF="http://www.winprog.org/">#winprog</A>]</FONT><HR><H1>Bitmaps, Device Contexts and BitBlt</H1><P>Example: bmp_one</P><IMG SRC="images/bmp_one.gif" ALT="[images/bmp_one.gif]" ALIGN="right"><H2>GDI</H2>The really great thing about MS Windows is that unlike DOS, you don't need to know anythingabout what video hardware you are using to display graphics.  Instead, windows providesan API called the Graphics Device Interface, or GDI.  The GDI uses a set of generic graphics objects that can be used to draw to the screen, to memory, or even to printers.<H3>Device Contexts</H3>The GDI revolves around an object called the Device Context (DC), represented by the data type <CODE>HDC</CODE> (Handle to Device Context).  An HDC is basically a handle to something you candraw on;  it can represent the entire screen, an entire window, the client area of a window,a bitmap stored in memory, or a printer.  The nice part is that you don't even need to know which one itrefers to, you can use it basically the same way, which is especially handy for writing customdrawing functions which you can then use on any of these devices without changing it for each one.<P>An HDC like most GDI objects is opaque, meaning thatyou can't access it's data directly... but you can pass it to various GDI functions that willoperate on it, either to draw something, get information about it, or change the object insome way.<P>For example, if you wanted to draw on a window, first you would retreive an <CODE>HDC</CODE> representing the window with <CODE>GetDC()</CODE>, then you could use any of the GDI functionsthat take an <CODE>HDC</CODE> like <CODE>BitBlt()</CODE> for drawing images, <CODE>TextOut()</CODE> for drawing text, <CODE>LineTo()</CODE> for lines and so on.<H3>Bitmaps</H3>Bitmaps can be loaded much like icons in earlier examples, there is <CODE>LoadBitmap()</CODE> for the most basic functionality of simply loading a bitmap resource, and <CODE>LoadImage()</CODE> can be used to load bitmaps from a <CODE>*.bmp</CODE> file just as it can for icons.<P>One of the quirks of GDI is that you can't draw to bitmap objects (<CODE>HBITMAP</CODE> type) directly.Remember that drawing operations are abstracted by Device Contexts, so in order to use these drawing functions on a bitmap, you need to create a Memory DC, and then select the <CODE>HBITMAP</CODE> intoit with <CODE>SelectObject()</CODE>.  The effect is that the "device" that the <CODE>HDC</CODE> refers to is the bitmap in memory, and when you operateon the <CODE>HDC</CODE>, the resulting graphic operations are applied to the bitmap.  As I mentioned, this is actuallya very conveiniant way of doing things, as you can write code that draws to an <CODE>HDC</CODE> and you can use iton a Window DC or a Memory DC without any checks or changes.<P>You do have the option of manipulating the bitmap data in memory yourself.  You cando this with Device Independant Bitmaps (DIB), and you can even combine GDI and manual operations on the DIB.However for the time being, this is beyond the scope of the basic tutorial and for now we're just cover thesimpler GDI operations on their own.<H3>GDI Leaks</H3><P>Once you're finished with an <CODE>HDC</CODE>, it's very important to release it (just how you do that dependson how you got it, which we'll talk about in a bit).  GDI objects are limited in number.  In versions of windows prior to Windows 95, they were not only incredably limited but also shared systemwide, so that if one program used up too many, none of the rest would be able to draw anything!Fortunately this isn't the case any longer, and you could get away with using up quite a lot ofresources in Windows 2000 or XP before anything too bad happened... but it's easy to forget tofree GDI objects and they can quickly run your program out of GDI resources under Windows 9x.Theorehtically you shouldn't be able to drain the system of GDI resources in NT systems (NT/2K/XP)but it still happens in extreme cases, or if you hit the right bug on the nose.<P>If your program runs fine for a few minutes and then starts drawing strangely or not at all, it's a good sign that you're leaking GDI resources.  HDCs aren't the only GDI objects you need to be carefulabout releasing, but generally it's ok to keep things like bitmaps and fonts around for the entirelifetime of your program, since it's much more efficiant than reloading them each time you need them.<P>Also, an HDC can only contain one of each type of object (bitmap, font, pen...) at a time, and when youselect a new one in it will return the last one.  It's very important that you deal with this objectproperly.  If you ignore it completely, it will be lost and they will pile up in memory causing GDIleaks.  When an HDC is created, it's also created with some default objects selectedinto it... it's a good idea to store these when they are returned to you, and then when you are completeddrawing with the <CODE>HDC</CODE> select them back into it.  This will not only remove any of your own objects from the <CODE>HDC</CODE> (which is a good thing) but it will also cause the default objects to be properlydisposed of when you release or destroy the <CODE>HDC</CODE> (a VERY good thing).<P><B>Important Update:</B> Not all objects have defaults selected into <CODE>HDC</CODE>s, and you can refer to MSDN for the few that don't.  Becauseof this I was previously uncertain as to wether <CODE>HBITMAP</CODE>s were one of them, since there doesn't seem to be any definitive documentation on it, and examples (even those by Microsoft) often ignored the default bitmap.Since the writing of the original tutorial several years ago, it was confirmed to me that there was in facta default bitmap that needs releasing.  This information is courtesy of Shaun Ivory, a software engineer forMS and a friend of mine from #winprog.  <P>Apparently there was a bug in a screensaver written at MS, and itturns out it was because the default bitmap wasn't getting replaced or destroyed, and it eventually ran outof GDI resources.  Be warned!  It's an easy mistake to make.<H2>Displaying Bitmaps</H2>Ok, down to business.  The simplest drawing operations on a window occure by handling <CODE>WM_PAINT</CODE>.When your window is first displayed, restored from being minimised, or uncovered from having another windowon top of it, Windows sends the <CODE>WM_PAINT</CODE> message to the window to let it know that it needsto redraw it's contents.  When you draw something on the screen it is NOT permanent, it's only there untillsomething else draws over it, and at that point you need to draw it again when the time comes.<PRE CLASS="SNIP">HBITMAP g_hbmBall = NULL;</PRE><PRE CLASS="SNIP">    case WM_CREATE:        g_hbmBall = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BALL));        if(g_hbmBall == NULL)            MessageBox(hwnd, "Could not load IDB_BALL!", "Error", MB_OK | MB_ICONEXCLAMATION);    break;</PRE>The first step is of course loading the bitmap, this is quite simple with a bitmap resource, there areno significant differences from loading other resource types.  Then we can get down to drawing...<PRE CLASS="SNIP">    case WM_PAINT:    {        BITMAP bm;        PAINTSTRUCT ps;        HDC hdc = BeginPaint(hwnd, &ps);        HDC hdcMem = CreateCompatibleDC(hdc);        HBITMAP hbmOld = SelectObject(hdcMem, g_hbmBall);        GetObject(g_hbmBall, sizeof(bm), &bm);        BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);        SelectObject(hdcMem, hbmOld);        DeleteDC(hdcMem);        EndPaint(hwnd, &ps);    }    break;</PRE><H3>Getting the Window DC</H3><P>To start off we declare a couple of variables we need.  Notice that the first one is a <CODE>BITMAP</CODE>, not an <CODE>HBITMAP</CODE>.  <CODE>BITMAP</CODE> is a struct that holds information about an <CODE>HBITMAP</CODE>which is the actual GDI object.  We need a way to get the height and width of the <CODE>HBITMAP</CODE> so weuse <CODE>GetObject()</CODE> which contrary to it's name doesn't really get an object, but rather informationabout an existing one.  "GetObjectInfo" would have been a more appropriate label.  <CODE>GetObject()</CODE> worksfor various GDI object types which it can distinguish based on the value of the second parameter, the size of thestructure.<P>The <CODE>PAINTSTRUCT</CODE> is a structure that contains information about the window being painted and what exactly isgoing on with the paint message.  For most simple tasks, you can simply ignore the information it contains, but it'srequired for the call to <CODE>BeginPaint()</CODE>.  <CODE>BeginPaint()</CODE> as it's name suggests is designedspecifically for handling the <CODE>WM_PAINT</CODE> message.  When not handling a <CODE>WM_PAINT</CODE> message you would use <CODE>GetDC()</CODE> which we will see in the timer animation examples in a while... but in <CODE>WM_PAINT</CODE>, it's importantto use <CODE>BeginPaint()</CODE> and <CODE>EndPaint()</CODE>.<P><CODE>BeginPaint()</CODE> returns us an <CODE>HDC</CODE> that represents the <CODE>HWND</CODE> that we pass to it, theone that <CODE>WM_PAINT</CODE> is being handled for.  Any drawing operation we perform on this <CODE>HDC</CODE> will immediately displayon the screen.<H3>Setting up a Memory DC for the Bitmap</H3><P>As I mention above, in order to draw on or with bitmaps, we need to create a DC in memory... the easiest way to do thathere is to <CODE>CreateCompatibleDC()</CODE> with the one we already have.  This gives us a Memory DC that iscompatible with the color depth and display properties of the <CODE>HDC</CODE> for the window.<P>Now we call <CODE>SelectObject()</CODE> to select the bitmap into the DC being careful to store the defaultbitmap so that we can replace it later on and not leak GDI objects.<H3>Drawing</H3><P>Once we've gotten the dimentions of the bitmap filled into the <CODE>BITMAP</CODE> struct, we can call <CODE>BitBlt()</CODE> to copy the image from our Memory DC to the Window DC, thus displaying on the screen.As always, you can look up each parameter in MSDN, but in short they are: The destination, the positionand size, the source and source position, and finally the Raster Operation (ROP code), which specifies how to do the copy.  In this case, we want a simple exact copy of the source made, no fancy stuff.<P><CODE>BitBlt()</CODE> is probably the all time happiest function in all of the Win32 API and is the staplediet of anyone learning to write games or other graphics applications in windows.  It was probably thefirst API that I memorised all the parameters to.<H3>Cleanup</H3><P>At this point the bitmap should be on the screen, and we need to clean up after ourselves.  The first thingto do is restore the Memory DC to the state it was when we got it, which means replacing our bitmap with thedefault one that we saved.  Next we can delete it altogether with <CODE>DeleteDC()</CODE>.<P>Finally we release the Window DC we got from <CODE>BeginPaint()</CODE> using <CODE>EndPaint()</CODE>.<P>Destroying an <CODE>HDC</CODE> is a little confusing sometimes because there are at least 3 ways to do itdepending on how you got it in the first place.  Here's a list of the common methods of gaining an HDC,and how to release it when you're done.<UL><LI>GetDC() - ReleaseDC()<LI>BeginPaint() - EndPaint()<LI>CreateCompatibleDC() - DeleteDC()</UL><P>And finally, at the termination of our program, we want to free any resources that we allocated.  Technicallyspeaking this isn't absolutely required, since modern Windows platforms are pretty good at freeing everythingwhen your program exists, but it's always a good idea to keep track of your own objects because if get lazyand don't delete them they have a habit of getting loose.  And no doubt, thereare still bugs in windows especially older versions that won't clean up all of your GDI objects if you don't do a thorough job.<PRE CLASS="SNIP">    case WM_DESTROY:        DeleteObject(g_hbmBall);        PostQuitMessage(0);    break;</PRE><HR><FONT SIZE="-1">Copyright &copy; 1998-2003, Brook Miles (<A HREF="mailto:forger(nospam)winprog.org">theForger</A>).  All rights reserved.</FONT><SCRIPT language="JavaScript"><!--   var re = /\(nospam\)/ig;   var str;   for(i = 0;i < document.links.length;i++)    {      str = "" + document.links(i).href;      if(str.search(re) != -1)         document.links(i).href = str.replace(re, "@");      str = "" + document.links(i).innerHTML;      if(str.search(re) != -1)         document.links(i).innerHTML = str.replace(re, "@");   }--></SCRIPT></BODY></HTML>

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久色视频免费观看| 天天操天天综合网| 午夜精品久久久| 国产福利一区二区三区视频 | 亚洲欧洲另类国产综合| 天天av天天翘天天综合网色鬼国产| 粉嫩蜜臀av国产精品网站| 欧美日韩精品欧美日韩精品一综合| 久久精品视频在线看| 午夜精品一区在线观看| 99久久伊人精品| 久久夜色精品国产噜噜av| 视频一区视频二区中文字幕| 91网站最新地址| 国产拍揄自揄精品视频麻豆| 美女被吸乳得到大胸91| 欧美唯美清纯偷拍| 国产精品超碰97尤物18| 国产高清成人在线| 26uuu久久天堂性欧美| 日本伊人色综合网| 欧美日本在线观看| 亚洲国产日韩一区二区| 色综合久久久久网| 中文字幕一区二区在线播放| 国产成人亚洲精品狼色在线 | 精品久久久久久久人人人人传媒| 亚洲免费观看高清| 91丨九色丨蝌蚪丨老版| 中文字幕电影一区| 国产精品538一区二区在线| 欧美va日韩va| 九一久久久久久| 日韩一级视频免费观看在线| 日本美女一区二区| 日韩一级成人av| 看片的网站亚洲| 精品对白一区国产伦| 激情图片小说一区| 精品国产乱码久久久久久夜甘婷婷 | 国产偷国产偷精品高清尤物| 国产一区高清在线| 久久亚洲一区二区三区明星换脸| 国精产品一区一区三区mba视频 | 日韩国产欧美视频| 欧美一级国产精品| 蓝色福利精品导航| 久久夜色精品国产噜噜av| 国产成人午夜视频| 国产精品久久久久永久免费观看 | 国产高清久久久| 亚洲欧洲色图综合| 欧美视频在线观看一区二区| 日韩精品国产欧美| 久久综合成人精品亚洲另类欧美| 风流少妇一区二区| 亚洲精品国产品国语在线app| 欧美三级日韩三级国产三级| 天堂成人国产精品一区| 久久欧美一区二区| 色诱视频网站一区| 日本不卡视频一二三区| 欧美极品少妇xxxxⅹ高跟鞋| 色久优优欧美色久优优| 日本va欧美va瓶| 国产精品伦一区二区三级视频| 色综合天天狠狠| 久久精品国产亚洲a| 亚洲丝袜另类动漫二区| 777久久久精品| 成人国产精品视频| 日本成人在线视频网站| 国产精品久久久久天堂| 欧美一区二区女人| 92精品国产成人观看免费| 日本麻豆一区二区三区视频| 国产精品国产成人国产三级| 91精品国产入口| 91香蕉视频污在线| 国产又粗又猛又爽又黄91精品| 亚洲另类在线一区| 久久尤物电影视频在线观看| 欧美艳星brazzers| eeuss国产一区二区三区| 色诱视频网站一区| 国产做a爰片久久毛片 | 亚洲欧洲精品一区二区三区| 日韩一区二区三区三四区视频在线观看| 国产电影精品久久禁18| 日韩成人午夜精品| 一区二区三区四区蜜桃| 国产调教视频一区| 日韩视频免费观看高清完整版| 色噜噜偷拍精品综合在线| 国产在线视频一区二区| 日韩国产一二三区| 亚洲一区在线看| 综合久久一区二区三区| 国产色产综合色产在线视频| 日韩精品专区在线| 91.com视频| 在线亚洲人成电影网站色www| 成人av网站在线观看| 国产在线不卡一卡二卡三卡四卡| 视频一区二区三区入口| 樱桃国产成人精品视频| 亚洲免费av高清| 中文字幕一区二区三区四区| 日本一区二区成人在线| 久久尤物电影视频在线观看| 日韩精品在线看片z| 欧美一级日韩免费不卡| 欧美日韩视频一区二区| 在线观看不卡一区| 日本韩国欧美一区二区三区| 99国产精品久久久| 色综合天天综合网国产成人综合天 | 成人av免费在线| 成人网页在线观看| av午夜一区麻豆| 91在线免费播放| 色婷婷综合激情| 欧美午夜宅男影院| 欧美日韩国产经典色站一区二区三区| 欧美怡红院视频| 欧美久久一二三四区| 日韩一区二区不卡| 精品国产制服丝袜高跟| 亚洲图片欧美综合| 午夜电影一区二区三区| 蜜桃视频在线观看一区| 免费在线成人网| 黄一区二区三区| 成人影视亚洲图片在线| 97久久精品人人爽人人爽蜜臀| 色婷婷综合久色| 6080国产精品一区二区| 精品成人一区二区三区四区| 久久在线免费观看| 综合激情成人伊人| 亚瑟在线精品视频| 久久99国产精品麻豆| 国产精品69毛片高清亚洲| 色综合天天综合给合国产| 91精品国产欧美日韩| 国产午夜精品一区二区| 亚洲天堂成人网| 日韩成人伦理电影在线观看| 国产精品综合一区二区三区| 一本久道久久综合中文字幕| 91精品欧美福利在线观看| 国产香蕉久久精品综合网| 一区二区三区美女视频| 麻豆极品一区二区三区| 成人激情免费视频| 欧美电影在线免费观看| 中文字幕精品综合| 日日骚欧美日韩| 国产成人免费在线视频| 欧美日韩另类国产亚洲欧美一级| 久久久美女艺术照精彩视频福利播放| 综合亚洲深深色噜噜狠狠网站| 日本特黄久久久高潮| 99热99精品| 精品国产伦一区二区三区观看方式 | 欧美伊人精品成人久久综合97| 日韩久久久精品| 亚洲激情综合网| 国产91精品精华液一区二区三区 | 国产不卡视频一区| 在线综合亚洲欧美在线视频| 国产精品初高中害羞小美女文| 蜜臀久久99精品久久久久久9| 91视频xxxx| 国产亚洲婷婷免费| 美女视频一区在线观看| 欧美专区日韩专区| 国产精品国产三级国产| 国产乱人伦偷精品视频不卡| 欧美高清精品3d| 一区二区三区四区视频精品免费| 成人在线综合网| 精品福利av导航| 日本sm残虐另类| 欧美天堂亚洲电影院在线播放| 亚洲天堂2014| 成人国产视频在线观看| 久久久99精品免费观看不卡| 蜜桃一区二区三区在线| 欧美久久久久久久久中文字幕| 亚洲另类中文字| 99在线视频精品| 国产精品黄色在线观看| 成人动漫中文字幕| 久久精品亚洲乱码伦伦中文| 国产乱子伦视频一区二区三区| 日韩精品一区二区三区中文不卡| 日韩av一区二区三区| 7777精品伊人久久久大香线蕉的| 亚洲高清一区二区三区|