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
J

JJeffrey

@JJeffrey
About
Posts
29
Topics
11
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Creating a column with bitmaps on CListCtrl residing on a dialog
    J JJeffrey

    Thanks again. I'm still trying to work out the solution after shifting everything to the CQuickList class. Took me a while to figure out how to use the class even with the webpage. Thanks.

    C / C++ / MFC graphics question

  • Creating a column with bitmaps on CListCtrl residing on a dialog
    J JJeffrey

    No change in output. Column 1 data disappears. Column 3 remains empty

    C / C++ / MFC graphics question

  • Creating a column with bitmaps on CListCtrl residing on a dialog
    J JJeffrey

    Sorry to trouble you guys, but I think I'm missing something in my understanding of the List Control boxes. I'm creating a CListCtrl box with 3 columns. The first 2 are text and the third will show bitmaps. My code goes like this:

    void PopulateList ()
    {
    LVCOLUMN lvColumn1,lvColumn2,lvColumn3;
    COLORREF rgbMask = RGB(0,0,0); //(rgb[0].rgbtRed, rgb[0].rgbtGreen, rgb[0].rgbtBlue);
    // I believe I need to create a CImageList for the bitmap column, right?
    CImageList ThumbList;
    ThumbList.Create(MAXWIDTH, MAXHEIGHT, ILC_COLOR, 1, 1);

    //Create Column 1
    lvColumn1.mask = LVCF\_FMT | LVCF\_TEXT | LVCF\_WIDTH;
    lvColumn1.fmt = Alignment;
    lvColumn1.cx = 120;
    lvColumn1.pszText = ColumnHeading\[0\];
    nCol = m\_MainList.InsertColumn(0, &lvColumn1);
    
    int NextIndex = nCol;
    
    //Populate Column 1
    while (!EOF)
        {
          //Read the Data from File and store in "OutputTitle"
          .
          .
          LVITEM lvItem;
      lvItem.mask = LVIF\_TEXT;
      lvItem.iItem = NextIndex;
      lvItem.iSubItem = 0;
      lvItem.pszText = OutputTitle;
      NextIndex = m\_MainList.InsertItem(&lvItem);
          .
        }
    ListView\_SortItemsEx( m\_MainList.m\_hWnd, CompareProc, (LPARAM)&m\_MainList );
    
    //Create Column 2
    lvColumn2.mask = LVCF\_FMT | LVCF\_TEXT | LVCF\_WIDTH;
    lvColumn2.fmt = Alignment;
    lvColumn2.cx = 120;
    lvColumn2.pszText = ColumnHeading\[1\];
    nCol = m\_MainList.InsertColumn(1, &lvColumn2);
    
    //Populate Column 2
    int NumOfEntries = m\_MainList.GetItemCount();
    
    for(int i=0; i>NumOfEntries; i++)
    {
           //Get data based on First Column entries
           .
           .
           .
       m\_MainList.SetItemText(i,1, );
    }
    
    //Create Column 3
    lvColumn3.mask = LVCF\_FMT | LVCF\_TEXT | LVCF\_WIDTH;
    lvColumn3.fmt = Alignment;
    lvColumn3.cx = 240;
    lvColumn3.pszText = ColumnHeading\[2\];
    nCol = m\_MainList.InsertColumn(2, &lvColumn3);
    
    
    NextIndex = nCol;
    
    //Populate Column 3
    BYTE PreviewInfo\[MAXHEIGHT\]\[MAXWIDTH\]\[3\]={0};
    int ImageIndex = 0;
    
    for(int i=0; i
    		CBitmap	\*ThumbNail = new CBitmap;
    		ThumbNail->Attach(Picture );
    		ImageIndex = ThumbList.Add(ThumbNail,rgbMask);
    		m\_MainList.SetImageList(&ThumbList, LVSIL\_SMALL);
    
    		LVITEM lvItem;
    		lvItem.mask = LVIF\_IMAGE;
    		lvItem.iItem = i;              // I tried
    		lvItem.iSubItem = 0;
    		lvItem.iImage = ImageIndex;
    		NextIndex =
    
    C / C++ / MFC graphics question

  • Sorting using CListCtrl::SortItems
    J JJeffrey

    Thank you. That solved it. So it's mostly Microsoft's fault then? For coming up with that stupid function? Really. Thanks. Was working on trying to make it work for a day now.

    C / C++ / MFC help c++ com algorithms debugging

  • Sorting using CListCtrl::SortItems
    J JJeffrey

    I'm having a problem using this function of the MFC List Control class I've read the article : Example of CListCtrl::SortItems(...) in MSDN By Ivor S. Sargoytchev Example of CListCtrl::SortItems(...) in MSDN[^] And am trying out his example Callback funtion this way:

    static int CALLBACK CompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
    {
    // lParamSort contains a pointer to the list view control.
    CListCtrl* pListCtrl = (CListCtrl*) lParamSort;
    CString strItem1 = pListCtrl->GetItemText(lParam1, 0);
    CString strItem2 = pListCtrl->GetItemText(lParam2, 0);

    return _tcscmp(strItem1, strItem2); // This should do ascending Sort, I believe?
    }

    Relevant Code:

    LVCOLUMN lvColumn;
    int nCol =0;

    lvColumn.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
    lvColumn.fmt = LVCFMT_LEFT;
    lvColumn.cx = 120;
    lvColumn.pszText = ColumnHeading[0]; //<-- Global Enum list of titles
    nCol = m_MainList.InsertColumn(0, &lvColumn);

    int NextIndex = nCol;
    .
    .
    .
    TCHAR Output[50]={0};
    while ()
    {

    LVITEM lvItem;
    lvItem.mask = LVIF_TEXT;
    lvItem.iItem = NextIndex;
    lvItem.iSubItem = 0;
    lvItem.pszText = Output;
    NextIndex = m_MainList.InsertItem(&lvItem);
    }

    m_MainList.SortItems(CompareProc, (LPARAM)&m_MainList);

    m_MainList is the Control variable for a List Control box I placed on a dialog I put a breakpoint inside the Sort Function CompareProc and found that lParam1 and lParam2 are always 0 constantly and never increasing. I have been told it could be a pointer issue, but I don't get it. Can anyone help? Thanks

    C / C++ / MFC help c++ com algorithms debugging

  • How do you refresh/update a parent dialog when Modal child dialog is active
    J JJeffrey

    Ok, call me an idiot, but how do i use the pointer to parent? I was trying this:

    CParentDialog* pParent = STATIC_DOWNCAST( CParentDialog, );
    pParent->m_Preview.SetBitmap(XXX);

    within the Exit routine of the child dialog but I can't get the program to recognise CParentDialog

    error C2065: CParentDialog: undeclared identifier

    How do I declare the Class of the parent window in the child's code? I can't seem to remember if there's a way with extern. Thanks again.

    C / C++ / MFC database graphics question announcement

  • How do you refresh/update a parent dialog when Modal child dialog is active
    J JJeffrey

    I've been trying to update data that is currently displayed on a parent dialog while the user is entering data on a modal child dialog, or at least when the user closes the modal child dialog. The parent window has a preview thumbnail of a picture file, the user can open a modal child dialog that allows him to edit this picture. What I want is for the editing of the picture or, at worst, the closing of the edit modal dialog. The editing is done by bitmap bit editing and the data is saved to a file. The parent's preview image is generated by retrieving the data on file and reconstructing the bitmap using SetBitmapBits. The preview 'window' is a Bitmap dialog object which I use SetBitmap to load the reconstructed bitmap.

    void CParentDialog::OnLbnSelchangeStringlist()
    {
    DWORD SelectedID =0;
    BYTE PreviewInfo[MAXHEIGHT][MAXWIDTH][3];

    SelectedID = m\_StringList.GetCurSel();  //Get the name of the image
    if(SelectedID!=LB\_ERR )
    	m\_StringList.GetText(SelectedID, SelString);
    
    BOOL ValidPicture = ReadDataFromDataFile(PreviewInfo);  //Read the appropriate Data from file
    HBITMAP PreviewDisplay = ArrayToBitmap(PreviewInfo); //convert from bit data to BMP format
    
    m\_Preview.SetBitmap(PreviewDisplay);  //Set the Preview image
    

    }

    void CParentDialog::OnEditbmp()
    {
    CChildDialog* EditImage = new CChildDialog;
    EditImage->Create(IDD_BITMAPEDIT, this);
    }

    At this moment, I can show the preview from file before the edit (triggering off a select event when the user selects the image name), but when the user opens the edit modal dialog (trigger from button press), makes changes, saves the changes to file and exits the modal dialog, the preview image on the parent window is not updated (expected behaviour since I didn't call for any change). Is there a method to trigger the update of the data on the parent dialog? Since the modal child dialog is a different class, I do not have access to the variables of the parent dialog, and I cannot create an instance of the parent dialog just to make changes, can I? Is there a triggering point when I close the child dialog that allows me to run some code on the parent dialog's side to cupdate the picture? Thanks in advance. Please feel free to ask any questions. I'll answer them asap.

    C / C++ / MFC database graphics question announcement

  • SetSelectionCharFormat difficulties when selection contains different charset
    J JJeffrey

    Thanks. That seems to have worked. Guess i missed that part. As for the question, I guess I'm used to the "Get" then "Set" process. Didn't think of any other way. Thanks again.

    C / C++ / MFC json tutorial question announcement

  • How to save the content of an "Rich Edit Control" As IT IS?
    J JJeffrey

    I am currently using

        TCHAR  TextArray\[MAXARRAY\]={0};
    m\_RichEditCtrlVariable.GetWindowText(TextArray, MAXARRAY);
    CHARFORMAT CharForm;
    m\_RichEditCtrlVariable.GetSelectionCharFormat(CharForm);
    

    GetWindowText will get the words and newline characters and what not. GetSelectionCharFormat will get the font type, font size, bold, italics, colour, etc. Though, this has a problem if the font changes at any point in the rich edit box. It'll only return the first character set details it encounters. Don't know if that'll help youi in any way

    C / C++ / MFC question c++ tutorial

  • SetSelectionCharFormat difficulties when selection contains different charset
    J JJeffrey

    I am using SetSelectionCharFormat in a RichEditCtrl object on my dialog box to allow a user to change the font/bold/etc text he is typing in the rich edit box. Basically the function should change the character formatting as needed; the code is as follows:

    void CRichEditProjDlg::OnSelchangeFontsize()
    {
    DWORD Selection=0, FontSize=0;
    CString SelFontSize;
    Selection = m_FontSize.GetCurSel(); //Get the current Selection

    m\_FontSize.GetLBText(Selection, SelFontSize);    //Get the requested Font Size from a drop down box
    FontSize = \_ttoi(SelFontSize);
    
    CHARFORMAT Cfm;
        Cfm.cbSize = sizeof(CHARFORMAT);
    m\_RichCatch.GetSelectionCharFormat(Cfm);        //Get the char set of the selection
    
    Cfm.yHeight = FontSize\*20;                      //Calculate the new font size
    
    m\_RichCatch.SetSelectionCharFormat(Cfm);        //Set the new font size
    m\_RichCatch.SetFocus();                         //Update the Rich Edit Box
    UpdateData(TRUE);
    

    }

    void CRichEditProjDlg::OnBold()
    {
    CHARFORMAT Cfm;
    Cfm.cbSize = sizeof(CHARFORMAT);

    m\_RichCatch.GetSelectionCharFormat(Cfm);       //Get the char set of selection
    
    Cfm.dwMask = CFM\_BOLD;                         //Apply "boldness"
    Cfm.dwEffects ^= CFE\_BOLD; 
    
    m\_RichCatch.SetSelectionCharFormat(Cfm);       //Set the char set
    m\_RichCatch.SetFocus();
    

    }

    This bold-ing function works fine, but the Font size one only works when the selected text are all of the same font size. For example, if all of the selected text are of font size 10, I selected all of them and chose Font size 20, they would all change to font size 20. But if the selected text was of differing font sizes, say the first few words were font size 10 and the rest font size 11, the code does not change the font size of any of the selelcted text. Am I approaching the function in the wrong way? Or must I do an internal check for different font sizes and change them all separately somehow? Please feel free to ask for more information if needed. Thank you.

    C / C++ / MFC json tutorial question announcement

  • Problems with CStatic GetBitmap
    J JJeffrey

    Never thought of it that way. Thought the Picture box would store the data so I can retrieve it later or allow another function to operate on it. If the data object is destroyed like that, all my functions would have to be tightly coupled together. and that would be rather wierd from an OO programming POV. You have anyway to retrieve a bitmap from a picture box object in a dialog AFTER the function that places it there destroys the CDC that was containing it? Jeffrey

    C / C++ / MFC graphics data-structures help question

  • Problems with CStatic GetBitmap
    J JJeffrey

    I am currently trying to get the bitarray of bitmap that has already been loaded into a picture box of a dialog window when I press a button on the dialog. The overall aim is, Button 1 takes data from user, takes editing parameters and creates a BMP from it the result of the editing , putting the BMP into a picture box in a dialog. Button 2 is the "save" feature, which allows the final changed Bitmap to be saved back into bitmapbits array. Here's the problem:

    void CProjectDlg::OnButton2Press()
    {
    CFile TestFile;
    HBITMAP CapturedBMP = m_PicBox.GetBitmap(); //------------ (1)
    CBitmap RS232BMP;
    RS232BMP.Attach(CapturedBMP);
    BITMAP TempBMStore;
    RS232BMP.GetBitmap(&TempBMStore); //------------- (2)
    BYTE* bmpBuffer=(BYTE*)GlobalAlloc(GPTR, TempBMStore.bmWidthBytes*TempBMStore.bmHeight);
    DWORD dwValue=RS232BMP.GetBitmapBits(TempBMStore.bmWidthBytes*TempBMStore.bmHeight, bmpBuffer);
    }

    I get a valid handle at (1) but I my TempBMStore is blank after I execute line (2), meaning I do not have a valid Bitmap or something (return value is 0). What Am I doing wrong here? When I cut and paste this code into the section of code that originally places the bitmap into the picture box, I have absolutely no problem. ie:

    void CProjectDlg::OnButton1Press()
    {
    .
    .
    .
    .
    .
    .
    .
    .
    .
    m_PicBox.SetBitmap(TmpBmp);

    CFile	TestFile;
    HBITMAP CapturedBMP = m\_PicBox.GetBitmap();              //------------ (1)
    CBitmap	RS232BMP;
    RS232BMP.Attach(CapturedBMP);
    BITMAP TempBMStore;
    RS232BMP.GetBitmap(&TempBMStore);                       //------------- (2)
    BYTE\* bmpBuffer=(BYTE\*)GlobalAlloc(GPTR, TempBMStore.bmWidthBytes\*TempBMStore.bmHeight);	
    DWORD dwValue=RS232BMP.GetBitmapBits(TempBMStore.bmWidthBytes\*TempBMStore.bmHeight, bmpBuffer);
    

    }

    Thje return for line (2) is valid and I can get the bitmap bits with no errors. Same code, different behaviour. Do I need to make the Picture Box valid or something?

    Thanks in advance

    C / C++ / MFC graphics data-structures help question

  • Debug Assertion failure in AFXWIN2.inl
    J JJeffrey

    Ah... I see. Cart before the horse issue... All because I was doing it in modules and didn't set up everything else yet before testing.. I'll try again... Thanks

    C / C++ / MFC help graphics debugging question

  • Debug Assertion failure in AFXWIN2.inl
    J JJeffrey

    I seem to have encountered a Debug Assertion failure in AFXWIN2.inl, line 572 The error happens in the following Code:

    void CBitmapEdit::PutUpImage()
    {
    HBITMAP PreEditImage = LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP1));

    m\_EdittingImage.SetBitmap(PreEditImage)   // <--- Error occurs here
    
        DoModal();
    

    }
    .
    .
    .
    .
    .
    .
    void CEditAndCapture::OnEditbmp()
    {
    CBitmapEdit* EditImage = new CBitmapEdit;
    EditImage->PutUpImage();
    }

    m_EdittingImage is a CStatic object that will contain the Bitmap to display a dialog CBitmapEdit is a class derived from CDialog that will create a popup modal dialog box CEditAndCapture is the class that handles the main window and the call to CBitmapEdit is as above. I kinda suspect is the way I'm calling CBitmapEdit's methods, am I right? BTW, Line 572 is :

    _AFXWIN_INLINE HBITMAP CStatic::SetBitmap(HBITMAP hBitmap)
    { ASSERT(::IsWindow(m_hWnd)); return (HBITMAP)::SendMessage(m_hWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap); }

    Can anyone help? Thanks. Jeffrey

    C / C++ / MFC help graphics debugging question

  • Today I am a Zero
    J JJeffrey

    There there. Cheer up. At least you know you aren't a heartless person and that you actually care. Not like the many companies that just let people go without even a blink. Without any compensation even. I have read in the papers on my side that a bank here let a bunch of their people go by calling them into the head office early in the morning and told to leave their door passes with HR on the spot and to not come back to work the next day then told to clear their desk within the next 10 minutes. Hope you did good by the guys you are laying off. Maybe help them look for a job opening somewhere with a business contact (if any opening exists in this economic climate... *sigh*). Treat them to a good dinner? It's not easy to be jobless at this time. We feel for you to have to do it to them, and all of us hope these tiems will end soon. Cheer up..

    The Lounge

  • Reading a MBCS string from a Rich Edit Text Box in VC6
    J JJeffrey

    Thanks, my problem is resolved, though now I need to iron out the bugs that appeared due to my hasty switchover to Unicode. I'll start building my programs using Unicode from the start next time. Thanks again. Jeffrey

    C / C++ / MFC question help

  • Reading a MBCS string from a Rich Edit Text Box in VC6
    J JJeffrey

    Maybe I'm just too embedded into the notion that Unicode is Unicode, MBCS is MBCS and never the twain should they meet... Guess that idea is obsolete now. I tried the "hack" with my MBCS build but nothing changed. I'll take some time to convert to a Unicode build and try again. Thanks for your time and sorry for fustrating you.

    C / C++ / MFC question help

  • Reading a MBCS string from a Rich Edit Text Box in VC6
    J JJeffrey

    Hi Rajesh Aren't Japanese, Chinese and Korean Double byte and thus MBCS? I read this page and many others that led me to think so: [^] My main focus are the Asian text for now. If I need Unicode for German, then I'll do another program for it later, I'm sorry for the confusion and perhaps my lack of understanding on it. Are you telling me I should do a unicode build to handle both double byte and other non-double-byte text? I can cut and copy any text I can get on Wordpad into my Rich Edit Control with no problems, but I cannot seem change my language settings when my program is in focus and is the main window, thus I cannot type directly into the rich edit control. Does this help to diagnose my problem? Thanks

    C / C++ / MFC question help

  • Reading a MBCS string from a Rich Edit Text Box in VC6
    J JJeffrey

    I'm sorry to trouble everyone, I have a feeling this should be a simple answer but I'm missing something. I need to take in from a Rich Edit Box on my dialog box a string which can be a string in Chinese, Japanese, English, German, etc. I'm currently using this:

    char TextArray[SIZE]={0};
    m_RichEditBox.GetWindowText(TextArray, SIZE);

    When I encounter a Multi-char string (like the Chinese or Japanese ones), the string TextArray is filled with "????" instead (Yes, Question marks, in case you thought you saw wrongly) I have tried to declare TextArray as a

    TCHAR

    , tried to convert it to a wchar, tried to declare as a CString, but so far nothing has worked. I have checked, I do not have _UNICODE declared, and since _MBCS is default in VC6, shouldn't I get some result instead of "????" ? Or is my problem the fact I'm using VC6? Thanks in advance, and if you need more info, feel free to ask. Jeffrey

    C / C++ / MFC question help

  • Having difficulty writing text on a bitmap
    J JJeffrey

    Thank you, Thank you... THANK. YOU! Your program is fantastic. I see where it went wrong now, the SelectObjects were causing the HDCs to overwrite with old images as they weren't done properly (I think...). I delayed it till later in the code. For the record, this code works:

    void CCaptureAndDisplayDlg::OnTest()
    {

    HBITMAP hbitmap = ::LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB\_BITMAP1));
    
    BITMAP bitm;
    GetObject( hbitmap, sizeof(BITMAP), &bitm );
    long width=bitm.bmWidth;
    long height=bitm.bmHeight;
    BITMAPINFO bmInfo;
    int rtn=0;
    
    memset(&bmInfo.bmiHeader,0,sizeof(BITMAPINFOHEADER));
    bmInfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
    bmInfo.bmiHeader.biWidth=width;
    bmInfo.bmiHeader.biHeight=height;
    bmInfo.bmiHeader.biPlanes=1;
    bmInfo.bmiHeader.biBitCount=24;
    
    //create a temporary dc in memory.
    HDC pDC = ::GetDC(0);
    HDC TmpDC=CreateCompatibleDC(pDC);
    
    //create a new bitmap and select it in the memory dc
    BYTE \*pbase;
    HBITMAP TmpBmp=CreateDIBSection(pDC, &bmInfo,DIB\_RGB\_COLORS,(void\*\*)&pbase,0,0);
    HGDIOBJ TmpObj=SelectObject(TmpDC,TmpBmp);
    
    //draw the background
    HDC dcBmp=CreateCompatibleDC(TmpDC);
    HGDIOBJ TmpObj2 = SelectObject(dcBmp,hbitmap);
    
    BitBlt(TmpDC,0,0,width,height,dcBmp,0,0,SRCCOPY);
    
    char \*myText = "Testing"; 
    HFONT oldFnt, font1;
        font1 = CreateFont(-13, 0, 0, 0, 400, FALSE, FALSE, FALSE, 1, 400, 0, 0, 0, "Tahoma Bold");
        oldFnt = (HFONT)SelectObject(TmpDC, font1);        
    
    // print text at an arbitrary position
        TextOut(TmpDC, 30, 30, myText, strlen(myText));
    
        SelectObject(TmpDC,TmpObj2);
    m\_Placemat.SetBitmap(TmpBmp);
    
        SelectObject(TmpDC, oldFnt);
        DeleteObject(oldFnt);
        DeleteDC(TmpDC);
    DeleteDC(dcBmp);
    

    }

    Great Program you have there.... Jeffrey

    modified on Friday, November 28, 2008 1:40 AM

    C / C++ / MFC graphics com performance
  • Login

  • Don't have an account? Register

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