Skip to content

C / C++ / MFC

C, Visual C++ and MFC discussions

This category can be followed from the open social web via the handle c-c-mfc@forum.codeproject.com

111.5k Topics 465.7k Posts
  • wildcard matching with strings

    database regex tutorial question
    7
    0 Votes
    7 Posts
    30 Views
    T
    Hello everybody and thanks for all tips and code. After all I wrote my own function that serves my needs. It is capable to handle ? and * correctly - as I think. Here it is: int wcmatch(const char *pPattern, const char *pStr; const char *mystrstr(const char *pPattern, const char *pStr, int *pLen; //similiar to strstr() but: // + the search pattern ends at a '\0' or a '*'. // + '?' matches to every character != '\0' // + Return value is pointer to the first char in pStr // that belongs to the first occurence of pPattern // or NULL if not found. // // Example: mystrstr("a?c*xyz", "123456abcdefg", &len) = "abcdefg" // len==3. const char *mystrstr(const char *pPattern, const char *pStr, int *pLen) { int iMatch; const char *pStart=pStr, *pp, *ps; if (pLen) *pLen = 0; if (!pPattern || !pStr) return FALSE; for (pStart=pStr; *pStart; pStart++) { ps = pStart; pp = pPattern; iMatch = TRUE; while (iMatch) { switch (*pp) { case '*': case '\0': if (pLen) *pLen = ps - pStart; return pStart; break; case '?': if (*ps) { pp++; ps++; } else iMatch = FALSE; break; default: if (*pp == *ps) { pp++; ps++; } else iMatch = FALSE; break; } } } return FALSE; } int wcmatch(const char *pPattern, const char *pStr) { if (!pPattern || !pStr) return FALSE; int iWildcardMode = FALSE, iLen; const char *pStarMatchStart; while (*pPattern && *pStr) { switch (*pPattern) { case '?': pPattern++; pStr++; break; case '*': // Switch to wildcard-mode. Keep this mode until a // character diffrent to '?' and '*' is found. iWildcardMode = TRUE; pPattern++; break; default: if (iWildcardMode) { iWildcardMode = FALSE; if (pStarMatchStart = mystrstr(pPattern, pStr, &iLen)) { pPattern += iLen; pStr = pStarMatchStart + iLen; } else return FALSE; } else { if (*pPattern != *pStr) return FALSE; pPattern++; pStr++; } break; } } if (*pPattern == *pStr) return TRUE; if (*pPattern == '\0') { if (iWildcardMode) return TRUE; // Last char of pattern was '*' else return FALSE; // String has additional non matching chars. No match. } if (*pStr=='\0') { // This is a match, if only '*'s follow while (*pPattern == '*')
  • How to change the default value of a DAO field object

    database tutorial question
    2
    0 Votes
    2 Posts
    9 Views
    L
    Look at DAOTABLE sample in VC++ help. It shows how to create tables, fields,and indexes... Walter ================== The original message was: I'm using an Access 97 database and I want to change this value programmatically (updating users databases). I can read it by calling GetFieldInfo() using AFX_DAO_ALL_INFO, but there is no SetFieldInfo() function. Any suggestions?
  • network monitor 2.0 SDK

    sysadmin question
    1
    0 Votes
    1 Posts
    5 Views
    No one has replied
  • 0 Votes
    3 Posts
    22 Views
    L
    Yep, that's it, thanks.
  • Print a dialog box!

    help question career
    2
    0 Votes
    2 Posts
    27 Views
    H
    Did you try giving your dialogs a WM_PRINTCLIENT message handler? And shouldn't you add the flag PRF_PRINTCLIENT? ================== The original message was: Hi! In my MDI app, i want to add a "Print" button at each dialog box to allow to the user to print it. Is it possible to print a dialog box? I try to use the CWnd::Print() function. The help says "Call this member function to draw the current window in the specified device context, which is most commonly in a printer device context." But it doesn't work! This is my code... void CSACellDefDlg::OnPrint() { CDC dc; CPrintDialog printDlg(FALSE); // Get printer settings from user if (printDlg.DoModal() == IDCANCEL) return; // Attach a printer DC dc.Attach(printDlg.GetPrinterDC()); dc.m_bPrinting = TRUE; // Get the application title and initialise print document details DOCINFO di; ::ZeroMemory (&di, sizeof (DOCINFO)); di.cbSize = sizeof (DOCINFO); di.lpszDocName = ""; // Begin a new print job BOOL bPrintingOK = dc.StartDoc(&di); // Get the printing extents and store in the m_rectDraw field of a // CPrintInfo object CPrintInfo Info; Info.m_rectDraw.SetRect(0,0,dc.GetDeviceCaps(HORZRES),dc.GetDeviceCaps(VERTRES)); // begin new page dc.StartPage(); this->Print(&dc,PRF_ERASEBKGND); // end page bPrintingOK = (dc.EndPage() > 0); if (bPrintingOK) // end a print job dc.EndDoc(); else // abort job. dc.AbortDoc(); // detach the printer DC dc.Detach(); } Thanks for your help Sandrine
  • DB grid control problem

    database question css help
    1
    0 Votes
    1 Posts
    8 Views
    No one has replied
  • What do I get back from OLEFormatPtr::GetObject() ?

    question com hardware tutorial
    1
    0 Votes
    1 Posts
    14 Views
    No one has replied
  • RE: Trying to print with a CWinThread...

    help question
    1
    0 Votes
    1 Posts
    5 Views
    No one has replied
  • remove scroll bars in Grid Control

    css tutorial question
    2
    0 Votes
    2 Posts
    15 Views
    C
    The autosize functions need some tweaking which I will do in the next release. This should solve the problem. cheers, Chris ================== The original message was: hi all, Could someone tell me how to remove the scroll bars in Chris Maunder's Grid Control? Thanks in advance! Jason
  • redirect cerr to a string stream

    tutorial question
    2
    0 Votes
    2 Posts
    8 Views
    A
    Hi Hung! You can use the assignment operator of the cere. Here is the small example which can help you: #include "stdafx.h" #include #include char szBuffer[1024]; ostrstream cstr(szBuffer, sizeof(szBuffer)-1); int main(int argc, char* argv[]) { // put something in the output streams cout << "Standart Output\n"; cerr << "Standart Error\n"; cstr << "***Our String**\n"; // use the assignment operator to change the cerr cerr = cstr; cout << "Standart Output\n"; cerr << "Standart Error After Assigment\n"; // show the content of our cstr //cout << cstr.str(); cout << endl << "Preess ENTER to exit" << endl; getchar(); return 0; } Alex Gorev, Dundas Software. ================== The original message was: Hi, Does anyone know how to redirect cerr to a string stream? Thank you Hung
  • How to get the caret's position in a richedit?

    tutorial question
    2
    0 Votes
    2 Posts
    18 Views
    P
    Thömmi, You are actualy very close to the solution to this problem. To get the caret position within current line you will have to look at two CRichEditCtrl member functions. GetSel - if you are not handling the 'EN_SELCHANGE' notification than use this function to get current position of the caret. Vales returned contain character position from the beginning of the rich edit string. Use the LineIndex function to get total number of characters before current line. By subtracting chars before line from the caret position you will get column index in current line. void CRichEditTestDlg::OnSelchangeRichedit(NMHDR* pNMHDR, LRESULT* pResult) { SELCHANGE *pSelChange = reinterpret_cast(pNMHDR); CString tempStr; tempStr.Format( "ln: %d, col: %d", m_richEdit.LineFromChar( -1 ), pSelChange->chrg.cpMin - m_richEdit.LineIndex( -1 )); SetDlgItemText( IDC_POS, tempStr ); *pResult = 0; } Peter Zajac Dundas Software ================== The original message was: Hi all, I am writing a MDI application, which views are derivated by CRichEditView. In the status bar, I want to display the current position of the caret. The line number is easy to get, just call GetRichEditCtrl().LineFromChar(-1), but how to determine the column? Thanks in advance, Thömmi
  • HtmlHelp in multi-threaded app

    help html question
    3
    0 Votes
    3 Posts
    20 Views
    M
    Hi Carole, thanks for your reply, but calling HtmlHelp via ShellExecute was not an option, because I want to handle it in one place, in CWinApp::WinHelp. But the problem is solved now. Downloading the newest version of the HTML Help Workshop from the microsoft site solved the problem. Martin
  • OnDraw, how can I get the rectangle that is painting ?

    question
    3
    0 Votes
    3 Posts
    26 Views
    L
    Use CDC::GetClipBox to get the area that needs to be repainted.
  • GetFieldValue() throws an exception

    question database help
    2
    0 Votes
    2 Posts
    15 Views
    U
    The problem is most like caused because you're trying to access the same column's value twice. I haven't debugged into the GetFieldValue code but I do know from experience that you may only retrieve a column's value once and in the proper order. In other words, if you do SELECT *, you must access the columns in the same order as they appear on the table. If you do a SELECT COL1, COL2, ... you must call GetFieldValue for COL1 before calling it for COL2. I hope this helps, Alvaro
  • [Q]Using the MAPI

    performance help announcement
    1
    0 Votes
    1 Posts
    9 Views
    No one has replied
  • mpeg extraction

    1
    0 Votes
    1 Posts
    9 Views
    No one has replied
  • Trying to print with a CWinThread...

    help question
    1
    0 Votes
    1 Posts
    15 Views
    No one has replied
  • CHtmlView

    question
    1
    0 Votes
    1 Posts
    5 Views
    No one has replied
  • MDI custom tile with open/close of childeren?

    question c++ tutorial
    2
    0 Votes
    2 Posts
    19 Views
    M
    Write a window class dervied from CWnd. class MdiClient : public CWnd { DECLARE_DYNAMIC( MdiClient ) public: // Construction/Destruction MdiClient(); protected: // ClassWizard generated message map functions //{{AFX_MSG( MdiClient ) //}}AFX_MSG afx_msg LRESULT OnMDICreate( WPARAM, LPARAM lParam ); afx_msg LRESULT OnMDIDestroy( WPARAM wParam, LPARAM ); DECLARE_MESSAGE_MAP() int m_nMDICount; }; IMPLEMENT_DYNAMIC( MdiClient, CWnd ) // Construction/Destruction MdiClient::MdiClient() : m_nMDICount( 0 ) { } // ClassWizard generated message map functions BEGIN_MESSAGE_MAP( CLASS, BASE ) //{{AFX_MSG_MAP( MdiClient ) //}}AFX_MSG_MAP ON_MESSAGE( WM_MDICREATE, OnMDICreate ) ON_MESSAGE( WM_MDIDESTROY, OnMDIDestroy ) END_MESSAGE_MAP() LRESULT MdiClient::OnMDICreate( WPARAM, LPARAM lParam ) { LPMDICREATESTRUCT lpmdic = (LPMDICREATESTRUCT)lParam; HWND hwndMDIChild = (HWND)CWnd::DefWindowProc( WM_MDICREATE, 0L, (LRESULT)lpmdic ); if ( hwndMDIChild != NULL ) { ++m_nMDICount; // Reposition the MDI childs like you want } return (LRESULT)hwndMDIChild; } LRESULT MdiClient::OnMDIDestroy( WPARAM wParam, LPARAM ) { --m_nMDICount; if ( m_nMDICount > 0 ) { // Reposition the MDI childs like you want } return CWnd::DefWindowProc( WM_MDIDESTROY, wParam, 0L ); } 2) Derive a class from CMDIFrameWnd, and overwrite OnCreate. int MdiFrameWnd::OnCreate( LPCREATESTRUCT lpCreateStruct ) { if( CMDIFrameWnd::OnCreate( lpCreateStruct ) == -1 ) { return -1; } m_pwndMdiClient = new MdiClient; if( !m_pwndMdiClient->SubclassWindow( m_hWndMDIClient ) ) { return -1; } return 0; } HTH Martin