|
I'd suggest you'd end up with the b constructor being called, then the class being downcast to an a*. I don't think you need the C style cast, it should work implicitly.
I'd write some code that outputs messages in the constructors and try it to see.
Christian
We're just observing the seasonal migration from VB to VC. Most of these birds will be killed by predators or will die of hunger. Only the best will survive - Tomasz Sowinski 29-07-2002 ( on the number of newbie posters in the VC forum )
Cats, and most other animals apart from mad cows can write fully functional vb code. - Simon Walton - 6-Aug-2002
|
|
|
|
|
b::b will be called. You don't need the cast. You'd need the cast if you'd derive b using private/protected inheritance.
Tomasz Sowinski -- http://www.shooltz.com
Never argue with an idiot, he'll bring you to his level and beat you with experience.
|
|
|
|
|
As mentioned this is perfectly leagal and often usefull, especially in conjuction with virtual functions.
[James Pullicino] wrote:
Which constructor will be called?
The answer is both. b's constructor is called which then imediately calls a's.
class a<br />
{<br />
public:<br />
a() {cout << "A's Constructor\n";}<br />
};<br />
<br />
class b : public a<br />
{<br />
public:<br />
b() {cout << "B's Constructor\n";}<br />
}
If you are in doubt about some feature it is always a good idea to use print statements or better yet step through the code with a debugger. Posting your question on a message board is also a good idea.
|
|
|
|
|
i have an unsigned char array which has certain data. I want that data of the array to be displayed in hexadecimal format in CListCtrl. For ex. if i have ch[0]=0x10,it should be displayed as 10 in the list control. can anybody help?
Here is my code, but it displays l in the list control.
******************************
unsigned char DataMsg[32];
LV_ITEM lvitem;
CString dataText= (CString)DataMsg[0];
lvitem.mask = LVIF_TEXT | 0;
lvitem.iItem = iItem;
lvitem.iSubItem = 0;
pStrTemp1= dataText.GetBuffer(dataText.GetLength());
lvitem.pszText = pStrTemp1;
m_listCntrl.InsertItem(&lvitem);
***********************************
Rsh
|
|
|
|
|
You could use an ostringstream and I think the modifier is hex() to make it display as hex.
Christian
We're just observing the seasonal migration from VB to VC. Most of these birds will be killed by predators or will die of hunger. Only the best will survive - Tomasz Sowinski 29-07-2002 ( on the number of newbie posters in the VC forum )
Cats, and most other animals apart from mad cows can write fully functional vb code. - Simon Walton - 6-Aug-2002
|
|
|
|
|
Use CString::Format with %x or %X
Tomasz Sowinski -- http://www.shooltz.com
Never argue with an idiot, he'll bring you to his level and beat you with experience.
|
|
|
|
|
Hello,
I have created a CDialog. Inside it I have put a CComboBox and have added items to it. Whats happening is that when i click the drop down arrow it clips the drop list inside the dialog only showing the number of items that will fit above the bottom of the dialog. Is it possible to get it not to clip the droplist within the dialog ?
Thanks ReX
|
|
|
|
|
Dialog shouldn't clip the dropdown part of combo. Make sure that dropdown rectangle is big enough - click on dropdown arrow in resource editor and adjust the rectangle height.
Tomasz Sowinski -- http://www.shooltz.com
Never argue with an idiot, he'll bring you to his level and beat you with experience.
|
|
|
|
|
The size of the dropdown rectangle is correct adjusted in the resource editor. If I size the dialog bigger, the the full dropdown list is shown (because dialog bottom is far enough)
ReX
|
|
|
|
|
Strange. I've never seen this behavior. Are you doing dirty tricks with subclassing the dropdown part?
Tomasz Sowinski -- http://www.shooltz.com
Never argue with an idiot, he'll bring you to his level and beat you with experience.
|
|
|
|
|
I want to replace the last character of a string represented by std::string with comma. How can i do so ??
Example:
std::string mystring("Hellow World");
I want to replace last character of "Hellow World" i.e 'd' by comma "'"
|
|
|
|
|
I wrote this function for this purpose. I hope this helps.
inline void Replace(std::string* pstr, const char old_char, char* pnew_char)
{
if(!pstr->empty())
{
int n = 0;
while((n = pstr->find(old_char)) != -1)
{
*pstr = pstr->erase(n, 1);
*pstr = pstr->insert(n, pnew_char);
}
}
}
Usage:
Replace(&mystring, 'd', ',');
For the last character only you can take:
mystring.erase(mystring.length(), 1);
mystring.append(',');
Greetings ReX
|
|
|
|
|
That's also a way to burn CPU cycles. Another (possibly better) way to do it could be
std::replace(string.begin(), string.end(), 'a', 'b');
to replace all instances of 'a' with 'b'.
|
|
|
|
|
*mystring.rbegin() = '.';
it works
nobody is perfect
|
|
|
|
|
Isn't that to be *(++mystring.rbegin()) = '.'; ?
|
|
|
|
|
nope
rbegin() returns last member of container, as i understand it ))
nobody is perfect
|
|
|
|
|
Then, AFAIK, your understanding is wrong. The doc's I've seen says "The rbegin member function returns a reverse iterator that points just beyond the end of the controlled sequence" and every experience I have with rbegin() says the same.
|
|
|
|
|
I'm trying to enumerate all the different formats for a specific format type, but every time i run the acmFormatEnum function it returns MMSYSERR_INVALPARAM meaning "At least one parameter is invalid.". Anyone know how to use that function? Anyone have some examples? All help is greatly appreciated, here's my code. I start by running the TagEnum function:
ACMFORMATTAGDETAILS acmTagDetails;
void TagEnum()
{
HACMDRIVER hAcm;
acmDriverOpen(&hAcm, id, 0);
acmTagDetails.cbStruct = sizeof(ACMFORMATTAGDETAILS);
acmFormatTagEnum(hAcm, &acmTagDetails, acmTagCallback, NULL, 0);
acmDriverClose(hAcm, 0);
}
BOOL WINAPI acmTagCallback(HACMDRIVERID hadid, LPACMFORMATTAGDETAILS paftd, DWORD dwInstance,DWORD fdwSupport)
{
ACMFORMATDETAILS acmFormat;
WAVEFORMATEX waveFormat = { 0 };
HACMDRIVER hAcm;
memset(&acmFormat, 0, sizeof(acmFormat));
acmFormat.cbStruct = sizeof(acmFormat);
acmFormat.cbwfx = sizeof(waveFormat);
acmFormat.pwfx = &waveFormat;
acmFormat.dwFormatTag = acmTagDetails.dwFormatTag;
waveFormat.wFormatTag = acmTagDetails.dwFormatTag;
acmDriverOpen(&hAcm, hadid, 0);
acmFormatEnum(hAcm, &acmFormat, formatCallback, NULL, ACM_FORMATENUMF_WFORMATTAG);
acmDriverClose(hAcm, 0);
return TRUE;
}
BOOL WINAPI formatCallback(HACMDRIVERID hadid, LPACMFORMATDETAILS pafd, DWORD dwInstance, DWORD fdwSupport)
{
ACMDRIVERDETAILS details;
details.cbStruct = sizeof(details);
acmDriverDetails(hadid, &details, NULL);
SendMessage(GetDlgItem(ghWnd, IDC_FORMATS), LB_INSERTSTRING, 0, (LPARAM)details.szLongName);
return TRUE;
}
id is a HACMDRIVERID holding a valid driver id of a driver. Anyone have a clue what could be wrong or have some examples?
All help is apprecaited.
-Rune Svendsen
|
|
|
|
|
Doesn't the MSDN sample ACMapp display how to do this???
|
|
|
|
|
Hi,
I have an ActiveX control that I want to view from a HTML view, I could embed it directly in my application but there are some features which are only activated when its a plugin for IE.
The problem is that the Control overrided the OnDblClick and OnChar messages from the HTMLView and handles them iteself.
Is there any way arround this?
If there isn't my only other solution is to make sure the View does not get focus. Is there any way to ENSURE that a view never gets the focus?
Thanks
Asim Hussain
e: asim@jawache.net
w: www.jawache.net
|
|
|
|
|
Yes, one solution is to override event handlers associated to the HTML document :
- ondblclick for OnDblClik windows command
- onkeyup for OnChar windows command
The HTML document is obtained with code like this :
CComQIPtr<IHTMLDocument2> pHtmlDoc( GetHtmlDocument() );
|
|
|
|
|
Hi,
I want to create a dialogue box that has a hole in it... Essentially, it is a window that covers another window created by another application. But I want a square hole in my dialogue that shows part of the window beneath it (kind of like those envelopes that you get with a square cutout in the front showing your address that is printed on the letter it contains).
Does anybody know how I can do this? I am using the Windows API.
Many thanks for any suggestions,
Keith
|
|
|
|
|
HRGN hOrgRgn;
::GetWindowRgn(hWnd, hOrgRgn);
HRGN hRectRgn = ::CreateRectRgn(0, 0, 100, 100);
HRGN hResultRgn;
::CombineRgn(hResultRgn, hOrgRgn, hRectRgn, RGN_XOR);
::SetWindowRgn(hWnd, hResultRgn);
something like this should help
nobody is perfect
|
|
|
|
|
Hi, many thanks for your reply.
I tried the rgn method, and finally got this code working:
hOrgRgn=CreateRectRgn(0,0,0,0);
GetWindowRgn(hWnd, hOrgRgn);
hRectRgn = CreateRectRgn(50, 10, 200, 200);
hResultRgn=CreateRectRgn(0,0,0,0);
CombineRgn(hResultRgn, hOrgRgn, hRectRgn, RGN_XOR);//RGN_DIFF); //rgn_diff makes no difference
SetWindowRgn(hWnd, hResultRgn,TRUE);
But unfortunately, this does exactly the *opposite* of what I want. This cuts out a square from the middle of the window, but it only shows the cut out square and not the rest of the window; I want to show the window with a square hole in the middle. I've tried swapping around "hOrgRgn" and "hRectRgn" in CombineRgn(), but it makes no difference.
Does anybody have any suggestions?
Again, many thanks,
Keith
|
|
|
|
|
// get screen coordinates
RECT OrgRect;
GetWindowRect(hWnd, &OrgRect);
POINT ptLT, ptRB;
ptLT.x = OrgRect.left;
ptLT.y = OrgRect.top;
ptRB.x = OrgRect.right;
ptRB.y = OrgRect.bottom;
// convert to client
ScreenToClient(hWnd, &ptLT);
ScreenToClient(hWnd, &ptRB);
// convert from client area to entire window area
ptRB.x -= ptLT.x;
ptRB.y -= ptLT.y;
ptLT.x -= ptLT.x;
ptLT.y -= ptLT.y;
// create new region for window
HRGN hNewRgn = CreateRectRgn(ptLT.x, ptLT.y, ptRB.x, ptRB.y);
// "hole" region
HRGN hRectRgn = CreateRectRgn(ptLT.x+50, ptLT.y+50, ptRB.x-50, ptRB.y-50);
// combine them
HRGN hResultRgn = CreateRectRgn(0, 0, 0, 0);
CombineRgn(hResultRgn, hNewRgn, hRectRgn, RGN_DIFF);
SetWindowRgn(hWnd, hResultRgn, TRUE);
this one works for sure
can send you a demo project
nobody is perfect
|
|
|
|
|