CreateWindowW () вначале завершается ошибкой, а затем работает [C ++] - PullRequest
0 голосов
/ 02 мая 2020

Поэтому я пытаюсь запрограммировать приложение, которое поможет мне что-то регистрировать и упростить мои действия в будущем.

Я хотел сделать его как можно более простым, поэтому я решил использовать Win32API.

Итак, я сделал необходимые и создал нужные мне окна / стили, и так далее.

Но есть кое-что, что вызывает у меня сильные эмоции:

Когда я нажимаю на кнопка «Добавить участника», появится окно и спросит у меня имя участника.

Но когда я нажимаю на него в первый раз, ничего не происходит. Но когда я нажимаю на него второй раз, вышеупомянутое окно появляется естественно.

Чтобы выяснить, что это за проблема, я решил поставить функцию GetLastError(), но, к сожалению, она возвращала 0 каждый раз, когда я нажимаю кнопку «Добавить участника» в первый раз (когда окно не неожиданно возникнуть).

Чтобы узнать, является ли CreateWindowW() проблемой или нет, я поставил std::clog << "Test" << std::endl; в начале события WM_CREATE. И, как и ожидалось, текст не отображается в первый раз, но во второй раз.

Чтобы узнать больше, я решил сделать следующее:

  • Put std::clog << "Test1" << std::endl; до CreateWindowW();
  • Поставить std::clog << "Test2" << std::endl; после CreateWindowW();
  • Поставить std::clog << "Test3" << std::endl; в начале события WM_CREATE;
  • Поставить std::clog << GetLastError() << std::endl; после std::clog << "Test2" << std::endl;.

Полученные результаты:

Первый время:

  • "Test1" успешно написано;

  • "Test2" успешно написано;

  • «Test3» не проходит и не отображается;

  • GetLastError() возвращает 0.

Второй раз:

  • «Test1» успешно написано;

  • «Test2» успешно написано;

  • «Test3» успешно записано;

  • GetLastError() возвращает 0.

После этого я попытался сделать следующее:

  • Поставить std::clog << "Terminate" << std::endl; в начало событий WM_DESTROY и WM_CLOSE.

И, как и ожидалось, «Завершить» не пишется, когда я нажимаю кнопку «Добавить участника» в первый раз, и он показывает во второй раз, когда я закрываю окно.

Итак, в соответствии с полученными результатами, я пришел к выводу, что проблема возникает из CreateWindowW(). Но настоящий вопрос почему? GetLastError() возвращает 0, поэтому обычно все будет хорошо.

Вот части моего кода, которые подразумевают вышеупомянутые результаты (весь код), получайте удовольствие:

#include <windows.h>
#include <windowsx.h>
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cstdint>
#include <sstream>
#include <string>
#include <cstring>
#include <iomanip>
#include <limits>
#include <memory>

// Check if a log already exists

HWND hIncrease;
HWND hDecrease;

std::map<std::string, std::vector<std::string>> GeneralDatabase;
BOOL LogExisting = false;

BOOL IfRegistered = false;


std::string TemporaryName;


BOOL IsWindowOpen = false;

BOOL IsAttendeeRegistered = false;

#define Size_X 900
#define Size_Y 600

// Values


HWND hAddAttBut;

int MaxScoreVal = 0;
std::string CoHostVal;
std::string TypeVal;
std::string LocationVal;

#define AttendeeButton 235

#define NewLOG 1
#define SaveLOG 2

#define AddAttendee 3
#define RemoveAttendee 4
#define DismissAttendee 5

HWND hPoint;
HWND hNames;

#define ListAttId 6
#define ListScrId 7
#define IncreaseButton (4<<3)
#define DecreaseButton (4<<4)

#define OtherButtonClick 18

#define DoneButton 22

HWND GeneralWindowHandler;

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

// Attendees + scores windows
HWND hListAtt, hListScore;

// Format + new log 

HWND hAddEdit;
HWND NewLog;
HWND MaxScore;
HWND Type;
HWND CoHost;
HWND Location;
HWND hOtherText;

