E
E
Evgeny Petryaev2020-02-20 23:11:20
C++ / C#
Evgeny Petryaev, 2020-02-20 23:11:20

How to make the program wait for a selection in one window, and then launch another?

I create a window, at first a small dialog box is loaded before SetFocus(hwnd2);
After the main one, how to make the second window appear after clicking ok on the dialog?

my code

GLboolean Window::CreateWindow_(wchar_t *title, GLint width, GLint height, GLint bits, GLboolean fullscreenflag)
{
  PWNDCLASS wc = new WNDCLASS();
  hinstance = GetModuleHandle(0);
  wc->style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  wc->lpfnWndProc = (WNDPROC)WndProc;
  wc->cbClsExtra = 0;
  wc->cbWndExtra = 0;
  wc->hInstance = hinstance;
  wc->hIcon = LoadIcon(0, IDI_WINLOGO);
  wc->hCursor = LoadCursor(0, IDC_ARROW);
  wc->hbrBackground = 0;
  wc->lpszMenuName = 0;
  wc->lpszClassName = L"My Window";
  if (!RegisterClass(wc))
  {
    MessageBox(0, L"Failed reg crea", L"ERROR", MB_OK | MB_ICONEXCLAMATION);
    return false;
  }
  fullscreen = fullscreenflag;
  if (fullscreen)
  {
    PDEVMODE dmscreensettings = new DEVMODE();
    memset(dmscreensettings, 0, sizeof(dmscreensettings));
    dmscreensettings->dmSize = sizeof(dmscreensettings);
    dmscreensettings->dmPelsWidth = width;
    dmscreensettings->dmPelsHeight = height;
    dmscreensettings->dmBitsPerPel = bits;
    dmscreensettings->dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
    if (ChangeDisplaySettings(dmscreensettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
    {
      if (MessageBox(0, L"Not support fulscreen", L"HINT", MB_YESNO | MB_ICONEXCLAMATION) == IDYES)
        fullscreen = false;
      else
      {
        MessageBox(0, L"Prog close", L"ERROR", MB_OK | MB_ICONSTOP);
        return false;
      }
    }
  }
  DWORD dwexstyle, dwstyle;
  if (fullscreen)
  {
    dwexstyle = WS_EX_APPWINDOW;
    dwstyle = WS_POPUP;
    ShowCursor(true);
  }
  else
  {
    dwexstyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
    dwstyle = WS_OVERLAPPED;
  }
  PRECT windowrect = new RECT();
  windowrect->left = (long)0;
  windowrect->right = (long)width + 0;
  windowrect->top = (long)0;
  windowrect->bottom = (long)height + 0;
  AdjustWindowRectEx(windowrect, dwstyle, false, dwexstyle);
  int menuheight = 0, menuwidth = 0;
  if (!fullscreenflag)
  {
    menuheight = 40;
    menuwidth = 20;
  }
  
  hwnd2 = CreateWindowEx(dwexstyle, L"My Window", L"Settings"/*title*/,
    WS_CLIPSIBLINGS | WS_CLIPCHILDREN | dwstyle,
    0, 0, 400,
    250, 0, 0, hinstance, 0);
  HWND button = CreateWindowEx(
    BS_PUSHBUTTON,
    L"BUTTON",
    L"OK",
    WS_CHILD | WS_VISIBLE,
    50,
    150,
    70,
    30,
    hwnd2,
    (HMENU)1001,
    hinstance,
    NULL
  );
  HWND RADIOBUTTON1 = CreateWindowEx(
    BS_PUSHBUTTON,
    L"BUTTON",
    L"OFFLINE",
    WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,
    50,
    100,
    70,
    30,
    hwnd2,
    (HMENU)1002,
    hinstance,
    NULL
  );
  HWND RADIOBUTTON2 = CreateWindowEx(
    BS_PUSHBUTTON,
    L"BUTTON",
    L"ONLINE",
    WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,
    150,
    100,
    70,
    30,
    hwnd2,
    (HMENU)1003,
    hinstance,
    NULL
  );
  edit1 = CreateWindowEx(/*DT_EDITCONTROL*/0L,L"Edit", L"[email protected]",
    WS_VISIBLE | WS_CHILD | WS_BORDER, 50, 10, 200,
    30, hwnd2, (HMENU)1004, hinstance, NULL);

  edit2 = CreateWindowEx(/*DT_EDITCONTROL*/0L, L"Edit", L"00000000",
    WS_VISIBLE | WS_CHILD , 50, 50, 200,
    30, hwnd2, (HMENU)1005, hinstance, NULL); 

  ShowWindow(hwnd2, SW_SHOW);
  SetForegroundWindow(hwnd2);
  SetFocus(hwnd2);

  if (!(hwnd = CreateWindowEx(dwexstyle, L"My Window", title,
    WS_CLIPSIBLINGS | WS_CLIPCHILDREN | dwstyle,
    0, 0, windowrect->right - windowrect->left + menuwidth,
    windowrect->bottom - windowrect->top + menuheight, 0, 0, hinstance, 0)))
  {
    KillWindow();
    MessageBox(0, L"Create w error", L"ERROR", MB_OK | MB_ICONEXCLAMATION);
    return false;
  }
  GLuint pixelformat;
  PPIXELFORMATDESCRIPTOR pfd = new PIXELFORMATDESCRIPTOR();
  pfd->nSize = sizeof(PPIXELFORMATDESCRIPTOR);
  pfd->nVersion = 1;
  pfd->dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
  pfd->iPixelType = PFD_TYPE_RGBA;
  pfd->cColorBits = bits;
  pfd->cRedBits = 0;
  pfd->cRedShift = 0;
  pfd->cGreenBits = 0;
  pfd->cGreenShift = 0;
  pfd->cBlueBits = 0;
  pfd->cBlueShift = 0;
  pfd->cAlphaBits = 0;
  pfd->cAlphaShift = 0;
  pfd->cAccumBits = 0;
  pfd->cAccumRedBits = 0;
  pfd->cAccumGreenBits = 0;
  pfd->cAccumBlueBits = 0;
  pfd->cAccumAlphaBits = 0;
  pfd->cDepthBits = 32;
  pfd->cStencilBits = 0;
  pfd->cAuxBuffers = 0;
  pfd->iLayerType = PFD_MAIN_PLANE;
  pfd->bReserved = 0;
  pfd->dwLayerMask = 0;
  pfd->dwVisibleMask = 0;
  pfd->dwDamageMask = 0;
  if (!(hdc = GetDC(hwnd)))
  {
    KillWindow();
    MessageBox(0, L"can't create dc", L"ERROR", MB_OK | MB_ICONEXCLAMATION);
    return false;
  }
  if (!(pixelformat = ChoosePixelFormat(hdc, pfd)))
  {
    KillWindow();
    MessageBox(0,L"can't pixelf", L"ERROR", MB_OK | MB_ICONEXCLAMATION);
    return false;
  }
  if (!SetPixelFormat(hdc, pixelformat, pfd))
  {
    KillWindow();
    MessageBox(0, L"can't setpixel", L"ERROR", MB_OK | MB_ICONEXCLAMATION);
    return false;
  }
  if (!(hrc = wglCreateContext(hdc)))
  {
    KillWindow();
    MessageBox(0, L"can't context",L"ERROR", MB_OK | MB_ICONEXCLAMATION);
    return false;
  }
  if (!wglMakeCurrent(hdc, hrc))
  {
    KillWindow();
    MessageBox(0, L"can't context cur", L"ERROR", MB_OK | MB_ICONEXCLAMATION);
    return false;
  }
  ShowWindow(hwnd, SW_SHOW);
  SetForegroundWindow(hwnd);
  SetFocus(hwnd);
  return true;
}

часть самой программы
int Game::Execute()
{
  bool fullscreen = false;
#if WINAPI_==1
  WindowsWinApi_ = new WindowsWinApi();
  if (!WindowsWinApi_->keyboard__->CreateWindow_(L"Tropic Island",700,500, 32, fullscreen))
    return 0;
#else
  SDL_GLContext context;
  SDL_Init(SDL_INIT_VIDEO);
  window = SDL_CreateWindow("Tropic Island", 10, 10,700 ,500, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
  context = SDL_GL_CreateContext(window);
  SDL_GL_SetSwapInterval(1);
#endif
  setup_opengl(700,500);
....

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Yudakov, 2020-02-20
@AlexanderYudakov

The button's parent window needs to handle the BN_CLICKED notification that comes in the WM_COMMAND message . In your example, this should be done in a procedure WndProc.
Read more here: https://docs.microsoft.com/en-us/windows/win32/con...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question