// text1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<windows.h>LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInst,LPSTR lpszCmdLine,int nCmdShow)
{
HWND hwnd;
MSG Msg;
WNDCLASS wndclass;
char lpszClassName[]="窗口";
char lpszTitle[]="My_windows"; wndclass.style=0;
wndclass.lpfnWndProc=WndProc;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hInstance=hInstance;
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground=(HBRUSH)(GetStockObject(BLACK_BRUSH));
wndclass.lpszMenuName=NULL;
wndclass.lpszClassName=lpszClassName; if(!RegisterClass(&wndclass))
{
return FALSE;
} hwnd=CreateWindow
(
lpszClassName,
lpszTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL
);
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd); while(GetMessage(&Msg,NULL,0,0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
int Xchar,Ychar;
SIZE size;
LPCTSTR *pstring="自定义的字体";
RECT rect;
HFONT holdFont,hnewFont;
switch(message)
{
case WM_CREATE: return 0;
case WM_PAINT:
hnewFont=CreateFont(64,0,0,0,500,0,0,0,GB2312_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH&FF_DONTCARE,"黑体");
hdc=BeginPaint(hwnd,&ps);
GetClientRect(hwnd,&rect);
holdFont=(HFONT)SelectObject(hdc,hnewFont);
SetTextColor(hdc,RGB(255,0,0));
SetBkColor(hdc,RGB(0,0,255));
GetTextExtentPoint32(hdc,pstring,12,&size);
Xchar=(rect.right-rect.left)/2-size.cx/2;
Ychar=(rect.bottom-rect.top)/2-size.cy/2;
TextOut(hdc,Xchar,Ychar,pstring,12);
SelectObject(hdc,holdFont);
DeleteObject(hnewFont);
EndPaint(hwnd,&ps); return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,message,wParam,lParam);
}
-------------------------------C:\text1\text1.cpp(66) : error C2440: 'initializing' : cannot convert from 'char [13]' to 'const char ** '
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
C:\text1\text1.cpp(79) : error C2664: 'GetTextExtentPoint32A' : cannot convert parameter 2 from 'const char ** ' to 'const char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
C:\text1\text1.cpp(82) : error C2664: 'TextOutA' : cannot convert parameter 4 from 'const char ** ' to 'const char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.text1.exe - 3 error(s), 0 warning(s)
//
#include "stdafx.h"
#include<windows.h>LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInst,LPSTR lpszCmdLine,int nCmdShow)
{
HWND hwnd;
MSG Msg;
WNDCLASS wndclass;
char lpszClassName[]="窗口";
char lpszTitle[]="My_windows"; wndclass.style=0;
wndclass.lpfnWndProc=WndProc;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hInstance=hInstance;
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground=(HBRUSH)(GetStockObject(BLACK_BRUSH));
wndclass.lpszMenuName=NULL;
wndclass.lpszClassName=lpszClassName; if(!RegisterClass(&wndclass))
{
return FALSE;
} hwnd=CreateWindow
(
lpszClassName,
lpszTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL
);
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd); while(GetMessage(&Msg,NULL,0,0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
int Xchar,Ychar;
SIZE size;
LPCTSTR *pstring="自定义的字体";
RECT rect;
HFONT holdFont,hnewFont;
switch(message)
{
case WM_CREATE: return 0;
case WM_PAINT:
hnewFont=CreateFont(64,0,0,0,500,0,0,0,GB2312_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH&FF_DONTCARE,"黑体");
hdc=BeginPaint(hwnd,&ps);
GetClientRect(hwnd,&rect);
holdFont=(HFONT)SelectObject(hdc,hnewFont);
SetTextColor(hdc,RGB(255,0,0));
SetBkColor(hdc,RGB(0,0,255));
GetTextExtentPoint32(hdc,pstring,12,&size);
Xchar=(rect.right-rect.left)/2-size.cx/2;
Ychar=(rect.bottom-rect.top)/2-size.cy/2;
TextOut(hdc,Xchar,Ychar,pstring,12);
SelectObject(hdc,holdFont);
DeleteObject(hnewFont);
EndPaint(hwnd,&ps); return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,message,wParam,lParam);
}
-------------------------------C:\text1\text1.cpp(66) : error C2440: 'initializing' : cannot convert from 'char [13]' to 'const char ** '
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
C:\text1\text1.cpp(79) : error C2664: 'GetTextExtentPoint32A' : cannot convert parameter 2 from 'const char ** ' to 'const char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
C:\text1\text1.cpp(82) : error C2664: 'TextOutA' : cannot convert parameter 4 from 'const char ** ' to 'const char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.text1.exe - 3 error(s), 0 warning(s)
GetTextExtentPoint32(hdc,pstring,12,&size);
TextOut(hdc,Xchar,Ychar,pstring,12);