[Make pictures] That directly in the picture
Author: enoloo
In the Forum, I often see how to tap characters directly on the picture. Today, I met, so I wrote a few small programs in the Black Wind.
The first program, the renderings are as follows:
The second program, the effect is as follows:
[Description]
The first program: I started thinking. Use a half-transparent text box (it's very uncomfortable, I can't take a picture of the transparent window. @ _ @). No SDK, use user32.dll's function setlayeredWindowAttributes. There are many introductions on the Internet. Main: 1, m_hdll = :: loadLibrary (_t ("user32.dll"));
2, :: setwindowlong (hwnd, gwl_exstyle, :: getwindowlong (hwnd, gwl_exstyle) | WS_EX_LAYERED);
3, if (m_hDll) {lpfnSetLayeredWindowAttributes pFn = NULL; pFn = (lpfnSetLayeredWindowAttributes) GetProcAddress (m_hDll, "SetLayeredWindowAttributes"); if (pFn) {bRetValue = pFn (hWnd, crKey, bAlpha, dwFlags);}}
4, if (m_hdll) :: freeElibrary (m_hdll); m_hdll = null;
5, there are several markers WS_EX_LAYERED, etc. need to be refine. #define WS_EX_LAYERED 0X00080000 # Define Lwa_colorKey 0x00000001 # Define Lwa_alpha 0x00000002
Write text on a form, or the old way, the CREATE is a text box (translucent) when the mouse is clicked, and when leaving, write the text in the text box to the location of the text box, then the DESTROY text box . After the window is translucent, although you can see something under the window, all things in the window are translucent, including insert, text, and more. Therefore, if the transparency is high, the writing written is very difficult to see, so if you want to implement a completely transparent input window and write something, it is difficult to control, because you can't find where the insert is. However, the translucent input box is also very interesting. I didn't write in this program.
Second program:
Function: 1. Click on a place in the form client area to generate an insert. 2, tap the keyboard can write characters directly on the form, including Chinese characters, letters. Because it is a test program, I only deal with the equation wide font. 3. Support Backspace to eliminate characters, and write back to business.
Because it is more in a hurry, there must be a lot of bugs, I have dealt with some. This is a throwing brick, and if you are interested, you can refer to and improve.
Program code (part): / *! * * Process the character message, and write the character on the form * / Note to process Chinese, support the backspace editing * / bug does not support HOME, END, LEFT, RIGHT, etc., need to improve * / bug character width requires improvement, one Some fonts are not supported * / author enoloo * / date 2004-6-14 / first Edition * / void cchildview :: onchar (uint nchar, uint nrepcnt, uint nflags) {// Todo: add your message handler code Here and / Or Call Default {CWND :: OnChar (nchar, nREPCNT, NFLAGS); return;} static char stmp [3] = "; static bool btmp = false; cclientdc dc (this); dc.setbkmode Transparent); CRECT RTTMP; if (nchar == vk_return) {m_bshow = false ;:: hidecaret (this-> getsafehwnd ());} else if (nchar == vk_back) {i (m_npos> 0) {--M_NPOS ; if (bChinese!) {rtTmp.left = m_xPos m_nPos * m_xChar; rtTmp.top = m_yPos; rtTmp.right = m_xPos m_strText.GetLength () * m_xChar; rtTmp.bottom = m_yPos m_yChar; InvalidateRect (& rtTmp); :: setCareTPOS ((M_XPOS M_NPOS * m_XCHAR), M_YPOS);} else {r r {f lef = m_XPOS M_NPOS * m_Xchar * 2; RTTMP.TOP = M_YPOS; RTTMP.Right = m_XPOS m_STRTEXT.GETLENGTH () * m_xc Har * 2; RTTMP.BOTTOM = M_YPOS M_YCHAR; INVALIDATERECT (& RTTMP); :: setCareTPOS ((m_xpos m_npos * m_xchar * 2), m_ypos);} m_strtext.delete (m_npos);
}}} Else // Normal character code {cstring stramp; if (nchar> 127 && btmp) {stmp [1] = nchar; stmp [2] = 0; bCHINESE = true; btmp = false;} else f (nchar> 127 &&! Btmp) {stmp [0] = nchar; btmp = true; cWnd :: onchar (nchar, nrepcnt, nflags); return;} else {bCHINESE = false; stmp [0] = nchar; stmp [1] = 0;} stramp = stmp; if (! BCHINESE) {DC.TEXTOUT ((M_XPOS M_NPOS * m_xchar 2), m_ypos, strtmp); m_npos ;:: setCareTPOS ((m_xpos m_npos * m_xchar), m_ypos) } Else {dc.textout (m_xpos m_npos * m_xchar * 2 2), m_ypos, strtmp); m_npos; :: setCareTPOS ((M_XPOS M_NPOS * m_xchar * 2), m_ypos);} m_strtext = Strtmp; CWnd :: OnChar (nchar, nrepcnt, nflags); return;} cwnd :: onchar (nchar, nrepcnt, nflags);}
My free space is upgrading, so there is no space for the time being to put on the project code. The space is good, I will post it.