why this code doesn't work.
I want to do, I have 3 numbers( x1,x2,y1,y2; ) in editbox and it makes an equation y2=x2/x1*y1; and after this what we will receive in y2 it will be writen on hwnd

#include <windows.h>
#include <stdio.h>

       HWND hwnd1,hwnd2,hwnd3;
       WCHAR x1[MAX_PATH],x2[MAX_PATH],y1[MAX_PATH],y2[MAX_PATH];
       wchar_t str[MAX_PATH];
/*  Declare Windows procedure  */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/*  Make the class name into a global variable  */
char szClassName[ ] = "WindowsApp";

int WINAPI WinMain (HINSTANCE hThisInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpszArgument,
                   int nFunsterStil)

{
   HWND hwnd;               /* This is the handle for our window */
   MSG messages;            /* Here messages to the application are saved */
   WNDCLASSEX wincl;        /* Data structure for the windowclass */

   /* The Window structure */
   wincl.hInstance = hThisInstance;
   wincl.lpszClassName = szClassName;
   wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
   wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
   wincl.cbSize = sizeof (WNDCLASSEX);

   /* Use default icon and mouse-pointer */
   wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
   wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
   wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
   wincl.lpszMenuName = NULL;                 /* No menu */
   wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
   wincl.cbWndExtra = 0;                      /* structure or the window instance */
   /* Use Windows's default color as the background of the window */
   wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

   /* Register the window class, and if it fails quit the program */
   if (!RegisterClassEx (&wincl))
       return 0;

   /* The class is registered, let's create the program*/
   hwnd = CreateWindowEx (
          0,                   /* Extended possibilites for variation */
          szClassName,         /* Classname */
          "Windows App",       /* Title Text */
          WS_OVERLAPPEDWINDOW, /* default window */
          CW_USEDEFAULT,       /* Windows decides the position */
          CW_USEDEFAULT,       /* where the window ends up on the screen */
          544,                 /* The programs width */
          375,                 /* and height in pixels */
          HWND_DESKTOP,        /* The window is a child-window to desktop */
          NULL,                /* No menu */
          hThisInstance,       /* Program Instance handler */
          NULL                 /* No Window Creation data */
          );

   /* Make the window visible on the screen */
   ShowWindow (hwnd, nFunsterStil);

   /* Run the message loop. It will run until GetMessage() returns 0 */
   while (GetMessage (&messages, NULL, 0, 0))
   {
       /* Translate virtual-key messages into character messages */
       TranslateMessage(&messages);
       /* Send message to WindowProcedure */
       DispatchMessage(&messages);
   }

   /* The program return-value is 0 - The value that PostQuitMessage() gave */
   return messages.wParam;
}


/*  This function is called by the Windows function DispatchMessage()  */

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{

   switch (message)                  /* handle the messages */
   {
          case WM_CREATE:
                    hwnd1=CreateWindow("edit","",WS_VISIBLE | WS_CHILD ,50, 50, 80, 25,hwnd,(HMENU) 1, NULL, NULL);//3
                    hwnd2=CreateWindow("edit","",WS_VISIBLE | WS_CHILD ,150, 50, 80, 25,hwnd,(HMENU) 2, NULL, NULL); //1000
                    hwnd3=CreateWindow("edit","",WS_VISIBLE | WS_CHILD ,250, 50, 80, 25,hwnd,(HMENU) 3, NULL, NULL); //107
                                         break;
                    case WM_LBUTTONDOWN:
GetWindowTextW(hwnd1,x1,MAX_PATH);
GetWindowTextW(hwnd2,x2,MAX_PATH);
GetWindowTextW(hwnd3,y1,MAX_PATH);
y2=x2/x1*y1; 
swprintf(str, L"%c", y2);
SetWindowTextW(hwnd, str);

                         break;
       case WM_DESTROY:
           PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
           break;
       default:                      /* for messages that we don't deal with */
           return DefWindowProc (hwnd, message, wParam, lParam);
   }

   return 0;
}

invalid operands of types `WCHAR[260]' and `WCHAR[260]' to binary `operator/'

the problem is in y2=x2/x1*y1;

I have down the problem, but now when in edit there is nothing written or there is 0 written it cycles why? how can I decide problem?

#include <windows.h>
#include <stdio.h>


/*  Declare Windows procedure  */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/*  Make the class name into a global variable  */
char szClassName[ ] = "WindowsApp";

HWND hwnd1,hwnd2,hwnd3;
WCHAR x1[MAX_PATH],x2[MAX_PATH],y1[MAX_PATH],y2[MAX_PATH];
int a,b,c,d;
wchar_t str[MAX_PATH];

int WINAPI WinMain (HINSTANCE hThisInstance,
                  HINSTANCE hPrevInstance,
                  LPSTR lpszArgument,
                  int nFunsterStil)

{
  HWND hwnd;               /* This is the handle for our window */
  MSG messages;            /* Here messages to the application are saved */
  WNDCLASSEX wincl;        /* Data structure for the windowclass */

  /* The Window structure */
  wincl.hInstance = hThisInstance;
  wincl.lpszClassName = szClassName;
  wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
  wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
  wincl.cbSize = sizeof (WNDCLASSEX);

  /* Use default icon and mouse-pointer */
  wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
  wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
  wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
  wincl.lpszMenuName = NULL;                 /* No menu */
  wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
  wincl.cbWndExtra = 0;                      /* structure or the window instance */
  /* Use Windows's default color as the background of the window */
  wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

  /* Register the window class, and if it fails quit the program */
  if (!RegisterClassEx (&wincl))
      return 0;

  /* The class is registered, let's create the program*/
  hwnd = CreateWindowEx (
         0,                   /* Extended possibilites for variation */
         szClassName,         /* Classname */
         "Windows App",       /* Title Text */
         WS_OVERLAPPEDWINDOW, /* default window */
         CW_USEDEFAULT,       /* Windows decides the position */
         CW_USEDEFAULT,       /* where the window ends up on the screen */
         544,                 /* The programs width */
         375,                 /* and height in pixels */
         HWND_DESKTOP,        /* The window is a child-window to desktop */
         NULL,                /* No menu */
         hThisInstance,       /* Program Instance handler */
         NULL                 /* No Window Creation data */
         );

  /* Make the window visible on the screen */
  ShowWindow (hwnd, nFunsterStil);

  /* Run the message loop. It will run until GetMessage() returns 0 */
  while (GetMessage (&messages, NULL, 0, 0))
  {
      /* Translate virtual-key messages into character messages */
      TranslateMessage(&messages);
      /* Send message to WindowProcedure */
      DispatchMessage(&messages);
  }

  /* The program return-value is 0 - The value that PostQuitMessage() gave */
  return messages.wParam;
}


/*  This function is called by the Windows function DispatchMessage()  */

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{

  switch (message)                  /* handle the messages */
  {
         case WM_CREATE:
                   hwnd1=CreateWindow("edit","1",WS_VISIBLE | WS_CHILD ,50, 50, 80, 25,hwnd,(HMENU) 1, NULL, NULL);//3
                   hwnd2=CreateWindow("edit","1",WS_VISIBLE | WS_CHILD ,150, 50, 80, 25,hwnd,(HMENU) 2, NULL, NULL); //1000
                   hwnd3=CreateWindow("edit","1",WS_VISIBLE | WS_CHILD ,250, 50, 80, 25,hwnd,(HMENU) 3, NULL, NULL); //107
                   break;
         case WM_LBUTTONDOWN:
                             GetWindowTextW(hwnd1,x1,MAX_PATH);//dzveli
                             GetWindowTextW(hwnd2,x2,MAX_PATH);//axali
                             GetWindowTextW(hwnd3,y1,MAX_PATH);//dzveli romelzec unda gadaeceros bolos y2
                             a=_wtoi(x1);
                             b=_wtoi(x2);
                             c=_wtoi(y1);
                             swprintf(str, L"%d %d %d %d", b,a,c,b/a*c);//anu   x2/x1*y1=y2;
                             /*if(a==0)
                             {
                              MessageBox(0,"chaicikla",0,0);
                              }
                              else*/
                              SetWindowTextW(hwnd, str);

                              break;
      case WM_DESTROY:
          PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
          break;
      default:                      /* for messages that we don't deal with */
          return DefWindowProc (hwnd, message, wParam, lParam);
  }

  return 0;
}

In your CreateWindow() calls for the edit controls, you are not passing the correct HINSTANCE of the app.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.