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

CodePudding user response:

reference 1st floor schlafenhamster response:
last time write content must be clear,
The rectangular area must Invalidate, let desktop redraw!


In theory, I know, in fact, don't know redraw process, can you give some code?
I added
the front in the function
 
# redraw window
HWND=win32gui. GetDesktopWindow ()
Win32gui. RedrawWindow (HWND (1000300140 0700), 0, win32con. RDW_UPDATENOW)
Print (" RedrawWindow getlasterror ", win32api getlasterror ())

HwndDC=win32gui. GetWindowDC (HWND)

No effect!!!!!!!!!!

CodePudding user response:

refer to the second floor zgl7903 response:
fill background redraw font
Can't erase the color piece is refers to the cursor? Try HideCaret SetCaretPos ShowCaret again


ExtTextOut drawing on the screen font always with background color!

CodePudding user response:



Rectangle is hollow, but always the text background color, but said the background color is not accurate, if SetBkMode set is not transparent, set O at the beginning of the parameter, the background color is gray, transparent is black,

Ps:
I added in this function for DC and screenshot of the code, the program execution 2 times, third time writing background transparent, so just text overlap,,, mad me,,,,

CodePudding user response:

The instructions are on the MSDN documentation

The ExtTextOut function draws a character string by using The currently selected font, background color, and The text color.

So you have to set the font and background colors
 
In case the WM_PAINT:
{
HDC=BeginPaint (hWnd, & amp; Ps);
Int nSaveDC=SaveDC (HDC);
The RECT rt.
GetClientRect (hWnd, & amp; Rt);
//DrawText (HDC, szHello, strlen (szHello), & amp; Rt, DT_CENTER);
COLORREF txColor=SetTextColor (HDC, RGB (255, 0, 0));
COLORREF bkColor=SetBkColor (HDC, RGB (255, 255, 255));
ExtTextOut (HDC, 10, 10, 0, NULL, szHello, _tcslen (szHello), NULL);
SetBkColor (HDC, bkColor);
SetTextColor (HDC, txColor);
RestoreDC (HDC, nSaveDC);
EndPaint (hWnd, & amp; Ps);
break;
}



CodePudding user response:

refer to 6th floor zgl7903 response:
instructions are on the MSDN documentation

The ExtTextOut function draws a character string by using The currently selected font, background color, and The text color.

So you have to set the font and background colors

First, I use the GetDesktopWindow can obtain the GetWindowDC drawing, BeginPaint - EndPaint can't draw, I looked at the BeginPaint & amp; Ps return value, there is no client area DesktopWindow,
Second, I have set up bkmode, did not move bkcolor, nature has a default background color, in fact I set bkmode for transparent

I understand the meaning of your code is:
With HWND applications for clients to DC, and then save the DCS, then the textout words, finally cover the cut with a front DC,
Wouldn't it be painted directly covered? Is no picture?

CodePudding user response:

 
Void CDesktopRectRefreshDlg: : ReFreshDesktopRect (the RECT * PRC, HRGN RGN and BOOL bDraw)
{
HWND hWndDesk=: : GetDesktopWindow ();
HDC HDC=: : GetWindowDC (hWndDesk);
If (bDraw)
{//red pen
HPEN pen=CreatePen (PS_SOLID, 1, RGB (255, 0, 0));
HPEN hOldPen=(HPEN) : : SelectObject (hDC, pen);
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related