Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define UNICODE
- #include <windows.h>
- #include <Commctrl.h>
- #include <stdio.h>
- #include <stdint.h>
- // winProc headers
- LRESULT CALLBACK WINSEM_Window_WindowProc_Create(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
- LRESULT CALLBACK WINSEM_Window_WindowProc_Run(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
- // store struct
- struct sTab_Example
- {
- HWND hWin;
- HWND hTab;
- };
- BOOL Tab_Example(struct sTab_Example *ps_example, LPCTSTR lpWindowName, HINSTANCE hThisInstance, HWND hParent, uintptr_t u0_id);
- int WINAPI WinMain (HINSTANCE hThisInstance,
- HINSTANCE hPrevInstance,
- LPSTR lpszArgument,
- int nFunsterStil)
- {
- struct sTab_Example s_tabA;
- struct sTab_Example s_tabB;
- DWORD dErr;
- // register class
- {
- WNDCLASSEX wcx;
- // Fill in the window class structure with parameters
- // that describe the main window.
- wcx.cbSize = sizeof(WNDCLASSEX); // size of structure
- wcx.style = CS_DBLCLKS; // redraw if size changes
- wcx.lpfnWndProc = WINSEM_Window_WindowProc_Create; // points to window procedure
- wcx.cbClsExtra = 0; // no extra class memory
- wcx.cbWndExtra = 0; // no extra window memory
- wcx.hInstance = hThisInstance; // handle to instance
- wcx.hIcon = LoadIcon(NULL, IDI_APPLICATION); // predefined app. icon
- wcx.hCursor = LoadCursor(NULL, IDC_ARROW); // predefined arrow
- wcx.hbrBackground = GetStockObject(LTGRAY_BRUSH); // white background brush
- wcx.lpszMenuName = NULL; // name of menu resource
- wcx.lpszClassName = L"WINSEMClass"; // name of window class
- wcx.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
- // Register the window class.
- if (RegisterClassExW(&wcx)==0)
- {
- dErr = GetLastError();
- if (dErr!=0)
- {
- printf("WIN Error:%u\n", dErr);
- }
- return -1;
- }
- }
- // create windows with tabs
- {
- if (Tab_Example(&s_tabA, L"WINSEM tab A", hThisInstance, NULL, 101)==FALSE)
- {
- return -1;
- }
- if (Tab_Example(&s_tabB, L"WINSEM tab B", hThisInstance, HWND_MESSAGE, 102)==FALSE)
- {
- return -1;
- }
- // THIS PROBABLY WORK BAD
- SetParent(s_tabB.hTab, s_tabB.hWin);
- }
- // show windows
- ShowWindow(s_tabA.hWin, SW_SHOW);
- ShowWindow(s_tabB.hWin, SW_SHOW);
- // message loop
- {
- MSG msg;
- BOOL bRet;
- while (1)
- {
- bRet = PeekMessage( &msg, NULL, 0, 0, PM_REMOVE);
- if (bRet==FALSE)
- {
- // no messages received
- }
- else
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- if (msg.message==WM_QUIT)
- {
- break;
- }
- }
- }
- return msg.wParam;
- }
- }
- BOOL Tab_Example(struct sTab_Example *ps_example, LPCTSTR lpWindowName, HINSTANCE hThisInstance, HWND hParent, uintptr_t u0_id)
- {
- DWORD dErr;
- // create window
- {
- ps_example->hWin = CreateWindowEx(0, // no extended styles
- L"WINSEMClass", // class name
- lpWindowName, // window name
- WS_OVERLAPPEDWINDOW, // overlapped window
- CW_USEDEFAULT, // default horizontal position
- CW_USEDEFAULT, // default vertical position
- 300, // default width
- 300, // default height
- HWND_DESKTOP, // no parent or owner window
- (HMENU) NULL, // class menu used
- hThisInstance,// instance handle
- (LPVOID)ps_example); // no window creation data
- if (ps_example->hWin==NULL)
- {
- dErr = GetLastError();
- if (dErr!=0)
- {
- printf("WIN Error:%u\n", dErr);
- }
- return FALSE;
- }
- }
- if (hParent==NULL) hParent = ps_example->hWin;
- // create tab
- {
- TCITEM tie;
- INITCOMMONCONTROLSEX icex;
- // Initialize common controls.
- icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
- icex.dwICC = ICC_TAB_CLASSES;
- InitCommonControlsEx(&icex);
- ps_example->hTab = CreateWindowExW(0, // no extended styles
- WC_TABCONTROL, // class name
- L"", // default text
- WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE, // overlapped window
- CW_USEDEFAULT, // default horizontal position
- CW_USEDEFAULT, // default vertical position
- 300, // default width
- 300, // default height
- hParent, // no parent or owner window
- (HMENU)u0_id, // class menu used
- hThisInstance,// instance handle
- (LPVOID)ps_example);
- if (ps_example->hTab == NULL)
- {
- dErr = GetLastError();
- if (dErr!=0)
- {
- printf("WIN Error:%u\n", dErr);
- }
- return FALSE;
- }
- // Add tabs for each day of the week.
- tie.mask = TCIF_TEXT;
- tie.pszText = L"TAB 0";
- if (TabCtrl_InsertItem(ps_example->hTab, 0, &tie) == -1)
- {
- dErr = GetLastError();
- if (dErr!=0)
- {
- printf("WIN Error:%u\n", dErr);
- }
- DestroyWindow(ps_example->hTab);
- return FALSE;
- }
- tie.pszText = L"TAB 1";
- if (TabCtrl_InsertItem(ps_example->hTab, 1, &tie) == -1)
- {
- dErr = GetLastError();
- if (dErr!=0)
- {
- printf("WIN Error:%u\n", dErr);
- }
- DestroyWindow(ps_example->hTab);
- return FALSE;
- }
- }
- return TRUE;
- }
- // winProc
- LRESULT CALLBACK WINSEM_Window_WindowProc_Create(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
- {
- {
- if (uMsg==WM_CREATE)
- {
- // special code for creation
- LPCREATESTRUCT pd_create;
- struct sTab_Example *ps_example;
- DWORD dErr;
- pd_create = (LPCREATESTRUCT)lParam;
- ps_example = (struct sTab_Example *)pd_create->lpCreateParams;
- while (1)
- {
- SetLastError(0);
- if (SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)ps_example)==0)
- {
- dErr = GetLastError();
- if (dErr!=0)
- {
- printf("WIN Error:%u\n", dErr);
- break;
- }
- }
- if (SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)WINSEM_Window_WindowProc_Run)==0)
- {
- dErr = GetLastError();
- if (dErr!=0)
- {
- printf("WIN Error:%u\n", dErr);
- break;
- }
- }
- return 0;
- }
- return -1;
- }
- }
- // error
- return DefWindowProc(hwnd, uMsg, wParam, lParam);
- }
- LRESULT CALLBACK WINSEM_Window_WindowProc_Run(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
- {
- if (uMsg==WM_COMMAND)
- {
- //WORD wID;
- WORD wNotification;
- // command from other object
- //wID = LOWORD(wParam);
- wNotification = LOWORD(wParam);
- if (wNotification>0)
- {
- HWND hWin;
- hWin = (HWND)lParam;
- printf("WM_COMMAND: win: %p code: %u\n", hWin, HIWORD(wParam));
- return FALSE;
- }
- }
- else if (uMsg==WM_NOTIFY)
- {
- LPNMHDR dInfo;
- dInfo = (LPNMHDR)lParam;
- printf("WM_NOTIFY: win: %p code: %u\n", dInfo->hwndFrom, dInfo->code);
- return FALSE;
- }
- else
- {
- // look for message in array
- printf("%u: win: %p wParam: %u lParam: %u\n", uMsg, hwnd, (unsigned int)wParam, (unsigned int)lParam);
- if (uMsg==WM_DESTROY)
- {
- printf("QUIT\n");
- PostQuitMessage(0);
- return FALSE;
- }
- //return FALSE;
- }
- return DefWindowProc(hwnd, uMsg, wParam, lParam);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement