|
I think you're supposed to do your drawing in CView::OnDraw instead.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I know it ,but I want them outside OnPaint or OnDraw ,any way it solve
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
|
|
|
|
|
You get the paintDC twice in the same WM_PAINT message, afai remember that's not allowed and the second one won't work. If you passed the dc as a parameter to CMyView::paintrect instaed I bet it would work.
void CMysView::OnPaint()
{
CPaintDC dc(this);
paintrect(dc)
}
int CMyView::paintrect(CDC& dc)
{
RECT rctA;
rctA.left = 20;
rctA.top = 30;
rctA.right = 180;
rctA.bottom = 230;
dc.Rectangle(&rctA);
return 0;
}
Cheers
Steen.
"To claim that computer games influence children is rediculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
thaaaaaaaaaaaaaaaanks,it woooooooooooooooooooorks
yohooooooooooooooooooooooooo
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
|
|
|
|
|
Now I want to use paintrect outside the OnPaint or OnDraw.How can I do that?
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
|
|
|
|
|
You can pass the DC from OnPaint to your other drawing functions... so paintrect(CDC *pDC)...
|
|
|
|
|
CMyView::SomeFunctionOtherThanOnPaintOrOnDraw()
{
CClintDC dc;
paintrect (dc);
}
Cheers
Steen.
"To claim that computer games influence children is rediculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
Sorry, forgot the paramter to CClientDC::CClientDC
CMyView::SomeFunctionOtherThanOnPaintOrOnDraw()
{
CClientDC dc(this);
paintrect (dc);
}
Cheers
Steen.
"To claim that computer games influence children is rediculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
The reason why this code will work instead is that in the constructor for CPaintDC, there is a call to BeginPaint in order to initialize the internal HDC. When begin paint is called, it sets something that is called the System region of the HDC.
For all intents and purposes, the System region is like a clipping region that cannot be changed. When you paint on a DC, the intersection of the system region, the clipping region, and the meta region are combined in order to give the developer the final region that is painted.
When a call to GetDC is made, the system region is set to the client area of the window.
When GetWindowDC is called, the system region is set to the window rect of the window.
When BeginPaint is called, the system region is set to the current invalid region of the window, then the invalid region is validated.
So, if you make two calls to BeginPaint, you will receive two successfully created DC's, however, the first one will contain a system region that has the invalid region set into it, and the second one will contain an empty second region. Therefore if you try to paint on the first region in one color, say blue, then it will succceed. Then if you try to paint on the second region in red, none of the operations would succeed because there is an empty second region.
|
|
|
|
|
How to load icon resource into hBitmap ?
thanx
|
|
|
|
|
Starting from an HICON , <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/icons_2227.asp">::GetIconInfo</a> fills an <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/icons_9eya.asp">ICONINFO</a> structure whose hbmColor member is the HBITMAP you're looking for.
An alternative method is to draw your into a bitmap DC.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanx
|
|
|
|
|
How to get the export table of a given module using c/c++ (such as quickview in winnt4 or DEPENDS.EXE from vs6)
thanx
|
|
|
|
|
You need to navigate through the Executable or DLL file. Most likely it will be in the windows PE format that was created for windows programs from 9x on.
I have done this quite alot, and what I have found the easiest is to map the file that you are interested in memory, and get a pointer to the base address of this file.
Next you can read through the entire file like it was a pointer to memory. At the base address of this file you will find a structure called:
PIMAGE_DOS_HEADER
from here you will be able to navigate through the EXE by the pointers and offsets that you are able to extract from that original header.
I can't remember the rest of the path right off of the top of my head, but if you search MSDN for Matt Pietrek's PEDUMP program, it will give all of the information that you need, and you can use most of the source code that he has written in order to get the export table that you want.
|
|
|
|
|
I would like to create a global variable which can be available in all my files of my MFC project.
Where must i declare it? (in which file ?)
thk you in advance
Appstmd
|
|
|
|
|
Try declaring it in stdafx.cpp, such as this:
<br />
int g_iCount;<br />
Then declare this variable externally in stdafx.h, this will allow all of the files in your project
to use it.
<br />
extern int g_iCount;<br />
This will work for all Visual C++ projects.
|
|
|
|
|
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
|
|
|
|