|
I think I understand some of it now, but theres still some things that elude me.
An example is
<br />
CClient* pDC(this);<br />
CPen penRed = new CPen()<br />
<br />
penRed.Create(PS_SOLID,1,RGB(255,0,0);
<br />
CPen penOld = dc->SelectObject(&penRed);
<br />
dc.DrawText(300,400,penRed,"Hello World");
<br />
dc.SelectObject(penOld)
I still am a bit confused like the previous snippet
<br />
CRect rc;<br />
GetWindowRect(&rc);<br />
Thanks in advance again
Tom
|
|
|
|
|
CClient* pDC(this);
CPen *penRed = new CPen();
penRed->Create(PS_SOLID,1,RGB(255,0,0));
CPen *penOld = dc->SelectObject(penRed);
dc.SelectObject(penOld) I've marked up the code you posted. Notice the bold areas.
1. The new operator returns the address of an object allocated on the heap. The value on the left side of the assignment therefore has to be a pointer variable.
2. If you refer to a member of an object through a pointer, you have to use the -> operator, as in penRed->Create .
3. The SelectObject function in the CDC class takes a pointer to a CGdiObject .
4. The CDC class doesn't have a DrawText member that takes a pen argument.
Software Zen: delete this;
|
|
|
|
|
hihi,
u should learn C++ before u know GetWindowRect().
&rc is address of the rc.
rc is rc.
address means memory place in which the data of rc stored.
it sounds very dangerous u go so far in programming.
A nice tool for optimizing your Microsoft html-help contents.
Includeh10
|
|
|
|
|
Hi,
I do know C++!
I did a programming course on it, but I covered a small portion of address of operator in it, and we didnt cover address of operator with objects.
Thanks
Tom
|
|
|
|
|
Hi Tom Moore,
int* m_pNumber1; //this operator is pointer
int* m_pNumber2;//this operator is pointer
int m_Number1;//It's a integer
int m_Number2;//It's a integer
m_Number1=20;//Value is Integer
m_Number2=30;//Value is Integer
The Follow these statement Address of Operator m_Number1 and m_Number2
m_pNumber1=&m_Number1;//////////& is Address of Operator
m_pNumber2=&m_Number2;
////////////////////////Now
int iResult=m_Number1+ m_Number2;///->>>>>>>>Result=50
iResult=*m_pNumber1+ *m_pNumber2;///->>>>>>>>Result=50
|
|
|
|
|
Thanks to everyone!
I think I understand everything now
You use address of the object to access the originl object,
eg. dc.SelectObject(&penBlue); // Uses the original CPen
plus the Windows GDI libary is written in Pure C therefore it requires the address of the object.
Where as dc.SelectObject(penBlue); // Creates a copy and is slow.
I think GDI+ was written in either .NET or C++ instead of C and therefore is slightly simpler to use.
Thanks again
Tom
|
|
|
|
|
Tom Moore wrote: Whats the difference between :
GetWindowRect(&rc); and
GetWindowRect(rc);
The function declaration for GetWindowRect is CWnd::GetWindowRect(LPRECT lpRect) const; so it takes a pointer to a RECT structure as it's parameter. The reason why you can pass a CRect object, either as a pointer or by 'reference' (remember that the values of the window rectangle are copied into the CRect object, so you can not pass it in using the copy c'tor) is because the CRect class is derived from the RECT structure and has member operator LPRECT. If you pass it by address, GetWindowRect() assumes that you passed in the address of a RECT structure, or the base class, and it works from there. If you pass it by reference, then the CRect::operator LPRECT() kicks in to pass it's own address ( return this; ).
It's all in the magic of overloaded operators. So the difference between the two examples you gave is that there is really no difference functionally, although passing by address will save a few CPU cycles as it saves a call to the CRect::operator LPRECT
You may be right
I may be crazy
But it just may be a lunatic you’re looking for
-- Billy Joel --
Within you lies the power for good - Use it!
|
|
|
|
|
In C, variables can be passed to a function either by-value or by-reference. For example:
void foo( int num )
{
num = 12;
}
...
int x = 5;
printf("%x\n", x);
foo(x);
printf("%x\n", x);
void foo( int *num )
{
*num = 12;
}
...
int x = 5;
printf("%x\n", x);
foo(&x);
printf("%x\n", x); Another consideration is the amount of memory pushed onto the stack when one or the other is used. For integral types such as int , char , and double , there is little, if any, difference between the two. A char is 1 byte, a double is 8 bytes, and a pointer to either is 4 bytes. Where this matters more is when large data structures are being passed to a function. Imagine an object that is 1497 bytes in size. Passing the object by-value will result in 1497 bytes being piushed onto the stack, whereas passing the object by-reference will result in only 4 bytes being pushed onto the stack.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
Hi all,
I have some message boxes that are triggered from some buttons on a dialog. The dialog is set to open in full screen mode. The funny thing is that when the message boxes are triggered they get focus but they go behind my dialog.
Any idea why this is happening and how to get the message box on top of the dialog?
Thanks in advance.
|
|
|
|
|
MessageBox(....,HWND hWnd).
if hWnd is hidden, the message box is hidden also.
A nice tool for optimizing your Microsoft html-help contents.
Includeh10
|
|
|
|
|
I'm quite new to MFC programming ... how do i make it visible?
|
|
|
|
|
Set your dialog as its parent .
int MessageBox( HWND hWnd (Set it as your dialog handle),
LPCTSTR lpText,
LPCTSTR lpCaption,
UINT uType
);
Regards,
FarPointer
|
|
|
|
|
Sorry i'm unfamiliar with how to create or use a handle. Could you please show me how to?
Thanks in advance
|
|
|
|
|
Hi,
Please try this out:-
m_hWnd :- this is the handle of the dialog
MessageBox(m_hWnd,"AM I Working");
Regards,
FarPointer
|
|
|
|
|
If you are using MFC, you can do the following:
CMyDialog::OnButton()
{
::MessageBox(m_hWnd,
"Your message text goes here",
"Caption for your message box",
(MB_OK | MB_ICONINFORMATION));
} In this case, CMyDialog is the name of your dialog class, derived from CDialog (which is in turn derived from CWnd ). One of the members of all CWnd -derived objects is m_hWnd , which is the window handle.
Software Zen: delete this;
|
|
|
|
|
I've just tried m_Hwnd as follows:
<br />
::MessageBox(m_hWnd,"This is the LAST record","Last Record",MB_ICONINFORMATION | MB_SYSTEMMODAL);<br />
But its still not coming to the front. Could there be something else wrong?
|
|
|
|
|
Kinda off topic...
Don't use MB_SYSTEMMODAL unless you absolutely have to. It prevents the user from doing anything else on the computer other than interact with your message box. It's an exceptionally good way to cause extreme frustration and loss of confidence in your product...
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Thanks for the information ... i'll sure take it into account
|
|
|
|
|
braveheartkenya wrote: ::MessageBox(m_hWnd,"This is the LAST record","Last Record",MB_ICONINFORMATION | MB_SYSTEMMODAL);
You can try this one...
MessageBox(_T("This is the LAST record"), _T("Last Record"), MB_ICONINFORMATION | MB_SETFOREGROUND);
Since you are using MFC you don't have to use m_hWnd here. MFC does that for you.
Nibu thomas
Software Developer
|
|
|
|
|
It didn't work, but i got another that did.
Replace the MB_SETFOREGROUND with MB_DEFAULT_DESKTOP_ONLY.
I don't know what it means, but it brings it on top and freezes the dialog. Any idea how i can bring it to the front but not freeze the dialog?
|
|
|
|
|
I just generate a owner-drawen class from CListBox, and I want to set the item text only in DrawItem function. If CListBox without add one null string previously, DrawItem function is not called.
Thank you for your helps.
Lichang Wu
|
|
|
|
|
DrawItem() is only called when items are to be drawn. If there are no items to draw, it's not called. You still have to add your items as normal.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Send this message from your dialog after doing AddString() to set LB_SETCOUNT...
lResult = SendMessage( // returns LRESULT in lResult (HWND)hWndControl, // handle to destination control
UINT) LB_SETCOUNT, // message ID
(WPARAM) wParam, // = (WPARAM) () wParam;
(LPARAM) lParam // = (LPARAM) () lParam; );
For example,
HRESULT lResult;
lResult = m_MyListBox.SendMessage( (UINT) LB_SETCOUNT,
(WPARAM) m_MyListBox.m_iTotalItemCount,
(LPARAM) 0);
where, m_MyListBox is member object of your Owner Draw ListBox derived class (like CMyListBox derived from CListBox). m_iTotalItemCount as WPARAM is total number of item data to be set. LPARAM can be sent as 0.
One thing needs to be taken into account that the LB_SETCOUNT works only when ListBox Style is "No Data" i.e. LBS_NODATA. Has Strings should be set as FALSE. Setting LB_SETCOUNT will call Draw Item.
Happy Programming ![Thumbs Up | :thumbsup:](https://codeproject.global.ssl.fastly.net/script/Forums/Images/thumbs_up.gif)
|
|
|
|
|
I have written a program which reads data from internet and displays it in the web browser control.
And now I'm fuzz about such problems( I have paste the code at the end):
Sometimes the 'DisplayInExplore' works well, but Sometimes it crashs.
1. I have debugged it , and found that 'pHD->write(pSFArray);' method would result in the 'Assert Debug' fatal error. And I can't step into the method write.
2. Sometimes, the 'pHD->write(pSFArray);' could execute successfully, but there was no data to display in the Web Browser control. And when cursor went into the client area of the Web Browser control, the cursor change to the 'wait' status.
So , I have no idea why it works so instable ? Or there are some errors in my function?
Plz give me some suggestion ,Thx.
---------------------------------------------------------------------------
The code is as below:
void CGameInfoDlg::DisplayInExplore(CString strContent)
{
//m_exploreView is the CWebBrowser2
IHTMLDocument2* pHD=(IHTMLDocument2*) m_exploreView.GetDocument();
VARIANT* pVATable=NULL;
SAFEARRAY* pSFArray;
pSFArray = SafeArrayCreateVector(VT_VARIANT, 0, 1);
if(pSFArray!=NULL && pHD!=NULL)
{
SafeArrayAccessData(pSFArray,(LPVOID*) &pVATable);
BSTR bstrContent=strContent.AllocSysString();
pVATable->vt=VT_BSTR;
pVATable->bstrVal=bstrContent;
SafeArrayUnaccessData(pSFArray);
pHD->write(pSFArray);
}
else
{
MessageBox("Errors!");
}
SysFreeString(pVATable->bstrVal);
if(pSFArray!=NULL)
{
SafeArrayDestroy(pSFArray);
}
}
|
|
|
|
|
who can give me some tins?? plz, thx very very very much....
|
|
|
|