HWND hOther;
HWND hDone;
// Your screen resolution

unsigned short int xScreen, yScreen;

// Class of primary and second window

void FirstWindowInitiation(HWND);
void SecondWindowInitiation(HWND);
inline VOID IncreaseButtonAction(HWND hwnd);
void AddListString(std::string);

HWND hRank;

WNDCLASSW wc;

inline void Menus(HWND);
int WINAPI WinMain(HINSTANCE hIn, HINSTANCE, LPSTR nShow, int nCmd){
    std::ios_base::sync_with_stdio(false);
    memset(&wc, 0, sizeof(wc));
    wc.hInstance = hIn;
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wc.hbrBackground = CreateSolidBrush(RGB(0,0,0));
    wc.lpszClassName = L"WindowClass";
    wc.lpfnWndProc = WndProc;
    if(!RegisterClassW(&wc)){
        MessageBoxW(NULL, L"Failed to register the window.", L"Application error.", MB_OK | MB_ICONERROR);
        return -1;
    }
    RECT rc;
    GetWindowRect(GetDesktopWindow(), &rc);
    xScreen = rc.right;
    yScreen = rc.bottom;
    CreateWindowW(L"WindowClass", L"Training application.", WS_VISIBLE | WS_SYSMENU | WS_MINIMIZEBOX, ((rc.right/2)-(Size_X/2)), ((rc.bottom/2)-(Size_Y/2)), Size_X, Size_Y, 0, 0,0,0);
    MSG msg_Translate;
    while(GetMessage(&msg_Translate, 0, 0, 0)){
        TranslateMessage(&msg_Translate);
        DispatchMessage(&msg_Translate);
    }

    return EXIT_SUCCESS;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp){
    GeneralWindowHandler = hwnd;
    switch(message){
        case WM_CTLCOLORSTATIC:{
            HDC dc = (HDC)wp;
            SetBkColor(dc, RGB(0, 0, 0));
            SetTextColor(dc, RGB(255, 255, 255));
            return reinterpret_cast<UINT_PTR>(CreateSolidBrush(RGB(0, 0, 0)));

        }
        case WM_COMMAND:{
            switch(wp){
                case NewLOG:{
                  if(IsWindowOpen){
                        MessageBoxW(hwnd, L"Cannot perform such an action; another window is already open.", L"", MB_ICONERROR | MB_OK);
                        break;
                  }
                  int ResponseMessage = IDYES;
                  ((LogExisting == false) ? :ResponseMessage = MessageBoxW(hwnd, L"Are you sure you want to reset the log?", L"", MB_YESNO | MB_ICONINFORMATION));
                  if(ResponseMessage == IDYES){
                    LogExisting = true;
                    // Reinitiation

                    if(hListAtt != NULL || hListScore != NULL){

                        SendMessageW(hListAtt, LB_RESETCONTENT, 0, 0);
                        SendMessageW(hListScore, LB_RESETCONTENT, 0, 0);

                        memset(&hListAtt, 0, sizeof(hListAtt));
                        memset(&hListScore, 0, sizeof(hListScore));
                    }

                    hListAtt = CreateWindowW(L"ListBox", L"", WS_VISIBLE | WS_CHILD | WS_BORDER, 150, 87, 300, 400, hwnd, (HMENU)ListAttId, 0, 0);
                    hListScore = CreateWindowW(L"ListBox", L"", WS_VISIBLE | WS_CHILD | WS_BORDER, 450, 87, 300, 400, hwnd, (HMENU)ListScrId, 0 ,0);
                    FirstWindowInitiation(hwnd);
                    memset(&wc, 0, sizeof(wc));

                    HINSTANCE hInst;

                    wc.hbrBackground = CreateSolidBrush(RGB(255, 255, 255));
                    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
                    wc.hInstance = hInst;
                    wc.lpszClassName = L"LogClass";
                    wc.lpfnWndProc = [](HWND hwnd2, UINT msg2, WPARAM wpp, LPARAM lpp)->LRESULT CALLBACK{
                        switch(msg2){
                            case WM_COMMAND:{
                                switch(wpp){
                                 case DoneButton:{
                                     char cohost[256], location[256], max[4], type[128];
                                     GetWindowText(CoHost, cohost, sizeof(cohost));
                                     ComboBox_GetText(Type, type, sizeof(type));
                                     ComboBox_GetText(MaxScore, max, sizeof(max));
                                     ComboBox_GetText(Location, location, sizeof(location));
                                     if(strcmp(location, "") == 0 || strcmp(max, "") == 0 || strcmp(type, "") == 0){
                                          MessageBoxW(hwnd2, L"One of the fields is empty, please fill it/them", L"", MB_ICONERROR | MB_OK);
                                          break;
                                     }

                                     MaxScoreVal = atoi(max);
                                     if(strcmp(cohost, "") == 0){
                                         CoHostVal = "N/A";
                                     }
                                     else{
                                       CoHostVal = cohost;
                                     }
                                     LocationVal = location;
                                     TypeVal = type;

                                     DestroyWindow(hwnd2);
                                     ZeroMemory(&hwnd2, sizeof(HWND));
                                     break;
                                 }
                                 case OtherButtonClick:{
                                      if(SendMessageW(hOther, BM_GETCHECK, 0, 0) == 1){
                                          EnableWindow(hOtherText, true);
                                          EnableWindow(Location, false);
                                      }
                                      else{
                                        EnableWindow(hOtherText, false);
                                        EnableWindow(Location, true);
                                      }
                                      break;
                                 }
                                }
                                break;
                            }
                            case WM_CTLCOLORSTATIC:{
                                HDC dc = (HDC)wpp;
                                SetBkColor(dc, RGB(255, 255, 255));
                                return reinterpret_cast<UINT_PTR>(CreateSolidBrush(RGB(255,255,255)));
                            }
                            case WM_CREATE:{
                                IsWindowOpen = true;
                                HFONT hFont = CreateFont(20, 0, 0, 0, FF_DONTCARE, 0 , 0 , 0 , 0 , 0 ,0 , 0 , 0, "Arial");
                                SendMessageW(CreateWindowW(L"Static", L"Max score : ", WS_VISIBLE | WS_CHILD, 40, 15, 100, 35, hwnd2, 0, 0, 0), WM_SETFONT, (WPARAM)hFont, (LPARAM)TRUE);
                                MaxScore = CreateWindowW(L"COMBOBOX", L"", WS_VISIBLE | WS_CHILD | CBS_DROPDOWN | CBS_DROPDOWNLIST ,180,15, 60, 210, hwnd2, 0, 0,0);

                                for(int x = 10; x < 21; x++){
                                    std::stringstream ss;
                                    ss << x;
                                    std::string Result = ss.str();
                                    std::wstring w_Result(Result.begin(), Result.end());
                                    SendMessageW(MaxScore, CB_ADDSTRING, 0, (LPARAM)w_Result.c_str());
                                }

                                SecondWindowInitiation(hwnd2);

                                break;
                            }
                            case WM_CLOSE:{
                                char cohost[256], location[256], max[4], type[128];
                                GetWindowText(CoHost, cohost, sizeof(cohost));
                                ComboBox_GetText(Type, type, sizeof(type));
                                ComboBox_GetText(MaxScore, max, sizeof(max));
                                ComboBox_GetText(Location, location, sizeof(location));
                                if(strcmp(location, "") == 0 || strcmp(max, "") == 0 || strcmp(type, "") == 0){
                                    MessageBoxW(hwnd2, L"One of the fields is empty, please fill it/them", L"", MB_ICONERROR | MB_OK);
                                    return 0;
                                }
                                MaxScoreVal = atoi(max);
                                if(strcmp(cohost, "") == 0){
                                         CoHostVal = "N/A";
                                }
                                else{
                                       CoHostVal = cohost;
                                }
                                LocationVal = location;
                                TypeVal = type; 
                                DestroyWindow(hwnd2);
                                memset(&hwnd2, 0, sizeof(hwnd2));
                                break;
                            }
                            case WM_DESTROY:{
                                DestroyWindow(hwnd2);
                                memset(&hwnd2, 0, sizeof(hwnd2));
                                IsWindowOpen = false;
                                break;
                            }
                            default:{
                                DefWindowProcW(hwnd2, msg2, wpp, lpp);
                            }
                        }
                    };
                    if(!IfRegistered){
                      if(!RegisterClassW(&wc)){
                        MessageBoxW(hwnd, L"Failed to register class... Exiting.", L"", MB_ICONERROR | MB_OK);
                        break;
                      }
                    }

                    IfRegistered = true;

                    CreateWindowW(L"LogClass", L"Format and log initiation", WS_VISIBLE | WS_SYSMENU | WS_MINIMIZEBOX, ((xScreen/2)-300), ((yScreen/2)-200), 600, 400, 0, 0, 0, 0); 

                  }
                  break;
                }
                case IncreaseButton:{
                    if(IsWindowOpen){
                        MessageBoxW(hwnd, L"Cannot perform such an action; another window is already open.", L"", MB_ICONERROR | MB_OK);
                        break;
                    }
                    IncreaseButtonAction(hwnd);
                    break;

                }
                case AddAttendee:{
                    if(!LogExisting){
                        MessageBoxW(hwnd, L"No existing log  currently.", L"Error 404 - No log found", MB_OK | MB_ICONERROR);
                        break;
                    }
                    if(IsWindowOpen){
                        MessageBoxW(hwnd, L"Cannot perform such an action; another window is already open.", L"", MB_ICONERROR | MB_OK);
                        break;
                    }
                    memset(&wc, 0, sizeof(wc));
                    HINSTANCE hin;
                    wc.hbrBackground = CreateSolidBrush(RGB(255, 255,255));
                    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
                    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
                    wc.hInstance = hin;
                    wc.lpszClassName = L"HAddAttendee";
                    wc.lpfnWndProc = [](HWND hwnd3, UINT msg3, WPARAM wp3, LPARAM lp3)->LRESULT CALLBACK{
                          switch(msg3){
                              case WM_CTLCOLORSTATIC:{
                                  HDC dc = GetDC(reinterpret_cast<HWND>(wp3));
                                  SetBkColor(dc, RGB(255, 255, 255));
                                  return reinterpret_cast<UINT_PTR>(CreateSolidBrush(RGB(255, 255, 255)));
                              }
                              case WM_COMMAND:{
                                  switch(wp3){
                                      case AttendeeButton:{
                                          std::allocator<char> Alloc;
                                          char name[512], Rank[256];
                                          GetWindowText(hAddEdit, name, sizeof(name));
                                          GetWindowText(hRank, Rank, sizeof(Rank));
                                          if(strcmp(name, "") == 0 || strcmp(Rank, "") == 0){
                                              MessageBoxW(hwnd3, L"One of the fields is empty, please fill it.", L"", MB_OK | MB_ICONERROR);
                                              break;
                                          }
                                          if(GeneralDatabase.find(name) != GeneralDatabase.end()){
                                              DestroyWindow(hwnd3);
                                              MessageBoxW(GeneralWindowHandler, L"Name is already existing.", L"", MB_OK | MB_ICONERROR);
                                              memset(&hwnd3, 0, sizeof(hwnd3));
                                              break;
                                          }
                                          GeneralDatabase[std::string(name)] = std::vector<std::string>{std::string(Rank), "0"};
                                          IsWindowOpen = false;
                                          std::string Name;
                                          Name.append(std::string(name));
                                          TemporaryName = Name;
                                          Name.append(std::string("("));
                                          Name.append(std::string(Rank));
                                          Name.append(std::string(")"));
                                          std::wstring NameW(Name.begin(), Name.end());
                                          SendMessageW(hListAtt, LB_ADDSTRING, (WPARAM)0, (LPARAM)NameW.c_str());
                                          char* score = Alloc.allocate(2);
                                          itoa(MaxScoreVal, score, 10);
                                          std::string Sentence = "0/" + std::string(score);
                                          std::wstring SentenceW(Sentence.begin(), Sentence.end());
                                          SendMessageW(hListScore, LB_ADDSTRING, (WPARAM)0, (LPARAM)SentenceW.c_str());
                                          DestroyWindow(hwnd3);
                                          memset(&hwnd3, 0, sizeof(hwnd3));

                                          Alloc.deallocate(score, 2);
                                          break;
                                      }
                                  }
                                  break;
                              }
                              case WM_CLOSE:{
                                          char name[512], Rank[256];
                                          GetWindowText(hAddEdit, name, sizeof(name));
                                          GetWindowText(hRank, Rank, sizeof(Rank));
                                          if(strcmp(name, "") == 0 || strcmp(Rank, "") == 0){
                                              MessageBoxW(hwnd3, L"One of the fields is empty, please fill it.", L"", MB_OK | MB_ICONERROR);
                                              break;
                                          }
                                          if(GeneralDatabase.find(name) != GeneralDatabase.end()){
                                              DestroyWindow(hwnd3);
                                              MessageBoxW(GeneralWindowHandler, L"Name is already existing.", L"", MB_OK | MB_ICONERROR);
                                              memset(&hwnd3, 0, sizeof(hwnd3));
                                              break;
                                          }

                                          GeneralDatabase[std::string(name)] = std::vector<std::string>{std::string(Rank), "0"};
                                          IsWindowOpen = false;
                                          std::string Name;
                                          Name.append(std::string(name));
                                          TemporaryName = Name;
                                          Name.append(std::string("("));
                                          Name.append(std::string(Rank));
                                          Name.append(std::string(")"));
                                          std::wstring NameW(Name.begin(), Name.end());
                                          SendMessageW(hListAtt, LB_ADDSTRING, (WPARAM)0, (LPARAM)NameW.c_str());
                                          std::allocator<char> Alloc;
                                          char* score = Alloc.allocate(2);
                                          itoa(MaxScoreVal, score, 10);
                                          std::string Sentence = "0/" + std::string(score);
                                          std::wstring SentenceW(Sentence.begin(), Sentence.end());
                                          SendMessageW(hListScore, LB_ADDSTRING, (WPARAM)0, (LPARAM)SentenceW.c_str());
                                          DestroyWindow(hwnd3);
                                          memset(&hwnd3, 0, sizeof(hwnd3));

                                          Alloc.deallocate(score, 2);
                                          break;
                              }
                              case WM_CREATE:{
                                  IsWindowOpen = true;

                                  SendMessageW(CreateWindowW(L"Static", L"Name : ", WS_VISIBLE | WS_CHILD, 5, 25, 55, 20, hwnd3, 0, 0, 0), WM_SETFONT, (WPARAM)CreateFontW(20, 0, 0, 0, FF_DONTCARE, 0, 0, 0, 0,0,0,0,0, L"Georgia"), (LPARAM)TRUE);

                                  hAddEdit = CreateWindowW(L"Edit", L"", WS_VISIBLE | WS_CHILD | ES_AUTOHSCROLL | WS_BORDER, 75, 27, 215, 20, hwnd3, 0, 0, 0);

                                  hAddAttBut = CreateWindowW(L"Button", L"Insert", WS_VISIBLE | WS_CHILD | WS_BORDER, 110, 170, 80, 40,  hwnd3, (HMENU)AttendeeButton, 0, 0);

                                  SendMessageW(CreateWindowW(L"Static", L"Rank : ", WS_VISIBLE | WS_CHILD, 5, 75, 55, 20, hwnd3, 0 ,0 ,0), WM_SETFONT, (WPARAM)CreateFontW(20, 0, 0, 0, FF_DONTCARE, 0, 0, 0, 0,0,0,0,0, L"Georgia"), (LPARAM)TRUE);
                                  hRank = CreateWindowW(L"ComboBox", L"", WS_VISIBLE | WS_CHILD | CBS_DROPDOWN | CBS_DROPDOWNLIST, 75, 77, 215, 120, hwnd3, 0, 0, 0);
                                  if(strcmp(TypeVal.c_str(), "Joint departmental training") == 0){
                                      SendMessageW(hRank, CB_ADDSTRING, (WPARAM)0, (LPARAM)L"SD");
                                      SendMessageW(hRank, CB_ADDSTRING, (WPARAM)0, (LPARAM)L"MTF");
                                  }
                                  else if(strcmp(TypeVal.c_str(), "Cadet test") == 0){
                                      SendMessageW(hRank, CB_ADDSTRING, (WPARAM)0, (LPARAM)L"Cadet");
                                      SendMessageW(hRank, CB_SETCURSEL, (WPARAM)0, (LPARAM)0);
                                      EnableWindow(hRank, false);
                                  }
                                  else{
                                      SendMessageW(hRank, CB_ADDSTRING, (WPARAM)0, (LPARAM)L"Cadet");
                                      SendMessageW(hRank, CB_ADDSTRING, (WPARAM)0, (LPARAM)L"Junior");
                                      SendMessageW(hRank, CB_ADDSTRING, (WPARAM)0, (LPARAM)L"Sentinel");
                                  }
                                  break;
                              }
                              case WM_DESTROY:{
                                  if(!TemporaryName.empty()){

                                      AddListString(TemporaryName);
                                      TemporaryName = "";
                                  }
                                  DestroyWindow(hwnd3);
                                  memset(&hwnd3, 0, sizeof(hwnd3));
                                  IsWindowOpen = false;

                                  break;
                              }
                              default:{
                                  DefWindowProcW(hwnd3, msg3, wp3, lp3);

                              }
                          }
                      };
                    if(IsAttendeeRegistered == false){
                       IsAttendeeRegistered = true;
                       if(!RegisterClassW(&wc)){
                          MessageBoxW(hwnd, L"Failed to register.", L"", MB_OK | MB_ICONERROR);
                          break;
                       }
                    }
                    CreateWindowW(L"HAddAttendee", L"Insert attendee to the list", WS_VISIBLE | WS_SYSMENU | WS_MINIMIZEBOX, ((xScreen/2)-150), ((yScreen/2)-125), 300, 250, 0, 0, 0, 0);
                    break;
                }
                case DismissAttendee:{
                    if(IsWindowOpen){
                        MessageBoxW(hwnd, L"Cannot perform such an action; another window is already open.", L"", MB_ICONERROR | MB_OK);
                        break;
                    }
                    if(!LogExisting){
                        MessageBoxW(hwnd, L"No log existing currently.", L"Error 404 - No log found", MB_OK | MB_ICONERROR);
                        break;
                    }
                    break;
                }
                case RemoveAttendee:{
                    if(IsWindowOpen){
                        MessageBoxW(hwnd, L"Cannot perform such an action; another window is already open.", L"", MB_ICONERROR | MB_OK);
                        break;
                    }
                    if(!LogExisting){
                        MessageBoxW(hwnd, L"No log existing currently.", L"Error 404 - No log found", MB_OK | MB_ICONERROR);
                        break;
                    }
                    break;
                }
                case SaveLOG:{
                    if(IsWindowOpen){
                        MessageBoxW(hwnd, L"Cannot perform such an action; another window is already open.", L"", MB_ICONERROR | MB_OK);
                        break;
                    }
                    if(!LogExisting){
                        MessageBoxW(hwnd, L"No log existing currently.", L"Error 404 - No log found", MB_OK | MB_ICONERROR);
                        break;
                    }
                    break;
                }
            }
            break;
        }
        case WM_CREATE:{
            Menus(hwnd);
            break;
        }
        case WM_DESTROY:{
            PostQuitMessage(0);
            break;
        }
        default:{
            DefWindowProcW(hwnd, message, wp, lp);
        }
    }
}

void SecondWindowInitiation(HWND hwnd){

                                HFONT hFont = CreateFont(20, 0, 0, 0, FF_DONTCARE, 0 , 0 , 0 , 0 , 0 ,0 , 0 , 0, "Arial");
                                HWND hType = CreateWindowW(L"Static", L"Type  : ", WS_VISIBLE | WS_CHILD, 40, 70, 100, 35, hwnd, 0, 0, 0);
                                SendMessageW(hType, WM_SETFONT, (WPARAM)hFont, (LPARAM)0);
                                Type = CreateWindowW(L"COMBOBOX", L"", WS_VISIBLE | WS_CHILD | CBS_DROPDOWN | CBS_DROPDOWNLIST ,180,70, 200, 210, hwnd, 0, 0,0);


                                SendMessageW(Type, CB_ADDSTRING, 0, (LPARAM)L"Cadet test");
                                SendMessageW(Type, CB_ADDSTRING, 0, (LPARAM)L"Standard training");
                                SendMessageW(Type, CB_ADDSTRING, 0, (LPARAM)L"Combative training");
                                SendMessageW(Type, CB_ADDSTRING, 0, (LPARAM)L"Introductory seminar");
                                SendMessageW(Type, CB_ADDSTRING, 0, (LPARAM)L"Joint departmental training");
                                HWND hCoHost = CreateWindowW(L"Static", L"Co-host(N/A)  : ", WS_VISIBLE | WS_CHILD, 40, 125, 100, 35, hwnd, 0, 0, 0);
                                SendMessageW(hCoHost, WM_SETFONT, (WPARAM)hFont, (LPARAM)0);

                                CoHost = CreateWindowW(L"Edit", L"", WS_VISIBLE | WS_CHILD | ES_AUTOHSCROLL | WS_BORDER, 180, 125, 150, 20, hwnd, 0, 0, 0);

                                HWND hLocation = CreateWindowW(L"Static", L"Location  : ", WS_VISIBLE | WS_CHILD, 40, 180, 100, 35, hwnd, 0, 0, 0);
                                SendMessageW(hLocation, WM_SETFONT, (WPARAM)hFont, (LPARAM)0);
                                Location = CreateWindowW(L"COMBOBOX", L"", WS_VISIBLE | WS_CHILD | CBS_DROPDOWN | CBS_DROPDOWNLIST ,180,180, 160, 210, hwnd, 0, 0,0);

                                SendMessageW(Location, CB_ADDSTRING, (WPARAM)0, (LPARAM)L"Zone-A(Surface exit)");
                                SendMessageW(Location, CB_ADDSTRING, (WPARAM)0, (LPARAM)L"SD spawn");
                                SendMessageW(Location, CB_ADDSTRING, (WPARAM)0, (LPARAM)L"Containment zones");
                                SendMessageW(Location, CB_ADDSTRING, (WPARAM)0, (LPARAM)L"Outside the facility");

                                hOther = CreateWindowW(L"Button", L"", WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX, 360, 176, 30, 30, hwnd, (HMENU)OtherButtonClick, 0, 0); 

                                HFONT hFontO = CreateFont(10, 0, 0, 0, FF_DONTCARE, 0 , 0 , 0 , 0 , 0 ,0 , 0 , 0, "Arial");
                                HWND sOther = CreateWindowW(L"Static", L"Other", WS_VISIBLE | WS_CHILD, 348, 200, 50, 30, hwnd, 0, 0, 0);   

                                SendMessageW(sOther, WM_SETFONT, (WPARAM)0, (LPARAM)hFontO);

                                hDone = CreateWindowW(L"Button", L"Save", WS_BORDER | WS_CHILD | WS_VISIBLE, 250, 300, 100, 50, hwnd, (HMENU)DoneButton, 0, 0);

                                HFONT hFontB = CreateFont(20, 0, 0, 0, FF_DONTCARE, 0 , 0 , 0 , 0 , 0 ,0 , 0 , 0, "Comic Sans MS");
                                SendMessageW(hDone, WM_SETFONT, (WPARAM)hFontB, (LPARAM)0);
}

void FirstWindowInitiation(HWND hwnd){

                    SendMessageW(CreateWindowW(L"Static", L"Name: ", WS_VISIBLE | WS_CHILD, 150, 25, 80, 40, hwnd, 0, 0, 0), WM_SETFONT, (WPARAM)CreateFontW(30, 0, 0, 0, FF_DONTCARE, 0, 0, 0, 0, 0, 0, 0, 0, L"Bold"), (LPARAM)TRUE);
                    hNames = CreateWindowW(L"ComboBox", L"", WS_VISIBLE | WS_CHILD | CBS_DROPDOWN | CBS_DROPDOWNLIST, 250, 29, 200, 500, hwnd, 0, 0, 0);
                    hPoint = CreateWindowW(L"ComboBox", L"", WS_VISIBLE | WS_CHILD | CBS_DROPDOWN | CBS_DROPDOWNLIST, 460, 29, 65, 300, hwnd, 0, 0, 0);

                    for(double x = 0.25; x != 4.25; x += 0.25){

                        std::stringstream ss;
                        ss << std::setprecision(std::numeric_limits<double>::digits10) << x;
                        std::string Num = ss.str();
                        std::wstring wNum(Num.begin(), Num.end());
                        SendMessageW(hPoint, CB_ADDSTRING, (WPARAM)0, (LPARAM)wNum.c_str());
                    }   
                    HFONT Font =  CreateFontW(20, 0, 0, 0, FF_DONTCARE, 0, 0, 0, 0, 0, 0, 0, 0, L"Britannic Bold");                 
                    hIncrease = CreateWindowW(L"Button", L"Increase", WS_VISIBLE | WS_BORDER | WS_CHILD, 550, 14, 150, 55, hwnd, (HMENU)IncreaseButton, 0, 0);
                    hDecrease = CreateWindowW(L"Button", L"Decrease", WS_VISIBLE | WS_BORDER | WS_CHILD, 720, 14, 150, 55, hwnd, (HMENU)DecreaseButton, 0, 0);
                    SendMessageW(hIncrease, WM_SETFONT, (WPARAM)Font, (LPARAM)TRUE);
                    SendMessageW(hDecrease, WM_SETFONT, (WPARAM)Font, (LPARAM)TRUE);

}

