📄 paint_fn.c
字号:
272 hPopMenu = GetSubMenu(hMenu, SIZEMENU);
273
274 while (GetMenuItemCount(hPopMenu) > 0)
275 DeleteMenu(hPopMenu, 0, MF_BYPOSITION);
276
277 if (FontSize.SizeNum)
278 for (i=0; i<FontSize.SizeNum; i++)
279 {
280 sprintf(szStr, "%2d",
281 ((FontSize.tm[i].tmHeight -
282 FontSize.tm[i].tmInternalLeading)*72
283 +nLogPixSy/2) / nLogPixSy) ;
284 AppendMenu(hPopMenu, 0, IDM_SIZE+i, szStr);
285 }
286 else
287 {
288 FontSize.lf[0] = DefLF;
289 lstrcpy(FontSize.lf[0].lfFaceName,
290 FontFace.FaceName[FaceID-IDM_FONT]);
291 AppendMenu(hPopMenu, 0, IDM_SIZE, "Default");
292 }
293
294 SizeID = -1;
295 SendMessage(hWnd, WM_COMMAND, IDM_SIZE, 0L);
296 }
297
298
299 void FillStrokeSize()
300 {
301 int i;
302 static LOGFONT DefLF;
303 int StrokeSize[] = { 8, 10, 12, 14, 16,
304 18, 20, 22, 24, 26,
305 28, 30, 32, 34, 36 };
306
307 FontSize.SizeNum = sizeof(StrokeSize)/sizeof(int);
308
309 for (i=0; i<FontSize.SizeNum; i++)
310 {
311 FontSize.lf[i] = DefLF;
312
313 lstrcpy(FontSize.lf[i].lfFaceName,
314 FontFace.FaceName[FaceID-IDM_FONT]);
315 FontSize.lf[i].lfCharSet = OEM_CHARSET;
316 FontSize.lf[i].lfHeight = StrokeSize[i]*nLogPixSy/72;
317
318 FontSize.tm[i].tmHeight = StrokeSize[i]*nLogPixSy/72;
319 FontSize.tm[i].tmInternalLeading = 0;
320 }
321 }
322
323
324 void MakeStyleMenu(HMENU hMenu)
325 {
326 HMENU hStyleMenu;
327
328 hBoldBM = LoadBitmap(hInst, "Bold");
329 hItalicBM = LoadBitmap(hInst, "Italic");
330 hUnderlineBM = LoadBitmap(hInst, "Underline");
331 hStrikeOutBM = LoadBitmap(hInst, "StrikeOut");
332
333 hStyleMenu = GetSubMenu(hMenu, STYLEMENU);
334 AppendMenu(hStyleMenu, MF_BITMAP, IDM_BOLD,
335 (LPSTR)(LONG)hBoldBM);
336 AppendMenu(hStyleMenu, MF_BITMAP, IDM_ITALIC,
337 (LPSTR)(LONG)hItalicBM);
338 AppendMenu(hStyleMenu, MF_BITMAP, IDM_UNDERLINE,
339 (LPSTR)(LONG)hUnderlineBM);
340 AppendMenu(hStyleMenu, MF_BITMAP, IDM_STRIKEOUT,
341 (LPSTR)(LONG)hStrikeOutBM);
342 }
343
344
345 void DeleteStyleMenu()
346 {
347 DeleteObject(hBoldBM);
348 DeleteObject(hItalicBM);
349 DeleteObject(hUnderlineBM);
350 DeleteObject(hStrikeOutBM);
351 }
352
353
354 HFONT CreateCurFont()
355 {
356 LOGFONT lf;
357 HFONT hFont;
358
359 lf = FontSize.lf[SizeID-IDM_SIZE];
360
361 lf.lfWeight = bBold ? 700 : 400;
362 lf.lfItalic = bItalic;
363 lf.lfUnderline = bUnderLine;
364 lf.lfStrikeOut = bStrikeOut;
365
366 hFont = CreateFontIndirect(&lf);
367 return (hFont);
368 }
369
370
371 void BeginWrite(HWND hWnd, int X, int Y)
372 {
373 HDC hDC;
374
375 bTextWorking = TRUE;
376 CharPosX = X;
377 CharPosY = Y;
378
379 if (bFontExist)
380 DeleteObject(hCurFont);
381
382 hCurFont = CreateCurFont();
383 bFontExist = TRUE;
384
385 hDC = GetDC(hWnd);
386 SelectObject(hDC, hCurFont);
387 GetTextMetrics(hDC, &CurTM);
388
389 CharX = CurTM.tmAveCharWidth;
390 CharY = CurTM.tmHeight;
391
392 if (bCaret)
393 {
394 HideCaret(hWnd);
395 DestroyCaret();
396 }
397
398 BackUpGraph(hDC, GetMenu(hWnd), OX, OY, CX, CY, 0, 0);
399
400 CreateCaret(hWnd, NULL, 1, CharY);
401 SetCaretPos(CharPosX, CharPosY);
402 ShowCaret(hWnd);
403 bCaret = TRUE;
404
405 nChar = 0;
406 Start.x = CharPosX;
407 Start.y = CharPosY;
408
409 ReleaseDC(hWnd, hDC);
410 }
411
412
413 void EndWrite(HWND hWnd)
414 {
415 bTextWorking = FALSE;
416
417 if (bFontExist)
418 {
419 DeleteObject(hCurFont);
420 bFontExist = FALSE;
421 }
422
423 if (bCaret)
424 {
425 HideCaret(hWnd);
426 DestroyCaret();
427 bCaret = FALSE;
428 }
429 }
430
431
432 void ChangeFont(HWND hWnd)
433 {
434 HDC hDC;
435 DWORD dwLen;
436 int StrW, StrH;
437
438 HideCaret(hWnd);
439 DestroyCaret();
440
441 hDC = GetDC(hWnd);
442
443 SelectObject(hDC, hCurFont);
444 StrW = LOWORD(GetTextExtent(hDC, Buffer, nChar));
445 StrH = CurTM.tmHeight;
446
447 DeleteObject(hCurFont);
448
449 hCurFont = CreateCurFont();
450 SelectObject(hDC, hCurFont);
451 GetTextMetrics(hDC, &CurTM);
452
453 if (nChar > 0)
454 {
455 BitBlt(hDC, Start.x-20, Start.y, StrW+21, StrH,
456 hMemDC, OX+Start.x-20, OY+Start.y,
457 SRCCOPY);
458
459 TextOut(hDC, Start.x, Start.y, Buffer, nChar);
460 CharPosX = Start.x - CurTM.tmOverhang +
461 LOWORD(GetTextExtent(hDC, Buffer, nChar));
462 }
463
464 CharX = CurTM.tmAveCharWidth;
465 CharY = CurTM.tmHeight;
466
467 CreateCaret(hWnd, NULL, 1, CharY);
468 SetCaretPos(CharPosX, CharPosY);
469 ShowCaret(hWnd);
470
471 ReleaseDC(hWnd, hDC);
472 }
473
474 void ProcessChar(HWND hWnd, WORD ch)
475 {
476 HDC hDC;
477 int CharWidth;
478
479 hDC = GetDC(hWnd);
480
481 switch (ch)
482 {
483 case '\r' : Start.y += CurTM.tmHeight;
484 CharPosX = Start.x;
485 CharPosY = Start.y;
486 SetCaretPos(CharPosX, CharPosY);
487 nChar = 0;
488 break;
489
490 case '\b' : if (nChar == 0) break;
491
492 HideCaret(hWnd);
493 SelectObject(hDC, hCurFont);
494
495 CharWidth = LOWORD(
496 GetTextExtent(hDC, Buffer+nChar-1, 1));
497 CharPosX -= (CharWidth-CurTM.tmOverhang);
498 BitBlt(hDC,
499 CharPosX-20, CharPosY,
500 CharWidth+21, CurTM.tmHeight,
501 hMemDC,
502 OX+CharPosX-20, OY+CharPosY,
503 SRCCOPY);
504
505 nChar--;
506 if (nChar > 0)
507 TextOut(hDC,
508 Start.x, CharPosY,
509 Buffer, nChar);
510
511 SetCaretPos(CharPosX, CharPosY);
512 ShowCaret(hWnd);
513 break;
514
515 default : Buffer[nChar] = ch;
516 HideCaret(hWnd);
517
518 SelectObject(hDC, hCurFont);
519 TextOut(hDC, CharPosX, CharPosY,
520 Buffer+nChar, 1);
521
522 CharWidth = LOWORD(
523 GetTextExtent(hDC, Buffer+nChar, 1))
524 - CurTM.tmOverhang;
525 CharPosX += CharWidth;
526 nChar ++;
527
528 SetCaretPos(CharPosX, CharPosY);
529 ShowCaret(hWnd);
530
531 if (! CanUndo)
532 {
533 EnableMenuItem(GetMenu(hWnd),
534 IDM_UNDO, MF_ENABLED);
535 CanUndo = TRUE;
536 }
537 break;
538 }
539
540 ReleaseDC(hWnd, hDC);
541 }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -