Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <tchar.h>
- #include <iostream>
- using namespace std;
- const char g_szClassName[] = "handle1";
- HWND Button1; /* HANDLE de nossos objetos */
- HWND NewContact; // HANDLE do Window Contatc
- HWND Nome, Numero, Add; // HANDLE do Window Contatc
- #define intButton1 1002 /*IDs de nossos objetos*/
- #define intEdit1 1003 /*IDs de nossos objetos*/
- #define intEdit2 1004 /*IDs de nossos objetos*/
- #define intAdd1 1005 /*IDs de nossos objetos*/
- // Step 4: the Window Procedure
- LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
- {
- switch(msg)
- {
- case WM_COMMAND:
- {
- if(LOWORD(wParam) == intButton1)
- {
- //MessageBox(NULL, "Você acabou de clicar em um botão", "Informação!", MB_ICONINFORMATION | MB_OK);
- ShowWindow(NewContact, SW_SHOW);
- UpdateWindow(NewContact);
- ShowWindow(Nome, SW_SHOW);
- UpdateWindow(Nome);
- ShowWindow(Numero, SW_SHOW);
- UpdateWindow(Numero);
- ShowWindow(Add, SW_SHOW);
- UpdateWindow(Add);
- }
- if(LOWORD(wParam) == intAdd1)
- {
- char GNome[128], GNumero[30];
- GetWindowText(Nome, (LPWSTR)GNome, 128);
- GetWindowText(Numero, (LPWSTR)GNumero, 30);
- cout << "Você Adicionou um Novo Contato:" << endl;
- cout << "Nome" << GNome << endl;
- cout << "Numero" << GNumero << endl;
- //DestroyWindow(NewContact);
- //DestroyWindow(Nome);
- //DestroyWindow(Numero);
- //DestroyWindow(Add);
- }
- break;
- }
- case WM_CLOSE:
- DestroyWindow(hwnd);
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- default:
- return DefWindowProc(hwnd, msg, wParam, lParam);
- }
- return 0;
- }
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR lpCmdLine, int nCmdShow)
- {
- WNDCLASSEX wc;
- HWND hwnd;
- MSG Msg;
- //Step 1: Registering the Window Class
- wc.cbSize = sizeof(WNDCLASSEX);
- wc.style = 0;
- wc.lpfnWndProc = WndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = hInstance;
- wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
- wc.lpszMenuName = NULL;
- wc.lpszClassName = (LPWSTR)g_szClassName;
- wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
- if(!RegisterClassEx(&wc))
- {
- MessageBox(NULL, _T("Window Registration Failed!"), _T("Error!"),
- MB_ICONEXCLAMATION | MB_OK);
- return 0;
- }
- // Step 2: Creating the Window
- hwnd = CreateWindowEx(
- WS_EX_CLIENTEDGE,
- (LPCWSTR)g_szClassName,
- _T("Agenda Virtual"),
- WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT, CW_USEDEFAULT, 440, 220,
- NULL, NULL, hInstance, NULL);
- if(hwnd == NULL)
- {
- MessageBox(NULL, _T("Falha na criação da GUI!"), _T("Error!"),
- MB_ICONEXCLAMATION | MB_OK);
- return 0;
- }
- NewContact = CreateWindowEx(
- WS_EX_CLIENTEDGE,
- (LPCWSTR)g_szClassName,
- _T("Adicionar Contato"),
- WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT, CW_USEDEFAULT, 200, 120,
- NULL, NULL, hInstance, NULL);
- Button1 = CreateWindowEx(0, _T("BUTTON"), _T("Adicionar Contato"), WS_CHILD + WS_VISIBLE + WS_TABSTOP, 50, 50, 120, 20, hwnd, (HMENU)intButton1, hInstance, 0); /*Nosso button */
- Nome = CreateWindowEx(0, _T("EDIT"), _T("Nome"), WS_CHILD + WS_VISIBLE + WS_TABSTOP, 20, 10, 120, 20, NewContact, (HMENU)intEdit1, hInstance, 0);
- Numero = CreateWindowEx(0, _T("EDIT"), _T("Numero"), WS_CHILD + WS_VISIBLE + WS_TABSTOP, 20, 30, 120, 20, NewContact, (HMENU)intEdit2, hInstance, 0);
- Add = CreateWindowEx(0, _T("BUTTON"), _T("Adicionar Contato"), WS_CHILD + WS_VISIBLE + WS_TABSTOP, 20, 50, 120, 20, NewContact, (HMENU)intAdd1, hInstance, 0); /*Nosso button */
- ShowWindow(Button1, nCmdShow);
- ShowWindow(hwnd, nCmdShow);
- UpdateWindow(hwnd);
- UpdateWindow(Button1);
- // Step 3: The Message Loop
- while(GetMessage(&Msg, NULL, 0, 0) > 0)
- {
- TranslateMessage(&Msg);
- DispatchMessage(&Msg);
- }
- return Msg.wParam;
- }
Advertisement
Add Comment
Please, Sign In to add comment