Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Podgotovka za TESTA.cpp : Defines the entry point for the application.
- //
- #include "stdafx.h"
- #include "Podgotovka za TESTA.h"
- #include "strsafe.h"//added by me
- #include <string>//added by me
- #define MAX_LOADSTRING 100
- // Global Variables:
- HINSTANCE hInst; // current instance
- TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
- TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
- // Forward declarations of functions included in this code module:
- ATOM MyRegisterClass(HINSTANCE hInstance);
- BOOL InitInstance(HINSTANCE, int);
- LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
- INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
- INT_PTR CALLBACK TestPROBA(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
- int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
- _In_opt_ HINSTANCE hPrevInstance,
- _In_ LPTSTR lpCmdLine,
- _In_ int nCmdShow)
- {
- UNREFERENCED_PARAMETER(hPrevInstance);
- UNREFERENCED_PARAMETER(lpCmdLine);
- // TODO: Place code here.
- MSG msg;
- HACCEL hAccelTable;
- // Initialize global strings
- LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
- LoadString(hInstance, IDC_PODGOTOVKAZATESTA, szWindowClass, MAX_LOADSTRING);
- MyRegisterClass(hInstance);
- // Perform application initialization:
- if (!InitInstance (hInstance, nCmdShow))
- {
- return FALSE;
- }
- hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_PODGOTOVKAZATESTA));
- // Main message loop:
- while (GetMessage(&msg, NULL, 0, 0))
- {
- if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- }
- return (int) msg.wParam;
- }
- //
- // FUNCTION: MyRegisterClass()
- //
- // PURPOSE: Registers the window class.
- //
- ATOM MyRegisterClass(HINSTANCE hInstance)
- {
- WNDCLASSEX wcex;
- wcex.cbSize = sizeof(WNDCLASSEX);
- wcex.style = CS_HREDRAW | CS_VREDRAW;
- wcex.lpfnWndProc = WndProc;
- wcex.cbClsExtra = 0;
- wcex.cbWndExtra = 0;
- wcex.hInstance = hInstance;
- wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_PODGOTOVKAZATESTA));
- wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
- wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
- wcex.lpszMenuName = MAKEINTRESOURCE(IDC_PODGOTOVKAZATESTA);
- wcex.lpszClassName = szWindowClass;
- wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
- return RegisterClassEx(&wcex);
- }
- //
- // FUNCTION: InitInstance(HINSTANCE, int)
- //
- // PURPOSE: Saves instance handle and creates main window
- //
- // COMMENTS:
- //
- // In this function, we save the instance handle in a global variable and
- // create and display the main program window.
- //
- BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
- {
- HWND hWnd;
- hInst = hInstance; // Store instance handle in our global variable
- hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
- if (!hWnd)
- {
- return FALSE;
- }
- ShowWindow(hWnd, nCmdShow);
- UpdateWindow(hWnd);
- return TRUE;
- }
- //
- // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
- //
- // PURPOSE: Processes messages for the main window.
- //
- // WM_COMMAND - process the application menu
- // WM_PAINT - Paint the main window
- // WM_DESTROY - post a quit message and return
- //
- //
- LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- int wmId, wmEvent;
- PAINTSTRUCT ps;
- HDC hdc;
- POINT pt;
- HMENU hMenu, hSubMenu, hPopUpMenu;
- DWORD dwRes;
- BOOL bRes;
- UINT uRes, uResPopUp;
- switch (message)
- {
- case WM_COMMAND:
- wmId = LOWORD(wParam);
- wmEvent = HIWORD(wParam);
- // Parse the menu selections:
- switch (wmId)
- {
- case IDM_MSGBOX:
- MessageBox(hWnd, L"Message", L"MSG", MB_OK);
- break;
- case IDM_DIALOGPROBA:
- DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG), hWnd, TestPROBA);
- break;
- case IDM_ENABLE_DISABLE:
- hMenu = GetMenu(hWnd);
- uRes = GetMenuState(hMenu, IDM_E_D, MF_BYCOMMAND);
- bRes = EnableMenuItem(hMenu, IDM_E_D, (uRes & MF_DISABLED) ? MF_ENABLED : MF_DISABLED);
- break;
- case IDM_CHECK_UNCHECK://we chech C/U in the menu
- hMenu = GetMenu(hWnd);
- dwRes = CheckMenuItem(hMenu, IDM_C_U, MF_BYCOMMAND);
- if (dwRes == CheckMenuItem(hMenu, IDM_C_U, MF_CHECKED)) {
- CheckMenuItem(hMenu, IDM_C_U, MF_CHECKED);
- }
- else CheckMenuItem(hMenu, IDM_C_U, MF_UNCHECKED);
- break;
- case IDM_A_D://iztrivam A/D kato go natisna
- hMenu = GetMenu(hWnd);
- bRes = DeleteMenu(hMenu, IDM_A_D, MF_BYCOMMAND);
- break;
- case IDM_ADD_DELETE://dobavqm A/D kato natisna Add/Delete,kato se vuzstanovqva purvonachalnoto menu
- hMenu = GetMenu(hWnd);
- hSubMenu = GetSubMenu(hMenu, 3);
- if (GetMenuState(hMenu, IDM_A_D, MF_BYCOMMAND) == -1) {
- MENUITEMINFO miinf;
- ZeroMemory(&miinf, sizeof(miinf));
- miinf.cbSize = sizeof(miinf);
- miinf.fMask = MIIM_ID | MIIM_TYPE | MIIM_STATE;
- miinf.wID = IDM_A_D;
- miinf.fType = MFT_STRING;
- miinf.dwTypeData = (LPWSTR)_T("A/D");
- miinf.fState = MFS_ENABLED;
- bRes = InsertMenuItem(hMenu, IDM_ADD_DELETE, FALSE, &miinf);
- }
- break;
- case IDM_ABOUT:
- DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
- break;
- case IDM_EXIT:
- DestroyWindow(hWnd);
- break;
- default:
- return DefWindowProc(hWnd, message, wParam, lParam);
- }
- break;
- case WM_RBUTTONDOWN://s tozi case se pokazva PopUp menuto
- hPopUpMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_POPUP_MENU));
- hSubMenu = GetSubMenu(hPopUpMenu, 0);
- hMenu = GetMenu(hWnd);//taka se Desable-va E/D osven v glavnoto menu a i v PopUp menuto
- uResPopUp = GetMenuState(hMenu, IDM_E_D, MF_BYCOMMAND);
- bRes = EnableMenuItem(hPopUpMenu, IDM_E_D, (!uResPopUp) ? MF_ENABLED : MF_DISABLED);
- pt = { LOWORD(lParam), HIWORD(lParam) };
- ClientToScreen(hWnd, &pt);
- TrackPopupMenu(hSubMenu, TPM_RIGHTBUTTON, pt.x, pt.y, 0, hWnd, NULL);
- DestroyMenu(hPopUpMenu);
- break;
- case WM_PAINT:
- hdc = BeginPaint(hWnd, &ps);
- // TODO: Add any drawing code here...
- EndPaint(hWnd, &ps);
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- default:
- return DefWindowProc(hWnd, message, wParam, lParam);
- }
- return 0;
- }
- // Message handler for about box.
- INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
- {
- UNREFERENCED_PARAMETER(lParam);
- switch (message)
- {
- case WM_INITDIALOG:
- return (INT_PTR)TRUE;
- case WM_COMMAND:
- if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
- {
- //int idMsg = MessageBox(hDlg, L"do you want to ext? Pls confirm", L"About exit", MB_ICONEXCLAMATION | MB_OKCANCEL); //v About izliza subshtenie i pita dali da ostana
- //if (idMsg == IDOK)
- EndDialog(hDlg, LOWORD(wParam));
- return (INT_PTR)TRUE;
- }
- break;
- }
- return (INT_PTR)FALSE;
- }
- INT_PTR CALLBACK TestPROBA(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) {//nova funkciq
- WCHAR szText[MAX_LOADSTRING];
- int intVal;//Извличане на текст – цяло число :
- BOOL bSigned, bSuccess;
- double dVal;//Извличане на текст – реално число
- std::string::size_type sz;
- UNREFERENCED_PARAMETER(lParam);
- switch (message)
- {
- case WM_INITDIALOG:
- return (INT_PTR)TRUE;
- case WM_COMMAND:
- UINT status;
- int wmId = LOWORD(wParam);
- switch (wmId)
- {
- case IDC_BTN_PROBA://Извличане на текст-стринг: GetDlgItemText
- if (!GetDlgItemText(hDlg, IDC_EDIT_EGN, szText, MAX_LOADSTRING))
- *szText = 0;
- MessageBox(hDlg, szText, L"Info", MB_OK);
- return (INT_PTR)TRUE;
- break;
- case IDC_BUTTON2://Извличане на текст – цяло число , pokazva go v Edit control
- // requires #include "strsafe.h"
- bSigned = IsDlgButtonChecked(hDlg, IDC_CB_HIDDEN);
- intVal = GetDlgItemInt(hDlg, IDC_EDIT_EGN, &bSuccess, bSigned);
- if (!bSuccess)
- {
- MessageBox(hDlg, L"Error to extract integer value", L"Error!", MB_OK);
- SetFocus(GetDlgItem(hDlg, IDC_EDIT_EGN));
- }
- else
- {
- StringCbPrintf(szText, ARRAYSIZE(szText),
- L"The value is \"%i\"", intVal);
- MessageBox(hDlg, szText, L"Done!", MB_OK);
- }
- return (INT_PTR)TRUE;
- case IDC_BUTTON3://Извличане на текст – реално число, pri natiskane na Buton 3 pravi chisloto realno
- // requires #include <string>
- try {
- if (!GetDlgItemText(hDlg, IDC_EDIT_EGN, szText, MAX_LOADSTRING))
- *szText = 0;
- dVal = std::stod(szText, &sz);
- StringCbPrintf(szText, ARRAYSIZE(szText), L"The value is \"%f\"",
- dVal);
- MessageBox(hDlg, szText, L"Done!", MB_OK);
- }
- catch (std::exception& e){
- MessageBox(hDlg, L"Error to extract double value", L"Error!",
- MB_ICONERROR | MB_OK);
- dVal = 0.0;
- }
- return (INT_PTR)TRUE;
- break;
- case IDC_BTN4:
- //MessageBox(hDlg, L"text", L"caption", MB_OK);
- //MessageBox(hDlg, L"text", L"caption", MB_OKCANCEL);
- //MessageBox(hDlg, L"text", L"caption", MB_YESNO);
- //MessageBox(hDlg, L"text", L"caption", MB_ICONWARNING);
- //MessageBox(hDlg, L"text", L"caption", MB_ICONINFORMATION);
- //MessageBox(hDlg, L"text", L"caption", MB_ICONQUESTION);
- //MessageBox(hDlg, L"text", L"caption", MB_ICONSTOP);
- MessageBox(hDlg, L"text", L"caption", MB_ICONHAND);
- case IDC_RB_ADULT://Установяване на текст - число : SetDlgItemInt
- case IDC_RB_CHILD://Установяване на текст - число : SetDlgItemInt
- SetDlgItemInt(hDlg, IDC_EDIT_EGN, IsDlgButtonChecked(hDlg, IDC_RB_ADULT), FALSE);
- return (INT_PTR)TRUE;
- case IDC_CB_ReadOnly:
- status = IsDlgButtonChecked(hDlg, IDC_CB_ReadOnly);
- MessageBox(hDlg, status == BST_CHECKED ? L"\"Checked" : L"\"Unchecked", L"Info", MB_OK);
- return (INT_PTR)TRUE;
- //MessageBox(hDlg, IsDlgButtonChecked(hDlg, IDC_CB_ReadOnly) ? L"Button is pressed" : L" Button is uncheckd", L"da", MB_OK);//kak se pravi MessageBox
- break;
- case IDOK:
- case IDCANCEL:
- //int idMsg = MessageBox(hDlg, L"do you want to ext? Pls connnnnfirmmm", L"About exit", MB_ICONEXCLAMATION | MB_OKCANCEL);//pita me dali iskam da zatvorq DIALOGA
- //if (idMsg == IDOK)
- EndDialog(hDlg, LOWORD(wParam));
- return (INT_PTR)TRUE;
- break;
- }
- }
- return (INT_PTR)FALSE;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement