|
Hi, everyone!
What means "smart pointer"? Where can I find some
online materials to refer?
Thanks in advance,
George
|
|
|
|
|
smart pointer is a class that wraps a pointer and overloads operator -> , to enable clients to use the smart pointer with same syntax as regular pointer. the class takes care of lifetime of the wrapped object (e.g. reference counting for COM objects, or deallocation for regular pointers).
Example:
void fn()
{
std::auto_ptr<CMyClass> pMyClass = new CMyClass();
pMyClass->SomeFunction();
}
some examples:
std::auto_ptr<> - check MSDN library
_com_ptr_t<> - wraps COM objects, VC++ compiler supported (check MSDN library)
CComPtr<> - wraps COM objects, provided by MFC (check MSDN library)
also, check Boost[^] for few other implementations
|
|
|
|
|
Thanks, Zed buddy!
George
|
|
|
|
|
Hi,
I have created a Deskband in internet Explorer and it is working fine. My Deskband contains two COM objects (designed by me and they are also doing fine). The problem i am facing is that if i right click a link in IE window, while my Deskband is selected, and click on "Open in New Window", then my Deskband also shows up in the new pane but it doesn't contain anything.
Please suggest me what to do!
regards,
|
|
|
|
|
Hello,
I'd like to create a toolbar (docked) with a width of 2 columns. I've searched newsgroups and the web, and all I can find is a way to set a CPaletteBar's width, via:
m_wndPaletteBar.SetColumns(AfxGetApp()->GetProfileInt(_T("General"),_T("Columns"),3));
I'd like to stick to a toolbar though - can it be done?
I'd like it to look like the paint program that comes with windows.
Also, when you pick the brush tool in Paint - you get a choice of brushes, I guess this is using a CDialogBar, but which control is it using?
Many thanks,
Josh
|
|
|
|
|
Dear Friends
My application which is in WINAPI doesn`t support 24bit color screen.it is wokring for all other options like 32 bit,256color etc.In 24 bit mode, I am getting garbled picture.
Kindly write to me how to solve it.
Thanking you.
Adarsh
|
|
|
|
|
I'm writing an unistaller and I want it to delete itself when all work is done. I tried to start a new tread but it finishes when the app exits. I need to ask the system to do the deletion. Can give me a solution how to do this or how to make the uninstaller if you have any other ideas.
|
|
|
|
|
|
There is an MSDN article about this (though I forget the title or KB number.) IF you search you'll find it.
But the most reliable, cross-platform way to do it is for the EXE to create and spawn a batch file that deletes it. The batch file will do something like this:
:deleteme
del program.exe
if exist program.exe goto deleteme
del thisbatchfile.bat
"When a man sits with a pretty girl for an hour, it seems like a minute. But let him sit on a hot stove for a minute and it's longer than any hour. That's relativity." - Albert Einstein
|
|
|
|
|
Dear Friends
My application doesn`t support 24bit color screen.it is wokring for all other options like 32 bit,256color etc.In 24 bit mode, I am getting garbled picture.
Kindly write to me how to solve it.
Thanking you.
Adarsh
|
|
|
|
|
When reading (or writing) through your bitmap data, you have to remember that each scan line is DWORD aligned. So when you reach the end of a scan line, you will have to realign your pointer to the next DWORD boundary. If you do not do this, you will get the garbage at the end of each scan line mixed into your data, causing the picture to appear messed up.
This code is from my PJAImage class and converts a 24bit bitmap to greyscale
else if (bm.bmBitsPixel == 24)
{
BYTE *dst=(BYTE*)pBits;
for (int dh = 0; dh < bm.bmHeight; dh++)
{
for (int dw = 0; dw < bm.bmWidth; dw++)
{
dst += 3;
}
int pos = (int)dst - (int)pBits;
int rem = pos % 4;
if (rem)
dst += 4 - rem;
}
} HTH
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
Dear PJ Arends,
In my code they have not used any class.It`s in WinAPI, as I am doing customization.
My progrmacode is like this:
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
hmemdc = CreateCompatibleDC(hdc);
hBmp = CreateCompatibleBitmap(hdc, WND_WIDTH, WND_HEIGHT);
SelectObject(hmemdc, hBmp);
hmemdc1 = CreateCompatibleDC(hdc);
SelectObject(hmemdc1, hBmpBckgnd);
StretchBlt(
hmemdc,
0,
0,
WND_WIDTH,
WND_HEIGHT,
hmemdc1,
0,
0,
1,
1,
SRCCOPY);
DeleteDC(hmemdc1);
This code has problem with 24bit screen resolution.What is needed...
Kindly let me know...
Thanking You.
AD
|
|
|
|
|
Other than a resource leak (you do not restore hmemdc1 before you delete it) I see nothing here that would break when using 24bit colour and would work with other colour settings. The only thing I can think of is that the bBmpBckgnd bitmap is corrupted before it gets to this point.
Check out http://www.codeproject.com/tools/imageviewer.asp[^]. It is a tool that I wrote so that I could check out these types of things in my own code. You can use it to check out what is contained in all your memory device contexts and bitmaps at any point in your code.
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
Hello!!
I have a program that shows a message box from a dll (in fact it's not a complete messagebox but a wnd that is a child of another window of my program).
When I call the function, I have a runtime error that says that the caling convention of the function from the dll is not corret. Here is the code:
In the program:
typedef void (WINAPI *SHOWTOOLDLG)(int, CRect,CWnd*);<br />
...<br />
...<br />
...<br />
void SomeDlgClass:OnSomeEvent()<br />
{ <br />
if (m_hToolDll)<br />
{<br />
SHOWTOOLDLG m_pShowDlg_Func = (SHOWTOOLDLG)GetProcAddress (m_hToolDll,"ShowToolDlg");<br />
if (m_pShowDlg_Func)<br />
m_pShowDlg_Func(0,ClientRect,this);<br />
}<br />
}<br />
in the dll:
extern "C" __declspec(dllexport) void ShowToolDlg(int ToolId, CRect Position,CWnd* pParent)<br />
{<br />
CToolConfDlg* Win;<br />
Win = new CToolConfDlg;<br />
Win->Create(IDD_EMPTYDLG,pParent);<br />
Win->ShowWindow(SW_SHOW);<br />
}
Could someone help me ??
Thanks!
|
|
|
|
|
1. Why extern "C" ?
2. If it is a regular DLL using MFC, you need to add:
AFX_MANAGE_STATE(AfxGetStaticModuleState());
at the beginning of your DLL-exported function.
Regards,
BB
|
|
|
|
|
After initializing the timer by:
SetTimer(ID_PLAYTIME_EVENT, 1000, NULL);
The following codes will result in exception: 0XC00000FD: stack overflow?
void CCPPPLAYERDlg::OnTimer (UINT nIDEvent)
{
MSG msg={0};
switch (nIDEvent) {
case ID_PLAYTIME_EVENT:
if(g_hwndMain)
{
// Main message loop
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg); DispatchMessage(&msg);
}
break;
}
CDialog::OnTimer(nIDEvent);
}
DJ
|
|
|
|
|
Don't put such a loop into a timer function. They were not designed to co-exist. The code you put into a timer function must be short, sweet and to the point, consuming as little CPU as possible.
|
|
|
|
|
If my brain is thinking right, if there are too many messages in the queue, this code will never finish and end up basically calling itself.
(I am baffled as to why you need to do a message look anyway.)
Finally, why use switch? Why not use if (nIDEvent == ID_PLAYTIME_EVENT)
|
|
|
|
|
After initializing the timer by:
SetTimer(ID_PLAYTIME_EVENT, 1000, NULL);
The following codes will result in exception: 0XC00000FD: stack overflow?
void CCPPPLAYERDlg::OnTimer (UINT nIDEvent)
{
MSG msg={0};
switch (nIDEvent) {
case ID_PLAYTIME_EVENT:
if(g_hwndMain)
{
// Main message loop
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg); DispatchMessage(&msg);
}
}
else
{
// AfxMessageBox(_T("Failed to create the main window!"));
}
break;
}
CDialog::OnTimer(nIDEvent);
}
DJ
|
|
|
|
|
Your implementation is not corectly!!
The return value of 'GetMessage' function can be:
zero - If the function retrieves the WM_QUIT message;
nonzero - If the function retrieves a message other than WM_QUIT;
-1 - If there is an error (ex. if hWnd is an invalid window handle or lpMsg is an invalid pointer).
In your function the 'GetMessage' returns nonzero always and when arrive a timer message this will be blocked in while loop, but after 1 sec. will arrive other timer message and will be blocked.
This is the problem, you never exit from OnTimer function, but OnTimer function is called at each 1 sec.
From this reason you have a Stack Overflow exception.
|
|
|
|
|
You are most likely right. The funciton (while uncommented) of AfxMessageBox(_T("Failed to create the main window!")); never be reached.
Thus I called KillTimer somewhere in the program to kill ID_PLAYTIME_EVENT and there were no more Stack Overflow problems.
But question again:
How do the following codes work? Once this code being called and run, how does it exit the while loop? Is it the correct way to process the message queue?
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
From my tests, once the program runs to this code, the while loop will exit forever until exiting the entire program. Actually that is what I had expected so that some other codes can run on a multitasking windows such 2000.
DJ
|
|
|
|
|
I'm trying to use the following code
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CDocument),
RUNTIME_CLASS(CMainFrame),
RUNTIME_CLASS(CLeftView));
AddDocTemplate(pDocTemplate);
But i'm getting an error because I haven't created an CDocument derived object. However I have to use this approach, because i'm trying to create splitter windows using this code:
m_wndSplitterLR.CreateStatic(this, 1, 2);
m_wndSplitterLR.CreateView(0, 1, RUNTIME_CLASS(CRightView), CSize(0, 0), pContext);
m_wndSplitterLR.SetColumnInfo(0, 200, 0);
m_wndSplitterUD.CreateStatic(&m_wndSplitterLR, 2, 1, WS_CHILD | WS_VISIBLE, m_wndSplitterLR.IdFromRowCol(0, 0));
m_wndSplitterUD.CreateView(0, 0, pContext->m_pNewViewClass, CSize(0, 200), pContext);
m_wndSplitterUD.CreateView(1, 0, RUNTIME_CLASS(CLeftView), CSize(0, 0), pContext);
And pContext is NULL unless I use Doc/View architechture and if it's NULL the second last line chokes...but I do not need a CDocument....
Any ideas or suggestions...? Should I just define a phantom CDocument class or soemthing, somehoe???
Thanks.
"Two wrongs don't make a right, but three lefts do!" - Alex Barylski
|
|
|
|
|
First: you don't need any document to create and use splitters.
If you want your CDocument to be a communication "media" among your views (via CDocument::UpdateAllViews ), you need to derive it and add this functionality. If you don't want to, you'll probably end up with the nasty code like:
((CMyRightPane*)((CSplitterWnd*)GetParent())->GetPane(x, y))->DoSomething();
which I personally hate.
So, run for your document or explicitly create/load a frame and create its views (in CYourFrame::OnCreateClient ) without using document templates.
Regards,
BB
|
|
|
|
|
If i don't use doc/view pContext->m_pNewViewClass is NULL inside OnCreateClient() and the application crashes???
How would I get the desired effect using the above I posted, without using DOC/VIEW???
Thanks!
"Two wrongs don't make a right, but three lefts do!" - Alex Barylski
|
|
|
|
|
Sample OnCreateClient for NULL document case (untested and not very elegant - but you will get the idea):
class CYourFrame : public CFrameWnd<br />
{<br />
CSplitterWnd Splitter;<br />
}
BOOL CYourFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext*) <br />
{<br />
CCreateContext cx;<br />
cx.m_pCurrentFrame = this;<br />
<br />
Splitter.CreateStatic(this, 1, 2);<br />
Splitter.CreateView(0, 0, RUNTIME_CLASS(CMyViewLeft), CSize(250, 250), &cx);<br />
Splitter.CreateView(0, 1, RUNTIME_CLASS(CMyViewRight), CSize(0, 0), &cx);<br />
<br />
if(bInitialUpdate) Splitter.SendMessageToDescendants(WM_INITIALUPDATE, 0, 0, FALSE);<br />
<br />
Splitter.SetActivePane(0, 0);<br />
return TRUE;<br />
}
Note: You may pass NULL as a last parameter to CSplitterWnd::CreateView , the WM_INITIALUPDATE message will then be automagically sent to the subsequently created views.
Regards,
BB
|
|
|
|
|