Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
can anyone tell how to make MDIclient to be scrollable in visual studio c++, I mean I have a program and there is an MDIClient control window on it so what I want is that I need to insert some item on that child window says some buttons and text box and etc, so i wanted to make the window to be scroll able. I could create the scroll bar and the window alright but I cannot connect them together to show me all the stuff I need. here is the code how I create MDIClient.
code :
C++
HWND ChildWindowCreation(HWND hWnd, HINSTANCE hInst){
	hwndClient = CreateWindow (TEXT ("MDICLIENT"), NULL, WS_CHILD |
			                  WS_CLIPCHILDREN | WS_VISIBLE, 0, 0,  
                              0, 0, hWnd, (HMENU) 1, hInst,
                              (PSTR)&clientcreate) ;

	MyRegisterClass(hInst);

	if(!hwndClient){
		MessageBox(NULL, "Program did not made the stuff ready for you", "Error", MB_OK|MB_ICONERROR);
	}

	return hwndClient;
}
and here is the code how I create scroll bar:
code:-
C++
hwndClient = CreateWindow (TEXT ("scrollbar"), NULL, WS_CHILD |
			                  WS_VISIBLE, 0, 0,  
                              0, 0, hWnd, (HMENU) 1, hInst,
                              NULL) ;

thanks
Posted
Updated 18-Jul-15 9:18am
v4

1 solution

Use WS_VSCROLL and WS_HSCROLL styles to create an MDI client window that allows respectively vertical or horizontal bars in the MDI child windows.
C++
hwndClient = CreateWindow (TEXT ("MDICLIENT"), NULL,
                               WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL,
                               0, 0, 0,  0, hWnd, (HMENU) 1, hInst,
                               (PSTR)&clientcreate) ;
 
Share this answer
 
v5
Comments
Member 11593571 19-Jul-15 4:16am    
Thanks for your answer it worked perfectly, one more thing if you could tell me, how do I change the MDIClient background color.
Frankie-C 19-Jul-15 6:31am    
You're welcome.
If the solution worked please accept it so we can close the question as solved.
For the background colour you cannot set it in the MDI client window, but you have to set it in any window intercepting the messages WM_ERASEBKGND.
See https://social.msdn.microsoft.com/Forums/vstudio/en-US/f5aecf40-1f22-400d-85d2-db601ec8d71b/changing-background-color-by-using-button-win32-api?forum=vcgeneral
Member 11593571 13-Aug-15 12:40pm    
can't believe i am saying this. but i need an new solution. i mean the above answer worked perfect but i thought instead of using mdiclient it would be good to use our self drawn window with its own class style. but in this one i can't add ws_vscroll or ws_hscroll, i mean i can but when i try to scroll down or something it just jump back to the top. so i would appreciate is somebody tell me how can i achieve creating the scroll bars to a self drawn window.
Here is the code how i create the window and class

Code:
wcs.cbSize = sizeof(wcs);
wcs.lpszClassName = szClassName;
wcs.hInstance = GetModuleHandle(0);
wcs.lpfnWndProc = CustWndProc;
wcs.hCursor = LoadCursor(NULL, IDC_ARROW);
wcs.hIcon = 0;
wcs.lpszMenuName = 0;
wcs.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcs.style = 0;
wcs.cbClsExtra = 0;
wcs.cbWndExtra = 0;
wcs.hIconSm = 0;

if(!RegisterClassEx(&wcs))
{
MessageBox(NULL, "Window Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}

hwndCtrl = CreateWindowEx(
0L, // give it a standard border
szClassName,
_T("A custom control"),
WS_VISIBLE|WS_CHILD|WS_VSCROLL|WS_BORDER,
0, 0, 0, 0,
hWnd,
NULL, GetModuleHandle(0), CustWndProc
);

thanks in advance
Member 11593571 14-Aug-15 4:55am    
anyone can help me?
Frankie-C 14-Aug-15 6:46am    
try this http://www.codeproject.com/Articles/32925/Scrollable-Dialog-in-Pure-Win-API.
Read https://msdn.microsoft.com/en-us/library/ms997557.aspx and http://www.functionx.com/win32/controls/scrollbars.htm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900