真正的菜鸟问题:用户在Edit框输入内容后,程序如何获取Edit框的内容!请给出实现细节,给100分!

zjcop 2002-02-27 09:33:55
我是菜鸟,请多多指教!!
...全文
37 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
8080 2002-02-27
  • 打赏
  • 举报
回复
to tangqin(唐僧)

大侠

学VB的吧

你的方法不行啊
  • 打赏
  • 举报
回复
edit.text 不是EDIT的内容吗?
有这么复杂?!
8080 2002-02-27
  • 打赏
  • 举报
回复
呵呵

为什么不用API啊
xming076 2002-02-27
  • 打赏
  • 举报
回复
这么多人抢分啊:)
WingfireWu(孤崖苍松)的方法最简洁
ydogg(灰毛兔频频)的方法是常规做法
8080 2002-02-27
  • 打赏
  • 举报
回复
#include "string.h"

#include "stdafx.h"
#include "stdlib.h"

HWND hEditItem,hButtonA,hButtonB,hButtonC,hButtonD,
hButtonE,hButtonF,hButtonG,hButtonH,hButtonI,hButton1,
hButton2,hButton3,hButton4,hButton5,hButton6;
HINSTANCE hInst;
char hh[]="2";
char tempadd[80]="";
char tempchar[80]="";
char tempfunction[80]="9";
char temp[80]="100";
int hhyy=0;
long hehe=0;;
char yy[80]="";
long add;
char *stop;
void jifunction(char);
void jifunction(char ji[80]="")
{
if(strcmp(tempfunction,""))
{
if(!strcmp(ji,"+")){

GetWindowText(hEditItem,tempchar,100);
MessageBox(hEditItem,tempchar,temp,100);
hehe=strtol(tempchar,&stop,100);
MessageBox(hEditItem,(LPSTR)hehe,"dd",100);
hehe=strtol(temp,&stop,100)+hehe;

ltoa(hehe,tempchar,100);
MessageBox(hEditItem,tempchar,"d",100);
SetWindowText(hEditItem,tempchar);
GetWindowText(hEditItem,temp,100);
strcpy(tempfunction,"+");
}
}
}
void buttonfunction(char);
void buttonfunction(char buttontmp[80]="")
{

GetWindowText(hEditItem,yy,100000);

if(!strcmp(yy,"0")){

SetWindowText(hEditItem,buttontmp);

}
else{

strcat(yy,buttontmp);SetWindowText(hEditItem,yy);}
}

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

