本文介绍了win32 tabControl,无法将对话框页面移动到选项卡中。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 大家好, 很抱歉昨天没有明确说明问题。 我想要在我的win32 cpp项目中使用tabcontrol。请检查代码: ------------------------------------- ------------------------------------------ BOOL OnInitTabControlDialog(HWND hWnd,HWND hWndFocus,LPARAM lParam) { // 加载和注册Tab控件类 INITCOMMONCONTROLSEX iccx; iccx.dwSize = sizeof (INITCOMMONCONTROLSEX); iccx.dwICC = ICC_TAB_CLASSES; if (!InitCommonControlsEx(& iccx)) return FALSE; // 创建标签控件 RECT rect; GetClientRect(hWnd,& rect); // | TCS_BOTTOM hTab = CreateWindowEx( 0 ,WC_TABCONTROL, 0 , TCS_FIXEDWIDTH | WS_CHILD | WS_VISIBLE, rect.left + 2 ,(rect.bottom-rect.top)/ 3 * 2 ,rect.right - 4 ,rect.bottom - 4 , hWnd,(HMENU)IDC_TAB,hInst, 0 ); // 将标签的字体设置为更典型的系统GUI字体 SendMessage(hTab,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT), 0 ); // 将项目添加到选项卡公共控件。 InsertTabItem(hTab, 第一页, 0 ); InsertTabItem(hTab, 第二页, 1 ); MoveWindow(hTab, 2 ,(rect.bottom-rect.top)/ 3 * 2 ,rect.right-rect.left,(rect.bottom-rect.top)/ 3,TRUE); / * SetWindowPos(hTab, HWND_TOP, rect.left + 2,(rect.bottom-rect.top)/ 3 * 2, rect.right-rect.left,(rect.bottom-rect.top)/ 3, SWP_SHOWWINDOW); * / // 使用 // RECT rect; // 具有相同的效果。 RECT TabRect; // 获取选项卡的矩形 GetClientRect(hTab,& TabRect); // 创建并添加标签对话框 h_TabDlg1 = CreateDialog (hInst,MAKEINTRESOURCE(IDD_TabDIALOG1),hTab,TabDlgProc1); h_TabDlg2 = CreateDialog(hInst,MAKEINTRESOURCE(IDD_TabDIALOG2),hTab,TabDlgProc2); MoveWindow(h_TabDlg1,TabRect.left + 4,TabRect.top + 4,TabRect.right - 10 ,TabRect.bottom- 15 , true ); MoveWindow(h_TabDlg2,TabRect.left + 4,TabRect.top + 4,TabRect.right - 10 ,TabRect.bottom- 15 , true ); / * SetWindowPos(h_TabDlg1, HWND_TOP, TabRect.left + 4, TabRect.top + 4, TabRect.right -10, TabRect.bottom-15, SWP_SHOWWINDOW); * / ShowWindow(h_TabDlg1,SW_SHOW); return TRUE; } ---------------------- -------------------------------------------------- ------- 无论我怎么努力,h_TabDlg1和h_TabDlg2都显示在屏幕的左上方。 有人能告诉我我的代码有什么问题吗? ps:win7,vs2010 此致, 知尚。解决方案 Hi everybody,Sorry for not stating the problem clearly yesterday.I want to use tabcontrol in my win32 cpp project. Please check the code:-------------------------------------------------------------------------------BOOL OnInitTabControlDialog(HWND hWnd, HWND hWndFocus, LPARAM lParam){ // Load and register Tab control class INITCOMMONCONTROLSEX iccx; iccx.dwSize = sizeof(INITCOMMONCONTROLSEX); iccx.dwICC = ICC_TAB_CLASSES; if (!InitCommonControlsEx(&iccx)) return FALSE; // Create the Tab control RECT rect; GetClientRect(hWnd, &rect);//|TCS_BOTTOM hTab = CreateWindowEx(0, WC_TABCONTROL, 0, TCS_FIXEDWIDTH | WS_CHILD | WS_VISIBLE, rect.left + 2, (rect.bottom-rect.top)/3*2 , rect.right - 4, rect.bottom - 4, hWnd, (HMENU)IDC_TAB, hInst, 0); // Set the font of the tabs to a more typical system GUI font SendMessage(hTab, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), 0); // Add items to the tab common control. InsertTabItem(hTab, "First Page", 0); InsertTabItem(hTab, "Second Page", 1); MoveWindow(hTab, 2, (rect.bottom-rect.top)/3*2, rect.right-rect.left,(rect.bottom-rect.top)/3, TRUE); /* SetWindowPos(hTab, HWND_TOP, rect.left + 2, (rect.bottom-rect.top)/3*2, rect.right-rect.left,(rect.bottom-rect.top)/3, SWP_SHOWWINDOW); *///using// RECT rect;//have the same effect.RECT TabRect;//get the Rect of the tab GetClientRect(hTab,&TabRect);//create and add tab dialogh_TabDlg1=CreateDialog(hInst,MAKEINTRESOURCE(IDD_TabDIALOG1),hTab, TabDlgProc1); h_TabDlg2=CreateDialog(hInst,MAKEINTRESOURCE(IDD_TabDIALOG2),hTab, TabDlgProc2);MoveWindow(h_TabDlg1,TabRect.left+4,TabRect.top+4,TabRect.right -10,TabRect.bottom-15,true);MoveWindow(h_TabDlg2,TabRect.left+4,TabRect.top+4,TabRect.right -10,TabRect.bottom-15,true); /*SetWindowPos(h_TabDlg1, HWND_TOP, TabRect.left+4, TabRect.top+4, TabRect.right -10, TabRect.bottom-15, SWP_SHOWWINDOW); */ShowWindow(h_TabDlg1,SW_SHOW); return TRUE;}-------------------------------------------------------------------------------No matter how hard I try, h_TabDlg1 and h_TabDlg2 display on the top left conner of the screen.Can somebody tell me what's wrong with my code ?ps: win7, vs2010Sincerely,Zhishang. 解决方案 这篇关于win32 tabControl,无法将对话框页面移动到选项卡中。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-29 16:09
查看更多