|
Hi,
I can able to create controls for a dialog box at run time. But how to create controls that are created automatically when scrolled. The help i need is that i will create some 10 buttons in a dialog while in its initialization. All the 10 buttons each will have one edit box beside. On clicking one button some text will get displayed on its associated edit box. Initially the scroll bar will be disabled. But if one button is clicked, the scroll bar should get enabled, and one more button and edit box have to be created (that is, 11th button and its edit box...). Please help me in this!!
Thanks in advance,
Sangeetha.
|
|
|
|
|
It is better to over ride a class of a button (usually from CButton) which has an Edit control as its memvber. when the control initializes, create the control and show it when click over (OnLbuttonDown message of Button). Using a custom class, you can create the control dynamically by calling "Create" function after creating an instance of this class.
SaRath.
"Do Next Thing..."
My Blog | Understanding State Pattern in C++
|
|
|
|
|
Thank you very much for your reply. Can you give me one example, please...? I can understand your suggestion. In that, you asked to create one overrided class of a CButton. I will create. But while the scroll bars is moved up and down all the buttons that are created should be displayed. It means for our first view of the dialog some 10 buttons will be displayed initially. At that time, scroll bar will be disabled. Because there are no more buttons to scroll and see. If i click any one of the button among that 10 buttons, then the 11th button should be automatically gets created, as well as the scroll bar will get enabled. That is, the scroll bar allows us to scroll down and see the newly created 11th button. The condition is that we can see only 10 buttons at once. If we want we have to scroll and see the other buttons. Can you get me..?
Thank you a lot,
Sangeetha.
|
|
|
|
|
|
I am creating buttons in a dialog.
Sangeetha.
|
|
|
|
|
|
You may have to put some effort on the source code, since you are creating controls dynamically.
I think, it is better to have a container dialog for button creation. thus you modify its height or width according to the number of control.
Create the container in the main window.
The nest way is to follow the scroll child example.
SaRath.
"Do Next Thing..."
My Blog | Understanding State Pattern in C++
|
|
|
|
|
I am creating buttons in a dialog. I gone through the link you had shown. In that the controls are already there. And we are scrolling and seeing the hidden ones. In my case, there will be no hidden controls (that is, there will be no 11th button. Only 10 buttons i will create initially). If i click any of the 10 buttons a new button should be created only after that just below the bottom most button in the dialog. And because the newly created button cannot be viewed without scrolling, the scroll bar is enabled. The best example is CAM software. In that for importing gerber data, one dialog will be displayed for importing gerber files, if we select FILE - IMPORT - GERBERDATA. In that only 15 buttons are there associated with a edit box each. And there will be a scroll bar which is disable for the first time. If we click on any of that 15 buttons and selected one gerber file, then the scroll bar will get enabled to scroll and see the newly created 16th button and its edit box.
Sangeetha.
|
|
|
|
|
Dear sangeetha,
I understood your problem. Currently I dont have any time to do a feasibility as you said that is why I have given the path.
You may have to do some work for the dynamic creation of controls and resizing the container window to accomodate new controls.
You can see whether the scrollbar need or not in WM_WINDOWPOSCHANGED Notification or you can have your own calculation on the same. if it bigger than the main window you should enable the scrollbar. you can get whether scrollbar enabled or not from the window style. call GetWindowLong to get the current style and & the result WM_VSCROLL (or the scrollbar you want to check it
Then you can set or remove using ModifyStyle function
e.g if(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_VSCROLL)
1. Hope you understood that you need to dynamically calclate the size of your container
2. Hope you need to place the container in a dialog.
3. Hope you know that scroollbar should enabled or disabled should be calculated according the main window size and container size
You are only needed to work on the 3rd point I have mentioned.
Just google at CP. You will get some inputs for it
SaRath.
"Do Next Thing..."
My Blog | Understanding State Pattern in C++
|
|
|
|
|
Thank you a lot and i will work on it and let you know the result. Thank you for spending your time in giving tips to solve my problem.
All the best,
Sangeetha.
|
|
|
|
|
|
how to set background color to the Dlg??
|
|
|
|
|
Hello
In MFC application,we can call SetDialogBkColor() member at application InitInstance !
good luck!
|
|
|
|
|
Example
// AppWizard implements the InitInstance overridable function
// according to options you select. For example, the single document
// interface (SDI) option was chosen for the AppWizard code created
// below. You can add other per-instance initializations to the code
// created by AppWizard.
BOOL CMyApp::InitInstance()
{
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
SetDialogBkColor(COLORREF clrCtlBk = RGB(192, 192, 192), COLORREF clrCtlText = RGB(0, 0, 255) ); // Set dialog background color to gray
LoadStdProfileSettings(); // Load standard INI file options (including MRU)
// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views.
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CMyDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CMyView));
AddDocTemplate(pDocTemplate);
// create a new (empty) document
OnFileNew();
if (m_lpCmdLine[0] != '\0')
{
// TODO: add command line processing here
}
return TRUE;
}
|
|
|
|
|
Since SetDialogBkColor is obsolete in new MFC, it has no effect. In order to change the background colour, I think the WM_ERASEBKGND notification has to be processed. The simplest handler can look like this:
BOOL CMyDialog::OnEraseBkgnd(CDC* pDC)
{
pDC->FillSolidRect(0, 0, 32000, 32000, RGB(0, 0, 255));
return TRUE;
}
-- modified at 4:39 Monday 26th June, 2006
|
|
|
|
|
You can use WM_PAINT instead OnEraseBkgnd
whitesky
|
|
|
|
|
In my opinion, changing of background colour in a WM_PAINT handler has a disadvantage: flickering. First the background is filled by the system colour in the WM_ERASEBKGND default handler, and then it is over-painted in WM_PAINT handler.
In order to avoid flickering, a new handler for WM_ERASEBKGND is to be provided, which simply does nothing and returns TRUE.
Therefore, the WM_ERASEBKGND message has to be handled anyway.
I think the WM_ERASEBKGND notification is the message which was originally designed for purpose under discussion.
|
|
|
|
|
You can use WM_CTLCOLOR or WM_PAINT
whitesky
|
|
|
|
|
|
I think yes but Onpaint is good
whitesky
|
|
|
|
|
|
I usually use ctlcolor and its good for me but i said WM_CTLCOLOR and WM_PAINT are possible SetDialogBkColor or WM_ERASEBKGND and...are possible
whitesky
|
|
|
|
|
Hi there,
Here is an exotic one:
BOOL CMyCoolApp::InitInstance()
{
WNDCLASS wc;
::GetClassInfo(m_hInstance, _T("#32770"), &wc);
wc.lpszClassName = _T("My cool Blue Dialog class");
CBrush brush(RGB(0,0,255));
wc.hbrBackground = brush;
brush.Detach();
wc.lpfnWndProc = DefWindowProc;
AfxRegisterClass(&wc);
}
Have fun!
Ovidiu Cucu
Microsoft MVP - Visual C++
|
|
|
|
|
How to apply "Force file output" option in Visual Studio.NET i.e. VC7. In Visual Studio 6.0, it is available in "Link-->Customize" option in Project Settings of VC++ project.
Can any one help me out please
|
|
|
|
|
I think you have to add the "/FORCE" option manually in Additional Options field of Project Properties --> Linker --> Command Line page.
Usually problems in your code should be solved without such options.
|
|
|
|