|
Use the appwizard to make handlers for each of the menu items, then set some member variable I'll call it "selectedimage" to a number one for each image. Once you've set the variable, then call Invalidate() (this will repaint the view and call OnDraw()). Then you just have a switch(selectedimage), and a case stament for each image:
class CMyView : public CView
{
public:
protected:
int selectedimage;
}
CMyView::CMyView()
{
selectedimage = -1;
}
void CMyView::OnPicture1()
{
selectedimage = 1;
Invalidate();
}
void CMyView::OnDraw(CDC *dc)
{
switch(selectedimage)
{
case 1:
DrawImage1();
break;
case 2:
etc...
break;
}
}
Hope thats helpful
With time we live, with money we spend!
Joel Holdsworth
|
|
|
|
|
Hi There,
I'm in the process of writing an MFC MDI application. I would like to have views in a docking window - getting the views into the docking window is not a problem, but getting pointer to document etc. is proving a little tricky. I originally though the easiest way to solve my problem was simply use the CCreateContext which I thought would be stored in lpCreateStruct in OnCreate in the CMainFrame, but it seems because the app is MDI that lpCreateStruct has NULL in its lpCreateParams. This raises questions: 1. How do I get pointers to the document? 2. How can I get my docking view to respond when the active document changes? 3. is it possible, or would I be better of using SDI? Thanks for your time...
With time we live, with money we spend!
Joel Holdsworth
|
|
|
|
|
1. How do I get pointers to the document?
Say you have these classes:
Application class : CMyApp
Main frame class : CMainFrame
MDI child frame class : CChildFrame
Document class : CMyDoc
// to get the active document
CMyApp* pApp = (CMyApp*)AfxGetApp();
CMainFrame* pwnd = (CMainFrame*)pApp->GetMainWnd();
CChildFrame* pChild = (CChildFrame*) pwnd->MDIGetActive();
CMyDoc* pDoc = (CMyDoc*) pChild->GetActiveDocument();
Not pretty but you could wrap this in a function.
2. How can I get my docking view to respond when the active document changes?
I would try to override OnActivateView of the view class and do the processing based on which view (thus document) is being activated or deactivated.
3. would I be better off using SDI?
I would say Yes. MDI is nice but it can be a royal pain in the neck if you are a rookie like me trying to write a big app. Also I read somewhere that the average computer user finds multiple documents too confusing.
|
|
|
|
|
That sounds pretty comprehensive - I'm much obliged!
With time we live, with money we spend!
Joel Holdsworth
|
|
|
|
|
This is so weird, I cannot explain.
In my Microsoft Visual Studio directory, the VC98 subdirectory comprises other numerous subdirectories, of which one is "Include". This is where all the '#include' header files are located. However (and this is the strange part), in this subdirectory, there is no 'stdafx.h' file present!! None!!
Yet! some programs which calls for this file get executed while some don't! But as if that's not bad enough, there is one program in particular (which is a Console Application program) that uses "stdafx.h" that wouldn't get 'Build' sometimes because the compiler says it cannot open the "stdafx.h" file.
In the directory where the application program is located, there is a 'stdafx.h' and a 'stdafx.cpp' file. So, I cannot understand why the compiler is saying it couldn't find it to open it.
Lastly, if from the Build menu I were to do a compile (Ctrl F7), it gets compiled cleanly, and then if I were to do a 'Build' (F7), I'd get a clean result: no errors, no warnings, and the program would run beautifully. No problem!
The problem would start over if I were to make changes to the code and then try to compile. Things would start back again with the same old error.
Resetting or rearranging the path directories doesn't seem to help. Does anybody know why this might be happening and have a suggestion?
Thanks!
William
|
|
|
|
|
The compiler will complain if you do this :-
#include <stdafx.h>
So do this instead :-
#include "stdafx.h"
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|
|
Thanks for the suggestion! I tried that before and it didn't work. I still got an error.
The error is: "fatal error C1086: Cannot seek precompiled header file."
The strange thing is, sometimes I get a clean "Build" and sometimes I do not. It just seems to be on whether something (e.g. a flag, a parameter, memory, etc.) got initialized a certain way that I would get lucky.
There are times when "#include <stdafx.h>" would work, so I don't believe that is really what's upsetting the compiler.
Thanks!
(P.S. If the angle bracket around stdafx.h doesn't get printed, it's not because I'm leaving them out.)
William
|
|
|
|
|
Hi,
Stdafx.h is a header file which is unique to every MFC project. stdafx.h contains things like this:
#if !defined(AFX_STDAFX_H__48A33CB4_51D8_45C7_8B74_162AA2953797__INCLUDED_)
#define AFX_STDAFX_H__48A33CB4_51D8_45C7_8B74_162AA2953797__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
#include <afxwin.h>
#include <afxext.h>
#include <afxadv.h>
#include <afxdisp.h>
#include <afxdtctl.h>
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h>
#endif // _AFX_NO_AFXCMN_SUPPORT
#endif // !defined(AFX_STDAFX_H__48A33CB4_51D8_45C7_8B74_162AA2953797__INCLUDED_)
The main thing obout it is that the header is precompiled for your application to do all the MFC includes once for all. If you created your project using MFC you should have a copy of the header in your project directory. Another thing to check is this: If you go into the "Project Settings" box for you project, go to the "C/C++" panel, and in the list box marked category go down to "Precompiled Headers". This is where stdafx.h is hooked in. If you want to remove stdafx.h from your project all together as you might do in a Console App, just switch to "Not using precompiled headers", and remove all references to stdafx.h. But beware of doing this because a precompiled header is the standard way of getting MFC into a project!
I don't know why the system complains when you change the code slightly . Because the stdafx.h should only be recompiled when you make changes to the file itself, if you change another part of your code it shouldn't make any difference!
Hope thats helpful...
With time we live, with money we spend!
Joel Holdsworth
|
|
|
|
|
Thanks! That solved the problem.
Because I'm not using MFC, I selected the "Not using precompiled headers" radio button, and did a 'Rebuild all' which got rid of the error once and for all.
Much obliged! I appreciate it!
William
|
|
|
|
|
Set to not use precompiled headers.. Not sure where the option is... but it's there somewhere
"When a friend hurts us, we should write it down in the sand, where the winds of forgiveness get in charge of erasing it away, and when something great happens, we should engrave it in the stone of the memory of the heart, where no wind can erase it"
Nish on life [methinks]
|
|
|
|
|
When i use the AnimateWindow my window is animated, but i don't see any control, my OnPaint() is not called, why?
|
|
|
|
|
If you look at the remarks in the documentation for AnimateWindow, it looks like it is calling WM_PRINT instead. WM_PRINT is basically like a WM_PAINT except that it gives a DC that should be drawn to.
So, if you are using the plain windows API, you could do something like this in your windowproc:
...
case WM_PRINT:
case WM_PAINT:
{
HDC hdc;
PAINTSTRUCT ps;
if (NULL != wParam)
{
hdc = (HDC)wParam;
}
else
{
hdc = ::BeginPaint(hWnd, &ps);
}
if (NULL == wParam)
{
::EndPaint(hWnd, &ps);
}
}
break;
...
If you are using MFC, you will simply need to call OnDraw from your OnPrint handler and be sure to pass in the DC that you received from the OnPrint handler.
Good Luck
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
My Window is a CMiniFrameWnd, and i added this, so i don't get anything to be shown, what's wrong?
|
|
|
|
|
Hey i need a way to search through ports and see if things are connected to them using WinSock... Any ideas.
The best idea i have had is to take a list of ports that are commonly used and enumrate through them and test to see if anything is connected to them. My only hang up is how to do this. Any suggestions would be great thanks also i need to be able to monitor more than one connection. Like i need to monitor all internet conenction like what websites they are connected to.
~~~~~~~~~~~~
~~NICHOLAS~~
~~~~~~~~~~~~
|
|
|
|
|
HTTP://WWW.SYSINTERNALS.COM has some utilities with source code that show hoe to do it. I am not sure whether they are overkill for you but they do what you ask.
|
|
|
|
|
Where can I get masm? I looked at MS's site and there doesn't seem to be a place where I can download it. Thanks.
|
|
|
|
|
If you own a copy of VisualC, you can get it from them for the cost of shipping.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
I have Visual C++ Standard edition, can I still get it?
|
|
|
|
|
Anonymous wrote:
Where can I get masm?
http://www2.dgsys.com/~raymoon/faq/masm.html#9
Nish
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|
|
|
i have a structure, call
<br />
struct FileType<br />
{<br />
char type[_MAX_EXT];<br />
char size[20];<br />
<br />
};<br />
<br />
and the text file that looks like
.txt 4140
.tif 4100
.doc 21000
.pdf 3459
.
.
.
so i want to read from the text file and put it into array.
so used vector.
<br />
#include <vector><br />
typedef vector<TypeSize> typeNsize;<br />
<br />
TypeSize typeNsize;<br />
<br />
ifstream filelist("TableOfType.txt",ios::in);
while(!filelist.eof())<br />
{<br />
filelist>>typeNsize.filetype>>typeNsize.size;<br />
<br />
}<br />
filelist.close();<br />
my application is dialog base.
and i have following errors
<br />
<br />
SMPprojectDlg.cpp<br />
E:\SMP\SMPprojectDlg.cpp(2161) : error C2143: syntax error : missing ';' before '<'<br />
E:\SMP\SMPprojectDlg.cpp(2161) : error C2143: syntax error : missing ';' before '<'<br />
E:\SMP\SMPprojectDlg.cpp(2163) : error C2065: 'TypeSize' : undeclared identifier<br />
E:\SMP\SMPprojectDlg.cpp(2163) : error C2146: syntax error : missing ';' before identifier 'typeNsize'<br />
E:\SMP\SMPprojectDlg.cpp(2163) : error C2065: 'typeNsize' : undeclared identifier<br />
E:\SMP\SMPprojectDlg.cpp(2168) : error C2228: left of '.filetype' must have class/struct/union type<br />
E:\SMP\SMPprojectDlg.cpp(2168) : error C2228: left of '.size' must have class/struct/union type<br />
Error executing cl.exe.<br />
<br />
SMPproject.exe - 7 error(s), 0 warning(s)<br />
i was thinking to use CStringArray like read the sentence like
<br />
char info[50];<br />
filelist.getline(info,50,'\n');<br />
CString infoline = (const char*)info;<br />
CStringArray array;<br />
array.add(infoline)<br />
if i do so , i have to separate the string into two parts, type and size, again. i dont' want to do that..
do you have any idea better than what i have right now?
|
|
|
|
|
Try this
================================================
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
/*
Other code here
*/
struct FileType
{
char type[_MAX_EXT];
char size[20];
};
/*
other code here
*/
vector<FileType> v_filetypes;
ifstream filelist("TableOfType.txt", ios::in); //ios:in is optional
while(!filelist.eof())
{
filelist >> v_filetypes.type >> v_filetypes.size;
}
filelist.close();
================================================
That should work fine... I think.. but my brain isn't working the best
|
|
|
|
|
Does anyone know how to remove a sunken style border from a CView? When I use ModifyStyle and ModifyStyleEx on it removing the border flags on it, it doesn't seem to make any difference? Does anybody know a way around this problem?
With time we live, with money we spend!
Joel Holdsworth
|
|
|
|
|
Joel, have you tried changing the style in: CJoelsView::PreCreateWindow(CREATESTRUCT& cs)?
Neville Franks, Author of ED for Windows. www.getsoft.com
|
|
|
|
|
After you change the style of a window, you need to call SetWindowPos in order to force a repaint of the frame. make this call:
::SetWindowPos(hWnd, NULL,0,0,0,0, SWP_NOMOVE SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOACTIVATE);
BTW, this is in the documentation for SetWindowLong.
Good Luck
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|