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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
C

CoffeeAddict19

@CoffeeAddict19
About
Posts
74
Topics
35
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Problem Converting string/const char* to OLECHAR FAR*
    C CoffeeAddict19

    The code I'm trying to use: std::string url = "http://www.psc-range.com/"; browser->Navigate(SysAllocString(url.c_str()),&vFlags,&vTargetFrameName,NULL,NULL); The error: 'SysAllocString' : cannot convert parameter 1 from 'const char *' to 'const OLECHAR *' I've managed to get this working: browser->Navigate(SysAllocString(L"http://www.psc-range.com/"),&vFlags,&vTargetFrameName,NULL,NULL); Unfortunately I need to get it work with any valid URL, not just one. If someone would please point me in the right direction I would appreciate it. :)

    C / C++ / MFC help com

  • Trouble w/ ReadConsoleInput
    C CoffeeAddict19

    The error I'm getting: 1>c:\users\john\documents\visual studio 2008\projects\torch\torch\main.cpp(18) : error C2065: 'lpBuffer' : undeclared identifier I've seen plenty of examples where ReadConsoleInput is setup to read only 1 INPUT_RECORD and then return, but I'm trying to set it up so that if multiple events occur at once, so they will be placed into a vector array instead. The trouble is that everything stops once ReadConsoleInput starts and I have no easy way of referencing the variable to be stored. Here is my code:

    #include "includeall.h"

    using namespace std;

    int main(int argc, char **argv)
    {
    HANDLE hIn = GetStdHandle(STD_INPUT_HANDLE);
    HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    DWORD NumRead;
    BOOL eventloop = FALSE;
    vector<INPUT_RECORD>InputRecs;

    printf("Welcome to Bloodhound 1.0a (torch).\\n");
    printf("Press the ESC key at any time to exit.\\n");
    
    do
    {
    	 X| if(ReadConsoleInput(hIn, InputRecs.push\_back(lpBuffer), (DWORD)InputRecs.capacity(), &NumRead) != 0)
    	{
    		//sort through events
    	}
    	else //error is present
    	{
    		printf("Unable to read from console error number (%d)", GetLastError());
    		printf(".\\n");
    		eventloop = FALSE;
    	}
    	InputRecs.clear();
    }while(eventloop == TRUE);
    
    
    
    return 0;
    

    }

    Ideas?

    C / C++ / MFC csharp c++ visual-studio graphics data-structures

  • Monochrome Bitmap Issue
    C CoffeeAddict19

    Thanks mark! I HAVE MADE COLOR! Check it out: http://img.photobucket.com/albums/v50/blackdwarf/piechart_color.jpg[^] Shouldn't take me long to get long of the pesky black area around the edges. Maybe I'll write a simple tutorial on making controls someday. There already is one, but another viewpoint couldn't hurt.

    C / C++ / MFC help question c++ com graphics

  • Monochrome Bitmap Issue
    C CoffeeAddict19

    Well the assert statement was wrong...it should have been ASSERT(ScreenDC != NULL), but it is still not rendering color for some reason. Fonts, brushes, and pens work fine, just not color.

    C / C++ / MFC help question c++ com graphics

  • Monochrome Bitmap Issue
    C CoffeeAddict19

    Actually I just got a cup about 30 minutes ago. :) Unfortunatly, the problem still remains. :( I tried using GetDC:

    CDC* ScreenDC = NULL;
    CreateResult = CWnd::Create(CPIEGRAPH_CLASSNAME, _T(""), dwStyle, rect, pParentWnd, nID);
    
    TextDCResult = TextMemDC.CreateCompatibleDC(NULL);
    PieDCResult = PieMemDC.CreateCompatibleDC(NULL);
    
    ScreenDC = GetDC();
    ASSERT(ScreenDC == NULL);
    SelectText = m_textBitmap.CreateCompatibleBitmap(ScreenDC, 250, 20);
    SelectPie = m_pieBitmap.CreateCompatibleBitmap(ScreenDC, 300, 300);
    ReleaseDC(ScreenDC);
    

    At first the assert statement wasn't in there and I just got black and white, then I put it in and I got a debug assertation on the same line, indicating that ScreenDC was null, and that GetDC didn't do the job. Any idea why?

    C / C++ / MFC help question c++ com graphics

  • Monochrome Bitmap Issue
    C CoffeeAddict19

    Thanks, both of you. I think it'll work. I'll try it tommorow when I wake up.

    C / C++ / MFC help question c++ com graphics

  • Monochrome Bitmap Issue
    C CoffeeAddict19

    I'm having a problem with memory device contexts and bitmaps in MFC. I've gotten to the point to where I can create and use them, but natrually they are all in black in white. See here: http://img.photobucket.com/albums/v50/blackdwarf/piegraphcontrol.jpg[^] With a CreateCompatibleDC(NULL) call, a monochrome bitmap gets created for and selected into the CDC. When I actually create my bitmap based off of that CDC, I'm stuck with the monochrome. So my question is, how do I initialize the bitmaps with color outside of OnPaint when I can't just use CPaintDC? Here is some of the code... Creating the two bitmaps without a CPaintDC (where I think the problem is): BOOL CPieGraph::Create(CWnd* pParentWnd, const RECT& rect, UINT nID, DWORD dwStyle /*=WS_VISIBLE*/) { BOOL OverallSuccess = FALSE; BOOL CreateResult = FALSE, TextDCResult = FALSE, PieDCResult = FALSE; int SelectText = 0, SelectPie = 0; CreateResult = CWnd::Create(CPIEGRAPH_CLASSNAME, _T(""), dwStyle, rect, pParentWnd, nID); TextDCResult = TextMemDC.CreateCompatibleDC(NULL); PieDCResult = PieMemDC.CreateCompatibleDC(NULL); SelectText = m_textBitmap.CreateCompatibleBitmap(&TextMemDC, 250, 20); SelectPie = m_pieBitmap.CreateCompatibleBitmap(&PieMemDC, 300, 300); OldtextBitmap = TextMemDC.SelectObject(&m_textBitmap); OldpieBitmap = PieMemDC.SelectObject(&m_pieBitmap); TextMemDC.SetBkColor(RGB(255,255,255)); PieMemDC.SetBkColor(RGB(255,255,255)); if((CreateResult == TRUE) && (TextDCResult == TRUE) && (PieDCResult == TRUE) && (SelectText != 0) && (SelectPie != 0)) { OverallSuccess = TRUE; ControlRect = rect; } else OverallSuccess = FALSE; return OverallSuccess; } And OnPaintDC:

    afx_msg void CPieGraph::OnPaint()
    {
    	CPaintDC dc(this);
    
    	CDC ControlMemDC;
    	CBitmap ControlBitmap;
    	CBitmap* OldBitmap = NULL;
    
    	ControlMemDC.CreateCompatibleDC(&dc);
    	ControlBitmap.CreateCompatibleBitmap(&ControlMemDC, 300, 360);
    	OldBitmap = ControlMemDC.SelectObject(&ControlBitmap);
    	ControlMemDC.SetBkColor(RGB(255,255,255));
    
    	if(UpdateNeeded == true)
    	{
    		RedrawPieText(TextMemDC);
    		RedrawPieChart(PieMemDC);
    		ControlMemDC.BitBlt(0, 0, 250, 20, &TextMemDC, 0, 0, SRCCOPY);
    		ControlMemDC.BitBlt(0, 25, MainPieGraph.radius * 2, 
    			MainPieGraph.radius * 2, &PieMemDC,
    
    C / C++ / MFC help question c++ com graphics

  • Trouble making a custom mfc control...
    C CoffeeAddict19

    I'm trying to make a MFC control that will show a pie graph. I've got most of the work done, but I don't know how to go from having a class to "creating" the control on the main window. I also keep getting debug assertions which I did not get when I implemented the same code in the main CFrameWnd class. I'm guessing that's because it won't give me access to the device contexts or something in a regular class. I don't know. Any help would be appreciated. I'm using CWnd as a base class. Basically I have two bitmaps (m_pieBitmap and m_textBitmap) which are selected into two CDCs (PieMemDC and TextMemDC). When the pie graph and text need to be updated, they are redrawn onto the bitmaps. Both are blitted onto CPaintDC in OnPaint in the control's class. Here is the header for CPieGraph (the control's class):

    class CPieGraph : public CWnd
    {
    public:
    	CPieGraph();
    	~CPieGraph();
    	void InitPieChart();
    	void SetPieChart(PieGraphDisplayType & PieGraph);
    	void ResetPieChartAngle(int Angle);
    protected:
    private:
    	void InitDCObjects();
    	void RedrawPieChart();
    	void RedrawPieText();
    	PieGraphDisplayType MainPieGraph;
    	CDC PieMemDC;
    	CDC TextMemDC;
    	CBitmap* OldpieBitmap;
    	CBitmap* OldtextBitmap;
    	CBitmap m_pieBitmap;
    	CBitmap m_textBitmap;
    	CBrush CombinedBrush;
    	CBrush TargetBrush;
    	CPen BlackPen;
    	//CBrush WhiteBrush;
    	CFont OutputFont;
    	//message handlers
    	afx_msg void OnPaint();
    	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
    DECLARE_MESSAGE_MAP()
    };
    

    Some of the class code:

    CPieGraph::CPieGraph()
    {
    	InitPieChart();
    	InitDCObjects();
    	OldpieBitmap = PieMemDC.SelectObject(&m_pieBitmap);
    	OldtextBitmap = TextMemDC.SelectObject(&m_textBitmap);
    }
    CPieGraph::~CPieGraph()
    {
    	PieMemDC.SelectObject(OldpieBitmap);
    	TextMemDC.SelectObject(OldtextBitmap);
    	m_pieBitmap.DeleteObject();
    	m_textBitmap.DeleteObject();
    }
    void CPieGraph::InitPieChart()
    {
    	CRect ClientArea;
    	GetClientRect(&ClientArea);
    
    	MainPieGraph.origin.SetPoint(static_cast(ClientArea.right / 1.5), 
    		static_cast(ClientArea.bottom / 2));
    	MainPieGraph.angle = 0;
    	MainPieGraph.PieGraphIsActive = false;
    	MainPieGraph.radius = 100;
    	MainPieGraph.data.denominator = 0.0;
    	MainPieGraph.data.numerator = 0.0;
    	MainPieGraph.data.ratio = 0.0;
    }
    void CPieGraph::InitDCObjects()
    {
    	CDC pDC;
    	VERIFY(OutputFont.CreateFont(16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, 0, ANSI_CHARSET,            
    			OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
    			DEFAULT_PITCH | FF_SWISS, "Aria
    
    C / C++ / MFC c++ data-structures debugging help tutorial

  • Destructor Not Getting Called
    C CoffeeAddict19

    Can I assume that CRatiosWin is not getting deleted in this segment of code?

    class CPRatiosApp : public CWinApp
    {
    	public:
    	BOOL InitInstance()
    	{
    		_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
    		m_pMainWnd = new CRatiosWin;
    		m_pMainWnd->ShowWindow(m_nCmdShow);
    		m_pMainWnd->UpdateWindow();
    		m_pMainWnd->SetWindowText("Ratios v0.1b");
    		m_pMainWnd->MoveWindow(0,0,800,600);
    	return TRUE;
    	}
    } CRatiosApp;
    
    C / C++ / MFC help data-structures performance

  • Destructor Not Getting Called
    C CoffeeAddict19

    I only have one CCharLinkedList object. It is allocated on the free store (not new/delete), here:

    class CRatiosWin : public CFrameWnd
    {
    public:
    	CRatiosWin(); //default constructor
    	~CRatiosWin(); //destructor
    	CRatiosLogic RatiosLogic;
    	bool GetNewFilePath(CString & Path);
    	void PrintResults(string results);
    	//accessor functions
    	bool ReturnValidFilePathSet();
    	//manipulator functions
    	void ResetSearchDialogFlag(); //set that the search dialog has not been opened
    	void SetDatabaseFilePathStatus(bool FilePathWasSet);
    	void SetTimeParameterStatus(bool NewTimeParametersWereSet);
    protected:
    private:
    	//classes
    	CRatiosNewSearchDialog NewSearchDialog;
    	CRatiosSearchTimeParameters TimeParametersDialog;
    	CCharLinkedList TestLinkedList; :(
    	//other private members
    	CEdit ResultsBox;
    	BOOL NewSearchDialogIsVisible; //if TRUE, the NewSearchDialog is active
    	bool ValidFilePathSet;
    	bool TimeParametersWereSet;
    	afx_msg void OnClose();
    	afx_msg void OnOpenFile();
    	afx_msg void OnNewSearch();
    	afx_msg void OnOpenSearch();
    	afx_msg void OnAbout();
    	afx_msg void OnTestList();
    DECLARE_MESSAGE_MAP()
    };
    

    I loaded some text into the list by calling this at runtime:

    afx_msg void CRatiosWin::OnTestList()
    {
    	fstream ListFileStream;
    	char chLine[MAXNUMCHARS_LINKLISTNODE];
    	string strLine = "";
    
    	ListFileStream.open("list_test.txt");
    	while(ListFileStream.eof() == false)
    	{
    		getline(ListFileStream, strLine);
    		ASSERT(strLine.length() < MAXNUMCHARS_LINKLISTNODE);
    		strcpy(chLine, strLine.c_str());
    		TestLinkedList.AddNodeToTail(chLine);
    	}
    	MessageBox("Sent to file.", "Boink", MB_OK);
    	ListFileStream.close();
    }
    

    All of the above worked fine. But I set breakpoints in the destructor in the previous post and none of them were reached, plus I have a big memory leak.

    C / C++ / MFC help data-structures performance

  • Destructor Not Getting Called
    C CoffeeAddict19

    I'm having a problem with a class I wrote- the destructor isn't being called for some reason and I'm getting a rather large memory leak as a result. I verified that the destructor was not being called through the use of breakpoints. Any help would be appreciated. Here is the class defenition:

    class CCharLinkedList
    {
    public:
    	CCharLinkedList();
    	~CCharLinkedList();
    	void AddNodeToHead(char DataToAdd[]);
    	void AddNodeToTail(char DataToAdd[]);
    	bool DeleteFromHead();
    	bool DeleteFromTail();
    	bool CopyFromHead(char DataToCopy[]);
    	bool CopyFromTail(char DataToCopy[]);
    	void PrintHeadToTail();
    	void PrintTailToHead();
    protected:
    private:
    	void DeleteList();
    	CharLinkedListNodeType* HeadPtr;
    	CharLinkedListNodeType* TailPtr;
    };
    

    The destructor implementation:

    CCharLinkedList::~CCharLinkedList()
    {
    
    	DeleteList();
    	HeadPtr = NULL;
    	TailPtr = NULL;
    }
    

    DeleteList():

    void CCharLinkedList::DeleteList()
    {
    	CharLinkedListNodeType* IterationPtr = HeadPtr;
    	CharLinkedListNodeType* DeletePtr = NULL;
    
    	while(IterationPtr != NULL)
    	{
    
    		DeletePtr = IterationPtr;
    		IterationPtr = IterationPtr->ForwardPtr;
    		delete DeletePtr;
    	}
    }
    

    The class is declared in the free store in another class header file. The other class has been working fine for a long time. So far I have been able to use the linked list to add nodes, but when it is time to call the destructor upon exiting and delete all the nodes, nothing happens.

    C / C++ / MFC help data-structures performance

  • Problem with Pointers
    C CoffeeAddict19

    Thanks for the help. I got it working now...I just have to get rid of all of those GetDlgItem calls now. Guess I'll be using find and replace a lot too. X|

    C / C++ / MFC help question debugging

  • Problem with Pointers
    C CoffeeAddict19

    This problem cropped up after I converted the dialog from modal to non-modal, so that might have something to do with it. The question: why should I have to call GetDlgItem to get a pointer to a dialog box control in every function instead of just once in OnInitDialog? I've got these pointers in my modeless dialog box header file:

    CListBox* ExpressionsListBoxPtr;
    CListBox* FiltersListBoxPtr;
    CListBox* TargetsListBoxPtr;
    

    All were initialized to null by the constructor. In OnInitDialog() I put this (I checked to make shure OnInitDialog got called, and that the pointers were not null afterwords):

    ExpressionsListBoxPtr = (CListBox*)(GetDlgItem(IDC_DLGS_EXPRESSIONLISTBOX));
    FiltersListBoxPtr = (CListBox*)(GetDlgItem(IDC_DLGS_FILTERLISTBOX));
    TargetsListBoxPtr = (CListBox*)(GetDlgItem(IDC_DLGS_TARGETLISTBOX));
    

    The issue is that when I execute this fuction I get a debug assertation error and I've determined that the class level pointers are the source of the problem. I have worked around it by calling GetDlgItem in the function itself instead of just in OnInitDialog:

    afx_msg void CRatiosNewSearchDialog::OnAddFilter()
    {
    	CListBox* TempListBoxPtr = (CListBox*)(GetDlgItem(IDC_DLGS_EXPRESSIONLISTBOX));
    	//int CurrentSelection = ExpressionsListBoxPtr->GetCurSel();
    	int CurrentSelection = TempListBoxPtr->GetCurSel();
    	
    	int Pos = 0;
    	CString Expression = "";
    
    	if(CurrentSelection == LB_ERR)
    		MessageBox("You must select an expression before you can add a filter. LB_ERR.", "User Error", MB_ICONHAND);
    	else //everything is cool, add the expression to the filter list box
    	{
    		ExpressionsListBoxPtr->GetText(CurrentSelection, Expression);
    		Pos = Expression.Find(" - ", 0);
    		Expression.Delete(0, Pos + 3);
    		Pos = FiltersListBoxPtr->AddString(Expression);
    		ResetListboxScrollbar(FiltersListBoxPtr);
    		FiltersListBoxPtr->SetCurSel(Pos);
    	}
    }
    

    Can anyone tell me why it is not letting me just call GetDlgItem once when the dialog pops up instead of making me call it every time I want to use a control?

    C / C++ / MFC help question debugging

  • Need help communicating with MFC dialog boxes (domodal) [modified]
    C CoffeeAddict19

    I think you have to use "\r \r". Edit...sorry that's wrong here...it's "\r\n". http://microsoft.ease.lsoft.com/scripts/wa-msn.exe?A2=ind9709a&L=mfc&T=0&P=10710[^] -- modified at 0:29 Thursday 15th March, 2007

    C / C++ / MFC

  • Need help communicating with MFC dialog boxes (domodal) [modified]
    C CoffeeAddict19

    Basically what I am trying to do is have two text strings pop in text boxes (CEdit) for the user when they open a dialog box. The problem is that when you call domodal, all control transfers to the dialog box, so everything has to be done before the call. In the past I have just set a flag in the dialog box class to let it know that something needs to be loaded, and placed the information there beforehand, and then called domodal. OnInitDialog gets called when the dialog pops up, checks for the flag, and loads whatever. It seems kind of messy though. Is there another more elegant way to do it? Is there some way I can modify DoModal to accept arguments?

    C / C++ / MFC

  • Question about accessor functions
    C CoffeeAddict19

    Sort of newbie question here. I've read in places that you should avoid returning large class objects (particulary the class String) or datastructures, and instead should call a function and send it back by reference. Like this (ExpressionData is a structure with 3 cstrings): void CRatiosNewSearchStringDialog::GetExpressionData(SearchExpressionType & Expression) { Expression = ExpressionData; } as opposed to: SearchExpressionType CRatiosNewSearchStringDialog::GetExpressionData() { return ExpressionData; } Where should I draw the line between a large and small piece of data i.e should I bother with all this for a single CString? When should I use return and when should I sent it back by reference? Advice?

    C / C++ / MFC

  • Problem using CStrings in a linked list (memory leak)
    C CoffeeAddict19

    I'm using a singly linked list of structures. Each structure has 3 cstrings and a pointer in it. The reason I'm using cstrings and not strings is that I'm populating a list box that has to stay persistent. I could use strings but I would have to use .c_str() every time. I wrote the code for the linked list with help from wikepedia and a book and it works, the problem is that I have a memory leak. I still can't find any error in the code though. My question is, are there any special issues with cstrings that would cause a memory leak in this situation? Are their any known problems with their destructors? Here is the function that destroys the linked list if you wouldn't mind checking it:CStringLListElement* CurrentPtr = HeadPtr; CStringLListElement* BackPtr = HeadPtr; while(CurrentPtr != NULL) { BackPtr = CurrentPtr; CurrentPtr = CurrentPtr->ForwardPtr; delete BackPtr; }
    Here is part of the error message from the compiler (I only listed a few lines): Detected memory leaks! Dumping objects -> {299} normal block at 0x010A65A8, 152 bytes long. Data: 48 EC 57 00 CD CD CD CD 32 30 30 33 31 30 00 CD {298} normal block at 0x010A64D0, 152 bytes long. Data: << W 200310 > 3C EC 57 00 CD CD CD CD 32 30 30 33 31 30 00 CD {297} normal block at 0x010A63F8, 152 bytes long. Data: < W 200310 > E4 EB 57 00 CD CD CD CD 32 30 30 33 31 30 00 CD {296} normal block at 0x010A6320, 152 bytes long. Data: < W 200310 > F8 EB 57 00 CD CD CD CD 32 30 30 33 31 30 00 CD {295} normal block at 0x010A6248, 152 bytes long.The program '[2212] CS_Project.exe: Native' has exited with code 0 (0x0). Thanks for looking at this. I would appreciate any help. :)

    C / C++ / MFC help question c++ data-structures performance

  • Strange errors related to getline()...
    C CoffeeAddict19

    I gave in and did it with a string...works fine. Thanks. Still annoys me the though. Has anyone written a defenitive guide on how all of these character and string formats work together? Has anyone done a performance analysis on the different types of strings and their functions to see what works fastest in what appication? Seems like someone could write a book on it.

    C / C++ / MFC help c++

  • Strange errors related to getline()...
    C CoffeeAddict19

    Yes. I rebuilt it. :) I hate Microsoft. e:\Work\Ratios\ratios_searchdialogs.cpp(61): error C2780: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem)' : expects 3 arguments - 2 provided

    C / C++ / MFC help c++

  • Strange errors related to getline()...
    C CoffeeAddict19

    getline(expressionFInput, FirstLineText); same error. :/ It doesn't care whether I have 3 arguments or two. Go figure.

    C / C++ / MFC help c++
  • Login

  • Don't have an account? Register

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