tailieunhanh - Lập trình sự kiện - các thư viện lập trình của windows - trần minh thái - 3
Bài 3:Các thiết bị nhập liệu crPrevBk = SetBkColor(hdc, RGB(0,0,0)); TextOut(hdc, nCaretPosX, nCaretPosY * dwCharY, &ch, 1); SetTextColor(hdc, crPrevText); SetBkColor(hdc, crPrevBk); } // Get the width of the character and // calculate the new horizontal position of the caret. GetCharWidth32(hdc, ch, ch, &nCharWidth); ReleaseDC(hwndMain, hdc); nCaretPosX = nCaretPosX + nCharWidth; } nCurChar++; ShowCaret(hwndMain); break; } break; case VK_UP: // UP ARROW case VK_DOWN: // DOWN ARROW MessageBeep((UINT) -1); return 0; case VK_HOME: // HOME // Set the caret's position to the upper left // corner of the client area. nCaretPosX = nCaretPosY = 0; nCurChar = 0; break; case VK_END: //. | Bài 3 Các thiết bị nhập liệu Trần Minh Thái 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 crPrevBk SetBkColor hdc RGB 0 0 0 TextOut hdc nCaretPosX nCaretPosY dwCharY ch 1 SetTextColor hdc crPrevText SetBkColor hdc crPrevBk Get the width of the character and calculate the new horizontal position of the caret. GetCharWidth32 hdc ch ch nCharWidth ReleaseDC hwndMain hdc nCaretPosX nCaretPosX nCharWidth nCurChar ShowCaret hwndMain break break case VK_UP UP ARROW case VK_DOWN DOWN ARROW MessageBeep UINT -1 return 0 case VK_HOME HOME Set the caret s position to the upper left corner of the client area. nCaretPosX nCaretPosY 0 nCurChar 0 break case VK_END END Move the caret to the end of the text. for i 0 i cch i Count the carriage returns and save the index of the last one. if pchInputBuf i 0x0D cCR nCRIndex i 1 _ nCaretPosY cCR Copy all text between the last carriage return and the end of the keyboard input buffer to a temporary buffer. Bài giảng Lập trình C for Win .Trang 37 69 Bài 3 Các thiết bị nhập liệu Trần Minh Thái 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 for i nCRIndex j 0 i cch i j szBufj pchInputBuf i szBufj TEXT 0 Retrieve the text extent and use it to set the horizontal position of the caret. hdc GetDC hwndMain GetTextExtentPoint32 hdc szBuf Istrlen szBuf sz nCaretPosX ReleaseDC hwndMain hdc nCurChar cch break default break SetCaretPos nCaretPosX nCaretPosY dwCharY break case WM_PAINT if cch 0 nothing in input buffer break hdc BeginPaint hwndMain ps HideCaret hwndMain Set the clipping rectangle and then draw the text into it. SetRect rc 0 0 dwLineLen dwClientY DrawText hdc pchInputBuf -1 rc DT_LEFT ShowCaret hwndMain EndPaint hwndMain ps break Process other messages. case WM_DESTROY .
đang nạp các trang xem trước