|
If you derive a class from CEdit , you can override OnChar() .
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi Masters!
I've an icon (with 3 dif. sizes, that's 16x16, 32x32, 48x48) in a DLL and I'm using it in an exe using DuplicateIcon() function.
The problem is that when exe runs, I expect to have 16x16 one on the taskbar button, but I'm just enjoying the 32x32 !
What can I do?
|
|
|
|
|
???????????????????????
-@SuDhIrKuMaR@-
|
|
|
|
|
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
|
Hi,
How can i add OnEraseBackgrnd for dialog. I cannot find in Add Message option in class wizard and also in Add Message Handler.
How can i override this function in my dialog??Pls..
Anu
|
|
|
|
|
Anu_Bala wrote: How can i add OnEraseBackgrnd for dialog.
Add a message map entry...
ON_WM_ERASEBKGND()
Function declaration...
BOOL OnEraseBkgnd( CDC *pDC );
Anu_Bala wrote: I cannot find in Add Message option in class wizard and also in Add Message Handler.
I would suggest to you, as a learning exercise to write a simple MFC application, may be just a hello world sample with some menu and some buttons "without using application wizard and class wizard".
Nibu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|
|
in header file add:
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
In CPP file add:
BEGIN_MESSAGE_MAP(<yourdialog>, CDialog)
//{{AFX_MSG_MAP(<yourdialog>)
ON_WM_ERASEBKGND()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BOOL <yourdialog> ::OnEraseBkgnd(CDC *pDC)
{
CDialog::OnEraseBkgnd(pDC);
return FALSE;
}
-@SuDhIrKuMaR@-
|
|
|
|
|
Anu_Bala wrote: I cannot find in Add Message option in class wizard...
Change the message filter from Dialog to Window.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi All,
I have a dll A which contains functions f1, f2, f3, and i use these functions in my application, say function f4 in my application uses them for some purpose, now the problem is dll A is from third party, and it can have multiple versions in the future?, how can i take care of this issue in my design of Application such that new version of this dll(new version may have more functions or changed function names) doesn't impact function f4, say if new version dll is just extension to previous dll, would it be automatically called by my app, or do i need to take some measure to support new version, please help by considering other similiar scenarios, if i have missed any?, Thanks in Advance!
_____________
princenrj23
|
|
|
|
|
If newer DLL is just an extension of old DLL then you dont have to worry about it. By extension I mean no existing functions were deleted, or changed - name or functionality. If newer DLL do makes some changes to existing function then it will break your code. Either way you can't do anything, except fixing you code when new new DLL comes. So stop worrying about it
-Saurabh
|
|
|
|
|
Is there any way to set the paper size, say A4, and orientation in OnPreparePrinting() function which is called before the print dialog is displayed?
The problem is that I am not able to use CWinApp::OnFilePrintSetup function since the code is inside a dll and there's no class derived from CWinApp. So, in my own code for OnFilePrintSetup, I display a page setup dialog box and takes various inputs from user. Now, I want these changes to appear in print dialog also(which I get by using CVIew::OnFilePrint) and not the default settings that are displayed by print dialog box. So, the only way that I could find is to make changes to pInfo member in OnPreparePrinting but I could not get any way to set paper size. m_pPD member does not provide any way to set paper size?
Please help.
Thanks.
|
|
|
|
|
DEVMODE *pDevMode=NULL;
CPrintDialog dlg(TRUE, PD_ALLPAGES | PD_USEDEVMODECOPIES | PD_NOPAGENUMS | PD_HIDEPRINTTOFILE | PD_NOSELECTION | PD_RETURNDC, this);
if(dlg.DoModal()== IDOK)
{
pDevMode = dlg.GetDevMode();
pDevMode->dmPaperWidth = 8.27;
pDevMode->dmPanningHeight = 11.69;
}
Nigah M Manzoor
|
|
|
|
|
My problem is because of the fact that I am using my own dialog box for print setup but using the mfc provided dialog box for print. When I use my own dialog box, I dont update the internal m_hDevMode structure which has the information for all settings like page size, orientation, dpi etc etc.
I did not update because I did not know how to update and precisely speaking, i did not know about GetPrinterDeviceDefaults API.
This is what I needed to do to set the default settings before the print dialog is displayed. No matter what you do, you will always get a print dialog box with a4 & landscape set. It's sufficient for my purpose.
[code]
OnPreparePrinting(CPrintInfo* pInfo)
{
if(GetPrinterDeviceDefaults(&pInfo->m_pPD->m_pd))
{
LPDEVMODE dev = pInfo->m_pPD->GetDevMode();
GlobalUnlock(dev);
dev->dmOrientation = DMORIENT_LANDSCAPE;
dev->dmPaperSize = DMPAPER_A4;
}
return CView::DoPreparePrinting(pInfo);
}
[/code]
Thanks!
|
|
|
|
|
I made it as follows:
BOOL CMyTabView::OnPreparePrinting(CPrintInfo* pInfo)
{
delete pInfo->m_pPD ;
pInfo->m_pPD = new CDlgPrinting(FALSE, PD_ALLPAGES | PD_USEDEVMODECOPIES | PD_NOPAGENUMS
| PD_HIDEPRINTTOFILE | PD_NOSELECTION, this) ;
pInfo->m_pPD->m_pd.hInstance = AfxGetInstanceHandle();
pInfo->m_pPD->m_pd.lpPrintTemplateName = MAKEINTRESOURCE(IDD_PRINT_PRDLG);
pInfo->m_pPD->m_pd.Flags |= PD_ENABLEPRINTTEMPLATE;
pInfo->m_pPD->m_pd.nMinPage = 1;
int nPages = 1 + (m_nTotalRules / 30);
pInfo->SetMaxPage (nPages);
pInfo->m_pPD->m_pd.nFromPage = (WORD) pInfo->GetMinPage ();
pInfo->m_pPD->m_pd.nToPage = (WORD) pInfo->GetMaxPage ();
if (pInfo->m_bPreview)
return DoPreparePrinting(pInfo);
int nAnswer = pInfo->m_pPD->DoModal ();
if (nAnswer == IDCANCEL)
return FALSE;
pInfo->m_pPD->m_pd.hDC = pInfo->m_pPD->CreatePrinterDC ();
return TRUE;
}
void CMyTabView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
if (pDC->IsPrinting ())
{ DEVMODE* devMode = pInfo->m_pPD->GetDevMode ();
devMode->dmOrientation = DMORIENT_LANDSCAPE;
devMode->dmFields |= DM_ORIENTATION;
pDC->ResetDC (devMode);
}
CFormView::OnPrepareDC(pDC, pInfo);
}
void CMyTabView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
pDC->SetMapMode (MM_LOMETRIC);
double dLeftOffset = 200 - (pDC->GetDeviceCaps (PHYSICALOFFSETX) * 254.0) / pDC->GetDeviceCaps (LOGPIXELSX);
double dTopOffset = 200 - (pDC->GetDeviceCaps (PHYSICALOFFSETY) * 254.0) / pDC->GetDeviceCaps (LOGPIXELSY);
double dRightMargin = 2770 - (pDC->GetDeviceCaps (PHYSICALOFFSETX) * 254.0) / pDC->GetDeviceCaps (LOGPIXELSX);
double dBottomMargin = 1950 - (pDC->GetDeviceCaps (PHYSICALOFFSETY) * 254.0) / pDC->GetDeviceCaps (LOGPIXELSY);
pInfo->m_rectDraw.left += (int) dLeftOffset;
pInfo->m_rectDraw.top += (int) dTopOffset;
pInfo->m_rectDraw.right = (int) dRightMargin;
pInfo->m_rectDraw.bottom = (int) dBottomMargin;
}
I hope it helps.
EDIT: I made the change of orientation in the OnPrepareDC because I had a quite funny error. I had 5 different views, some on Landscape and some in Portrait. Every time I changed from "type" and printed, the first page was always with the last orientation used. Changing it there solved my error. There maybe is better place to do it, but it works :P
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
thanks for the code.
I can see that you have modified the standard DoPreparePrinting code. But I am using the standard DoPreparePrinting code as it provides better error checking like what if CreatePrinterDC fails? your funciton will still return TRUE but not so in case of standard code.
also, I have not tried your code inside OnPreparePrinting but if you deleting the print dialog at beginning, then wont the settings entered by user in print setup box will be lost?
Say, you select A4 size in print setup box and when you go to print->properties, will it show A4 size selected or default size, probably letter selected?
And I am using the MM_TEXT mode throughout. Just adjusting the font size etc accordingly whether we are in print preview mode or displaying on monitor or sending to printer.
One weird thing I noticed is that if you are in print preview mode, then ::GetDeviceCaps (pDC->GetSafeHDC(), LOGPIXELSY) returns a different value from pDC->GetDeviceCaps(LOGPIXELSY) and the value returned by latter is correct one.
And dmPaperLength and dmPaperWidth were always zero although dmPaperSize was changing properly. I initially thought of storing length, width in a table but that would have been very very and very tedious. I found a better solution of creating a printer dc using
dc.Attach(pd.GetPrinterDC()); and then you can obtain paper length and width from dc.
I have not still tried multiple pages, so cant say if there can be problem with that.
the fruits of your success will be in direct ratio to the honesty and sincerity of your own efforts in keeping your own records, doing your own thinking and, reaching your own conclusions.
..surviving in autumn..in love with spring..
|
|
|
|
|
First of all, thank you for your comments. They have make me notice some things I can improve in my code
theCPkid wrote: the standard DoPreparePrinting code as it provides better error checking like what if CreatePrinterDC fails? your funciton will still return TRUE but not so in case of standard code.
Yes, you are right, but you can add that error checking all the security you want/need before returning TRUE. (I will change it)
theCPkid wrote: but if you deleting the print dialog at beginning, then wont the settings entered by user in print setup box will be lost?
No. You are right, I am deleting the standard CPrintDialog, but changing it with my CDlgPrinting that is derivation of it (I actually made a copy of the standard and modified it to fit my needs), so it has the support for print-setup as well.
theCPkid wrote: Say, you select A4 size in print setup box and when you go to print->properties, will it show A4 size selected or default size, probably letter selected?
The trick is that I have no "print setup" in the main frame menu, it has to be made through my dialog if you don't want to print with the standards (A4, portrait, black and white). I made a test in a plotter and it was successfull with A4 and A3, I don't allow smaller pages because of my application's workspace. I print graphics, tables and other things, needed info wouldn't fit otherwise or, I have to zoom it out it would be too small to be clearly understood. But I restrict some setup because of depending on where is being printed it "must" be printed with some specifical configuration, so I give it "manually" in the code of the view.
theCPkid wrote: Just adjusting the font size etc accordingly whether we are in print preview mode or displaying on monitor or sending to printer.
Why? I am using the same font for both and it works good. I create them with:
CFont fontLabels, fontInfo;
fontLabels.CreatePointFont (80, "MS Sans Serif", pDC);
fontInfo.CreatePointFont (140, "MS Sans Serif", pDC);
theCPkid wrote: And dmPaperLength and dmPaperWidth were always zero although dmPaperSize was changing properly. I initially thought of storing length, width in a table but that would have been very very and very tedious.
I don't use it because I directly work with the pInfo->m_rectDraw it makes it more portable (I think, but maybe I am wrong). Its dimensions change automatically with the change of paper size or orientation by print setup. In my case I want to use A4s for the info pages (both portrait and/or landscape) and I allow an A3 for the project workspace. I do it dinamically in my CDlgPrinting disabling some options according to which view called it.
Once returned I modify the pInfo->m_rectDraw according to orientation and paper size in each view thanks to the "offset" I calculate at the beggining of OnPrint. The only thing I don't like is the repetition of the calculation on every page. I will change it in future versions.
I whish you good luck and success with your printing code, let me know about it when you are finished. I'll like to have other perspectives
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
Hello
I have a pop up context menu for a treeview where one item displays further sub items when selected. The exact items displayed depends on the current program state and what items are in the tree view.
I am able to achieve this quite simply by checking the program state and then using RemoveMenu() or EnableMenuItem().
However, there are some circumstances where I want to disable or remove the parent item. checking the properties page in the visual studio resource editor shows that this menu item has not been assigned an ID and in fact it prevents me from doing so.
I've tried using GetMenuItemID() as I know the items position but this returns NULL.
E.g Menu is:
View Properties
Move To Segment
When user selects Move To Segment further menu options appear,
how many appear is dependent on the number of segments:
Move To Segment One
Move To Segment Two
Move To Segment Three
However in some circumstances (when there are no segments) I want to remove the parent item Move To Segment from the menu.
Any suggestions?
Cheers
Rich
|
|
|
|
|
GetMenuItemId return a valid ID only for simple menu items and for pop-up menus it returns -1. I am not 100% sure but you should use GetSubMenu for the popup menus. See MSDN[^].
-Saurabh
|
|
|
|
|
One sugesstion:
Instead of creating main menu and removing menus depending on program state
Why not create menus based on program stateso no need to remove anything.
I hope it makes sense.
Regards,
Sandip.
|
|
|
|
|
This is only possible if states of the program is static and do not change at run-time.
-Saurabh
|
|
|
|
|
Thanks Sandip
I think that's exactly what i'll do. In fact I already do this and have several menus for different situations. However I think I got so focused on trying to correct the problem that I did not think to apply this practice again!
|
|
|
|
|
Hi,
I`m somewhat new to programming and I just have a question about strings.
Say I have a string that is read from a .csv file and looks like
word1,word2,word3,word4
how would I isolate, say, word3, and have the value in a seperate variable.
Any help in working with .csv in C++ would be great as well. I`ve only figured out how to extract rows from the file using streams. However, as my question states, I still have trouble with columns being seperated by commas and how to perform operations on them. Any help would be appreciated, thanks.
-Alex
|
|
|
|
|
You can use CString::Tokenize() method to get values separated by any separater like comma, space etc.
See the example from MSDN:
Example
The following example demonstrates the use of CStringT::Tokenize.
CAtlString str( "%First Second#Third" );
CAtlString resToken;
int curPos= 0;
resToken= str.Tokenize("% #",curPos);
while (resToken != "")
{
printf("Resulting token: %s\n", resToken);
resToken= str.Tokenize("% #",curPos);
};
Output
Resulting Token: First
Resulting Token: Second
Resulting Token: Third
--
"Programming is an art that fights back!"
modified on Thursday, June 12, 2008 3:52 AM
|
|
|
|
|
toasttime wrote: Say I have a string that is read from a .csv file and looks like
word1,word2,word3,word4
how would I isolate, say, word3, and have the value in a seperate variable.
You need to tokenize this string based on a separator char (for you it will be ',').
You can use either Tokenize function of CString or _tcstok_s . Then you can do additional operations based on the tokens, like compare and decide whether it's the string that you were looking for.
Nibu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|
|
CString's Tokenize method helps
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|