返回列表 发帖

[原创]取机器名

[watermark]

[原创]取机器名

头文件:
//EZFONT.H
/*---------------------------------------------------------------------------
   EZFONT.H header file
----------------------------------------------------------------------------*/
HFONT EzCreateFont (HDC hdc, TCHAR * szFaceName, int iDeciPtHeight,
                    int iDeciPtWidth, int iAttributes, BOOL fLogRes) ;
#define EZ_ATTR_BOLD          1
#define EZ_ATTR_ITALIC        2
#define EZ_ATTR_UNDERLINE     4
#define EZ_ATTR_STRIKEOUT     8

//---------------------------

//resource.h
#define IDI_ICON1                       101
// Next default values for new objects
//
#ifdef  APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE        102
#define _APS_NEXT_COMMAND_VALUE         40001
#define _APS_NEXT_CONTROL_VALUE         1000
#define _APS_NEXT_SYMED_VALUE           101
#endif
#endif

TOP

[原创]取机器名

//FontFill.cpp #include #include "ezfont.h" void PaintRoutine (HWND hwnd, HDC hdc, int cxArea, int cyArea) { TCHAR EnvName[]="ComputerName" ; TCHAR szString [20] = TEXT ("NoNamefound") ; HFONT hFont ; SIZE size ; GetEnvironmentVariable( EnvName, szString, 80) ; //È¡»·¾³±äÁ¿µÄÖµ hFont = EzCreateFont (hdc, TEXT ("Times New Roman"), 1200, 0, 0, TRUE) ; SelectObject (hdc, hFont) ; SetBkMode (hdc, TRANSPARENT) ; GetTextExtentPoint32 (hdc, szString, lstrlen (szString), &size) ; BeginPath (hdc) ; TextOut (hdc, (cxArea - size.cx) / 2, (cyArea - size.cy) / 2, szString, lstrlen (szString)) ; EndPath (hdc) ; SelectObject (hdc, CreateHatchBrush (HS_DIAGCROSS, RGB (0, 255, 255))) ; SetBkColor (hdc, RGB (255, 0, 0)) ; SetBkMode (hdc, OPAQUE) ; StrokeAndFillPath (hdc) ; DeleteObject (SelectObject (hdc, GetStockObject (WHITE_BRUSH))) ; SelectObject (hdc, GetStockObject (SYSTEM_FONT)) ; DeleteObject (hFont) ; }[DISABLELBCODE]

TOP

[原创]取机器名

//ezFont.cpp #include #include #include "ezfont.h" HFONT EzCreateFont (HDC hdc, TCHAR * szFaceName, int iDeciPtHeight, int iDeciPtWidth, int iAttributes, BOOL fLogRes) { FLOAT cxDpi, cyDpi ; HFONT hFont ; LOGFONT lf ; POINT pt ; TEXTMETRIC tm ; SaveDC (hdc) ; SetGraphicsMode (hdc, GM_ADVANCED) ; ModifyWorldTransform (hdc, NULL, MWT_IDENTITY) ; SetViewportOrgEx (hdc, 0, 0, NULL) ; SetWindowOrgEx (hdc, 0, 0, NULL) ; if (fLogRes) { cxDpi = (FLOAT) GetDeviceCaps (hdc, LOGPIXELSX) ; cyDpi = (FLOAT) GetDeviceCaps (hdc, LOGPIXELSY) ; } else { cxDpi = (FLOAT) (25.4 * GetDeviceCaps (hdc, HORZRES) / GetDeviceCaps (hdc, HORZSIZE)) ; cyDpi = (FLOAT) (25.4 * GetDeviceCaps (hdc, VERTRES) / GetDeviceCaps (hdc, VERTSIZE)) ; } pt.x = (int) (iDeciPtWidth* cxDpi / 72) ; pt.y = (int) (iDeciPtHeight* cyDpi / 72) ; DPtoLP (hdc, &pt, 1) ; lf.lfHeight = - (int) (fabs (pt.y) / 10.0 + 0.5) ; lf.lfWidth = 0 ; lf.lfEscapement = 0 ; lf.lfOrientation = 0 ; lf.lfWeight = iAttributes & EZ_ATTR_BOLD ?700:0 ; lf.lfItalic = iAttributes & EZ_ATTR_ITALIC ?1:0 ; lf.lfUnderline = iAttributes & EZ_ATTR_UNDERLINE ?1:0 ; lf.lfStrikeOut = iAttributes & EZ_ATTR_STRIKEOUT ?1:0 ; lf.lfCharSet = DEFAULT_CHARSET ; lf.lfOutPrecision = 0 ; lf.lfClipPrecision = 0 ; lf.lfQuality = 0 ; lf.lfPitchAndFamily = 0 ; lstrcpy (lf.lfFaceName, szFaceName) ; hFont = CreateFontIndirect (&lf) ; if (iDeciPtWidth != 0) { hFont = (HFONT) SelectObject (hdc, hFont) ; GetTextMetrics (hdc, &tm) ; DeleteObject (SelectObject (hdc, hFont)) ; lf.lfWidth = (int) (tm.tmAveCharWidth * fabs (pt.x) / fabs (pt.y) + 0.5) ; hFont = CreateFontIndirect (&lf) ; } RestoreDC (hdc, -1) ; return hFont ; }

TOP

[原创]取机器名

//主程序: #include #include "resource.h" extern void PaintRoutine (HWND, HDC, int, int) ; int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { int cxClient, cyClient ; HDC hdc ; cxClient=GetSystemMetrics (SM_CXSCREEN) ; cyClient=GetSystemMetrics (SM_CYSCREEN) ; hdc = CreateDC (TEXT ("DISPLAY"), NULL, NULL, NULL) ; PaintRoutine (NULL, hdc, cxClient, cyClient) ; DeleteDC (hdc) ; return 0 ; }

TOP

[原创]取机器名

先下载来看看

TOP

[原创]取机器名

不知道是我的电脑名字太长,还是字体太大的缘故,前后两个都只显示了一半..

TOP

[原创]取机器名

你的计算机名字太长啦!
字体不是你能左右的,字体大是我故意设计的特效,在屏幕居中显示。

TOP

返回列表 回复 发帖