I am very new to win32 gui applications.I am trying to create simple calculator application.
In that i have designed a GUI for calculator.Now i want to get text of textbox entered by user and also want to set text on click of any button i designed from 0 to 9.
For testing purpose i wrote a code to get text from textbox and tried to display it in a messagebox. But my messagebox is showing empty message. Following is my code in WinProc:
LRESULT CALLBACK WinProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
HWND B[16];// these are the saperate handles to each button in the main window.
HWND hEditA,hEditB,hEditC;//handle for text box.
char c[16][2]={"1","2","3","4","5","6","7","8","9","0","+","-","*","/",".","="};
int i=0,j,x=100,y=130;
int id[15]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
int cnt;
//char val[20];
TCHAR val[30] = {0};
int len;
switch(msg)
{
case WM_PAINT:
hdc=BeginPaint(hWnd,&ps);
TextOut(hdc,10,12,"Number 1:",strlen("Number 1:")+1);
TextOut(hdc,10,47,"Number 2:",strlen("Number 2:")+1);
TextOut(hdc,10,87,"Result :",strlen("Result :")+1);
// TextOut(hdc,10,100,"hellow sachin",strlen("hello sachin")+1);
EndPaint(hWnd,&ps);
break;
case WM_DESTROY:
PostQuitMessage (0);
break;
case WM_CREATE:
hEditA=CreateWindow(TEXT("Edit"), TEXT(""), WS_CHILD | WS_VISIBLE | WS_BORDER|ES_NUMBER|ES_RIGHT, 100, 10, 150, 25, hWnd, NULL, NULL, NULL);
hEditB=CreateWindow(TEXT("Edit"), TEXT(""), WS_CHILD | WS_VISIBLE | WS_BORDER|ES_NUMBER|ES_RIGHT, 100, 45, 150, 25, hWnd, NULL, NULL, NULL);
hEditC=CreateWindow(TEXT("Edit"), TEXT(""), WS_CHILD | WS_VISIBLE | WS_BORDER|ES_NUMBER|ES_RIGHT, 100, 85, 150, 25, hWnd, NULL, NULL, NULL);
cnt=0;
for(i=0;i<16;i++)
{
if(cnt==4)
{
y=y+40;
x=100;
cnt=0;
}
if(cnt<4)
{
B[i] = CreateWindow(TEXT("button"), TEXT(c[i]),
WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
x, y, 30, 30,
hWnd, (HMENU) id[i], NULL, NULL);
x=x+40;
//y=y+30;
cnt++;
}
}
case WM_COMMAND:
switch(LOWORD(wParam))
{
case 1:
len=GetWindowText( hEditA,val,10);
MessageBox(hWnd,(LPSTR)val, "Info", MB_OK);
SetWindowText( hEditB,val);
break;
}
}
}
B. I also want to display the caption of the button pressed in the textbox.
So please can anyone help me to find the way to correct it.
thanx in advance..