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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? bitmaps.html

?? forgers-win32-tutorial
?? 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>

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产日韩精品一区二区浪潮av| 成人国产精品免费| 久草精品在线观看| 国产精品伊人色| 91视频91自| 51久久夜色精品国产麻豆| 欧美成人r级一区二区三区| 久久久蜜桃精品| 最新国产の精品合集bt伙计| 亚洲午夜电影网| 免费人成精品欧美精品 | 亚洲午夜av在线| 免费在线观看成人| 理论电影国产精品| 成人天堂资源www在线| 91福利区一区二区三区| 日韩欧美亚洲国产精品字幕久久久| 国产偷国产偷亚洲高清人白洁 | 亚洲精品日韩一| 日韩电影免费在线看| 国产乱码精品一区二区三区av| 成人免费不卡视频| 欧美精品tushy高清| 久久免费视频色| 亚洲综合色网站| 久久99国产精品免费网站| www.久久久久久久久| 欧美精品高清视频| 久久先锋影音av鲁色资源网| 亚洲欧美电影院| 秋霞电影一区二区| 99精品久久99久久久久| 91精品国产高清一区二区三区| 欧美国产1区2区| 偷拍日韩校园综合在线| 国产成人无遮挡在线视频| 在线观看国产91| 久久久国产精品不卡| 亚洲自拍偷拍九九九| 国产一区激情在线| 欧美日韩国产免费一区二区| 国产精品久线观看视频| 亚洲午夜羞羞片| 成人午夜av电影| 欧美成人a视频| 亚洲福利国产精品| av电影天堂一区二区在线| 日韩三区在线观看| 亚洲男人的天堂av| 国产成人免费在线视频| 91精品国产色综合久久不卡蜜臀| 国产精品国产三级国产| 久久99蜜桃精品| 欧美日韩黄视频| 综合激情成人伊人| 国产成人av自拍| 精品免费视频一区二区| 亚洲午夜视频在线| 91丨porny丨首页| 国产午夜精品久久久久久久| 青青草原综合久久大伊人精品 | 国产一区二区电影| 欧美一区二区免费| 亚洲va在线va天堂| 欧洲av在线精品| 成人免费在线观看入口| 国产精品一区二区久久不卡| 欧美一级搡bbbb搡bbbb| 亚洲国产精品视频| 91在线无精精品入口| 中文字幕免费一区| 国产很黄免费观看久久| 2023国产一二三区日本精品2022| 老司机精品视频在线| 欧美精品色综合| 亚洲第四色夜色| 精品视频1区2区3区| 亚洲人快播电影网| 99riav久久精品riav| 国产精品的网站| 成人精品在线视频观看| 日韩欧美国产wwwww| 蜜臀av性久久久久蜜臀aⅴ四虎 | 欧美日韩性生活| 亚洲成人免费电影| 欧美日韩国产一级二级| 亚洲最新在线观看| 欧美日韩一区二区三区不卡| 亚洲高清不卡在线观看| 欧美高清视频在线高清观看mv色露露十八| 一区二区三区在线免费视频| 色欲综合视频天天天| 亚洲欧美日韩人成在线播放| 92国产精品观看| 樱桃国产成人精品视频| 欧美丝袜第三区| 亚洲成av人影院| 欧美一区二区三区人| 精东粉嫩av免费一区二区三区 | 加勒比av一区二区| 精品福利一二区| 国产一区不卡精品| 欧美激情一区二区三区蜜桃视频| 丁香亚洲综合激情啪啪综合| 国产精品天天看| 日本道在线观看一区二区| 亚洲激情图片小说视频| 精品视频一区三区九区| 蜜桃一区二区三区四区| 久久精品视频一区| 成人黄色国产精品网站大全在线免费观看| 国产精品麻豆一区二区| 色婷婷亚洲一区二区三区| 亚洲一卡二卡三卡四卡五卡| 在线不卡免费欧美| 国产一区二区在线视频| 国产精品电影一区二区三区| 欧美系列日韩一区| 日韩精品一级二级| 精品国产乱码久久久久久老虎| 国产91精品一区二区麻豆亚洲| 国产精品福利一区| 欧美图片一区二区三区| 精品影视av免费| 国产精品美女一区二区在线观看| 在线观看av一区| 久久电影网站中文字幕| 国产精品成人一区二区三区夜夜夜| 色94色欧美sute亚洲线路二 | 亚洲影院免费观看| 欧美一区二区免费视频| 成人黄色777网| 亚洲国产视频在线| 久久久久国产精品麻豆ai换脸| 99精品视频免费在线观看| 日韩av中文在线观看| 国产精品剧情在线亚洲| 欧美日韩在线观看一区二区| 国产精品一级黄| 亚洲成精国产精品女| 26uuu另类欧美| 在线欧美小视频| 国产福利一区二区三区视频在线 | 欧美日韩亚洲综合在线 欧美亚洲特黄一级| 欧美aa在线视频| 亚洲男同1069视频| 久久综合九色综合97_久久久| 91美女蜜桃在线| 久久99蜜桃精品| 一区二区三区四区激情| 久久久久久一级片| 欧美色成人综合| 成人动漫av在线| 久久99精品国产91久久来源 | 欧美性大战久久久久久久蜜臀| 国产精品99久久久久久宅男| 首页国产欧美久久| 亚洲欧美在线高清| 欧美日本韩国一区| 成人av网站大全| 捆绑紧缚一区二区三区视频 | 激情综合网激情| 亚洲国产一区在线观看| 国产精品理伦片| 国产无人区一区二区三区| 欧美一区二区三区影视| 色88888久久久久久影院野外| 久久精品噜噜噜成人av农村| 亚洲综合在线电影| 亚洲日本欧美天堂| 国产精品网站导航| 国产亚洲欧洲一区高清在线观看| 91精品视频网| 欧美亚洲综合久久| 色综合久久久久综合99| 国产成人精品亚洲午夜麻豆| 精品一区二区综合| 免费不卡在线观看| 亚洲mv在线观看| 亚洲亚洲精品在线观看| 一区二区三区精品视频| 自拍偷拍国产精品| 国产精品久久福利| 国产欧美1区2区3区| 国产午夜一区二区三区| 久久午夜国产精品| 精品国产乱码久久久久久久| 精品美女被调教视频大全网站| 欧美日韩情趣电影| 欧美少妇bbb| 欧美亚洲一区二区三区四区| 日本韩国一区二区三区视频| 91麻豆123| 色综合激情五月| 日本高清不卡aⅴ免费网站| 国产成人精品影视| 成人黄色电影在线| 91香蕉视频黄| 色猫猫国产区一区二在线视频| 成人黄色综合网站|