Новичок
Профиль
Группа: Участник
Сообщений: 10
Регистрация: 27.2.2017
Репутация: нет Всего: нет
|
Код | // Project.h #include <windows.h> #include "Form.h" #include "Properties.h" namespace e { HINSTANCE hinst; HMENU hmenu; HWND htoolbar; HWND hpicturebox; char appname[256]; int width; int height; char propertiesclass[256]; char propertiesstr[120][256]; int propertiesfocus; int propertiestab; HWND propertieshwnd[100]; WNDPROC propertieswndproc[100]; int propertiesubound; } LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
|
Код | // Project.cpp #include "Project.h" int APIENTRY WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow) { strcpy(e::appname, "Test"); e::width = 800; e::height = 600; HWND hwnd; MSG msg; POINT point; e::hinst = hinstance; WNDCLASS w; memset(&w, 0, sizeof(WNDCLASS)); w.cbClsExtra = 0; w.cbWndExtra = 0; w.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1); w.hCursor = LoadCursor(NULL, IDC_ARROW); w.hIcon = LoadIcon(hinstance, MAKEINTRESOURCE(IDI_ICON_A)); w.hInstance = hinstance; w.lpfnWndProc = WndProc; w.lpszClassName = e::appname; w.lpszMenuName = NULL; w.style = CS_HREDRAW | CS_VREDRAW; RegisterClass(&w); point = FormAlignCenter(); hwnd = CreateWindow(e::appname, e::appname, WS_OVERLAPPEDWINDOW, point.x, point.y, e::width, e::height, NULL, NULL, hinstance, NULL); ShowWindow(hwnd, ncmdshow); UpdateWindow(hwnd); while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return (INT) msg.wParam; } LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) { switch (message) { case WM_CREATE: e::hmenu = FormCreateGeneralMenu(hwnd); e::htoolbar = FormCreateToolbar(hwnd, e::hinst); e::hpicturebox = FormCreatePictureBox(hwnd, e::hinst); PropertiesCreateDlg(e::hinst); case WM_SIZE: switch (LOWORD(wparam)) { case SIZE_RESTORED: FormResize(hwnd, e::htoolbar, e::hpicturebox, TRUE); break; default: FormResize(hwnd, e::htoolbar, e::hpicturebox, FALSE); } return 0; case WM_COMMAND: switch (LOWORD(wparam)) { case IDM_START: PropertiesShowDlg(hwnd, e::hinst); //MessageBox(hwnd, "Test program", " Start", MB_OK | MB_ICONINFORMATION); break; case IDM_EXIT: SendMessage(hwnd, WM_CLOSE, NULL, NULL); break; } return 0; case WM_ERASEBKGND: return 0; case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hwnd, message, wparam, lparam); }
|
Код | // Properties.h #include <windows.h> #include <commctrl.h> #pragma comment (lib, "comctl32.lib") namespace e { extern char propertiesclass[256]; extern char propertiesstr[120][256]; extern int propertiesfocus; extern int propertiestab; extern HWND propertieshwnd[100]; extern WNDPROC propertieswndproc[100]; extern int propertiesubound; } void PropertiesCreateDlg(HINSTANCE hinstance); void PropertiesShowDlg(HWND hwnd, HINSTANCE hinstance); void PropertiesTabFocus(); void PropertiesTabSelect(); LRESULT CALLBACK WndProcProperties(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); LRESULT CALLBACK WndProcPropertiesSubclassing(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
|
Код | // Properties.cpp #include "Properties.h" void PropertiesCreateDlg(HINSTANCE hinstance) { int i, j; char str[][256] = { "Name", "mm", "x", "Name of properties" }; strcpy(e::propertiesclass, "PropertiesClass"); for (i=0; i<30; i++) { for (j=0; j<4; j++) { strcpy(e::propertiesstr[4*i+j], str[j]); } } e::propertiesubound = 85; InitCommonControls(); WNDCLASSEX w; w.cbSize = sizeof(w); w.cbClsExtra = 0; w.cbWndExtra = 0; w.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1); w.hCursor = LoadCursor(NULL, IDC_ARROW); w.hIcon = LoadIcon(hinstance, NULL); w.hIconSm = LoadIcon(hinstance, NULL); w.hInstance = hinstance; w.lpfnWndProc = WndProcProperties; w.lpszClassName = e::propertiesclass; w.lpszMenuName = NULL; w.style = NULL; RegisterClassEx(&w); } void PropertiesShowDlg(HWND hwnd, HINSTANCE hinstance) { int i, width, height; HWND hdlg; HFONT hfont; POINT point; DWORD dwstyle, dwstyletab, dwstyleframe, dwstylebutton, dwstylepicture, dwstylelabel, dwstyleedit, dwstylecombo; TCITEM tcitem; EnableWindow(hwnd, FALSE); width = 480; height = 480; dwstyle = WS_POPUP | WS_BORDER | WS_SYSMENU | WS_CAPTION; // | WS_CLIPCHILDREN; hdlg = CreateWindowEx(WS_EX_DLGMODALFRAME, e::propertiesclass, " Properties", dwstyle, 0, 0, 0, 0, hwnd, NULL, hinstance, NULL); point.x = 350; point.y = 250; MoveWindow(hdlg, point.x, point.y, width, height, FALSE); ShowWindow(hdlg, SW_SHOW); dwstyletab = WS_CHILD | WS_VISIBLE; // | WS_CLIPCHILDREN; // | WS_CLIPSIBLINGS; dwstyleframe = WS_CHILD | WS_VISIBLE | SS_ETCHEDFRAME; // | WS_CLIPCHILDREN; // | WS_CLIPSIBLINGS; dwstylebutton = WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON; dwstylepicture = WS_CHILD | WS_VISIBLE | SS_WHITERECT; dwstylelabel = WS_CHILD | WS_VISIBLE; dwstyleedit = WS_CHILD | WS_VISIBLE; dwstylecombo = WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST; // e::propertieshwnd[0] = CreateWindowEx(0, WC_TABCONTROL, NULL, dwstyletab, 6, 7, width - 18, height - 70, hdlg, (HMENU) 1000, hinstance, NULL); tcitem.mask = TCIF_TEXT; tcitem.iImage = -1; tcitem.pszText = "Tab 1"; TabCtrl_InsertItem(e::propertieshwnd[0], 0, &tcitem); tcitem.pszText = "Tab 2"; TabCtrl_InsertItem(e::propertieshwnd[0], 1, &tcitem); tcitem.pszText = "Tab 3"; TabCtrl_InsertItem(e::propertieshwnd[0], 2, &tcitem); e::propertieshwnd[1] = CreateWindowEx(0, WC_STATIC, "Frame1", dwstyleframe, 8, 31, 445, 260, e::propertieshwnd[0], (HMENU) 1001, hinstance, NULL); e::propertieshwnd[2] = CreateWindowEx(0, WC_STATIC, "Frame2", dwstyleframe, 8, 31, 445, 260, e::propertieshwnd[0], (HMENU) 1002, hinstance, NULL); e::propertieshwnd[3] = CreateWindowEx(0, WC_STATIC, "Frame3", dwstyleframe, 8, 31, 445, 260, e::propertieshwnd[0], (HMENU) 1003, hinstance, NULL); // e::propertieshwnd[4] = CreateWindowEx(0, WC_STATIC, NULL, dwstylepicture, 9, 9, 135, 242, e::propertieshwnd[1], (HMENU) 1004, hinstance, NULL); for (i=0; i<10; i++) { e::propertieshwnd[3*i+5] = CreateWindowEx(0, WC_STATIC, e::propertiesstr[4*i+0], dwstylelabel, 154, 15+24*i, 100, 20, e::propertieshwnd[1], (HMENU) (1000 + (3*i+5)), hinstance, NULL); e::propertieshwnd[3*i+6] = CreateWindowEx(0, WC_STATIC, e::propertiesstr[4*i+1], dwstylelabel, 255, 15+24*i, 20, 20, e::propertieshwnd[1], (HMENU) (1000 + (3*i+6)), hinstance, NULL); e::propertieshwnd[3*i+7] = CreateWindowEx(0, WC_STATIC, e::propertiesstr[4*i+2], dwstylelabel, 280, 15+24*i, 20, 20, e::propertieshwnd[1], (HMENU) (1000 + (3*i+7)), hinstance, NULL); } e::propertieshwnd[38] = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, "100", dwstyleedit, 301, 12, 135, 20, e::propertieshwnd[1], (HMENU) 1038, hinstance, NULL); e::propertieshwnd[39] = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, "200", dwstyleedit, 301, 36, 111, 20, e::propertieshwnd[1], (HMENU) 1039, hinstance, NULL); e::propertieshwnd[40] = CreateWindowEx(WS_EX_CLIENTEDGE, WC_STATIC, NULL, dwstyleedit, 416, 36, 20, 20, e::propertieshwnd[1], (HMENU) 1040, hinstance, NULL); e::propertieshwnd[41] = CreateWindowEx(0, WC_BUTTON, "...", dwstylebutton, 418, 38, 16, 16, e::propertieshwnd[1], (HMENU) 1041, hinstance, NULL); e::propertieshwnd[42] = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, "300", dwstyleedit, 301, 60, 135, 20, e::propertieshwnd[1], (HMENU) 1042, hinstance, NULL); e::propertieshwnd[43] = CreateWindowEx(WS_EX_CLIENTEDGE, WC_COMBOBOX, NULL, dwstylecombo, 301, 84, 135, 200, e::propertieshwnd[1], (HMENU) 1043, hinstance, NULL); e::propertieshwnd[44] = CreateWindowEx(WS_EX_CLIENTEDGE, WC_COMBOBOX, NULL, dwstylecombo, 301, 108, 135, 200, e::propertieshwnd[1], (HMENU) 1044, hinstance, NULL); e::propertieshwnd[45] = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, "600", dwstyleedit, 301, 132, 135, 20, e::propertieshwnd[1], (HMENU) 1045, hinstance, NULL); e::propertieshwnd[46] = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, "700", dwstyleedit, 301, 156, 135, 20, e::propertieshwnd[1], (HMENU) 1046, hinstance, NULL); e::propertieshwnd[47] = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, "", dwstyleedit, 301, 180, 135, 20, e::propertieshwnd[1], (HMENU) 1047, hinstance, NULL); e::propertieshwnd[48] = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, "", dwstyleedit, 301, 204, 135, 20, e::propertieshwnd[1], (HMENU) 1048, hinstance, NULL); e::propertieshwnd[49] = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, "", dwstyleedit, 301, 228, 135, 20, e::propertieshwnd[1], (HMENU) 1049, hinstance, NULL); // SendMessage(e::propertieshwnd[43], CB_ADDSTRING, 0, (LPARAM) (LPCTSTR) "401"); SendMessage(e::propertieshwnd[43], CB_ADDSTRING, 0, (LPARAM) (LPCTSTR) "402"); SendMessage(e::propertieshwnd[44], CB_ADDSTRING, 0, (LPARAM) (LPCTSTR) "501"); SendMessage(e::propertieshwnd[44], CB_ADDSTRING, 0, (LPARAM) (LPCTSTR) "502"); EnableWindow(e::propertieshwnd[47], FALSE); EnableWindow(e::propertieshwnd[48], FALSE); EnableWindow(e::propertieshwnd[49], FALSE); // e::propertieshwnd[50] = CreateWindowEx(0, WC_STATIC, NULL, dwstylepicture, 9, 9, 135, 242, e::propertieshwnd[2], (HMENU) 1050, hinstance, NULL); for (i=0; i<10; i++) { e::propertieshwnd[3*i+51] = CreateWindowEx(0, WC_STATIC, e::propertiesstr[4*i+40], dwstylelabel, 154, 15+24*i, 100, 20, e::propertieshwnd[2], (HMENU) (1000 + (3*i+51)), hinstance, NULL); e::propertieshwnd[3*i+52] = CreateWindowEx(0, WC_STATIC, e::propertiesstr[4*i+41], dwstylelabel, 255, 15+24*i, 20, 20, e::propertieshwnd[2], (HMENU) (1000 + (3*i+52)), hinstance, NULL); e::propertieshwnd[3*i+53] = CreateWindowEx(0, WC_STATIC, e::propertiesstr[4*i+42], dwstylelabel, 280, 15+24*i, 20, 20, e::propertieshwnd[2], (HMENU) (1000 + (3*i+53)), hinstance, NULL); } // e::propertieshwnd[81] = CreateWindowEx(0, WC_STATIC, NULL, dwstylepicture, 9, 9, 135, 242, e::propertieshwnd[3], (HMENU) 1081, hinstance, NULL); // e::propertieshwnd[82] = CreateWindowEx(0, WC_BUTTON, "Apply", dwstylebutton, width - 253, height - 55, 75, 23, hdlg, (HMENU) 1082, hinstance, NULL); e::propertieshwnd[83] = CreateWindowEx(0, WC_BUTTON, "OK", dwstylebutton, width - 170, height - 55, 75, 23, hdlg, (HMENU) 1083, hinstance, NULL); e::propertieshwnd[84] = CreateWindowEx(0, WC_BUTTON, "Cancel", dwstylebutton, width - 87, height - 55, 75, 23, hdlg, (HMENU) 1084, hinstance, NULL); // hfont = (HFONT) GetStockObject(DEFAULT_GUI_FONT); for (i=0; i<e::propertiesubound; i++) { SendMessage(e::propertieshwnd[i], WM_SETFONT, (WPARAM) hfont, NULL); e::propertieswndproc[i] = (WNDPROC) SetWindowLong(e::propertieshwnd[i], GWL_WNDPROC, (LONG) WndProcPropertiesSubclassing); } e::propertiesfocus = 0; SetFocus(e::propertieshwnd[e::propertiesfocus]); e::propertiestab = 0; TabCtrl_SetCurSel(e::propertieshwnd[0], e::propertiestab); PropertiesTabSelect(); } void PropertiesTabFocus() { int i, n, max; char str[256]; n = e::propertiesfocus; max = e::propertiesubound; for (i=0; i<max; i++) { n = (n + ((GetKeyState(VK_SHIFT) < 0) ? (max-1) : 1)) % max; if (IsWindowVisible(e::propertieshwnd[n]) && IsWindowEnabled(e::propertieshwnd[n])) { GetClassName(e::propertieshwnd[n], str, 256); if (strcmp(str, "Static") != 0) { e::propertiesfocus = n; if (strcmp(str, "Edit") == 0) { SendMessage(e::propertieshwnd[n], EM_SETSEL, 0, -1); } break; } } } SetFocus(e::propertieshwnd[e::propertiesfocus]); } void PropertiesTabSelect() { int i, t; t = 3; for (i=0; i<t; i++) { ShowWindow(e::propertieshwnd[i+1], SW_HIDE); } ShowWindow(e::propertieshwnd[e::propertiestab+1], SW_SHOW); } LRESULT CALLBACK WndProcProperties(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) { HDC hdc; //PAINTSTRUCT ps; HWND hparent; LPNMHDR lpnmhdr; hparent = GetParent(hwnd); switch (message) { case WM_CREATE: hdc = GetDC(hwnd); ReleaseDC(hwnd, hdc); return 0; //case WM_PAINT: //hdc = BeginPaint(hwnd, &ps); //EndPaint(hwnd, &ps); //return 0; case WM_KEYDOWN: switch (LOWORD(wparam)) { case VK_TAB: PropertiesTabFocus(); break; case VK_ESCAPE: SendMessage(hwnd, WM_CLOSE, NULL, NULL); break; } return 0; case WM_NOTIFY: lpnmhdr = (LPNMHDR) lparam; switch (lpnmhdr->code) { case TCN_SELCHANGE: e::propertiesfocus = 0; SetFocus(e::propertieshwnd[e::propertiesfocus]); e::propertiestab = TabCtrl_GetCurSel((HWND) lpnmhdr->hwndFrom); PropertiesTabSelect(); //RedrawWindow(e::propertieshwnd[0], 0, 0, RDW_INVALIDATE | RDW_ERASE); break; } return 0; case WM_COMMAND: switch (LOWORD(wparam)) { case 1082: e::propertiesfocus = 82; MessageBox(hwnd, "Apply", "Message", MB_OK); SetFocus(e::propertieshwnd[e::propertiesfocus]); break; case 1083: e::propertiesfocus = 83; MessageBox(hwnd, "OK", "Message", MB_OK); SetFocus(e::propertieshwnd[e::propertiesfocus]); break; case 1084: SendMessage(hwnd, WM_CLOSE, NULL, NULL); break; } return 0; case WM_CLOSE: EnableWindow(hparent, TRUE); SetFocus(hparent); BringWindowToTop(hparent); ShowWindow(hwnd, SW_HIDE); DestroyWindow(hwnd); return 0; } return DefWindowProc(hwnd, message, wparam, lparam); } LRESULT CALLBACK WndProcPropertiesSubclassing(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) { int i, n; HWND hwndfocus; //HDC hdc; //HBRUSH hbrush; //HPEN hpen; //PAINTSTRUCT ps; //RECT rect; n = GetDlgCtrlID(hwnd) - 1000; switch (message) { case WM_KEYDOWN: switch (LOWORD(wparam)) { case VK_TAB: PropertiesTabFocus(); break; case VK_ESCAPE: SendMessage(GetParent(e::propertieshwnd[0]), WM_CLOSE, NULL, NULL); break; case WM_LBUTTONDOWN: MessageBox(NULL, "Click", "Message", MB_OK); break; } break; case WM_COMMAND: switch (LOWORD(wparam)) { case 1041: e::propertiesfocus = 41; MessageBox(hwnd, "1041", "Message", MB_OK); SetFocus(e::propertieshwnd[e::propertiesfocus]); break; } break; case WM_LBUTTONUP: hwndfocus = GetFocus(); for (i=0; i<e::propertiesubound; i++) { if (e::propertieshwnd[i] == hwndfocus) { e::propertiesfocus = i; } } break; //case WM_PAINT: // if ((hwnd == e::propertieshwnd[4]) || (hwnd == e::propertieshwnd[50])) // { // BeginPaint(hwnd, &ps); // hdc = GetDC(hwnd); // hbrush = CreateSolidBrush(RGB(255, 255, 255)); // SelectObject(hdc,hbrush); // hpen = CreatePen(PS_INSIDEFRAME, 1, RGB(255, 255, 255)); // SelectObject(hdc,hpen); // GetClientRect(hwnd, &rect); // Rectangle(hdc, rect.left+10, rect.top+10, rect.right-50, rect.bottom-50); // DeleteObject(hbrush); // DeleteObject(hpen); // ReleaseDC(hwnd, hdc); // EndPaint(hwnd, &ps); // } // break; //case WM_ERASEBKGND: // if ((hwnd == e::propertieshwnd[4]) || (hwnd == e::propertieshwnd[50])) // { // message = WM_NULL; // } // break; } return CallWindowProc(e::propertieswndproc[n], hwnd, message, wparam, lparam); }
|
исходник Это сообщение отредактировал(а) EarlBrooks - 27.2.2017, 20:40
Присоединённый файл ( Кол-во скачиваний: 1 )
test.rar 43,53 Kb
|