Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
F

frx96

@frx96
About
Posts
15
Topics
0
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Safe ActiveX control..
    F frx96

    This page might interest you. How to mark MFC ActiveX controls as Safe for Scripting and Initialization[^]">

    C / C++ / MFC c++ com question

  • GDI+ DrawImage() Speed Issue
    F frx96

    Another idea: Use two temp memory image(first is display,second is create in memory; change them when second is ready).

    C / C++ / MFC graphics help winforms hardware performance

  • CFONTDialog usage
    F frx96

    CDC::GetTextExtent BOOL ok = FALSE; int richeditwidth = CRichEditCtrl::GetRect get richeditwidth CFont font = CRichEditCtrl::GetFont do{ 1.CDC::GetTextExtent get stringwidth 2.if(stringwidth < richeditwidth) { ok = TRUE; } else { font size -- CRichEditCtrl::SetFont } }while(!ok); hope this can help u .

    C / C++ / MFC question

  • Error - hr = 0x80040110 Class does not support aggregation (or class object is remote)
    F frx96

    //sClassName eg:ResoftSign.ResoftSignCtrl //ResoftSign is the lib name //ResoftSignCtrl is the class name IDispatch* CreateClassComDispatch(BSTR sClassName) { CLSID clsid; IUnknown *pUnk; IDispatch *pDisp; HRESULT hr; CLSIDFromProgID(sClassName, &clsid); hr = CoInitialize(NULL); //see here. if(FAILED(hr)) return FALSE; hr = CoCreateInstance(clsid,NULL,CLSCTX_ALL,IID_IUnknown,(void**)&pUnk); if(FAILED(hr)) return FALSE; hr = pUnk->QueryInterface(IID_IDispatch, (void **)&pDisp); if(FAILED(hr)) { pUnk->Release(); return FALSE; } return pDisp; }

    COM help testing tools

  • Is there any way to control menus (e.g File--&gt; Save) in Office 2007 documents?
    F frx96

    1.Word eg: you can rewrite the sub of "save" in VBA template file: Sub FileSave() 'ActiveDocument.Save End Sub 2.word eg: set enble property: activedocument.CommandBars("File").Controls(5).Enabled = False 'office2003

    COM question

  • parse object array into string....
    F frx96

    1.Modify like this: [out] BSTR* pawSuggArray 2. "SAFEARRAY" maybe also can do this.

    COM help csharp c++ com data-structures

  • Sharing variable between instances of COM object?
    F frx96

    you can use share memory when sharing data between EXE and COM or between COM and COM: CreateFileMapping OpenFileMapping MapViewOfFile

    COM c++ com sysadmin help question

  • Convert const string& to CByteArray ?
    F frx96

    char str[] = "abcdef"; int iSize = strlen(str); BYTE * pByte = (BYTE *) str; CByteArray arr; for (int i = 0; i < iSize; i++) { arr.Add(pByte[i]); } the loop is must use.

    C / C++ / MFC question tutorial

  • (modeless?)dialog in sdi
    F frx96

    ClassLib, A C++ class library: http://www.codeproject.com/KB/library/classlib.aspx[^] the "MDI" Sample maybe you need.

    C / C++ / MFC help question business tutorial

  • (modeless?)dialog in sdi
    F frx96

    Second: // Simple MDI frame. class MDIFrame : public ClsMDIMainWindow { _NO_COPY( MDIFrame ); public: // Construction/destruction. MDIFrame() {;} virtual ~MDIFrame() {;} protected: // A child window has been closed. void OnMDIChildRemoved( ClsMDIChildWindow *pWnd ) { // Look it up in our array. for ( int i = 0; i < m_Children.GetSize(); i++ ) { // Is this the one? if ( m_Children[ i ] == reinterpret_cast( pWnd )) { // Free it and remove the entry // from the array. delete pWnd; m_Children.RemoveAt( i, 1 ); break; } } } // We do not want the system to erase the background of // the frame window. virtual LRESULT OnEraseBkgnd( ClsDC *pDC ) { return 1; } // WM_CLOSE handler. virtual LRESULT OnClose() { // Make sure the children are all destroyed. while ( m_Children.GetSize()) m_Children[ 0 ]->MDIDestroy(); PostQuitMessage( 0 ); return 0; } // WM_SIZE handler. virtual LRESULT OnSize( UINT nSizeType, int nWidth, int nHeight ) { // Size the splitter which will in turn size and // move it's panes. ClsRect rc, tb; GetClientRect( rc ); // Does it exist already? if ( m_Toolbar.GetSafeHWND()) { // Pass the message on to the toolbar. m_Toolbar.SendMessage( WM_SIZE, nSizeType, MAKELPARAM( nWidth, nHeight )); // Adjust client rectangle. m_Toolbar.GetWindowRect( tb ); rc.Top() += tb.Height(); } // Setup splitter rectangle. This will automatically // resize and reposition the panes aswell. m_Splitter.SetSplitRect( rc ); m_Splitter.RedrawPanes(); return 0; } // WM_CREATE overidable. virtual LRESULT OnCreate( LPCREATESTRUCT pCS ) { // First the base. if ( ClsMDIMainWindow::OnCreate( pCS ) == -1 ) return -1; // Create file/dir treeview. ClsRect rc( 0, 0, 0, 0 ); if ( m_Tree.Create( this, rc, IDC_FILEDIRTREE, WS_CHILD | WS_VISIBLE | TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS )) { // Setup the tree. m_Tree.ModifyExStyle( 0, WS_EX_CLIENTEDGE ); m_Tree.FileFilter() = _T( "*.c;*.cpp;*.h;*.hpp;*.txt" ); m_Tree.DoubleBuffer() = TRUE; m_Tree.LoadingTextColor() = RGB( 255, 0, 0 ); if ( m_Tree.SetupTree()) { // Create splitter. if ( m_Splitter.Create( this, 0 )) { // Setup the splitter and it's panes. m_Splitter.SetPanes( m_Tree, GetMDIClient()->GetSafeHWND()); m_Splitter.SetPaneMinSize( 100, 100 ); m_Splitter.Set

    C / C++ / MFC help question business tutorial

  • (modeless?)dialog in sdi
    F frx96

    First: // Simple MDI child. class MDIChildWnd : public ClsMDIChildWindow { _NO_COPY( MDIChildWnd ); public: // Construction/destruction. MDIChildWnd() {;} virtual ~MDIChildWnd() {;} // Create a child. BOOL Create( ClsString& str, ClsMDIMainWindow *pFrame ) { // We let the base create it for us. This will automatically call the // OnMDINCCreate() overidable in which we do our thing... ClsRect rc( CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT ); // Create it. BOOL bMaximized; if ( pFrame->MDIGetActive( &bMaximized ) == NULL ) bMaximized = TRUE; return ClsMDIChildWindow::Create( str, WS_VISIBLE | ( bMaximized ? WS_MAXIMIZE : 0 ), rc, pFrame ); } protected: // Handle the WM_CLOSE messages. virtual LRESULT OnClose() { // Destroy the window. MDIDestroy(); return 0; } // WM_SIZE handler. virtual LRESULT OnSize( UINT nSizeType, int nWidth, int nHeight ) { ........... // Base class. return ClsMDIChildWindow::OnSize( nSizeType, nWidth, nHeight ); } // WM_MDICREATE handler. virtual LRESULT OnMDINCCreate( LPCREATESTRUCT pCS ) { // Make sure the child has a client edge. NOTE: Simply adding this // bit to the CREATESTRUCT.dwExStyle will not work... // // We do it here like this also because the PreCreateWindow() overide // will not be called when creating MDI child windows. ModifyExStyle( 0, WS_EX_CLIENTEDGE ); return TRUE; } };

    C / C++ / MFC help question business tutorial

  • Printing using GDI
    F frx96

    also you can do like this: PRINTDLGEX pd; LPPRINTPAGERANGE ppr=NULL; ....... ZeroMemory(&pd, sizeof(PRINTDLGEX)); pd.lStructSize = sizeof(PRINTDLGEX); pd.hwndOwner = hwndFrame; pd.hDevMode = NULL; pd.hDevNames = NULL; pd.Flags = PD_RETURNDC | PD_USEDEVMODECOPIESANDCOLLATE | PD_NOSELECTION; pd.nCopies = 1; /* by default print all pages */ pd.nPageRanges =1; pd.nMaxPageRanges = MAXPAGERANGES; ppr = (LPPRINTPAGERANGE)malloc(MAXPAGERANGES*sizeof(PRINTPAGERANGE)); pd.lpPageRanges = ppr; ppr->nFromPage = 1; ppr->nToPage = dm->pageCount(); pd.nMinPage = 1; pd.nMaxPage = dm->pageCount(); pd.nStartPage = START_PAGE_GENERAL; if (PrintDlgEx(&pd) == S_OK) { if (pd.dwResultAction==PD_RESULT_PRINT) { if (CheckPrinterStretchDibSupport(hwndFrame, pd.hDC)){ if (pd.Flags & PD_CURRENTPAGE) { pd.nPageRanges=1; pd.lpPageRanges->nFromPage=currentPageNo(); pd.lpPageRanges->nToPage =currentPageNo(); } else if (!(pd.Flags & PD_PAGENUMS)) { pd.nPageRanges=1; pd.lpPageRanges->nFromPage=1; pd.lpPageRanges->nToPage =pageCount(); } PrintToDevice(dm, pd.hDC, (LPDEVMODE)pd.hDevMode, pd.nPageRanges, pd.lpPageRanges); } } } else { if (CommDlgExtendedError()) { /* if PrintDlg was cancelled then CommDlgExtendedError is zero, otherwise it returns the error code, which we could look at here if we wanted. for now just warn the user that printing has stopped becasue of an error */ MessageBox(win->hwndFrame, "Cannot initialise printer", "Printing problem.", MB_ICONEXCLAMATION | MB_OK); } } free(ppr); if (pd.hDC != NULL) DeleteDC(pd.hDC); if (pd.hDevNames != NULL) GlobalFree(pd.hDevNames); if (pd.hDevMode != NULL) GlobalFree(pd.hDevMode); }

    C / C++ / MFC graphics help tutorial question

  • Printing using GDI
    F frx96

    char devstring[256]; // array for WIN.INI data HANDLE printer; LPDEVMODE devMode = NULL; DWORD structSize, returnCode; GetProfileString("Devices", printerName, "", devstring, sizeof(devstring)); char *driver = strtok (devstring, (const char *) ","); char *port = strtok((char *) NULL, (const char *) ","); if (!driver || !port) { MessageBox(win->hwndFrame, "Printer with given name doesn't exist", "Printing problem.", MB_ICONEXCLAMATION | MB_OK); return; } BOOL fOk = OpenPrinter((LPSTR)printerName, &printer, NULL); if (!fOk) { MessageBox(win->hwndFrame, _TR("Could not open Printer"), _TR("Printing problem."), MB_ICONEXCLAMATION | MB_OK); return; } HDC hdcPrint = NULL; structSize = DocumentProperties(NULL, printer, /* Handle to our printer. */ (LPSTR) printerName, /* Name of the printer. */ NULL, /* Asking for size, so */ NULL, /* these are not used. */ 0); /* Zero returns buffer size. */ devMode = (LPDEVMODE)malloc(structSize); if (!devMode) goto Exit; // Get the default DevMode for the printer and modify it for your needs. returnCode = DocumentProperties(NULL, printer, (LPSTR) printerName, devMode, /* The address of the buffer to fill. */ NULL, /* Not using the input buffer. */ DM_OUT_BUFFER); /* Have the output buffer filled. */ if (IDOK != returnCode) { // If failure, inform the user, cleanup and return failure. MessageBox(win->hwndFrame, "Could not obtain Printer properties", "Printing problem.", MB_ICONEXCLAMATION | MB_OK); goto Exit; } .......... if (bitmapDx >bitmapDy) { devMode->dmOrientation = DMORIENT_LANDSCAPE; } else { devMode->dmOrientation = DMORIENT_PORTRAIT; } DocumentProperties(NULL, printer, (LPSTR) printerName, devMode, /* Reuse our buffer for output. */ devMode, /* Pass the driver our changes. */ DM_IN_BUFFER | /* Commands to Merge our changes and */ DM_OUT_BUFFER); /* write the result. */ ClosePrinter(printer); hdcPrint = CreateDC(driver, printerName, port, devMode); if (!hdcPrint) { MessageBox(win->hwndFrame, "Couldn't initialize printer", "Printing pro

    C / C++ / MFC graphics help tutorial question

  • Printing using GDI
    F frx96

    static bool CheckPrinterStretchDibSupport(HWND hwndForMsgBox, HDC hdc) { // most printers can support stretchdibits, // whereas a lot of printers do not support bitblt // quit if printer doesn't support StretchDIBits int rasterCaps = GetDeviceCaps(hdc, RASTERCAPS); int supportsStretchDib = rasterCaps & RC_STRETCHDIB; if (supportsStretchDib) return true; MessageBox(hwndForMsgBox, "This printer doesn't support StretchDIBits function", "Printing problem.", MB_ICONEXCLAMATION | MB_OK); return false; } static void PrintToDevice(DisplayModel *dm, HDC hdc, LPDEVMODE devMode, int nPageRanges, LPPRINTPAGERANGE pr, int printRange = 0) { ................ DOCINFO di = {0}; di.cbSize = sizeof (DOCINFO); di.lpszDocName = filename; if (StartDoc(hdc, &di) <= 0) return; ................. SetMapMode(hdc, MM_TEXT); int printAreaWidth = GetDeviceCaps(hdc, HORZRES); int printAreaHeight = GetDeviceCaps(hdc, VERTRES); int topMargin = GetDeviceCaps(hdc, PHYSICALOFFSETY); int leftMargin = GetDeviceCaps(hdc, PHYSICALOFFSETX); ......... // use pixel sizes for printer with non square pixels float fLogPixelsx= (float)GetDeviceCaps(hdc, LOGPIXELSX); float fLogPixelsy= (float)GetDeviceCaps(hdc, LOGPIXELSY); bool bPrintPortrait=fLogPixelsx*printAreaWidth<flogpixelsy*printareaheight;> BOOL isSameFile = IsSameFile(dm); int realWidth = printAreaWidth; int realHeight = printAreaHeight; // print all the pages the user requested unless // bContinue flags there is a problem. for (int i=0; i < nPageRanges; i++) { assert(pr->nFromPage <= pr->nToPage); for (DWORD pageNo = pr->nFromPage; pageNo <= pr->nToPage; pageNo++) { ............ StartPage(hdc); .............. bmp->stretchDIBits(hdc, leftMargin, topMargin, realWidth, realHeight); delete bmp; if (EndPage(hdc) <= 0) { AbortDoc(hdc); return; } } pr++; } Error: EndDoc(hdc); }

    C / C++ / MFC graphics help tutorial question

  • COM : ATL DLL?
    F frx96

    IDispatch* DllBase::CreateClassComDispatch(BSTR sClassName) { CLSID clsid; IUnknown *pUnk; IDispatch *pDisp; HRESULT hr; CLSIDFromProgID(sClassName, &clsid); hr = CoInitialize(NULL); if(FAILED(hr)) return FALSE; hr = CoCreateInstance(clsid,NULL,CLSCTX_ALL,IID_IUnknown,(void**)&pUnk); if(FAILED(hr)) return FALSE; hr = pUnk->QueryInterface(IID_IDispatch, (void **)&pDisp); if(FAILED(hr)) { pUnk->Release(); return FALSE; } return pDisp; } GetPrinterList(char* printLib, char* printersUrl, char* username, char* password) { char* retValue = NULL; HRESULT hr; DISPID idd; VARIANTARG varResult; IDispatch *pDisp; try { VariantInit(&varResult); retValue = NULL; //lib _bstr_t bstrLib = _bstr_t(printLib); pDisp = CreateClassComDispatch(bstrLib.GetBSTR()); if(pDisp == NULL) return NULL; //function LPOLESTR str = L"GetPrinterList"; //params int ParamsNumber = 3; VARIANTARG avarParams[3]; for(int i=0;i<paramsnumber;i++){> ::VariantInit( &avarParams[i] ); } _bstr_t bstrTemp1 = _bstr_t(password); avarParams[0].vt = VT_BSTR; avarParams[0].bstrVal = bstrTemp1.copy(); _bstr_t bstrTemp2 = _bstr_t(username); avarParams[1].vt = VT_BSTR; avarParams[1].bstrVal = bstrTemp2.copy(); _bstr_t bstrTemp3 = _bstr_t(printersUrl); avarParams[2].vt = VT_BSTR; avarParams[2].bstrVal = bstrTemp3.copy(); DISPPARAMS params = { avarParams, NULL, ParamsNumber, 0 }; //get ID hr = pDisp->GetIDsOfNames(IID_NULL,&str,1,NULL,&idd); if(!FAILED(hr)) { hr = pDisp->Invoke(idd, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, ¶ms, &varResult, NULL, NULL); if(FAILED(hr)) retValue = NULL; else { _bstr_t retvalue = _bstr_t(varResult.bstrVal); retValue = strdup((char*)retvalue); } } else { retValue = NULL; } for(int j=0;j<paramsnumber;j++){> ::VariantClear( &avarParams[j] ); } ::VariantClear( &varResult ); return retValue; } catch(...) { } return NULL; }

    C / C++ / MFC c++ com question
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups