帮我解决这个问题!

lsw111 2007-12-10 04:23:50
我用控制台写的程序,现在我要把GetClientRect (hwnd, &rect)得到的矩形的两个点的坐标值(4个值)用MessageBox的方式显示出来,怎么做?谢谢!
...全文
175 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
青稞 2007-12-12
  • 打赏
  • 举报
回复
相应的头文件没有引入。。
#include <stdio.h>
以后楼主要是再遇到这种问题,你就应该明白了,你调用一个函数,应该引入这个函数所在的库,然后包含其头文件,这样才行的。。
iyranly 2007-12-12
  • 打赏
  • 举报
回复
include <stdio.h>
jjfwenwenti 2007-12-12
  • 打赏
  • 举报
回复
#include <stdio.h>
lsw111 2007-12-12
  • 打赏
  • 举报
回复
#include <windows.h>
#include<iostream.h>

LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,

PSTR szCmdLine, int iCmdShow)

{

static TCHAR szAppName[] = TEXT ("AltWind") ;

HWND hwnd ;

MSG msg ;

WNDCLASS wndclass ;

wndclass.style = CS_HREDRAW | CS_VREDRAW ;

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 (WHITE_BRUSH) ;

wndclass.lpszMenuName= NULL ;

wndclass.lpszClassName= szAppName ;



if (!RegisterClass (&wndclass))

{

MessageBox ( NULL, TEXT ("Program requires Windows NT!"),

szAppName, MB_ICONERROR) ;

return 0 ;

}



hwnd = CreateWindow (szAppName, TEXT ("Alternate and Winding Fill Modes"),

WS_OVERLAPPEDWINDOW,

CW_USEDEFAULT, CW_USEDEFAULT,

CW_USEDEFAULT, CW_USEDEFAULT,

NULL, NULL, hInstance, NULL) ;



ShowWindow (hwnd, iCmdShow) ;

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)

{

static POINT aptFigure [10] = {10,70, 50,70, 50,10, 90,10, 90,50,

30,50, 30,90, 70,90, 70,30, 10,30 };

static int cxClient, cyClient ;

HDC hdc ;

int i ;

PAINTSTRUCT ps ;



POINT apt[10] ;





switch (message)

{

case WM_SIZE:

cxClient = LOWORD (lParam) ;

cyClient = HIWORD (lParam) ;

return 0 ;


case WM_PAINT:

hdc = BeginPaint (hwnd, &ps) ;

RECT rect;

GetClientRect (hwnd, &rect) ;

char s[4];

sprintf(s,"(%d,%d),(%d,%d)",rect.left,rect.top,rect.right,rect.bottom);

MessageBox(NULL,s,NULL,MB_OK);


SelectObject (hdc, GetStockObject (GRAY_BRUSH)) ;


for (i = 0 ; i < 10 ; i++)

{

apt[i].x = cxClient * aptFigure[i].x / 200 ;

apt[i].y = cyClient * aptFigure[i].y / 100 ;

}


SetPolyFillMode (hdc, ALTERNATE) ;

Polygon (hdc, apt, 10) ;


for (i = 0 ; i < 10 ; i++)

{

apt[i].x += cxClient / 2 ;

}


SetPolyFillMode (hdc, WINDING) ;

Polygon (hdc, apt, 10) ;



EndPaint (hwnd, &ps) ;

return 0 ;



case WM_DESTROY:

PostQuitMessage (0) ;

return 0 ;

}

return DefWindowProc (hwnd, message, wParam, lParam) ;

}

编译错误:
--------------------Configuration: DTOL - Win32 Debug--------------------
Compiling...
Sou.cpp
E:\PRO\DTOL\Sou.cpp(136) : error C2065: 'sprintf' : undeclared identifier
Error executing cl.exe.

DTOL.exe - 1 error(s), 0 warning(s)
看看怎么回事?
lsw111 2007-12-12
  • 打赏
  • 举报
回复
不好意思啊,我是新手,遇到问题还是要请教的!
谢谢各位!
qaz2008 2007-12-11
  • 打赏
  • 举报
回复
控制台可以直接printf输出
sprintf(("(%d,%d),(%d,%d)",rect四个属性)
lizmei001 2007-12-11
  • 打赏
  • 举报
回复
控制台你建工程的时候可以加入支持mfc阿

控制台可以直接print出来啊
Chivalry 2007-12-11
  • 打赏
  • 举报
回复
控制台哪有CString,MessageBox
要用sprintf(("(%d,%d),(%d,%d)",rect四个属性);
lsw111 2007-12-11
  • 打赏
  • 举报
回复
谢谢你,shakaqr!
我也试过了用你的方法呀,可是编译的时候提示
不能打开头文件 CString呀!
koko_han 2007-12-11
  • 打赏
  • 举报
回复
char str[4];
sprintf(str,"(%d,%d),(%d,%d)",rect.left,rect.top,rect.right,rect.bottom);
MessageBox(NULL,str,NULL,MB_OK);
青稞 2007-12-11
  • 打赏
  • 举报
回复
cstring这些东西是MFC中的,楼主要用的话可以选择工程支持MFC。。
否则的话直接打出来就是了。。呵呵。。搞得这么麻烦。。printf就可以的。。
zhangystc 2007-12-10
  • 打赏
  • 举报
回复
控制台的程序?那必须包含必要的头文件才能弹出对话框哦
shakaqrj 2007-12-10
  • 打赏
  • 举报
回复
cstring str;
str.format("(%d,%d),(%d,%d)",rect四个属性)
messageBox(str);

16,550

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