Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <string>
- #include "commctrl.h"
- #include <fstream>
- #include <vector>
- #include <algorithm>
- #include <tchar.h>
- #define ID_BUTTON 1
- #define ID_DROPBOX 2
- LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
- HANDLE hwndButton, hwndDropbox;
- bool isInTheVectorc(std::string passedString, std::vector<std::string>& passed_vector);
- void CenterWindow(HWND);
- std::string lpwstrToString(LPWSTR var);
- LPWSTR stringToLPWSTR(const std::string& instr);
- std::ifstream groups("groups_ldap_primary");
- std::string shareGroup;
- int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
- {
- MSG msg;
- WNDCLASSW wc = {0};
- wc.lpszClassName = L"test";
- wc.hInstance = hInstance;
- wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
- wc.lpfnWndProc = WndProc;
- wc.hCursor = LoadCursor(0, IDC_ARROW);
- RegisterClassW(&wc);
- CreateWindowW(wc.lpszClassName, L"Test106", WS_OVERLAPPEDWINDOW|WS_VISIBLE, 260, 118, 231, 235, 0, 0, hInstance, 0);
- while(GetMessage(&msg, NULL, 0, 0))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- return (int) msg.wParam;
- }
- LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
- {
- //shareGroup = "ABS";
- int counter = 0;
- std::vector<std::string> groupList;
- std::string passedGroup;
- TCHAR ListItem[256];
- switch(msg)
- {
- case WM_KEYDOWN:
- if (wParam == VK_ESCAPE)
- {
- int ret = MessageBoxW(hwnd, L"Woot?", L"Message", MB_OKCANCEL);
- if (ret == IDOK)
- {
- SendMessage(hwnd, WM_CLOSE, 0, 0);
- }
- }
- break;
- case WM_CREATE:
- CenterWindow(hwnd);
- hwndButton=CreateWindowW(L"Button", L"Click", WS_VISIBLE|WS_CHILD, 50, 50, 61, 21, hwnd, (HMENU)ID_BUTTON, NULL, NULL);
- hwndDropbox = CreateWindow(WC_COMBOBOX, TEXT(""), CBS_DROPDOWN | CBS_HASSTRINGS | WS_VSCROLL | WS_CHILD | WS_OVERLAPPED | WS_VISIBLE, 10, 10, 200, 200, hwnd, (HMENU)ID_DROPBOX, NULL, NULL);
- while(getline(groups, passedGroup, '\n'))
- {
- std::transform(passedGroup.begin(), passedGroup.end(),passedGroup.begin(), ::toupper);
- groupList.push_back(passedGroup);
- SendMessageW(GetDlgItem(hwnd, ID_DROPBOX), (UINT)CB_ADDSTRING, (WPARAM)counter, (LPARAM)stringToLPWSTR(passedGroup));
- counter++;
- }
- groups.close();
- SendMessage(GetDlgItem(hwnd, ID_DROPBOX), (UINT)CB_SETCURSEL, (WPARAM)0, (LPARAM)0);
- break;
- case WM_COMMAND:
- if(LOWORD(wParam)==ID_BUTTON)
- {
- if(shareGroup == "")
- {
- shareGroup = "ABS";
- }
- MessageBox(hwnd, stringToLPWSTR(shareGroup), TEXT("équipe"), MB_OK);
- }
- if(HIWORD(wParam) == CBN_SELCHANGE)
- {
- shareGroup.clear();
- int ItemIndex = SendMessage(GetDlgItem(hwnd, ID_DROPBOX), (UINT)CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
- (TCHAR) SendMessage(GetDlgItem(hwnd, ID_DROPBOX), (UINT) CB_GETLBTEXT, (WPARAM) ItemIndex, (LPARAM)ListItem);
- OutputDebugString(ListItem);
- shareGroup = lpwstrToString(ListItem);
- }
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- }
- return DefWindowProcW(hwnd, msg, wParam, lParam);
- }
- void CenterWindow(HWND hwnd)
- {
- RECT rc = {0};
- GetWindowRect(hwnd, &rc);
- int win_w = rc.right - rc.left;
- int win_h = rc.bottom - rc.top;
- int screen_w = GetSystemMetrics(SM_CXSCREEN);
- int screen_h = GetSystemMetrics(SM_CYSCREEN);
- SetWindowPos(hwnd, HWND_TOP, (screen_w - win_w)/2, (screen_h - win_h)/2, 0, 0, SWP_NOSIZE);
- }
- std::string lpwstrToString(LPWSTR input)
- {
- int cSize = WideCharToMultiByte (CP_ACP, 0, input, wcslen(input), NULL, 0, NULL, NULL);
- std::string output(static_cast<size_t>(cSize), '\0');
- WideCharToMultiByte (CP_ACP, 0, input, wcslen(input), reinterpret_cast<char*>(&output[0]), cSize, NULL, NULL);
- return output;
- }
- LPWSTR stringToLPWSTR(const std::string& instr)
- {
- int bufferlen = ::MultiByteToWideChar(CP_ACP, 0, instr.c_str(), instr.size(), NULL, 0);
- LPWSTR widestr = new WCHAR[bufferlen + 1];
- ::MultiByteToWideChar(CP_ACP, 0, instr.c_str(), instr.size(), widestr, bufferlen);
- widestr[bufferlen] = 0;
- return widestr;
- }
- bool isInTheVectorc(std::string passedString, std::vector<std::string>& passedVector)
- {
- bool isInTheVector=false;
- for(size_t i=0, size=passedVector.size(); i<size; ++i)
- {
- std::transform(passedString.begin(), passedString.end(), passedString.begin(), ::tolower);
- if(passedVector.at(i)==passedString)
- {
- isInTheVector = true;
- break;
- }
- }
- return isInTheVector;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement