Win32 assembly tutorial eight graphical interface operation

zhaozj2021-02-08  252

-------------------------------------------------- ------------------------------ About GDI and bitmap GDI, the graphics device interface is one of the most important parts of Windows, It is handled by the API of the GDI32.DLL library. One of the main purposes of GDI is to support graphical programming with equipment. For graphics programming under DOS, many people may "have a sense of heart" because there are too many kinds in the PC. The display card, and almost every display card is different, even if there is VESA programming, we still can't open the specific hardware, Windows GDI makes our programming more simpler, due to GDI It is the largest part of Windows, not a few words can be clear, this section is to talk about the basic processing steps of the GDI under Windows, and simple bitmap processing does not involve DirectX programming. I only hope to be inspired by friends. Windows does not allow programmers to access the display hardware, all of which handles the screen is processed through the environment device (DC), each window on the screen corresponds to a DC, you can imagine the video buffer of this window District, your results of the DC will be reflected on the screen. You can also build DCs yourself in the window of the window. This is equivalent to establishing a buffer in a memory, and you save the operation of this DC in memory . You can also copy data between different DCs in different DCs. For example, you can create data in the memory DC, then copy to the DC of the window, is equivalent to completing the screen. With DC, establish a cancellation-related API has the following: getDC (hwnd) - acquiring a window of DC, API returns the corresponding DC handle ReleaseDC (HWnd, HDC) - Release DC Handle CreateCompatible CreateCompableDc with Getdc (HDC - Create a memory DC, various parameters, attribute references from a known DC handle, and delete 4 APIs above the DC established with CreateComparableDC, must be paired, with getDC The DC must be released with ReleaseDC, and the DC established with CreateCompatibleDC must be deleted with deletedc and cannot be confused. Scope of DC: Window DC obtained with GETDC must be released as soon as possible, you should not save the DC handle between Windows, and the DC created with CreateCompaTibleDC can save long-term, for example, if you are in WM_Paint and WM_SIZE messages To operate the window's DC, you can't get Getdc in WM_INIT, then save your handle, and finally in the WM_Close message, it must be started at the place where WM_Paint and WM_SIZE will start, and it is ReleaseDC at the end of the message. Conversely CreateCompatibleDC, the opposite, you can build when WM_INIT, delete when WM_Close. If you want to draw a bit drawing into the DC, you only need to use Invoke SelectObject, HDC, hbitmap, is it simple? However, the graphic operation is not placing the bitmap in the screen, and it is also involved in the operation, such as the edge of the foreground bitmap removes the background bitmap.

Windows GDI provides copy APIs between the following DCs, including copy mode: Bitblt HDCDest, XDest, YDEST, Width, Height, HDCSource, XSRC, YSRC, DWROP This API puts the XSRC, YSRC coordinate of HDCSource Copy to HDCDest's XDest, YDEST, copy size is Width, Height. PATBLT HDC, X, Y, Width, Height, DWROP are Object, HDCDest, XDest, YDEST, Width, Height, HDCSource, XSRC, YSRC, Widthsrc, Heightsrc, DWROP, such as predefined brushes, etc. Size, you can notice that it is more than two parameters compared to Bitblt, Widthsrc and HeightSRC, other are the same. The DWROP parameters in the above API are the most critical. Its values ​​are SRCCopy, SrcPaint, Srcand, Dstinvert, etc., indicating that the source DC copy to the calculation method of the pixel after the target DC, SRCCopy indicates that the source DC coverage target DC, SrcPaint is executed OR operation, Srcand is executing the AND operation, Dstinvert is inversely, for example, if a certain point in the source DC is black, the point of the target DC corresponds to red, then use Srccopy, the point of the target DC becomes black, with SrcPaint It is still red because black (000000) OR red (0000FF) = red (0000FF). The steps corresponding to the screen or window of the screen or window are as follows. The DC to obtain the target window with GETDC Use createCompatibleDC to create a DC in memory as a buffer to fill the memory DC or other ways to operate, one sentence, first put the things you want to display, use Bitblt to put memory DC Copy to the window DC and complete the screen refresh. The example of this section is a screen magnifying glass that enlarges the screen content of the mouse to the screen to zoom in to your own window.

