|
The idea of getter and setter method is that it let the programmer hide the implementation of the data ( decoupling ).
when dealing with containers, I would create an iterator (non STL ) class over that container, so that I can eventually change the container type without having to change every client accessing that class.
in your example, the user need to know that you are using an STL list, he does'nt need to know that, only to get a printer in that class.
I'm sorry I don't have a definitive solution for you; but it's a good question.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
Hello,
As some other user suggested, creating another iterator over the container is the ideal solution. You can change the container and nobody has to know it.
If you don't mind that the class exposes the data structure (container), you can override the index operator: operator[](int nIndex) to make life simple and easy.
I also suggest that you hide the STL completely from your class to make it more reusable and hide implementation details from users. I assume that you use the std::wstring as return values and such. It's better to return const wchar_t* instead of a string class. This way, you don't foce your users to use STL or an other library.
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
CDC dc;
CPrintDialog pdlg(FALSE,PD_NOPAGENUMS|PD_NOSELECTION,this);
BOOL bFindPrinter=pdlg.GetDefaults();
//////////////////////////////////////////////
//using the following code,I want to stop the 24-Pin Dot Matrix Printer at the 100mm length.But something is wrong ,it doesn't work.
DEVMODE* lpDevMode = NULL;
lpDevMode = (DEVMODE*)::GlobalLock(pdlg.m_pd.hDevMode);
lpDevMode->dmFields |= DM_PAPERSIZE;
lpDevMode->dmFields |= DM_PAPERLENGTH;
lpDevMode->dmFields |= DM_PAPERWIDTH;
lpDevMode->dmPaperSize = DMPAPER_USER;
lpDevMode->dmPaperLength = 100;
lpDevMode->dmPaperWidth = 100;
::GlobalUnlock(pdlg.m_pd.hDevMode);
/////////////////////////////////////////////////////
dc.Attach(pdlg.GetPrinterDC());
CFont font;
VERIFY(font.CreatePointFont(120, "System", &dc));
CFont* def_font = dc.SelectObject(&font);
int nPageHeight, nPageWidth;
nPageHeight = dc.GetDeviceCaps(VERTRES);
nPageWidth = dc.GetDeviceCaps(HORZRES);
TEXTMETRIC TextM;
dc.GetTextMetrics(&TextM);
int nCharHeight = (unsigned short)TextM.tmHeight;
int nCharWidth=(unsigned short)TextM.tmAveCharWidth;
DOCINFO di;
di.cbSize = sizeof(DOCINFO);
di.lpszDocName = "FarFly printing";
di.lpszOutput = (LPTSTR) NULL;
di.lpszDatatype = (LPTSTR) NULL;
di.fwType = 0;
dc.StartDoc(&di);
dc.StartPage();
int line = 0;
CString s = "My Test String";
dc.TextOut(2,line++,s,strlen(s));
dc.EndPage();
dc.EndDoc();
dc.SelectObject(def_font);font.DeleteObject();
DeleteDC(dc.Detach());
thanks for your help...
|
|
|
|
|
yujia120 wrote:
lpDevMode->dmPaperLength = 100;
lpDevMode->dmPaperWidth = 100;
dmPaperLength and dmPaperWidth are in tenths of a millimetre.
Phil
|
|
|
|
|
Thank Phil ,i modified them as the following:
lpDevMode->dmPaperLength = 1000;
lpDevMode->dmPaperWidth = 1000;
but the printer doesn't stop at the 100mm-length line.
How does 'Word 2003' implement the function?
it can define the paper length and width,and the printer can stop when running at the length line.
|
|
|
|
|
Hello all,
Making an app that works off an active windows explorer window. Currently can successfully obtain the handle to the CabinetWClass and SysListView32, but need to and am stuck on how to obtain the current directory pidl of the windows explorer window.
Any help/advice appreciated!
|
|
|
|
|
Does this help?
"The words of God are not like the oak leaf which dies and falls to the earth, but like the pine tree which stays green forever." - Native American Proverb
|
|
|
|
|
Thanks however I have already looked at the IShellView (and IShellBrowser) but unless I have missed something I don't see how it could help...
Basically I need something similar to the pidl sent by IShellExtInit when a shortcut menu extension is initialized, excpet that I need it manually.
|
|
|
|
|
Does anyone out there know of a way to tell the difference between USB flash drives through code? I can catch the USB Flash drive being connected, find out the drive letter, and find out the registry mounted drive information but if you have two of the exact same USB flash drives this information is the same if you connect them one at a time. I need to find a way to tell the difference between the two identical flash drives. Thanks in advance.
|
|
|
|
|
;PIf they are identical then there is no difference!
|
|
|
|
|
Getting the volume serial number using GetVolumeInformation() might help. Each disk gets a VSN when it is formatted although it's not always unique.
The two most common elements in the universe are Hydrogen and stupidity. - Harlan Ellison
Awasu 2.2 [^]: A free RSS/Atom feed reader with support for Code Project.
|
|
|
|
|
Thank you for the suggestion but after doing some research and testing, I found that GetVolumnInformation does indeed give me a unique serial number but the serial number changes everytime you format the drive. This will probably work for me, but it's not water proof. I need to create a list of valid USB flash drives in my program for security purposes. If the user formats the drive down the road, the new serial number won't be in the list. I found this example: http://www.thecodeproject.com/csharp/hard_disk_serialNo.asp[^] but it only seems to work for Windows XP and doesn't seem to work well with USB flash drives.
|
|
|
|
|
I think you will have to send a command directly to the device.
If you send the (SCSI) command INQUIRY, the you can ask for the pages Unit Serial Number page (80h) or Device Identification page (81h)
That should give you the serial number of the device, but those pages aren't mandatory...
|
|
|
|
|
Deal all,
can you guys look at this and tell me if you see anything wrong with it:
I am declaring a vector of IHTMLElement pointers.
vector[IHTMLElement(*)] pool;
I am then calling a method to fill in the vector.
fill(pool);
now, whenever i try to acces the elements of that vector i get an exception.
BSTR tagName;
int size = (int)pool.size();
for(int i=0; i (less) size; i++){
pool[size]->get_tagName(&tagName);
}
what can be the reason ???
by the way, when specifying an index eg. pool[5]->get_tagName(&tagName); everything works fine.
whats making this loop throw an exception,
any help will be appreciated
llp00na
-- modified at 11:52 Wednesday 25th January, 2006
|
|
|
|
|
Is this absolutely correct?
BSTR tagName;
int size = (int)pool.size();
for(int i=0; i (less) size; i++){
pool[size]->get_tagName(&tagName);
}
I think you need this change
BSTR tagName;
int size = (int)pool.size();
for(int i=0; i (less) size; i++){
pool[i]->get_tagName(&tagName);
}
Happens to the best of us .. especially eight beers into coding
People that start writing code immediately are programmers (or hackers), people that ask questions first are Software Engineers - Graham Shanks
|
|
|
|
|
sorry i wrote wrong, Thats exactly what i have and its not working.
llp00na
|
|
|
|
|
You're running off the end of your vector. The valid indexes are 0 to size-1.
Also, always init your BSTR variables to NULL. COM may try to marshal your uninitialized pointer to the server, depending on the type of the server, and cause a crash.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
|
|
|
|
|
I'm not sure what's going on here. First off you do not seem to be running off the end of the vector since your loop is using i<size . You do not have to initailise the BSTR to NULL - The idl of IHTMLElement::tagName looks something like this:
[propget, id(DISPID_IHTMLELEMENT_TAGNAME)] HRESULT tagName([retval, out] BSTR * p);
Notice the out attribute - This parameter is only marshalled one way. You are leaking BSTR s however, you should be calling SysFreeString(tagName) to free the old before you get a new one. This will not cause a crash however - Just leak memory. Can you provide more information? The type of exception and the code which fills the vector and perhaps a stack trace of the crash?
Steve
|
|
|
|
|
Sorry I'm not sure whether this has been asked before. Will appreciate it if someone points out to me how to run a search through this forum.
I have an application that draws a rectangle across my viewport(a rectangle in a dialog box) by the standard operation (left mouse down, left mouse held, mouse goes right, mouse up). A rectangle of height of my viewport will be drawn starting from the point.x value where the mouse is clicked to where it is released. but recently i notice a problem in that since my viewport in my dialog is limited, if i shift the mouse at a reasonable speed, it seems to be unable to draw a full rectangle from the start point to the end point. It seems to end prematurely at some random point before the extreme right end. But there is no such problem if i move my mouse slowly. I believe changing the way i handle mouse down, mouse move and mouse up can handle this prob.
But curious and troublesome me just want to know, wat is the frequency that the mouse moving message is sent to Windows? Or could the complexity of my app be the reason behind this problem? Thanks for any answer!!
|
|
|
|
|
You are doing SetCapture aren't you. If you don't then your dialog will stop getting mousemove messages when the mouse is outside the dialog so it will stop updating the drag rect.
This may be one of your problems, but I suspect you have some others, too.
Phil
|
|
|
|
|
Thanks Phil for teaching me about SetCapture. Have nv encountered it beforein my short programming experience.
But maybe to make my problem clearer, it's not about capturing mouse position in a sense. I'm more curious about how often is this mousemove message sent out. For example, every second? every millisecond? every pixel?
It's just a question that suddenly popped into my brain...because i can draw a rectangle within a rectangle nicely if i shift the mouse at a slightly slower or normal speed( depending on how you perceive it). But if i am to slowly approach the boundary of my drawing area (a rectangle) within my dialog box, and near the end suddenly increase the speed of shifting my mouse, suddenly zooming past the extreme right of my drawing rectangle (and not my dialog), the rectangle drawn will not be covering a certain area on the right of my drawing area.
I tried it a few times, and notice it's pretty random, as in the area left undrawn, despite my mouse moving over it, is always changing.
Hence this question:
Is the mousemove msg sent every sec, every pixel or what?
I hope this is much clearer =)
|
|
|
|
|
misugi wrote: Will appreciate it if someone points out to me how to run a search through this forum.
See here.
"The words of God are not like the oak leaf which dies and falls to the earth, but like the pine tree which stays green forever." - Native American Proverb
|
|
|
|
|
|
hi folks,
i want to make a MFC application which only should have a tray icon and a popup menu (accessible via the tray icon). but i don't know what kind of application i should choose. should i make a dialog based or a sdi one ? i mean i only need the message map.
thanks in advance.
greets
|
|
|
|
|