|
You can declare it as a member variable of your CWinApp derived class. Then from anywhere in your program, use AfxGetApp() to get a pointer, cast it to your derived class, and access the member variable.
I think it's better than using explicit C style globals.
Just my opinion though.
Nish
My most recent CP article :-
A newbie's elementary guide to spawning processes
www.busterboy.org
|
|
|
|
|
Thks a lot !
Appstmd
|
|
|
|
|
Does anyone know how to fix this OnPaint bug... i am having a harding updating my window. it displays it but after i minimize it or after a few minutes the data or the Board gets lost. i know i need to use the OnPaint function but is there any way i can use it but implement my function from another class? here is what i am doing...
// Class interface
class Board
{
private:
CString mCell[3][3];
// ommitted
public:
void DisplayData() const;
}
// Display the board together with the data inside it.
void CBoard::DisplayData()
{
for (int r = 0; r < mRow; r++)
for (int c = 0; c < mCol; c++)
{
// sets mCell to a string
CString str = mCell[r][c];
mpDC->DrawText(str,mpGrid[r][c],
DT_SINGLELINE | DT_CENTER | DT_VCENTER); }
}
and on my CChildView here is what i did...
void CChildView::OnPaint()
{
mpBoard->DisplayBoard();
}
is this a good idea. if not can you tell me a better way to do it. a more efficient way. well, thank you in advance
|
|
|
|
|
John Cruz wrote:
// Display the board together with the data inside it.
void CBoard::DisplayData()
{
for (int r = 0; r < mRow; r++)
for (int c = 0; c < mCol; c++)
{
// sets mCell to a string
CString str = mCell[r][c];
mpDC->DrawText(str,mpGrid[r][c],
DT_SINGLELINE | DT_CENTER | DT_VCENTER); }
}
and on my CChildView here is what i did...
void CChildView::OnPaint()
{
mpBoard->DisplayBoard();
}
What you have done is perfectly fine, however there is one mistake. If I am reading your code correctly, mpDC is a DC object that you have cached inside of your Board class. Generally you should not cache DCs. Especially in the case of handling on Paint messages, you should create a new DC every time.
I would recommend code more like this:
<br />
void CBoard::DisplayData(&CPaintDC dc)<br />
{<br />
for (int r = 0; r < mRow; r++)<br />
for (int c = 0; c < mCol; c++)<br />
{<br />
CString str = mCell[r][c];<br />
<br />
dc->DrawText(str,mpGrid[r][c],<br />
DT_SINGLELINE | DT_CENTER | DT_VCENTER); }<br />
} <br />
and on my CChildView here is what i did...<br />
void CChildView::OnPaint() <br />
{<br />
CPaintDC dc;<br />
mpBoard->DisplayBoard(dc);<br />
}<br />
Windows only generates a paint message for your window when there is an invalid region inside of that window. In regular WIN32 programming you need to call BeginPaint in your paint handler in order to create a DC that will paint on that current invalid area, and validate that area so that Windows does not turn right around and generate a new paint message.
The CPaintDC objects constructor will call BeginPaint for you, hiding this detail.
If you have any more questions, or want more detail just let me know.
|
|
|
|
|
Thank you very much for the help kilowatt. ill try rewrite my program.
|
|
|
|
|
I am trying to write some scripts in VB for use in VC6 and have run into two problems (what only TWO ? )
Config
--------------------------------
XP Home, MSVC6, Windows Script Debugger, Windows Script 5.5
Service Pack 5 for VC6 (before that it would even crash the IDE when you tried accessing files. Bah !)
Problems
--------------------------------
1. Object Required: 'WScript'
This code, run as a VC macro gives the above error in the second line:
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "%windir%\notepad " & WScript.ScriptFullName
Saved in a text.vbs and double clicked on the same computer, it works fine
What is wrong with the VC VB runtime environment ? Why can't I access WScript ? I read somewhere else that "for security purposes" some aspects of the VB runtime were disabled in VC and this could be registry hacked.
Well if necessary, I'll do that. Does anyone have ideas ? Does code containing WScript calls work in your VCVB macros ?
2. The object model is half-baked
I don't know who designed the object model for the add ins but they must have stopped right in the middle of it ! You can't iterate over the files in a project ? Or set attributes per file ?
Is there a workaround for this half-assed job ? Has someone built a C++ addin that exposes this extra functionality to the scripting engine somehow ? Or do I really have to parse through dsp files (please no)
Your help is much appreciated - I just found this site tonight after googling for answers to the above - it is awesome !
Thanks in advance
Robert
|
|
|
|
|
|
OK,
Last question today. I am using the CDynViewDocTemplate class from the MSJ, where the doc template is supposed to swap views in a frame at run time for the same document. I have no problems running the sample, but run into trouble when I try and use this in my app. I am getting a debug assertion when the ReplaceView method of the doc template is called, something about don't paint the view until after you have called SetScrollInfo or something or other with CScrollView. I noticed the views in the sample from this MSJ artical were CView derived, not CScrollView derived. Anybody had any success with something similar? The initial view comes up fine, but swapping them out seems to be a problem.
Thanks,
Aaron
|
|
|
|
|
I don't know what's your sample article but this is a good sample for this purpose.You can use it for all kind of view.
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
How can I load bitmap, draw circle inside it and then select it to CStatic object?
This code doesn't work, anyone know why?
Some problem with SelectObject()!?!
// IN: CStatic m_cDisplay;
if ((hBitmap = ::LoadBitmap(theApp.m_hInstance, MAKEINTRESOURCE(IDB_DISPLAY))) == NULL) return false;
HDC hWinDC = ::GetDC(m_hWnd);
if (hWinDC == NULL) return false;
if ((hDisplayDC = ::CreateCompatibleDC(hWinDC)) == NULL)
{
::ReleaseDC(m_hWnd, hWinDC);
return false;
}
SelectObject(hDisplayDC, hBitmap);
// Call draw circle
DrawCircle(&hDisplayDC);
m_cDisplay.ModifyStyle(0, SS_BITMAP, 0);
m_cDisplay.SetBitmap(hBitmap);
::ReleaseDC(m_hWnd, hWinDC);
return true;
|
|
|
|
|
What error is SelectObject returning?
One thing that I think may be a problem is the fact that you are trying to set the bitmap into the static control while it is still selected into the MemDC.
Try releasing the MemDC before you call SetBitmap.
<br />
DrawCircle(&hDisplayDC);<br />
<br />
m_cDisplay.ModifyStyle(0, SS_BITMAP, 0);<br />
<br />
<br />
::ReleaseDC(m_hWnd, hWinDC);<br />
<br />
m_cDisplay.SetBitmap(hBitmap);<br />
<br />
return true;<br />
This is just a guess, tell me what happens.
|
|
|
|
|
It doesn't work, but I've found other solution.
Thanks for trying.
|
|
|
|
|
What was the solution that you found, I am curious to know the answer.
|
|
|
|
|
Hi Again,
I need to send a command message to my app. I have a class which handles some command message through WM_COMMAND entries, but I need to be able to invoke these handlers programmatically.
I was thinking that this probably involves calling SendMessage with WM_COMMAND and the ID of the command, let's say for example ID_EDIT_COPY. Does this sound about right? Which window, the main frame window, and let it percolate downwards from there?
Thanks,
Aaron
|
|
|
|
|
AfxGetMainWnd()->SendMessage( WM_COMMAND, ID_EDIT_COPY );
That sends the message to the main frame, which should then do the MFC routing stuff. (My MFC's a bit rusty, I think sending to the main frame will do the trick.)
--Mike--
Fetchez la vache!
My really out-of-date homepage
Sonork - 100.10414 AcidHelm
Big fan of Alyson Hannigan and Jamie Salé.
|
|
|
|
|
Michael Dunn wrote:
That sends the message to the main frame, which should then do the MFC routing stuff. (My MFC's a bit rusty, I think sending to the main frame will do the trick.)
I should think that will work. It is basically handled by main frame anyway as the menu is owned by the main frame window. That's why if we have a menu item handler in both the view and the main frame, the handler in the frame window class gets called and not the one in the view class.
Nish [not logged in today]
|
|
|
|
|
i have a file with the following:
score1 300
score2 400
score3 500
if i need to change the 400 in score2 to 50, how can I delete the whole 400 so it says:
score2 50
as opposed to:
score2 500
-Raffi
The truth about C++
|
|
|
|
|
Perhaps you should define a struct. Then you actually read or write a struct directly. If you want to edit one record [where each record is a struct], delete the record and add the new record which is a modification on the deleted record.
Nish
|
|
|
|
|
I know that you can use LoadCursor(NULL, IDC_WAIT) to load the standard hourglass cursor. The help that came with VC6 shows several other standard cursor IDs (such as a hand, a slashed circle, resizing arrows, etc) but I don't see one to show a cursor for dropping (such as moving a file to Explorer) -- an arrow with a little plus-sign.
Does anyone know an ID for that? Is there one, or do I have to create my own cursor image and load that? It seems like this one would be standard, but I don't see an ID for it.
Thanks in advance.
|
|
|
|
|
If you use OLE it will display those cursors for you (I think). Otherwise you can find them in ole32.dll. You can either extract the cursors or you can...
HMODULE hDll = LoadLibrary(TEXT("ole32.dll"));
HCURSOR hCursor = LoadCursor(hDll, id); The resource IDs are the following:
#define IDC_DRAG_CANNOT 1
#define IDC_DRAG_MOVE 2
#define IDC_DRAG_COPY 3
#define IDC_DRAG_LINK 4
|
|
|
|
|
Hi,
I've got another Doc/View qustion for the experts in MFC. I've got an app with a single document, and multiples views (sort of modeled after the MFC CHKBOOK sample, ie there are multiple doc templates registerd in the InitApplication method). Anyway, I've got a navigation control (a tree) in a dialogbar. Some of the nodes of this tree are associated with different view classes. The idea is that the user double clicks on a tree node to bring up a certain screen.
So, I would like to know how to iterate though all of the open views (looking for a specific type of view). If it is open, maximize it. If not, open that type of view in a window, then maximize it.
Where should I start?
Thanks
Aaron
|
|
|
|
|
Use CDocument::GetFirstViewPosition() and GetNextView() to iterate through the open views. Something like this:
POSITION pos = AfxGetMainWnd()->GetActiveDocument()->GetFirstViewPosition();
while ( NULL != pos )
{
CView* pView = AfxGetMainWnd()->GetActiveDocument()->GetNextView(pos);
if ( pView->IsKindOf ( RUNTIME_CLASS(CTheViewYoureLookingFor) ))
{
CFrameWnd* pFrame = pView->GetParentFrame();
pFrame->ShowWindow ( SW_SHOWMAXIMIZED );
break;
}
}
--Mike--
Fetchez la vache!
My really out-of-date homepage
Sonork - 100.10414 AcidHelm
Big fan of Alyson Hannigan and Jamie Salé.
|
|
|
|
|
I have a rectangle in my view,I want this rectangle to move,so I use SetTimer
to repaint the view for every 50 milliseconds,so it moves,but there is a bad thing here,
it just flickering Does anybody know any better way for moving objects or get rid of this flickering.
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
|
I'll try it
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|