for everything else, let the default window message handler do its thing return DefWindowProc(wnd,msg,w,l) we are also interested in the WM_DESTROY message, as that lets us know when to close the window case WM_DESTROY: HDC screen = BeginPaint(wnd,&ps) // Get the screen DCĭrawImage(screen) // draw our image to our screen DC we are interested in WM_PAINT, as that is how we draw case WM_PAINT: what kind of message is this? switch(msg) LRESULT CALLBACK wndProc(HWND wnd,UINT msg,WPARAM w,LPARAM l) SRCCOPY // tell it to do a pixel-by-pixel copy ImageDC, // the DC to get the rect from (our image DC)Ġ,0, // take it from position 0,0 in the image DC ScreenSize_X, // width of the rect to draw Screen, // tell it we want to draw to the screenĠ,0, // as position 0,0 (upper-left corner) SelectObject(imageDC,imageBmpOld) // put the old bmp back in our DCĭeleteObject(imageBmp) // delete the bmp we loadedĭeleteDC(imageDC) // delete the DC we created ImageBmpOld = (HBITMAP)SelectObject(imageDC,imageBmp) // put the loaded image into our DC LR_DEFAULTSIZE | LR_LOADFROMFILE // use the default bitmap size (whatever the file is), and load it from a file NULL, // not loading from a module, so this is NULLĠ,0, // don't need to specify width/height ImageBmp = (HBITMAP)LoadImageA( // load the bitmap from a file ImageDC = CreateCompatibleDC(NULL) // create an offscreen DC HBITMAP imageBmpOld // the DC's old bitmap (for cleanup) const int screenSize_X = 640 HBITMAP imageBmp // the actual bitmap which contains the image (will be put in the DC) I did not intentionally make the WinAPI version confusing - WinAPI just really is that confusing: I tried to make both of these as simple as possible. Plus I don't even really know how to do it. it will be EVEN SLOWER, even clunkier, and much, much more confusing. but you are limited in the number of colors it will display. There are ways to display the image directly to the console. The image is a singular static image of a fixed size that takes up the whole screen You want to create a new window that just houses the image and does nothing else You'll see why when you look at the code belowĮach of these approaches assume the following: Working directly with WinAPI for a game is a horrendous choice. I know you said you didn't want to download any libs. But does require an additional download). is much much faster, and is much, much easier to write, use and understand. I've created 2 working examples for you below.ġ) Using WinAPI only (only works on Windows, is slow, is clunky, and is much more confusing, but does not require any additional downloads)Ģ) Using SFML (crossplatform - works on Windows, *nix, Mac. If you would have just started with a real window from day 1, you would have had a much easier time. It's especially difficult to add images as an afterthought. Usually it's much easier to use a proper window. and any attempt to use the console to make them usually twists the console into a mockery of its primary function. The console really just isn't designed with them in mind. another newbie that got sucked into the foreboding vortex of console games.Ĭonsole games are difficult to make.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |