Doesn't paint Win32Api?



  • Here's the code:

     sx = LOWORD(lParam); //Ширина окна
     sy = HIWORD(lParam); //Высота окна
     a = sx / 2; //Координаты
     b = sy / 2; //центра окна
     h = 3 * M_PI / a; //Шаг по оси х
    

    MoveToEx(hdc, 0, b, NULL);
    for (x = -M_PI, x_scr = y_scr = 0; x < M_PI; x += h)
    {
    x_scr = ((x + M_PI)*a / M_PI);
    y_scr = (grafik('2', x, y_scr, b));
    LineTo(hdc, x_scr, y_scr);
    }

    int grafik(char c, double x, int y_scr, int b)
    

    {
    switch (c)
    {
    case '1':
    return y_scr = b * (1 - tan(x));
    case '2':
    return y_scr = b * (1 - sin(x));
    case '3':
    return y_scr = b * (1 - cos(x));
    case '4':
    return y_scr = x;
    case '5':
    return y_scr = x*x;
    case '6':
    return y_scr = sqrt(x);
    }
    }

    The code draws one of the schedules that the user asks, and draws, but as soon as I get it in. swith He stops drawing.

    case WM_KEYDOWN:
    switch (wParam) {
    case VK_ESCAPE:
    SendMessage(hwnd, WM_CLOSE, 0, 0);
    break;
    case VK_NUMPAD1:

        sx = LOWORD(lParam); //Ширина окна
        sy = HIWORD(lParam); //Высота окна
        a = sx / 2; //Координаты
        b = sy / 2; //центра окна
        h = 3 * M_PI / a; //Шаг по оси х
    
        MoveToEx(hdc, 0, b, NULL);
        for (x = -M_PI, x_scr = y_scr = 0; x &lt; M_PI; x += h)
        {
            x_scr = ((x + M_PI)*a / M_PI);
            y_scr = (grafik('2', x, y_scr, b));
            LineTo(hdc, x_scr, y_scr);
        }
    
        break;
    }
    break;
    

    case WM_PAINT:
    switch (wParam) {
    case VK_NUMPAD1:

    sx = LOWORD(lParam); //Ширина окна
    sy = HIWORD(lParam); //Высота окна
    a = sx / 2; //Координаты
    b = sy / 2; //центра окна
    h = 3 * M_PI / a; //Шаг по оси х
    
    MoveToEx(hdc, 0, b, NULL);
    for (x = -M_PI, x_scr = y_scr = 0; x &lt; M_PI; x += h)
    {
        x_scr = ((x + M_PI)*a / M_PI);
        y_scr = (grafik('2', x, y_scr, b));
        LineTo(hdc, x_scr, y_scr);
    }
    
    break;
    



  • I'm gonna talk about C, but I don't think that's gonna make a big difference.

    lParam and wParam this is the parameters transmitted by the LO to the annex. And they have different meanings depending on the type of event. There's no way to check what's behind the keyboard in the drawing event, which means we need to report the necessary data on our own.

    You need to keep the "constant apps" somewhere. The entry will change it and the withdrawal will be based. Choice the vault for you: this may be the structure or set of variables, the static variable in the function or the global (and if C++ is involved, this may be the field in the class). It's important that she be available for reading and recording from any place of your processor.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2