int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInst,
LPSTR lpszCmdLine,
int nCmdShow)
{
HWND hwnd;

MSG Msg;

char TextItem[]="";
char nameclass[]="wo ff cao";
WNDCLASS wndclass;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=(HBRUSH)(COLOR_WINDOW+2);
wndclass.hCursor=LoadCursor(NULL,IDC_CROSS);
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=WndProc;
wndclass.lpszClassName=nameclass;
wndclass.lpszMenuName=NULL;
wndclass.style=0;
RegisterClass(&wndclass);
hwnd=CreateWindow(nameclass,nameclass,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)
{
switch(message)
{
case WM_DESTROY:
PostQuitMessage(0);
case WM_CREATE:
hEditItem=CreateWindow("EDIT",
"0",
ES_AUTOHSCROLL|ES_MULTILINE|WS_CHILD|WS_VISIBLE|ES_RIGHT|WS_BORDER,
130,20,
260,20,
hwnd,
(HMENU)120,
hInst,
NULL);
hButtonA=CreateWindow("BUTTON",
"1",
WS_CHILD|WS_VISIBLE|ES_LEFT|WS_BORDER,
130,45,
80,20,
hwnd,
(HMENU)121,
hInst,
NULL);
hButtonB=CreateWindow("BUTTON",
"2",
WS_CHILD|WS_VISIBLE|ES_LEFT|WS_BORDER,
220,45,
80,20,
hwnd,
(HMENU)122,
hInst,
NULL);
hButtonC=CreateWindow("BUTTON",
"3",
WS_CHILD|WS_VISIBLE|ES_LEFT|WS_BORDER,
310,45,
80,20,
hwnd,
(HMENU)123,
hInst,
NULL);
hButtonD=CreateWindow("BUTTON",
"4",
WS_CHILD|WS_VISIBLE|ES_LEFT|WS_BORDER,
130,70,
80,20,
hwnd,
(HMENU)124,
hInst,
NULL);
hButtonE=CreateWindow("BUTTON",
"5",
WS_CHILD|WS_VISIBLE|ES_LEFT|WS_BORDER,
220,70,
80,20,
hwnd,
(HMENU)125,
hInst,
NULL);
hButtonF=CreateWindow("BUTTON",
"6",
WS_CHILD|WS_VISIBLE|ES_LEFT|WS_BORDER,
310,70,
80,20,
hwnd,
(HMENU)126,
hInst,
NULL);
hButtonG=CreateWindow("BUTTON",
"7",
WS_CHILD|WS_VISIBLE|ES_LEFT|WS_BORDER,
130,95,
80,20,
hwnd,
(HMENU)127,
hInst,
NULL);
hButtonH=CreateWindow("BUTTON",
"8",
WS_CHILD|WS_VISIBLE|ES_LEFT|WS_BORDER,
220,95,
80,20,
hwnd,
(HMENU)128,
hInst,
NULL);
hButtonI=CreateWindow("BUTTON",
"9",
WS_CHILD|WS_VISIBLE|ES_LEFT|WS_BORDER,
310,95,
80,20,
hwnd,
(HMENU)129,
hInst,
NULL);
hButton1=CreateWindow("BUTTON",
"0",
WS_CHILD|WS_VISIBLE|ES_LEFT|WS_BORDER,
130,120,
80,20,
hwnd,
(HMENU)130,
hInst,
NULL);
hButton2=CreateWindow("BUTTON",
"-",
WS_CHILD|WS_VISIBLE|ES_LEFT|WS_BORDER,
220,120,
80,20,
hwnd,
(HMENU)131,
hInst,
NULL);
hButton3=CreateWindow("BUTTON",
"*",
WS_CHILD|WS_VISIBLE|ES_LEFT|WS_BORDER,
310,120,
80,20,
hwnd,
(HMENU)132,
hInst,
NULL);
hButton4=CreateWindow("BUTTON",
"/",
WS_CHILD|WS_VISIBLE|ES_LEFT|WS_BORDER,
130,145,
80,20,
hwnd,
(HMENU)133,
hInst,
NULL);
hButton5=CreateWindow("BUTTON",
"+",
WS_CHILD|WS_VISIBLE|ES_LEFT|WS_BORDER,
220,145,
80,20,
hwnd,
(HMENU)134,
hInst,
NULL);
hButton6=CreateWindow("BUTTON",
"清零",
WS_CHILD|WS_VISIBLE|ES_LEFT|WS_BORDER,
310,145,
80,20,
hwnd,
(HMENU)135,
hInst,
NULL);

break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case 121:
buttonfunction("1");
break;
case 122:
buttonfunction("2");
break;
case 123:
buttonfunction("3");
break;
case 124:
buttonfunction("4");
break;
case 125:
buttonfunction("5");
break;
case 126:
buttonfunction("6");
break;
case 127:
buttonfunction("7");
break;
case 128:
buttonfunction("8");
break;
case 129:
buttonfunction("9");
break;
case 130:
buttonfunction("0");
break;
case 134:
jifunction("+");
break;
case 135:
SetWindowText(hEditItem,"0");
break;

default:
return DefWindowProc(hwnd,message,wParam,lParam);
}
break;




default:
return DefWindowProc(hwnd,message,wParam,lParam);
}
return (0);
}
8080 2002-02-27
  • 打赏
  • 举报
回复
GetWindowText(HWND,LPSTR,int);
yj_nj 2002-02-27
  • 打赏
  • 举报
回复
你可以给Edit框连接一个CString变量:m_edit
但一定要用UpdateData(TRUE)把你的输入存储到m_edit中.
dct1999 2002-02-27
  • 打赏
  • 举报
回复
用ClassWizard为Edit控件增加变量,类型你自己选择。例如你增加的变量为
m_Edit.当用户输入完毕以后,你在对话框的OnOk()函数调用
UpdateData(true);那么m_Edit变量此时就等于你用户输入的东西了。
另外楼上说的也是对的
ydogg 2002-02-27
  • 打赏
  • 举报
回复
1.联系变量
UpdataData(TRUE);

2.CString str;
GetDlgItemText(IDC_EDIT_YOUR,str);
WingfireWu 2002-02-27
  • 打赏
  • 举报
回复
GetDlgItem(IDC_EDIT1)->GetWindowText();

16,551

社区成员

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

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

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