void Menus(HWND hwnd){
            // Menus
            HMENU hMenu = CreateMenu();
            HMENU hFileMenu = CreateMenu();
            HMENU Attendee = CreateMenu();

            // Log menu
            AppendMenuW(hMenu, MF_POPUP, reinterpret_cast<UINT_PTR>(hFileMenu), L"Log");
            AppendMenuW(hFileMenu, MF_STRING, static_cast<UINT_PTR>(NewLOG), L"New log");
            AppendMenuW(hFileMenu, MF_SEPARATOR, 0, 0);
            AppendMenuW(hFileMenu, MF_STRING, static_cast<UINT_PTR>(SaveLOG), L"Save log");

            // Attendee Menu

            AppendMenuW(hMenu, MF_POPUP, reinterpret_cast<UINT_PTR>(Attendee), L"Attendees");
            AppendMenuW(Attendee, MF_STRING, static_cast<UINT_PTR>(AddAttendee), L"Add an attendee");
            AppendMenuW(Attendee, MF_SEPARATOR, 0, 0);
            AppendMenuW(Attendee, MF_STRING, static_cast<UINT_PTR>(DismissAttendee), L"Dismiss an attendee");
            AppendMenuW(Attendee, MF_STRING, static_cast<UINT_PTR>(RemoveAttendee), L"Remove an attendee");

            SetMenu(hwnd, hMenu);

            // Lists

}
void AddListString(std::string str){
    std::wstring d(str.begin(), str.end());
    SendMessageW(hNames, CB_ADDSTRING, (WPARAM)true, (LPARAM)d.c_str());

}

inline void IncreaseButtonAction(HWND hwnd){
    char Name[256], point[4];
}

1 Ответ

0 голосов
/ 04 мая 2020

Этот ответ от имени @Igor Tandetnik:

Все, что мне нужно сделать, это поставить return 0; в конце каждого оператора switch-case и каждого сообщения следующим образом:

WM_CREATE:{
 ... // Code
 return 0; // If everything goes fine.
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...