真正的菜鸟问题:用户在Edit框输入内容后,程序如何获取Edit框的内容!请给出实现细节,给100分!
我是菜鸟,请多多指教!! 问题点数:100、回复次数:10Top
1 楼WingfireWu(休息,休息一下...)回复于 2002-02-27 09:35:31 得分 20
GetDlgItem(IDC_EDIT1)->GetWindowText();Top
2 楼ydogg(灰毛兔频频)回复于 2002-02-27 09:39:32 得分 20
1.联系变量
UpdataData(TRUE);
2.CString str;
GetDlgItemText(IDC_EDIT_YOUR,str);Top
3 楼dct1999(宇宙天空)回复于 2002-02-27 09:41:01 得分 30
用ClassWizard为Edit控件增加变量,类型你自己选择。例如你增加的变量为
m_Edit.当用户输入完毕以后,你在对话框的OnOk()函数调用
UpdateData(true);那么m_Edit变量此时就等于你用户输入的东西了。
另外楼上说的也是对的Top
4 楼yj_nj(流浪部落)回复于 2002-02-27 09:42:09 得分 10
你可以给Edit框连接一个CString变量:m_edit
但一定要用UpdateData(TRUE)把你的输入存储到m_edit中.Top
5 楼8080(````www.9bu.com````)回复于 2002-02-27 09:42:28 得分 10
GetWindowText(HWND,LPSTR,int);Top
6 楼8080(````www.9bu.com````)回复于 2002-02-27 09:50:01 得分 10
#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);
}
Top
7 楼xming076(虚名)回复于 2002-02-27 09:50:10 得分 0
这么多人抢分啊:)
WingfireWu(孤崖苍松)的方法最简洁
ydogg(灰毛兔频频)的方法是常规做法Top
8 楼8080(````www.9bu.com````)回复于 2002-02-27 09:54:37 得分 0
呵呵
为什么不用API啊Top
9 楼tangqin(吞云)回复于 2002-02-27 09:55:51 得分 0
edit.text 不是EDIT的内容吗?
有这么复杂?!Top
10 楼8080(````www.9bu.com````)回复于 2002-02-27 10:07:04 得分 0
to tangqin(唐僧)
大侠
学VB的吧
你的方法不行啊Top




