📄 demo7_1.c
字号:
231 CheckMenuItem(hMenu, wParam,
232 MF_UNCHECKED);
233 else
234 CheckMenuItem(hMenu, wParam,
235 MF_CHECKED);
236
237 bStrikeOut = ! bStrikeOut;
238 break;
239
240 case IDM_NORM :
241 if (bNormal)
242 break;
243
244 bNormal = TRUE;
245 CheckMenuItem(hMenu, IDM_NORM,
246 MF_CHECKED);
247
248 bBold = bItalic = FALSE;
249 bUnderLine = bStrikeOut = FALSE;
250 CheckMenuItem(hMenu, IDM_BOLD,
251 MF_UNCHECKED);
252 CheckMenuItem(hMenu, IDM_ITALIC,
253 MF_UNCHECKED);
254 CheckMenuItem(hMenu, IDM_UNDERLINE,
255 MF_UNCHECKED);
256 CheckMenuItem(hMenu, IDM_STRIKEOUT,
257 MF_UNCHECKED);
258
259 break;
260 }
261
262 InvalidateRect(hWnd, NULL, TRUE);
263 return (0);
264
265 case WM_PAINT :
266 hDC = BeginPaint(hWnd, &ps);
267
268 lf = FontSize.lf[SizeID-IDM_SIZE];
269
270 lf.lfWeight = bBold ? 700 : 400;
271 lf.lfItalic = bItalic;
272 lf.lfUnderline = bUnderLine;
273 lf.lfStrikeOut = bStrikeOut;
274
275 hFont = CreateFontIndirect(&lf);
276 hPreFont = SelectObject(hDC, hFont);
277
278 GetTextMetrics(hDC, &tm);
279 TextOut(hDC, 10, 10,
280 szStr1, lstrlen(szStr1));
281 TextOut(hDC, 10, 10+tm.tmHeight,
282 szStr2, lstrlen(szStr2));
283
284 SelectObject(hDC, hPreFont);
285 DeleteObject(hFont);
286
287 EndPaint(hWnd, &ps);
288 return (0);
289
290 case WM_DESTROY :
291 DeleteObject(hBoldBM);
292 DeleteObject(hItalicBM);
293 DeleteObject(hUnderlineBM);
294 DeleteObject(hStrikeOutBM);
295 PostQuitMessage(0);
296 return (0) ;
297
298 default :
299 return (DefWindowProc(hWnd, message, wParam, lParam));
300 }
301 }
302
303
304
305 int FAR PASCAL EnumFaces(LPLOGFONT lpLF, LPTEXTMETRIC lpTM,
306 short nType, LPSTR lpData)
307 {
308 lstrcpy(FontFace.FaceName[FontFace.FaceNum],
309 lpLF->lfFaceName);
310 FontFace.bRaster[FontFace.FaceNum] = nType & 1;
311
312 FontFace.FaceNum++;
313
314 if (FontFace.FaceNum >= MAXFACES)
315 return (0);
316 return (1);
317 }
318
319
320 int FAR PASCAL EnumSizes(LPLOGFONT lpLF, LPTEXTMETRIC lpTM,
321 short nType, LPSTR lpData)
322 {
323 if (nLogPixSx != lpTM->tmDigitizedAspectX ||
324 nLogPixSy != lpTM->tmDigitizedAspectY)
325 return (1);
326
327 FontSize.lf[FontSize.SizeNum] = *lpLF;
328 FontSize.tm[FontSize.SizeNum] = *lpTM;
329
330 FontSize.SizeNum++;
331
332 if (FontSize.SizeNum >= MAXSIZES)
333 return (0);
334 return (1);
335 }
336
337
338 void MakeFontMenu(HWND hWnd)
339 {
340 int i;
341 HDC hDC;
342 HMENU hMenu, hPopMenu;
343 FARPROC lpEnumFaces;
344
345 FontFace.FaceNum = 0;
346 lpEnumFaces = MakeProcInstance(EnumFaces, hInst);
347
348 hDC = GetDC(hWnd);
349 EnumFonts(hDC, NULL, lpEnumFaces, NULL);
350 ReleaseDC(hWnd, hDC);
351
352 hMenu = GetMenu(hWnd);
353 hPopMenu = GetSubMenu(hMenu, FONTMENU);
354
355 DeleteMenu(hPopMenu, 0, MF_BYPOSITION);
356
357 for (i=0; i<FontFace.FaceNum; i++)
358 AppendMenu(hPopMenu, 0, IDM_FONT+i,
359 FontFace.FaceName[i]);
360
361 FaceID = -1;
362 SendMessage(hWnd, WM_COMMAND, IDM_FONT, 0L);
363 }
364
365
366 void MakeSizeMenu(HWND hWnd)
367 {
368 int i;
369 HDC hDC;
370 HMENU hMenu, hPopMenu;
371 FARPROC lpEnumSizes;
372 char szStr[10];
373 static LOGFONT DefLF;
374
375 FontSize.SizeNum = 0;
376 lpEnumSizes = MakeProcInstance(EnumSizes, hInst);
377
378 if (FontFace.bRaster[FaceID-IDM_FONT])
379 {
380 hDC = GetDC(hWnd);
381 EnumFonts(hDC, FontFace.FaceName[FaceID-IDM_FONT],
382 lpEnumSizes, NULL);
383 ReleaseDC(hWnd, hDC);
384 }
385 else
386 FillStrokeSize();
387
388 hMenu = GetMenu(hWnd);
389 hPopMenu = GetSubMenu(hMenu, SIZEMENU);
390
391 while (GetMenuItemCount(hPopMenu) > 0)
392 DeleteMenu(hPopMenu, 0, MF_BYPOSITION);
393
394 if (FontSize.SizeNum)
395 for (i=0; i<FontSize.SizeNum; i++)
396 {
397 sprintf(szStr, "%2d",
398 ((FontSize.tm[i].tmHeight -
399 FontSize.tm[i].tmInternalLeading)*72
400 +nLogPixSy/2) / nLogPixSy) ;
401 AppendMenu(hPopMenu, 0, IDM_SIZE+i, szStr);
402 }
403 else
404 {
405 FontSize.lf[0] = DefLF;
406 lstrcpy(FontSize.lf[0].lfFaceName,
407 FontFace.FaceName[FaceID-IDM_FONT]);
408 AppendMenu(hPopMenu, 0, IDM_SIZE, "Default");
409 }
410
411 SizeID = -1;
412 SendMessage(hWnd, WM_COMMAND, IDM_SIZE, 0L);
413 }
414
415
416 void FillStrokeSize()
417 {
418 int i;
419 static LOGFONT DefLF;
420 int StrokeSize[] = { 8, 10, 12, 14, 16,
421 18, 20, 22, 24, 26,
422 28, 30, 32, 34, 36 };
423
424 FontSize.SizeNum = sizeof(StrokeSize)/sizeof(int);
425
426 for (i=0; i<FontSize.SizeNum; i++)
427 {
428 FontSize.lf[i] = DefLF;
429
430 lstrcpy(FontSize.lf[i].lfFaceName,
431 FontFace.FaceName[FaceID-IDM_FONT]);
432 FontSize.lf[i].lfCharSet = OEM_CHARSET;
433 FontSize.lf[i].lfHeight = StrokeSize[i]*nLogPixSy/72;
434
435 FontSize.tm[i].tmHeight = StrokeSize[i]*nLogPixSy/72;
436 FontSize.tm[i].tmInternalLeading = 0;
437 }
438 }
439
440
441 void MakeStyleMenu(HMENU hMenu)
442 {
443 HMENU hStyleMenu;
444
445 hBoldBM = LoadBitmap(hInst, "Bold");
446 hItalicBM = LoadBitmap(hInst, "Italic");
447 hUnderlineBM = LoadBitmap(hInst, "Underline");
448 hStrikeOutBM = LoadBitmap(hInst, "StrikeOut");
449
450 hStyleMenu = GetSubMenu(hMenu, STYLEMENU);
451 AppendMenu(hStyleMenu, MF_BITMAP, IDM_BOLD,
452 (LPSTR)(LONG)hBoldBM);
453 AppendMenu(hStyleMenu, MF_BITMAP, IDM_ITALIC,
454 (LPSTR)(LONG)hItalicBM);
455 AppendMenu(hStyleMenu, MF_BITMAP, IDM_UNDERLINE,
456 (LPSTR)(LONG)hUnderlineBM);
457 AppendMenu(hStyleMenu, MF_BITMAP, IDM_STRIKEOUT,
458 (LPSTR)(LONG)hStrikeOutBM);
459 }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -