主题:计算窗口坐标的问题
以下程序是想在一个窗口中显示一个字符串Hellow world,然后再在这个窗口中计算出此窗口在屏幕坐标系中的坐标。但是运行结果却只显示了Hellow world。不知道哪儿错了?
LRESULT CALLBACK WndProc(HWND hwnd,UINT message, WPARAM wparam, LPARAM lparam)
{HDC hDC1,hDC2;
PAINTSTRUCT ps1,ps2;
RECT rect1,rect2;
char sname[]="Hellow world.",str[35];
int size=strlen(sname);
int x1,x2,y1,y2,len;
switch(message)
{case WM_PAINT:hDC1=BeginPaint(hwnd,&ps1);
GetClientRect(hwnd,(LPRECT)&rect1);
SetTextAlign(hDC1,TA_CENTER);
TextOut(hDC1,rect1.right/2,rect1.bottom/2,sname,size);
EndPaint(hwnd,&ps1);
hDC2=BeginPaint(hwnd,&ps2);
GetClientRect(hwnd,(LPRECT)&rect1);
GetWindowRect(hwnd,&rect2);
x1=rect2.right,y1=rect2.top,x2=rect2.right,y2=rect2.bottom;
sprintf(str,"x1=%d,y1=%d,x2=%d,y2=%d,len=%d",x1,y1,x2,y2,strlen(str));
len=strlen(str);
TextOut(hDC2,rect1.right/2,rect1.bottom/2+17,str,len);
EndPaint(hwnd,&ps2);break;
case WM_DESTROY:PostQuitMessage(0);
default: return (DefWindowProc(hwnd,message,wparam,lparam));}
return 0;}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message, WPARAM wparam, LPARAM lparam)
{HDC hDC1,hDC2;
PAINTSTRUCT ps1,ps2;
RECT rect1,rect2;
char sname[]="Hellow world.",str[35];
int size=strlen(sname);
int x1,x2,y1,y2,len;
switch(message)
{case WM_PAINT:hDC1=BeginPaint(hwnd,&ps1);
GetClientRect(hwnd,(LPRECT)&rect1);
SetTextAlign(hDC1,TA_CENTER);
TextOut(hDC1,rect1.right/2,rect1.bottom/2,sname,size);
EndPaint(hwnd,&ps1);
hDC2=BeginPaint(hwnd,&ps2);
GetClientRect(hwnd,(LPRECT)&rect1);
GetWindowRect(hwnd,&rect2);
x1=rect2.right,y1=rect2.top,x2=rect2.right,y2=rect2.bottom;
sprintf(str,"x1=%d,y1=%d,x2=%d,y2=%d,len=%d",x1,y1,x2,y2,strlen(str));
len=strlen(str);
TextOut(hDC2,rect1.right/2,rect1.bottom/2+17,str,len);
EndPaint(hwnd,&ps2);break;
case WM_DESTROY:PostQuitMessage(0);
default: return (DefWindowProc(hwnd,message,wparam,lparam));}
return 0;}