Source program - assembly source file; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Yunbin, Bigluo@telekbird.com.cn; Website: http://asm.yeah.net; Luoyunbin's Win32 ASM Page (Luo Yunbin's programming park); >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Folder - July 1, 2000; >>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> STDCallOption Casemap: None; Case Sensitive >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>; include data; >>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>

include windows.incinclude user32.incinclude kernel32.incinclude comctl32.incinclude comdlg32.incinclude gdi32.incincludelib user32.libincludelib kernel32.libincludelib comctl32.libincludelib comdlg32.libincludelib gdi32.lib; >>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>; EQU data; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>> DLG_MAIN EQU 1000ID_bitmap EQU 1001; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Data segment; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>> Data? hwinpic dd? HDCMEM DD? HBitmap DD? HWINDESKTOP DD? HINSTANCE DD? SZBUFFER DB 256 DUP (?); >>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>> - PROCDLGMAIN Proto: DWORD,: DWORD,: DWORD,: DWORD.DATA; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Code segment; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>> FoldenClude win.asm; ********************** ****************************************************** _ ProCDLGMAIN Proc Uses EBX EDI esi, / hWnd: DWORD, wMsg: DWORD, wParam: DWORD, lParam: DWORDlocal @stPoint: POINTlocal @ hDcDesktop, @ hDcPicmov eax, wMsg.if eax == WM_CLOSEinvoke EndDialog, hWnd, NULLinvoke KillTimer, hWnd, 1invoke DeleteDC, hDcMeminvoke DeleteObject Hbitmap; *********************************************************************************************************************************************************************************************************************************** ********************. elseif eax == WM_INITDIALOGinvoke GetDlgItem, hWnd, ID_BITMAPmov hWinPic, eaxinvoke GetDesktopWindowmov hWinDesktop, eaxinvoke SetWindowPos, hWnd, HWND_TOPMOST, 0,0,0, 0, / SWP_NOMOVE or SWP_NOSIZE; **************************************************** *********************** Invoke getdc, hwindesktopmov @ hdcdesktop, EaxInvoke CreateCompAfeeDC , @ hdcdesktopmov hdcmem, EaxInvoke CreateCompAtibleBitmap, @

HDCDESKTOP, 80, 80MOV HBITMAP, EAXINVOKE SELECTOBJECT, HDCMEM, HBITMAPINVOKE ReleaseDC, HWINDESKTOP, @ HDCDesktopinvoke settimer, hwnd, 1,100, null; ******************************************** ***************************************************. Elseif Eax == WM_TIMERINVOKE Getcursorpos, addr @stpointsub @ stpoint.x, 20sub @ stpoint.y, 20.if @ stpoint.x <0mov @ stpoint.x, 0mov @ stpoint.y <0mov @ stpoint.y, 0.EndifInvoke getdc , hWinDesktopmov @ hDcDesktop, eaxinvoke GetDC, hWinPicmov @ hDcPic, eaxinvoke PatBlt, hDcMem, 0,0,80,80, BLACKNESSinvoke StretchBlt, hDcMem, 0,0,80,80, / @ hDcDesktop, @ stPoint.x, @ stPoint. Y, 40, 40, srcopyinvoke bitblt, @ hdcpic, 0,0,80,80, / hdcmem, 0,0, srccopyinvoke releasedc, hwindesktop, @ hdcdesktopinvoke rec, hwinpic, @ hdcpic.else; ******* *********************************************************** **********; Note: After the message processing of the dialog box, you want to return True, to the unprocessed message; return false; ************* *********************************************************** *** MOV EAX, FALSERET.ENDIF MOV EAX, TRUERET_PROCDLGMAIN ENDP; ********************************************* *********************** ********* start: invoke GetModuleHandle, NULLmov hInstance, eaxinvoke DialogBoxParam, hInstance, DLG_MAIN, NULL, offset _ProcDlgMain, analysis and points 0invoke ExitProcess, NULLend start the program in the initialization process, we take with GetDc The DC of the desktop screen, then create a memory DC to make a buffer with CreateCompatibleDC, create a bitmap and use SelectObject to set the HDCMEM to this bitmap is to be 80x80.

转载请注明原文地址:https://www.9cbs.com/read-1429.html

New Post(0)