Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string.h>
- #include <windows.h>
- const char g_szClassName[] = "myWindowClass";
- const char class2[] = "class2";
- #define IDC_MAIN_BUTTON 101 // Button identifier
- #define IDC_MAIN_EDIT 102 // Edit box identifier
- HWND hEdit, hEdit2, w2;
- LRESULT CALLBACK WinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
- LRESULT CALLBACK WinProc2(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR lpCmdLine, int nCmdShow)
- {
- WNDCLASSEX wc, wc2;
- HWND hwnd;
- MSG Msg;
- //Step 1: Registering the Window Class
- wc.cbSize = sizeof(WNDCLASSEX);
- wc.style = 0;
- wc.lpfnWndProc = WinProc;
- 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 = g_szClassName;
- wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
- wc2.cbSize = sizeof(WNDCLASSEX);
- wc2.style = 0;
- wc2.lpfnWndProc = WinProc2;
- wc2.cbClsExtra = 0;
- wc2.cbWndExtra = 0;
- wc2.hInstance = hInstance;
- wc2.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- wc2.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc2.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
- wc2.lpszMenuName = NULL;
- wc2.lpszClassName = class2;
- wc2.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
- if (!RegisterClassEx(&wc) || !RegisterClassEx(&wc2))
- {
- MessageBox(NULL, "Window Registration Failed!", "Error!",
- MB_ICONEXCLAMATION | MB_OK);
- return 0;
- }
- // Step 2: Creating the Window
- hwnd = CreateWindowEx(
- WS_EX_CLIENTEDGE,
- g_szClassName,
- "The title of my window",
- WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT, CW_USEDEFAULT, 480, 480,
- NULL, NULL, hInstance, NULL);
- if (hwnd == NULL)
- {
- MessageBox(NULL, "Window Creation Failed!", "Error!",
- MB_ICONEXCLAMATION | MB_OK);
- return 0;
- }
- ShowWindow(hwnd, nCmdShow);
- UpdateWindow(hwnd);
- // Step 3: The Message Loop
- while (GetMessage(&Msg, NULL, 0, 0) > 0)
- {
- TranslateMessage(&Msg);
- DispatchMessage(&Msg);
- }
- return Msg.wParam;
- }
- LRESULT CALLBACK WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
- {
- switch (msg)
- {
- case WM_CREATE:
- {
- hEdit = CreateWindowEx(WS_EX_CLIENTEDGE,
- "EDIT",
- "",
- WS_CHILD | WS_VISIBLE |
- ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL,
- 50,
- 100,
- 200,
- 25,
- hWnd,
- (HMENU) IDC_MAIN_EDIT,
- GetModuleHandle(NULL),
- NULL);
- HGDIOBJ hfDefault = GetStockObject(DEFAULT_GUI_FONT);
- SendMessage(hEdit,
- WM_SETFONT,
- (WPARAM) hfDefault,
- MAKELPARAM(FALSE, 0));
- SendMessage(hEdit,
- WM_SETTEXT,
- NULL,
- (LPARAM)"Insert text here...");
- // Create a push button
- HWND hWndButton = CreateWindowEx(NULL,
- "BUTTON",
- "OK",
- WS_TABSTOP | WS_VISIBLE |
- WS_CHILD | BS_DEFPUSHBUTTON,
- 50,
- 220,
- 100,
- 24,
- hWnd,
- (HMENU) IDC_MAIN_BUTTON,
- GetModuleHandle(NULL),
- NULL);
- /*SendMessage(hWndButton,
- WM_SETFONT,
- (WPARAM) hfDefault,
- MAKELPARAM(FALSE, 0));*/
- w2 = CreateWindowEx(
- WS_EX_CLIENTEDGE,
- class2,
- "window 2",
- WS_TILEDWINDOW,
- CW_USEDEFAULT, CW_USEDEFAULT, 480, 480,
- hWnd, NULL, NULL, NULL);
- WINDOWINFO wi;
- GetWindowInfo(hWnd, &wi);
- //keep from overlapping
- SetWindowPos(w2, NULL, wi.rcWindow.right + 25, wi.rcWindow.top, 480, 480, NULL);
- ShowWindow(w2, 1);
- }
- break;
- case WM_COMMAND:
- switch (LOWORD(wParam))
- {
- case IDC_MAIN_BUTTON:
- {
- char buffer[256];
- SendMessage(hEdit,
- WM_GETTEXT,
- sizeof(buffer) / sizeof(buffer[0]),
- reinterpret_cast<LPARAM>(buffer));
- SendMessage(hEdit2,
- WM_SETTEXT,
- sizeof(buffer) / sizeof(buffer[0]),
- reinterpret_cast<LPARAM>(buffer));
- }
- break;
- }
- break;
- case WM_DESTROY:
- {
- PostQuitMessage(0);
- return 0;
- }
- break;
- }
- return DefWindowProc(hWnd, msg, wParam, lParam);
- }
- LRESULT CALLBACK WinProc2(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
- {
- switch (msg)
- {
- case WM_CREATE:
- {
- // Create an edit box
- hEdit2 = CreateWindowEx(WS_EX_CLIENTEDGE,
- "EDIT",
- "",
- WS_CHILD | WS_VISIBLE |
- ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL,
- 50,
- 100,
- 360,
- 260,
- hWnd,
- (HMENU) IDC_MAIN_EDIT,
- GetModuleHandle(NULL),
- NULL);
- HGDIOBJ hfDefault = GetStockObject(DEFAULT_GUI_FONT);
- SendMessage(hEdit2,
- WM_SETFONT,
- (WPARAM) hfDefault,
- MAKELPARAM(FALSE, 0));
- }
- break;
- case WM_COMMAND:
- switch (LOWORD(wParam))
- {
- }
- break;
- case WM_DESTROY:
- {
- PostQuitMessage(0);
- return 0;
- }
- break;
- }
- return DefWindowProc(hWnd, msg, wParam, lParam);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement