Like Tree1Likes
  • 1 Post By Salem

IDR_MENU_POPUP Color Option in VS2010 from VC++ 6.0

This is a discussion on IDR_MENU_POPUP Color Option in VS2010 from VC++ 6.0 within the Windows Programming forums, part of the Platform Specific Boards category; Hello Alex, Congratulations for your book "Jumping into Cplusplus"; it must had been a long journey since you first started ...

  1. #1
    Registered User
    Join Date
    Jun 2012

    IDR_MENU_POPUP Color Option in VS2010 from VC++ 6.0

    Hello Alex, Congratulations for your book "Jumping into Cplusplus"; it must had been a long journey since you first started learning C++ until then you finally published this book, right?And Hello programmers,my User Name is Falconcpp and before stating my thread subject, first I want to express my gratitude for the excellent C++ tutorials on this Cprogramming Site, which are a magnificent way to start learning C++.Now I will display my subject:Creating a Popup Color Menu in Visual Studio 2010 Ultimate in a Project of C++ Language / Templates Visual C++ MFC / MFC Application.Background:I saw the 4 tutorial videos about MatrixGrid by thomastom99 on the internet site "Reference for internet search: VC++ GUI Tutorials using MFC | VC++ IN".These 4 videos are about creating a Matrix Grid of 8 rows and 8 columns, which 64 cells you can eventually paint in different colors and add text within the cells.This original MatrixGrid program is made in VC++ 6.0 and using MFC. You can download the source code and give it a try.Situation:I’m a beginner in both C++ and MFC.By analyzing the 4 MatrixGrid videos, I wrote 445 blocks of instructions to follow "step by step" in order to reproduce the MatrixGrid creation.So far, I´m already on the block 344 of 445, and my project is running OK. Nevertheless, I’m stuck in the part where the Popup Color Menu should allow me to see the colors palette in order to customize new colors for the 64 cells within the Matrix Grid.Request:Therefore, my request to all of you -especially for experts about VS2010 Ultimate, C++ and MFC, and that also have knowledge about VC++ 6.0- is to provide me with some advice in order to be able to see the colors palette after clicking with the Mouse Button on the option "Color" of my submenu named "IDR_MENU_POPUP".Special considerations:The original 4 MatrixGrid videos project were made in VC++ 6.0.And my own program which I’m developing is being made in VS2010 Ultimate in a Project of C++ Language / Templates: Visual C++ MFC / MFC Application / Visual Style and Colors: Visual Studio 2008.So I’ve been having lots of adjustments to implement already due to the difference of versions and yet so far the project is running OK, except for the Color option of IDR_MENU_POPUP.Visual Display:In my own program, after I click "Debug" and "Start without debugging" Compilation is OK and the Main Frame displays the following drawing in the North West corner of the screen:"Please imagine a simple drawing of 8 rows and 8 columns, like a chessboard, and the 64 cells are all in white color; since I don't find a way to paste this drawing here. Thanks."Zoom: Then -within the Main Frame screen- I can resize the whole Matrix Grid to 25%, 50%, 100% or 200% with the [Zoom] button that I created on the top toolbar of the Main Frame.Paint: Then I can paint each one of the 64 cells: with 1 click of the Left Mouse Button "LMB" 1 cell becomes painted in Red color; Next, if 1 cell is painted in Red color already then with 1 more click of the LMB this cell becomes painted in Green color; Next, if 1 cell is painted in Green color already then with 1 more click of the LMB this cell becomes painted in Blue color; Next, if 1 cell is painted in Blue color already then with 1 more click of the LMB this cell becomes painted in Black color; Finally, if 1 cell is painted in Black color already then with 1 more click of the LMB this cell becomes painted in White color, so the cell goes back to its original color.Popup Menu: Then, if I paint 1 cell in Red color for example, and after this, I click on this Red cell with the Right Mouse Button "RMB" -that is, the secondary mouse button- then my submenu -named IDR_MENU_POPUP- appears on the screen and it displays the following 4 options:"Cut"."Copy"."Paste"."Color".The Problem:If I place the cursor on the option "Color" then this submenu button becomes highlighted in soft blue color, however, the Problem is that if I click on the option "Color" either with the LMB or the RMB then the Colors Palette DOESN’T APPEAR AT ALL; thus I can’t customize a new color for the cell. And at the present stage this should be possible already.And this is why hereby I am requesting your expert advice. Source Code:I will display the source code related exclusively to my submenu IDR_MENU_POPUP and after this, also I will display the file entitled “MatrixGrid.clw” that appears in the source code of the videos example and that doesn’t appear in my own program, since the Class Wizard is a special class in the version VC++ 6.0, but in my own Version VS2010 Class Wizard it is just a submenu option of the top toolbar "Project" and then "Class Wizard" . . . and I believe that this has something to do with the present Problem. The comments before the code are my descriptions of the code reference, and please excuse me if I haven't learned yet to use the Code Tags:My project regarding OnPopupColor() in the file MatrixGridView.cpp "Definition":
    void CMatrixGridView::OnPopupColor(){ CColorDialog ColorDialog; CMatrixGridDoc *pDoc=GetDocument(); if(ColorDialog.DoModal()==IDOK)  {   pDoc->m_cColor=ColorDialog.GetColor();   pDoc->m_arrCellArray[m_iRowIndex][m_iColIndex].m_cColor=pDoc->m_cColor;   pDoc->m_arrCellArray[m_iRowIndex][m_iColIndex].m_iColor=CUSTOM;  } Invalidate();}
    My project regarding OnPopupColor() in the file MatrixGridView.h "Declaration":
    // Generated message map functionsprotected:  //{{AFX_MSG(CMatrixGridView)  afx_msg void OnZoom25();  afx_msg void OnZoom50();  afx_msg void OnZoom100();  afx_msg void OnZoom200();  afx_msg void OnEditUndo();  afx_msg void OnEditPaste();  afx_msg void OnEditCut();  afx_msg void OnEditCopy();  afx_msg void OnLButtonDown(UINT nFlags, CPoint point);  afx_msg void OnPopupColor();  afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);  //}}AFX_MSG  DECLARE_MESSAGE_MAP()};
    My project regarding OnContextMenu(CWnd* pWnd, CPoint point), created function for the Context Menu:This is how this member function was created in the file MatrixGridView.cpp "Definition" by my program after using the option "Project" and "Class Wizard":
    void CMatrixGridView::OnContextMenu(CWnd* /* pWnd */, CPoint point){#ifndef SHARED_HANDLERS  theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EDIT, point.x, point.y, this, TRUE);#endif}
    By the way, these 3 lines mentioned above were creating a shadow popup menu that was appearing behind of the popup menu that was created following the videos example.I believe that these 3 lines must be a new characteristic in VS2010 that wasn't present in VC++ 6.0, but since I don't know how to use it, then I decided to erase these 3 lines and copy & paste the source code from the videos example.Therefore, this is how I modified this function by replacing the green comment /* pWnd */ with the text pWnd and by erasing the 3 lines about:
    1. "#ifndef";2. "theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EDIT, point.x, point.y, this, TRUE);";3. And its respective "#endif";
    And then I added the code according to the video’s example source code:
    void CMatrixGridView::OnContextMenu(CWnd* pWnd, CPoint point){ CMatrixGridDoc *pDoc=GetDocument(); // DeleteWindow(); ScreenToClient(&point); for(int iRowIndex=0;iRowIndexm_iRow;iRowIndex++) {  for(int iColIndex=0;iColIndexm_iColoums;iColIndex++)   {    if(pDoc->m_arrCellArray[iRowIndex][iColIndex].m_Rect.PtInRect(point))     {      CMenu Menu;      Menu.LoadMenu(IDR_MENU_POPUP);      CMenu *pMenu =Menu.GetSubMenu(0);      pMenu->TrackPopupMenu(TPM_LEFTALIGN  |TPM_RIGHTBUTTON,point.x,point.y,this,pDoc->m_arrCellArray[iRowIndex][iColIndex].m_Rect);     }   } }}
    This is the file MatrixGridDoc.h after adding code about COLORREF m_cColor;
    class CMatrixGridDoc : public CDocument{protected: // create from serialization only CMatrixGridDoc(); DECLARE_DYNCREATE(CMatrixGridDoc)// Attributespublic: COLORREF m_cColor; CCell m_arrCellArray[500][500]; int m_iYoffset; int m_iXoffset; int m_iWidth; int m_iHeight; int m_iColoums; int m_iRow;Etc...};
    This is the file MatrixGrid.clw that appears in the example’s videos source code -but it doesn’t appear in my own program-:
    ; CLW file contains information for the MFC ClassWizard[General Info]Version=1LastClass=CMatrixGridViewLastTemplate=CDialogNewFileInclude1=#include "stdafx.h"NewFileInclude2=#include "MatrixGrid.h"LastPage=0ClassCount=5Class1=CMatrixGridAppClass2=CMatrixGridDocClass3=CMatrixGridViewClass4=CMainFrameResourceCount=3Resource1=IDR_MAINFRAMEClass5=CAboutDlgResource2=IDR_MENU_POPUPResource3=IDD_ABOUTBOX[CLS:CMatrixGridApp]Type=0HeaderFile=MatrixGrid.hImplementationFile=MatrixGrid.cppFilter=N[CLS:CMatrixGridDoc]Type=0HeaderFile=MatrixGridDoc.hImplementationFile=MatrixGridDoc.cppFilter=N[CLS:CMatrixGridView]Type=0HeaderFile=MatrixGridView.hImplementationFile=MatrixGridView.cppFilter=CBaseClass=CScrollViewVirtualFilter=VWCLastObject=CMatrixGridView[CLS:CMainFrame]Type=0HeaderFile=MainFrm.hImplementationFile=MainFrm.cppFilter=TLastObject=ID_EDIT_UNDO[CLS:CAboutDlg]Type=0HeaderFile=MatrixGrid.cppImplementationFile=MatrixGrid.cppFilter=D[DLG:IDD_ABOUTBOX]Type=1Class=CAboutDlgControlCount=4Control1=IDC_STATIC,static,1342177283Control2=IDC_STATIC,static,1342308480Control3=IDC_STATIC,static,1342308352Control4=IDOK,button,1342373889[MNU:IDR_MAINFRAME]Type=1Class=CMainFrameCommand1=ID_FILE_NEWCommand2=ID_FILE_OPENCommand3=ID_FILE_SAVECommand4=ID_FILE_SAVE_ASCommand5=ID_FILE_PRINTCommand6=ID_FILE_PRINT_PREVIEWCommand7=ID_FILE_PRINT_SETUPCommand8=ID_FILE_MRU_FILE1Command9=ID_APP_EXITCommand10=ID_EDIT_UNDOCommand11=ID_EDIT_CUTCommand12=ID_EDIT_COPYCommand13=ID_EDIT_PASTECommand14=ID_VIEW_TOOLBARCommand15=ID_VIEW_STATUS_BARCommand16=ID_ZOOM_25Command17=ID_ZOOM_50Command18=ID_ZOOM_100Command19=ID_ZOOM_200Command20=ID_APP_ABOUTCommandCount=20[ACL:IDR_MAINFRAME]Type=1Class=CMainFrameCommand1=ID_FILE_NEWCommand2=ID_FILE_OPENCommand3=ID_FILE_SAVECommand4=ID_FILE_PRINTCommand5=ID_EDIT_UNDOCommand6=ID_EDIT_CUTCommand7=ID_EDIT_COPYCommand8=ID_EDIT_PASTECommand9=ID_EDIT_UNDOCommand10=ID_EDIT_CUTCommand11=ID_EDIT_COPYCommand12=ID_EDIT_PASTECommand13=ID_NEXT_PANECommand14=ID_PREV_PANECommandCount=14[TB:IDR_MAINFRAME]Type=1Class=?Command1=ID_FILE_NEWCommand2=ID_FILE_OPENCommand3=ID_FILE_SAVECommand4=ID_EDIT_CUTCommand5=ID_EDIT_COPYCommand6=ID_EDIT_PASTECommand7=ID_FILE_PRINTCommand8=ID_ZOOM_50Command9=ID_APP_ABOUTCommandCount=9[MNU:IDR_MENU_POPUP]Type=1Class=?Command1=ID_POPUP_CUTCommand2=ID_POPUP_COPYCommand3=ID_POPUP_PASTECommand4=ID_POPUP_COLOURCommandCount=4
    ----------------------------------------Final comment and request:Expert programmers, I will appreciate your kind advice in order to allow the option "Color" of my submenu named IDR_MENU_POPUP to provide the Colors Palette in order to customize a new color for the cells within the Matrix Grid.Thank you very much.Falconcpp.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    I suggest you look at your post and keep looking at it until you figure out that a "wall-of-unformatted-text" and code all on one line just isn't going to attract any useful comments.

    Format your text and make sure your code is laid out properly. Press the "Go Advanced" button and preview your post until it looks half-decent.
    antred likes this.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [VS2010] adding *.dll files to a project
    By kulfon in forum C++ Programming
    Replies: 3
    Last Post: 06-27-2011, 07:08 AM
  2. DLL: Port Issue from VS6 to VS2010
    By cnfwriter in forum C++ Programming
    Replies: 11
    Last Post: 04-13-2011, 09:56 AM
  3. VS2010 C++/CLI Bug
    By nvoigt in forum C++ Programming
    Replies: 3
    Last Post: 10-15-2010, 10:27 AM
  4. VS2010 vs VS2008
    By zacs7 in forum General Discussions
    Replies: 29
    Last Post: 06-13-2010, 02:40 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21