Наши проекты:
Журнал · Discuz!ML · Wiki · DRKB · Помощь проекту |
||
ПРАВИЛА | FAQ | Помощь | Поиск | Участники | Календарь | Избранное | RSS |
[18.220.13.70] |
|
Сообщ.
#1
,
|
|
|
Проблема в мерцании рисунка при переключении закладок.
Согласно статьи Джеймса Брауна "Flicker-Free Drawing in Windows" мерцание происходит тогда когда рисуется дважды и более в одном месте. Цитата: "Ваша обязанность обеспечить отсутствие перерисовки одних и тех же областей экрана более одного раза..." См. рисунки 1-4. Как сделать так, чтобы перерисовывалось все, кроме контролла - рисунка (поле статик), на котором собираюсь рисовать с помощью WM_PAIN ? Прикреплённая картинка
Прикреплённая картинка
Прикреплённая картинка
Прикреплённая картинка
Добавлено // 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); } |
Сообщ.
#3
,
|
|
|
Цитата Mr.Brooks @ Как сделать так, чтобы перерисовывалось все, кроме контролла - рисунка (поле статик).. Т.е. ты решил рисовать прямо на статике ? На статике я не делал, рисовал на кнопке. Вероятно, это тоже самое. Делал так - из процедуры саб-классинга сначала вызывал оригинальную процедуру. Уже после неё фильтровал сообщения и в WM_PAINT выводил на кнопку иконку. Если кнопке делался "disable", рисовалась иконка "в серых тонах". Можно и порисовать чего-нибудь. Никаких неприятных эффектов замечено не было. |
Сообщ.
#4
,
|
|
|
Цитата Mr.Brooks @ // | WS_CLIPCHILDREN; // | WS_CLIPSIBLINGS; Насколько я помню, эти флаги как раз и отвечают за перерисовку контролов в диалоге Добавлено Во всяком случае у меня, в старом коде, в OnInitDialog() стоит ModifyStyle(0, WS_CLIPCHILDREN);. Думаю, как раз для решения этой проблемы |
Сообщ.
#5
,
|
|
|
Цитата | WS_CLIPCHILDREN Пробовал, результат на рисунке 2. А статик как мерцал, так и мерцает. Если бы в цвет фона (сине-зеленый) закрасились контроллы на форме, это было бы то что нужно - значит, программа их не перерисовывает и можно самому рисовать. Цитата | WS_CLIPSIBLINGS Это, насколько я понимаю, для перекрывающихся дочерних окон. Но у меня их нет, т.е из трех Frame виден только один. Поэтому, как и положено этот флаг эффекта мне не дает. ... Либо я что-то делаю не так. |
Сообщ.
#6
,
|
|
|
Цитата Mr.Brooks @ 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); Т.е. у тебя для каждого таба создаётся своё окно, с одинаковым наборов контролов? Добавлено Если так, то оно и будет мерцать. Лучше, наверное, создать контролы поверх таба и менять их значение при переключении вкладок Добавлено Цитата Mr.Brooks @ 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); } Собственно, мерцает у тебя потому, что ты сначала делаешь невидимым старое окно, а потом показываешь новое. Попробуй наоборот. |
Сообщ.
#7
,
|
|
|
Во-первых не совсем одинаковые, контроллы. Т.е. их в любом случае будет много и разного типа (static, combobox, edit, edit + button [...]).
Если убрать промежеточные окна Frame (1, 2, 3), то придется каждому элементу менять видимость в зависимости от выбранной вкладки. И еще не известно, что получится (в смысле отсутсвие мерцания). Но как вариант, спасибо. Во-вторых с Frame более стройная и логичная программа выходит. Прошу простить за представленный выше код, все это еще только черновик. |
Сообщ.
#8
,
|
|
|
Цитата Mr.Brooks @ PropertiesTabSelect() Видел насчёт PropertiesTabSelect()? |
Сообщ.
#9
,
|
|
|
Цитата Попробуй наоборот void PropertiesTabSelect() { int i, t; t = 3; ShowWindow(e::propertieshwnd[e::propertiestab+1], SW_SHOW); for (i=0; i<t; i++) { if (e::propertiestab != i) { ShowWindow(e::propertieshwnd[i+1], SW_HIDE); } } //ShowWindow(e::propertieshwnd[e::propertiestab+1], SW_SHOW); } Неа, не помогло. |
Сообщ.
#10
,
|
|
|
Цитата Mr.Brooks @ Неа, не помогло. По-моему, проблема именно в этом. А ещё в том, что они у тебя на разных уровнях иерархии. Надо ещё активное окно, таб, поднимать наверх, не знаю только как. Добавлено Возможно, сделать SetWindowPos Добавлено Ну да, вместо ShowWindow надо сделать SetWindowPos c таб-контролом в hWndInsertAfter и SWP_SHOWWINDOW |
Сообщ.
#11
,
|
|
|
Цитата Mr.Brooks @ Неа, не помогло. Если запустить твоё приложение из архива, то никаких эффектов у меня не видно. Ещё ты забыл сделать: UnregisterClassA в ответ на RegisterClassA DestroyMenu -> CreatePopupMenu DestroyMenu -> CreateMenu UnregisterClassA -> RegisterClassExA Добавлено Цитата Mr.Brooks @ Если убрать промежеточные окна Frame (1, 2, 3), то придется каждому элементу менять видимость в зависимости от выбранной вкладки. Кроме того, сообщения от дочерних контролов будут передаваться паренту, те табу. И все сообщения придётся обрабатывать в его оконной процедуре, что не очень удобно делать. --- Можно оставить одно окно - "Frame". Весь набор и расположение контролов оставить то-же, а при переключении вкдадок делать "нужные" контролы видимыми, ненужные - скрытыми. Ещё лучше сделать класс "вид" - некий набор контролов для конкретной вкладки. При включении конкретной вкладки делать видимым соответствующий ей "вид". --- Не заметно каких-то существенных эффектов даже при запуске теста из-под виртуальной машины. Т.е. при существенном падении производительности процессора и видео системы. |
Сообщ.
#12
,
|
|
|
Цитата Mr.Brooks @ Проблема в мерцании рисунка при переключении закладок. Скрытый текст // 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); } о боже на MFC эта портянка создается в два клика мышей и ничего не мерцает бедолага |
Сообщ.
#13
,
|
|
|
Цитата Если запустить твоё приложение из архива, то никаких эффектов у меня не видно. Немного есть - на белом прямоугольнике проскакивает полоса серого фона (у меня контролы серые типа классика) при переключении закладок. Некоторые считают это придирчивостью. Цитата Ещё ты забыл сделать:... Всегда рад конструктивной критике. Цитата Можно оставить одно окно - "Frame". Весь набор и расположение контролов оставить то-же, а при переключении вкладок делать "нужные" контролы видимыми, ненужные - скрытыми. Так и сделал. Спасибо. Вопрос решен. |