|
|
Hi,
I have used this as suggested by Khan:
CFileDialog fd(TRUE);
int nResult = fd.DoModal();
if (nResult == IDOK)
{
CString strPath = fd.GetPathName();
}
as soon as it hits the line CFileDialog fd(TRUE), then it goes into
CFileDialog::CFileDialog(BOOL bOpenFileDialog,
LPCTSTR lpszDefExt, LPCTSTR lpszFileName, DWORD dwFlags,
LPCTSTR lpszFilter, CWnd* pParentWnd) : CCommonDialog(pParentWnd)
{
memset(&m_ofn, 0, sizeof(m_ofn)); // initialize structure to 0/NULL
m_szFileName[0] = '\0';
m_szFileTitle[0] = '\0';
m_pofnTemp = NULL;
m_bOpenFileDialog = bOpenFileDialog;
m_nIDHelp = bOpenFileDialog ? AFX_IDD_FILEOPEN : AFX_IDD_FILESAVE;
m_ofn.lStructSize = sizeof(m_ofn);
m_ofn.lpstrFile = m_szFileName;
m_ofn.nMaxFile = _countof(m_szFileName);
m_ofn.lpstrDefExt = lpszDefExt;
m_ofn.lpstrFileTitle = (LPTSTR)m_szFileTitle;
m_ofn.nMaxFileTitle = _countof(m_szFileTitle);
m_ofn.Flags |= dwFlags | OFN_ENABLEHOOK | OFN_ENABLESIZING;
if (!afxData.bWin4 && AfxHelpEnabled())
m_ofn.Flags |= OFN_SHOWHELP;
if (afxData.bWin4)
{
m_ofn.Flags |= OFN_EXPLORER;
--> problem here m_ofn.hInstance = AfxGetResourceHandle();
}
m_ofn.lpfnHook = (COMMDLGPROC)_AfxCommDlgProc;
The problem is in m_ofn.hInstance = AfxGetResourceHandle();
// Global helper functions
_AFXWIN_INLINE CWinApp* AFXAPI AfxGetApp()
{ return afxCurrentWinApp; }
_AFXWIN_INLINE HINSTANCE AFXAPI AfxGetInstanceHandle()
{ ASSERT(afxCurrentInstanceHandle != NULL);
return afxCurrentInstanceHandle; }
/* problem in the following Aserttion */
_AFXWIN_INLINE HINSTANCE AFXAPI AfxGetResourceHandle()
--->>>> { ASSERT(afxCurrentResourceHandle != NULL); <<<<<<<---------PROBLEM
return afxCurrentResourceHandle; }
_AFXWIN_INLINE void AFXAPI AfxSetResourceHandle(HINSTANCE hInstResource)
{ ASSERT(hInstResource != NULL); afxCurrentResourceHandle = hInstResource; }
_AFXWIN_INLINE LPCTSTR AFXAPI AfxGetAppName()
{ ASSERT(afxCurrentAppName != NULL); return afxCurrentAppName; }
_AFXWIN_INLINE COleMessageFilter* AFXAPI AfxOleGetMessageFilter()
{ ASSERT_VALID(AfxGetThread()); return AfxGetThread()->m_pMessageFilter; }
_AFXWIN_INLINE CWnd* AFXAPI AfxGetMainWnd()
{ CWinThread* pThread = AfxGetThread();
return pThread != NULL ? pThread->GetMainWnd() : NULL; }
Jim
|
|
|
|
|
Hi...sorry but I'm poor English..
I want make Dialog Box without its class.
Nice Days...
void CMExOdbcView::OnModedata()
{
CDialog* pDlg = new (*((CDialog*) GetDlgItem(IDD_EDIT_DLG)));
if(pDlg->DoModal() == IDOK)
{
m_pSet->m_name.Format("%s", GetDlgItemText(IDC_EDIT_NAME));
m_pSet->m_address.Format("%s", GetDlgItemText(IDC_EDIT_ADDRESS));
m_pSet->m_tel.Format("%s", GetDlgItemText(IDC_EDIT_TEL));
m_pSet->m_bigo.Format("%s", GetDlgItemText(IDC_EDIT_BIGO));
m_pSet->Update();
}
}
|
|
|
|
|
when you enter the if(...== IDOK), the dialog box has already been destroyed.
So you can't use the GetDlgItemText(...) over there. You got to subclass and store in member variables of the class and you should access the member variables of the pDlg object after it comes out.
|
|
|
|
|
I create a 1 column, 2 row splitter window. use CreateStatic, because I want too different view in each panes. But I also want dynamically delete a pane, how to do this?
Thank u.
|
|
|
|
|
Hi,
I have a nested structure FREQ_ANAL, I want to return this structure from a VC++ DLL to a VB client. What is the best way to do that?
typedef struct FrequencyData
{
DWORD specData[FRMBUFF][FFTSIZE];
DWORD timeVal[FRMBUFF][FFTSIZE];
}FREQ_DATA;
typedef struct FrequencyAnalysis
{
FREQ_DATA freqData;
int result;
}FREQ_ANAL;
Thanks, Ratna
|
|
|
|
|
I'm no VB expert (I've used it a little) but I the way I'd proceed is to wrap the data structure with a COM object.
Steve
|
|
|
|
|
You need to create a SafeArray. There are probably some examples here on CodeProject ...
Phil
|
|
|
|
|
In MDI project. I want my child frame fill main frame window. So I inplement this in
BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying the CREATESTRUCT cs
CWnd* pwnd = AfxGetMainWnd();
CRect rect;
pwnd->GetClientRect( &rect );
cs.cx = rect.Width(); cs.cy = rect.Height();
if( !CMDIChildWnd::PreCreateWindow(cs) )
return FALSE;
return TRUE;
}
It's very close to success. But look closely, you will find a bit off. main frame overlapped child frame a little bit. I think that is because of edge of main frame window. But I am getting client area, it should not include edge right? any one can explain?
|
|
|
|
|
|
Many people recommend using member Get/Set functions in order to access class data, with the data members themselves being private/protected . I am pretty much sold on the idea, and though it means it takes longer to knock together even a basic class, the benefits are worth the effort IMHO.
However, I also make use of STL containers in my classes, but I have yet to find a satisfying way in which I should allow access to a private container. I have seen many classes that simply return a reference to the container, e.g.:
class CFoo
{
private:
std::list<std::wstring> m_strings;
public:
inline std::list<std::wstring>& GetStrings(void) { return m_strings; }
};
I'm sure you'll agree that this is pretty useless - you may as well make the container public and be done with it (OK, you can change the name of the container without having to change code that uses it, but this is still fairly insignificant).
So, how do others here offer access to such containers (doesn't have to be an STL container - could be an MFC/ATL CList/CArray/etc. )?
Take an example - I have a class that enumerates installed printers and stores the name of each printer in a std::vector . Now, if I wanted to fill a listbox with these printer names, I *could* offer a class method to do this for me, and thus hide the internal container implementation from the caller. However, in reality, I might also want the list of printers in a listbox, or a list control, or as text in an edit, etc. etc. so allowing calling code access to the vector is essential. How would you go about this while adhering to the Get/Set methodology?
One thought - for STL containers - would be to return const iterators, e.g.:
class CFoo
{
private:
std::list<std::wstring> m_strings;
public:
inline std::list<std::wstring>::const_iterator begin() const { return m_strings.begin(); }
inline std::list<std::wstring>::const_iterator end() const { return m_strings.end(); }
};
...
CFoo foo;
for (std::list<std::wstring>::const_iterator it = foo.begin(); it != foo.end(); ++it)
{
}
Thoughts?
The Rob Blog Google Talk: robert.caldecott
|
|
|
|
|
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
|
|
|
|