|
Hi,
I've read the two articles on this site "Creating Custom Controls" and "The Art Of Subclassing" by Chirs Maunder. They're pretty nice but i'm still confused.
Now, i want to build a custom control derived from CWnd.
As far as i understood, if we want to initialize something we use OnPaint function. Is that right?
And how do we add other controls to our control? For example, i want to build some kind of a table and i want column headers drawn on initialization. How and where should i do that?
And finally can you recommend me other tutorials about creating custom controls?
I'm really confused here, any bit of help is highly appreciated. Thanks.
|
|
|
|
|
Declare a class inheriting directly from CWnd. Put the initialisation code in the Create() member. You should also create any child windows at this point. FOr example, you mentioned column headers.
To do that you would declare a member varaible of type CHeaderCtrl in the .h file and call Create on it in the Create() of your Cwnd derived class. You would also need to add code to the OnSize of you CWnd class to place the headre control in the correct place on the CWnd's main window. When it comes to drawing the control you put your drawing code i nyour OnPaint() and make sure you don't overwrite areas taken up by the child controls.
Roger Allen
Sonork 100.10016
I think I need a new quote, I am on the prowl, so look out for a soft cute furry looking animal, which is really a Hippo in disguise. Its probably me.
|
|
|
|
|
Thanks for your reply. Now i have a starting point and thinks will sink better as i go the way.
|
|
|
|
|
When I right click on my tree, I would like to change the selection before displaying the context menu. Just like the behaviour in the class view window of VS.
How do I achieve this?
It's probably obvious, and just can't see it.
Thanks,
BW
{insert witty/thought-provoking saying here}
|
|
|
|
|
::GetMessagePos, CTreeCtrl::ScreenToClient, CTreeCtrl::HitTest and CTreeCtrl::SelectItem.
Tomasz Sowinski -- http://www.shooltz.com
** Putt knot yore thrust inn spel chequers. **
|
|
|
|
|
BW
{insert witty/thought-provoking saying here}
|
|
|
|
|
I'm interested in windows programming and I was looking for some books but I don't know wich one to buy. Do you have any suggestions?
marekm
|
|
|
|
|
If your interested in MFC, then I'd recommend "Windows Programming with MFC" by Jeff Prosise. It's helped me out, along with the help I've gotten out here.
Good Luck!
BW
{insert witty/thought-provoking saying here}
|
|
|
|
|
Second that... Jeff's book is great.
Also Sams 'teach yourself c++ in 21 days is quite good'. There's no Windows stuff in it which is great because it sidetracks you from learning the theory.
"I spent a lot of my money on booze, birds and fast cars. The rest I just squandered"
George Best.
|
|
|
|
|
Do you want to learn MFC or Win32 API?
For MFC, I highly recommend that you study from these two books in the exact order listed.
Introduction to MFC Programming with Visual C++ by Richard M. Jones
Programming Windows With MFC by Jeff Prosise
For Win32 API, Programming Windows, The Definitive Guide to the Win32 API by Charles Petzold is unparalleled.
Kuphryn
|
|
|
|
|
For learning straight Win32 API programming - Programming Windows Fifth Edition, Charles Petzold. MS Press, ISBN 1-57231-995-X
For learning the Visual C++ environment and some MFC fundementals - Programming Visual C++ Fifth Edition, Kruglinski, Shepherd, Wingo. MS Press ISBN 1-57231-857-0
and finally...
Programming Windows with MFC Second Edition, Jeff Prosise. MS Press, ISBN 1-57231-695-0
I own all three of these books and find them to be invaluable resources.
Paul Lyons, CCPL Certified Code Project Lurker What a long, strange trip it's been - Robert Hunter
|
|
|
|
|
Hi.
I have two questions about menu in a dialog based application.
First, how do you add an on command for menu items in a dialog based app? In other words, without ON_COMMAND how do you add an event handle for menu item?
Second, I saw two solutions for updating, i.e. enable or disable, menu items in a dialog based app.
1) CMenu *pMenu = GetMenu(0)
This solutions is exactly like updating contextmenu. Am I correct? Do you have to call function to redraw the menu?
2) Add an event handle for WM_KICKIDLE
http://www.codeguru.com/dialog/OnUpdate.shtml
I would like to know the preferred solution for updating menu items in a dialog based app.
Thanks,
Kuphryn
|
|
|
|
|
I'd go for (2) - it will work with toolbar as well.
Tomasz Sowinski -- http://www.shooltz.com
** Putt knot yore thrust inn spel chequers. **
|
|
|
|
|
Okay. Thanks.
-----
LRESULT CTestDlg::OnKickIdle(WPARAM, LPARAM)
{
CMenu* pMainMenu = GetMenu();
CCmdUI cmdUI;
for (UINT n = 0; n < pMainMenu->GetMenuItemCount(); ++n)
{
CMenu* pSubMenu = pMainMenu->GetSubMenu(n);
cmdUI.m_nIndexMax = pSubMenu->GetMenuItemCount();
for (UINT i = 0; i < cmdUI.m_nIndexMax;++i)
{
cmdUI.m_nIndex = i;
cmdUI.m_nID = pSubMenu->GetMenuItemID(i);
cmdUI.m_pMenu = pSubMenu;
cmdUI.DoUpdate(this, FALSE);
}
}
return TRUE;
}
-----
The code above is from solution #2 using WM_KICKIDLE. I am not sure what to set to enable and/or disable an item. Does this line do it?
-----
cmdUI.DoUpdate(this, FALSE);
-----
Kuphryn
|
|
|
|
|
And you can use UpdateDialogControls() for updating toolbars and anything that has a ON_COMMAND_UI handler in your dialog.
|
|
|
|
|
You do use ON_COMMAND to handle menu commands in a dialog based app. I'm not sure what you are getting at.
As for disabling menu items, add an OnInitMenuPopup handler similar to this:
void CMyDialog::OnInitMenuPopup(CMenu* pPopupMenu,
UINT nIndex,
BOOL bSysMenu)
{
CDialog::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu);
CCmdUI cmdui;
cmdui.m_pMenu = pPopupMenu;
cmdui.m_nIndexMax = pPopupMenu->GetMenuItemCount();
for (cmdui.m_nIndex = 0; cmdui.m_nIndex < cmdui.m_nIndexMax; cmdui.m_nIndex++) {
cmdui.m_nID = pPopupMenu->GetMenuItemID(cmdui.m_nIndex);
if (cmdui.m_nID == 0) continue;
cmdui.DoUpdate(this, FALSE);
}
}
Then you can use the normal ON_UPDATE_COMMAND_UI mechanism to enable/disable your menu items.
|
|
|
|
|
Nice!!! Thanks.
One last question. JohnCz of CodeGuru criticized the use of a dialog based app. He mentioned about using SDI without doc and using a CFormView. What are you inputs on using CFormView? What are the advantagesand disadvantages o using CFormView over a dialog based app and vice versa?
Thanks
Kuphryn
|
|
|
|
|
Using ADO, I want to check and see in a database (its only got one table) what the name of the table is. Any clues or links to this?
Thanks,
ns
|
|
|
|
|
Use ADOX.... You can see the catalog...
Or with ado, you can make a select to the sysobjects catalog.
For example
select name, id, xtype from sysobjects where xtype='u'
regards
Carlos Antollini.
Sonork ID 100.10529 cantollini
|
|
|
|
|
I just ran into your cadox class on CP....I'm going to try it....
|
|
|
|
|
In you cadox class,
void GetTableName(long nTableIndex, CString strTableName);
if I only have one table what is the index?
Thanks,
ns
|
|
|
|
|
What i would like to do is, that I'm enumerating a list with all the system's different audio compressors. Each time i add a compressor name to the list, i want to set that item's user data to a driver identifier to the compressor. The driver identifier is 4 bytes so it should fit, but when i send the message, it returns LB_ERR. Here's the code:
BOOL WINAPI listCallback(HACMDRIVERID hadid, DWORD dwInstance, DWORD fdwSupport)
{
ACMDRIVERDETAILS details;
int i;
details.cbStruct = sizeof(details);
acmDriverDetails(hadid, &details, NULL);
SendMessage(GetDlgItem(ghWnd, IDC_CODECS), LB_INSERTSTRING, -1, (LPARAM)details.szLongName);
i = SendMessage(GetDlgItem(ghWnd, IDC_CODECS), LB_GETCOUNT, 0, 0) - 1;
SendMessage(GetDlgItem(ghWnd, IDC_CODECS), LB_SETITEMDATA, i, (LPARAM)hadid);
return TRUE;
}
I've also tested if the GetDlgItem(ghWnd, IDC_CODECS) returns a valid handle and it does. And I've also tried replacing the (LPARAM)hadid with, for instance, 2, but it still returns LB_ERR. What am i doing wrong?
Thanks in advance.
-Rune Svendsen
|
|
|
|
|
What happens if you omit the LB_SETITEMDATA part? Do the list items appear (altough without being associated with their respective HACMDRIVERID )? If not, then the problem is somewhere else.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hello,
This is code from an OnEditCopy handler of the Visualization Toolkit. I am trying to add animations to my application by generating the frames (as bitmaps) and then redisplaying them. I have tried using the CPicture class here and the vtk offscreen rendering (using a bitmap writer object), but it is unreliable, crashing the program.
Another solution would be to adapt this code to store the contents. I have never used LPBITMAPINFOHEADER. Can anyone point me in the right direction on how to copy this bitmap data onto the view, thus displaying it? Thanks.
Ted
LPBITMAPINFOHEADER lpbi; // pointer to BITMAPINFOHEADER
DWORD dwLen; // size of memory block
HANDLE hDIB = NULL; // handle to DIB, temp handle
vtkWindow *vtkWin = pView->GetVTKWindow();
int *size = vtkWin->GetSize();
int dataWidth = ((size[0]*3+3)/4)*4;
dwLen = sizeof(BITMAPINFOHEADER) + dataWidth*size[1];
// allocate memory for the bitmap
hDIB = ::GlobalAlloc(GHND, dwLen);
// setup bitmap info header
lpbi = (LPBITMAPINFOHEADER) ::GlobalLock(hDIB);
lpbi->biSize = sizeof(BITMAPINFOHEADER);
lpbi->biWidth = size[0];
lpbi->biHeight = size[1];
lpbi->biPlanes = 1;
lpbi->biBitCount = 24;
lpbi->biCompression = BI_RGB;
lpbi->biClrUsed = 0;
lpbi->biClrImportant = 0;
lpbi->biSizeImage = dataWidth*size[1];
// start memory rendering
pView->SetupMemoryRendering(size[0],size[1], pView->GetDC()->GetSafeHdc());
vtkWin->Render();
// copy the bitmap data into the bitmap
memcpy((LPSTR)lpbi + lpbi->biSize, pView->GetMemoryData(), dataWidth*size[1]);
::GlobalUnlock(hDIB);
// turn screen rendering back on
pView->ResumeScreenRendering();
// now how can we draw this bitmap on the view (CDC)?
|
|
|
|
|
Ted Christiansen wrote:
now how can we draw this bitmap on the view (CDC)?
use CDC::StretchDIBits
-c
"I am angry that so many of the sons of the powerful and well-placed... managed to wangle slots in Reserve and National Guard units...Of the many tragedies of Vietnam, this raw class discrimination strikes me as the most damaging to the ideal that all Americans are created equal and owe equal allegiance to their country."
--Colin Powell, not talking about his boss
|
|
|
|