Advertisement
AHelpfulOne

My Full Code

Sep 14th, 2013
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.75 KB | None | 0 0
  1. #define _WIN32_WINNT 0x0600
  2. #define _WIN32_IE 0x0900
  3. #include <windows.h>
  4. #include <commctrl.h>
  5. #include <Tchar.h>
  6.  
  7. #define IDC_BUTTON_1 101
  8. #define IDC_EDIT_1 201
  9. #define IDC_EDIT_2 202
  10. #define IDC_STATIC_1 301
  11. #define IDC_STATIC_2 302
  12. #define IDC_COMBO_BOX_1 401
  13.  
  14. const char g_ClassName[] = "WindowClass1";
  15. HIMAGELIST g_himl;
  16.  
  17. LRESULT CALLBACK MainWindowProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
  18.     switch(Message) {
  19.         case WM_CTLCOLORSTATIC: {
  20.             DWORD CtrlID = GetDlgCtrlID((HWND)lParam);
  21.  
  22.             if (CtrlID = IDC_STATIC_1) {
  23.                 HDC hdcStatic = (HDC) wParam;
  24.                 SetBkMode(hdcStatic, TRANSPARENT);
  25.                 SetBkColor(hdcStatic, RGB(230,230,230));
  26.             }
  27.         }
  28.         break;
  29.         case WM_COMMAND: {
  30.             switch(LOWORD(wParam)) {
  31.                 case IDC_BUTTON_1: {
  32.  
  33.                     int TextLen1 = GetWindowTextLength(GetDlgItem(hwnd, IDC_EDIT_1));
  34.                     int TextLen2 = GetWindowTextLength(GetDlgItem(hwnd, IDC_EDIT_2));
  35.  
  36.                     if(TextLen1 > 0) {
  37.                         char* buf;
  38.  
  39.                         buf = (char*)GlobalAlloc(GPTR, TextLen1 + 1);
  40.                         GetDlgItemText(hwnd, IDC_EDIT_1, buf, TextLen1 + 1);
  41.  
  42.                         if(TextLen2 > 0) {
  43.                             char* buf2;
  44.  
  45.                             buf2 = (char*)GlobalAlloc(GPTR, TextLen2 + 1);
  46.                             GetDlgItemText(hwnd, IDC_EDIT_2, buf2, TextLen2 + 1);
  47.  
  48.                             MessageBox(hwnd, buf, buf2, MB_OK | MB_ICONINFORMATION);
  49.  
  50.                             GlobalFree((HANDLE)buf2);
  51.  
  52.                         } else {
  53.                              MessageBox(hwnd, "Not enough information!", "ERROR", MB_OK | MB_ICONWARNING);
  54.                         }
  55.  
  56.  
  57.                         GlobalFree((HANDLE)buf);
  58.                     } else {
  59.                         MessageBox(hwnd, "Not enough information!", "ERROR", MB_OK | MB_ICONWARNING);
  60.                     }
  61.  
  62.                 }
  63.             }
  64.         }
  65.         break;
  66.         case WM_CREATE: {
  67.             HWND Combo1 = CreateWindowEx(
  68.             NULL, WC_COMBOBOXEX, NULL,
  69.             WS_BORDER | WS_VISIBLE | WS_CHILD | CBS_DROPDOWN,
  70.             0, 0, 0, 100,
  71.             hwnd, (HMENU)IDC_COMBO_BOX_1,
  72.             GetModuleHandle(NULL), NULL);
  73.  
  74.             //Combo Box Items START
  75.             COMBOBOXEXITEM cbei;
  76.             int iCnt;
  77.  
  78.             typedef struct {
  79.                 int iImage;
  80.                 int iSelectedImage;
  81.                 int iIndent;
  82.                 LPTSTR pszText;
  83.             } ITEMINFO, *PITEMINFO;
  84.  
  85.             ITEMINFO IInf[] = {
  86.                 {0, 3, 0, _T("first")},
  87.                 {1, 4, 1, _T("second")},
  88.                 {2, 5, 2, _T("third")},
  89.                 {0, 3, 0, _T("fourth")},
  90.                 {1, 4, 1, _T("fifth")},
  91.                 {2, 5, 2, _T("sixth")},
  92.                 {0, 3, 0, _T("seventh")},
  93.                 {1, 4, 1, _T("eighth")},
  94.                 {2, 5, 2, _T("ninth")},
  95.                 {0, 3, 0, _T("tenth")},
  96.                 {1, 4, 1, _T("eleventh")},
  97.                 {2, 5, 2, _T("twelfth")},
  98.                 {0, 3, 0, _T("thirteenth")},
  99.                 {1, 4, 1, _T("fourteenth")},
  100.                 {2, 5, 2, _T("fifteenth")},
  101.             };
  102.  
  103.             cbei.mask = CBEIF_TEXT | CBEIF_INDENT | CBEIF_IMAGE | CBEIF_SELECTEDIMAGE;
  104.  
  105.             for(iCnt = 0; iCnt < 15; iCnt++) {
  106.                 cbei.iItem = iCnt;
  107.                 cbei.pszText = IInf[iCnt].pszText;
  108.                 cbei.cchTextMax = sizeof(IInf[iCnt].pszText);
  109.                 cbei.iImage = IInf[iCnt].iImage;
  110.                 cbei.iSelectedImage = IInf[iCnt].iSelectedImage;
  111.                 cbei.iIndent = IInf[iCnt].iIndent;
  112.  
  113.                 if(SendMessage(Combo1, CBEM_INSERTITEM, 0, (LPARAM)&cbei) == -1) {
  114.                     return FALSE;
  115.                 }
  116.             }
  117.  
  118.             SendMessage(Combo1, CBEM_SETIMAGELIST, 0, (LPARAM)g_himl);
  119.             SetWindowPos(Combo1, NULL, 20, 20, 250, 120, SWP_NOACTIVATE);
  120.  
  121.  
  122.             //Combo Box Items END
  123.  
  124.             HWND Button1 = CreateWindowEx(
  125.                 NULL,
  126.                 "BUTTON",
  127.                 "Create Message Box",
  128.                 WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | BS_TEXT,
  129.                 10, 275, 360, 25,
  130.                 hwnd,
  131.                 (HMENU)IDC_BUTTON_1,
  132.                 GetModuleHandle(NULL),
  133.                 NULL);
  134.  
  135.             if (Button1 == NULL) {
  136.                 MessageBox(NULL, "Failed to create button1!", "ERROR!", MB_OK | MB_ICONWARNING);
  137.                 return -1;
  138.             }
  139.  
  140.             HWND Edit1 = CreateWindowEx(
  141.                 WS_EX_CLIENTEDGE,
  142.                 "EDIT",
  143.                 "",
  144.                 WS_VISIBLE | WS_BORDER | WS_CHILD | ES_MULTILINE,
  145.                 100, 110, 270, 150,
  146.                 hwnd,
  147.                 (HMENU)IDC_EDIT_1,
  148.                 GetModuleHandle(NULL),
  149.                 NULL);
  150.  
  151.             if (Edit1 == NULL) {
  152.                 MessageBox(NULL, "Failed to create edit1!", "ERROR!", MB_OK | MB_ICONWARNING);
  153.                 return -1;
  154.             }
  155.  
  156.             HWND Edit2 = CreateWindowEx(
  157.                 WS_EX_CLIENTEDGE,
  158.                 "EDIT",
  159.                 "",
  160.                 WS_VISIBLE | WS_BORDER | WS_CHILD,
  161.                 100, 70, 270, 30,
  162.                 hwnd,
  163.                 (HMENU)IDC_EDIT_2,
  164.                 GetModuleHandle(NULL),
  165.                 NULL);
  166.  
  167.             if (Edit2 == NULL) {
  168.                 MessageBox(NULL, "Failed to create edit2!", "ERROR!", MB_OK | MB_ICONWARNING);
  169.                 return -1;
  170.             }
  171.  
  172.             HWND Static1 = CreateWindowEx(
  173.                 NULL,
  174.                 "STATIC",
  175.                 "Title:",
  176.                 WS_VISIBLE | WS_CHILD | SS_CENTER,
  177.                 0, 75, 100, 20,
  178.                 hwnd,
  179.                 (HMENU)IDC_STATIC_1,
  180.                 GetModuleHandle(NULL),
  181.                 NULL);
  182.  
  183.             if (Static1 == NULL) {
  184.                 MessageBox(NULL, "Failed to create static1!", "ERROR!", MB_OK | MB_ICONWARNING);
  185.                 return -1;
  186.             }
  187.  
  188.             HWND Static2 = CreateWindowEx(
  189.                 NULL,
  190.                 "STATIC",
  191.                 "Message:",
  192.                 WS_VISIBLE | WS_CHILD | SS_CENTER,
  193.                 0, 115, 100, 20,
  194.                 hwnd,
  195.                 (HMENU)IDC_STATIC_2,
  196.                 GetModuleHandle(NULL),
  197.                 NULL);
  198.  
  199.             if (Static2 == NULL) {
  200.                 MessageBox(NULL, "Failed to create static2!", "ERROR!", MB_OK | MB_ICONWARNING);
  201.                 return -1;
  202.             }
  203.  
  204.  
  205.         }
  206.         break;
  207.         case WM_CLOSE:
  208.             DestroyWindow(hwnd);
  209.             ImageList_Destroy(g_himl);
  210.         break;
  211.         case WM_DESTROY:
  212.             PostQuitMessage(0);
  213.         break;
  214.         default:
  215.             DefWindowProc(hwnd, Message, wParam, lParam);
  216.     }
  217. }
  218.  
  219. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
  220.     INITCOMMONCONTROLSEX icex;
  221.     icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
  222.     icex.dwICC = ICC_STANDARD_CLASSES;
  223.     InitCommonControlsEx(&icex);
  224.  
  225.     g_himl = ImageList_Create(
  226.     20, 20, NULL, 3, 5);
  227.  
  228.     ImageList_AddIcon(g_himl, LoadIcon(GetModuleHandle(NULL), IDI_ASTERISK));
  229.     ImageList_AddIcon(g_himl, LoadIcon(GetModuleHandle(NULL), IDI_ERROR));
  230.     ImageList_AddIcon(g_himl, LoadIcon(GetModuleHandle(NULL), IDI_EXCLAMATION));
  231.  
  232.     WNDCLASSEX wnd1;
  233.     HWND MainWin;
  234.     MSG Msg;
  235.  
  236.     wnd1.cbSize = sizeof(WNDCLASSEX);
  237.     wnd1.style = 0;
  238.     wnd1.lpfnWndProc = MainWindowProc;
  239.     wnd1.cbClsExtra = 0;
  240.     wnd1.cbWndExtra = 0;
  241.     wnd1.hInstance = hInstance;
  242.     wnd1.hIcon = LoadIcon(NULL, IDI_WINLOGO);
  243.     wnd1.hCursor = LoadCursor(NULL, IDC_ARROW);
  244.     wnd1.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  245.     wnd1.lpszMenuName = NULL;
  246.     wnd1.lpszClassName = g_ClassName;
  247.     wnd1.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
  248.  
  249.     if(!RegisterClassEx(&wnd1)) {
  250.         MessageBox(NULL, "Failed to register wnd1 class!", "ERROR!", MB_OK | MB_ICONWARNING);
  251.         return -1;
  252.     }
  253.  
  254.     MainWin = CreateWindowEx(
  255.         WS_EX_CLIENTEDGE,
  256.         g_ClassName,
  257.         "Message Box Creator",
  258.         WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
  259.         CW_USEDEFAULT, CW_USEDEFAULT, 400, 350,
  260.         NULL, NULL, hInstance, NULL);
  261.  
  262.     if (MainWin == NULL) {
  263.         MessageBox(NULL, "Failed to create window handle!", "ERROR!", MB_OK | MB_ICONWARNING);
  264.         return -1;
  265.     }
  266.  
  267.     ShowWindow(MainWin, nCmdShow);
  268.     UpdateWindow(MainWin);
  269.  
  270.     while(GetMessage(&Msg, NULL, 0, 0) > 0) {
  271.         TranslateMessage(&Msg);
  272.         DispatchMessage(&Msg);
  273.     }
  274. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement