Home > Software engineering > Writing a desktop frame to write words using winapi program, in addition to the problem. Don't
Writing a desktop frame to write words using winapi program, in addition to the problem. Don't
Time:09-23
Recently wrote a screenshot of the program, but there is no screen display, just thinking about what mark a box on the screen, for this reason, has written the following code, Yet, but we have a problem,,,,
Def checkarea (argTitle, argTL argBR, argPostion="T") : "' Annotation parameters area on the screen, text + rectangle ArgPostion: T, B, R, L, I corresponding to the top, bottom, right, left, in case-insensitive and other default values for T "' HWND=None HwndDC=win32gui. GetWindowDC (HWND) # text Tw, th=win32gui. GetTextExtentPoint32 (hwndDC argTitle) # capture text width TPS=argPostion. Upper () TXTPS=(0, 0) # # computing text vertex coordinates If the TPS=="L" : TXTPS=(argTL [0] - tw - 2, argTL [1]) Elif TPS=="B" : ArgBR TXTPS=(argTL [0], [1] + 2) Elif TPS=="R" : TXTPS=(argBR [0] + 2, argTL [1]) Elif TPS=="I" is: TXTPS=the tuple (x + 2 for x in argTL) The else: ArgTL TXTPS=(argTL [0], [1] - th - 2) # # text background transparent Win32gui. SetBkMode (hwndDC, win32con. TRANSPARENT) PreClr=win32gui. SetTextColor (hwndDC, win32api. RGB (255,0,255)) Win32gui. ExtTextOut (hwndDC, * TXTPS, 0, None, argTitle) Win32gui. SetTextColor (hwndDC preClr) # rectangular box part HPen=win32gui. CreatePen (win32con. PS_SOLID, 1, win32api RGB (255,0,255)) Win32gui. SelectObject (hwndDC, hPen) HBrush=win32gui. GetStockObject (win32con. NULL_BRUSH) PreBrush=win32gui. SelectObject (hwndDC, hBrush) ArgTL win32gui. A Rectangle (hwndDC, * and * argBR) Win32gui. SelectObject (hwndDC preBrush) # recycling Win32gui. DeleteObject (hPen) Win32gui. DeleteObject (hBrush) Win32gui. DeleteObject (preBrush) Win32gui. ReleaseDC (HWND, hwndDC) Return True
Phenomenon 1: because the pywin32 no textout function, can only use ExtTextOut output, use ExtTextOut output text, there is always a color, not transparent, No matter why SetBkMode mode, transparent mode, show black background, the transparent mode, the display background gray, Phenomenon 2: in theory, the function has been releaseDC, but the second time to write, will appear the text overlap problem, although the picture on the screen box, wrote the words, move a window was set off a little, didn't, but continue to run the function, the text will overlap in the last write words, only after the Win + L lock, can eliminate,
Question: 1 how to make me ExtTextOut text on the screen background transparent? 2 how to refresh ExtTextOut off last words?
CodePudding user response:
Last time to write the content must be removed, The rectangular area must Invalidate, let desktop redraw!
CodePudding user response:
Fill the background redraw font Can't erase the color piece is refers to the cursor? Try HideCaret SetCaretPos ShowCaret again