|
This may seem like an obvious question, but i'd like to check the answer with more experienced COM programmers nonetheless...
My app is a COM client (but not a server). I am calling CoInitializeEx , with the COINIT_MULTITHREADED flag, in my apps CWinApp::InitInstance() override.
My app also has worked threads which need to use COM objects too.
1. Should I be calling CoInitializeEx() in the worker thread too?
2. Is is "safe" to use interface pointers (with proper AddRef'ing) in my worker threads, where the pointers were gained from QueryInterface()/CoCreateInstance() in my main UI thread?
3. Or is (2) dependant on the individual COM object?
----
Last question is not COM related:-
4. Is it correct/ok for my worker thread to call SetWindowText() on a control in my dialog (whose message loop is the main, UI thread? Or am I risking deadlock? it seems to work; but should it work in all situations?
Thanks for the help
Jon
using System.Beer;
|
|
|
|
|
1. I normally call CoInitializeEx and Couninitialise in the worker threads
2. & 3. I don't know. Though I guess it is not safe.
4. It is possible to cause a deadlock using SetWindowText (it uses SendMessage with WM_SETTEXT). Probably better to send a message for the main thread to update the text.
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fruity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Walliams (Little Britain)
|
|
|
|
|
I’m creating a menu when I right-click on an item in my CTreeCtrl. If the item I click do have children the tree expands. I don’t want it on right-click just on left-click!!
_____________________________
...and justice for all
APe
|
|
|
|
|
catch PreTranslateMessage() in your dialog (or view). see if the message is being sent to the tree control. If it is and the message is a right-click, return TRUE, thus signalling that you have handled the event and it won't be passed down to your tree control.
If I write code in my sleep, does that make me brilliant, or just a lazy programmer?
My articles
www.stillwaterexpress.com
BlackDice - the programmer formerly known as bdiamond
|
|
|
|
|
i wanted to derive a class that has the properties of both the CDialog and CStatic class but when i use the wizard to make a new class they give the provision only for one base class??
is it possible to have more than one base class ??if so.....how is it done??
thanx!!!!!
|
|
|
|
|
I am not sure it is a good idea. Both CDialog and CStatic are derived from CWnd, and you would get a diamond of death[^] (unless CWnd is a virtual base, but I doubt it is )
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
|
|
|
|
|
Not that I condone it, but can you use ClassWizard to derive your class from CDialog , and then manually add CStatic to the base list in the class' .h file?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
what property does CStatic contains that can be usefull for a CDialog ?
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
Dear friendz....
i would like to know how i can change the color of the frame of a picture control placed on a dialog box when a certain event(say onmousemove())takes place??
all suggestionz are welcome.....
thanx in advance...
|
|
|
|
|
plz help!!!!!
HICON hIcon = AfxGetApp()->LoadCursor( IDC_CURSOR1 );
SetCursor( hIcon );
return TRUE;
is a working code coz i have put this in my Dialog based application (Xyz) in a class called CXyzDlg..... that is, i have already added this function "OnSetCursor()".....and the cursor changes......in the main Dlg box but..... i have derived a class from the CStatic Class named it as "CMyClass".....and i have created obcts of it in the CXyzDlg class.....basically these objects i have created by placing the "static control" on the dialog box and then..... thru the class wizard created an object linking it with the picture control of type CMyClass(that is .....SUBCLASSING).....
also in thiz CMyClass i have added the "OnSetCursor()" function as well......and many other mouse functions like "onmousemove()","LbuttonDown()".....etc.....but here when i put in the same code as i had put in the main Dlg box for the "OnsetCursor()".....it does not change!!!!!......y???
heres the code......that i have put in the derived class CMyClass......
#include "stdafx.h"
#include "creamz.h"
#include "MyClass.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CMyClass::CMyClass()
{
m_DragOn1=FALSE;
m_pot1=0;
m_update=TRUE;
}
CMyClass::~CMyClass()
{
}
BEGIN_MESSAGE_MAP(CMyClass, CStatic)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_WM_SETCURSOR()
END_MESSAGE_MAP()
void CMyClass::OnLButtonDown(UINT nFlags, CPoint point)
{
HICON hIcon = AfxGetApp()->LoadCursor( IDC_CURSOR2 );
SetCursor( hIcon );
m_DragOn1=TRUE;
CStatic::OnLButtonDown(nFlags, point);
}
void CMyClass::OnLButtonUp(UINT nFlags, CPoint point)
{
HICON hIcon = AfxGetApp()->LoadCursor( IDC_CURSOR1 );
SetCursor( hIcon );
m_DragOn1=FALSE;
CStatic::OnLButtonUp(nFlags, point);
}
void CMyClass::onmousemove(UINT nFlags, CPoint point)
{
if(m_DragOn1==TRUE)
{
if(m_pot1<62)
m_pot1+=1;
else
m_pot1=0;
if(m_pot1%2==0)
m_update=TRUE;
}
CStatic::onmousemove(nFlags, point);
}
BOOL CMyClass::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
if(m_DragOn1==FALSE)
{
HICON hIcon = AfxGetApp()->LoadCursor( IDC_CURSOR1 );
SetCursor( hIcon );
}
else
{
HICON hIcon = AfxGetApp()->LoadCursor( IDC_CURSOR2 );
SetCursor( hIcon );
}
return TRUE;
}
plz help me out......
thanx in advance.....and thanx for ur intrest!!!!!
|
|
|
|
|
I think your problem maybe use of local variable that goes out of scope immediately after your call to SetCursor.
I suggest making a member variable for your class:
HICON m_CursorIcon;
In your constructor, set it to NULL:
m_CursorIcon = (HICON)0;
Add a new member function you call anytime you want to change the cursor:
void MySetCursor(UINT idCursor){<br />
m_CursorIcon = AfxGetApp()->LoadCursor( idCursor );<br />
if( !m_CursorIcon ){<br />
return;<br />
}<br />
SetCursor( m_CursorIcon );<br />
}
|
|
|
|
|
thanx for the reply.....but that too doesnt work..... .....i dont think m_cursorIcon being a local variable is a prob actually coz i had put in a code to trace if the control was going to the OnSetCursor() and it does.....only thing is that the mouse pointer doesnt get updated......
any ideas???
thanx a lot for ur reply.....
|
|
|
|
|
Here is an idea, from the MSDN:
If your application must set the cursor while it is in a window, make sure the class cursor for the specified window's class is set to NULL. If the class cursor is not NULL, the system restores the class cursor each time the mouse is moved.
|
|
|
|
|
can u elaborate a little more please!!!!!.....what am i to make NULL??is it the OnSetCursor
|
|
|
|
|
It involves checking and possibly changing the HCURSOR field of the WNDCLASS associated with your CStatic window. However, in the context of MFC, this can get you into trouble really quick, since you would be changing it for EVERY CStatic in the program - and every window using the class registered (which cna be other types, knowing hwo MFC seems ot work...).
As a different approach, why don't you look at Chris' CHyperLink control on this website. Study his code, because, as I recall, it changes the cursor to a pointy hand when the mouse is over the window. Using his code as an exmaple, you should be able to see how to get the cursor changed in your window. I think his is even derived from CStatic.
http://www.codeproject.com/miscctrl/hyperlink.asp
|
|
|
|
|
Is there a minimum size when allocating memory using CoTaskMemAlloc() ?
For ex;
LPBITMAPINFO pDibImage = NULL;
pDibImage = (LPBITMAPINFO)CoTaskMemAlloc(400);
once I do this, the BIMAPINFO fileds such as bmiHeader and bmiColor values
are not set to 0. They are filled with Garabage...
Why ?
but if I assign a larger memory block like..
pDibImage = (LPBITMAPINFO)CoTaskMemAlloc(6606760);
Then everything is initlized properly....
any ideas? thoughts?
Thanks
|
|
|
|
|
I suppose, because the MSDN DOCUMENTATION has this to say...
The initial contents of the returned memory block are undefined – there is no guarantee that the block has been initialized.
So, if you want the memoryto be all ZEROed out, you must do it yourelf, thusly:
pDibImage = (LPBITMAPINFO)CoTaskMemAlloc(400);
if( pDibImage ){
ZeroMemory(pDibImage, 400);
}
You just randomly drew some 'zeroes' when you allocated the larger block.
The minimum size is 0:
If cb is zero, CoTaskMemAlloc allocates a zero-length item and returns a valid pointer to that item. If there is insufficient memory available, CoTaskMemAlloc returns NULL.
Also...
Note Applications should always check the return value from this method, even when requesting small amounts of memory, because there is no guarantee the memory will be allocated.
|
|
|
|
|
I'm attempting to write an MFC based program that uses Arabic fonts for an Arabic class I'm taking. I'm using WinXP and have the fonts installed (i.e. I can type in Arabic in MS word), but I can't seem to associate one of those fonts with a CFont object. Well I can, but it seems that text still comes out in English. I set the justification mode from right to left and specified the enumerated type ARABIC_CHARSET when initializing the CFont. Here is a sample of the display callback in my code where I'm simply just outputting the string "hahah". It shoudl come out in
Arabic (the letters "sheen" and "alif"). Any ideas? Do I need to link to some DLL? Does some sort of preprocessor definition have to be declared? Oh and I'm using visual c++ 6.0.
void CFACKDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CPaintDC dc(this);
dc.SetTextColor(RGB(0,0,0));
dc.SetTextAlign(TA_RTLREADING);
fntArab.CreateFont(rcClient.Height()/20, 0, 0, 0,
FW_DONTCARE, FALSE, FALSE, 0, ARABIC_CHARSET,
OUT_TT_PRECIS, CLIP_LH_ANGLES,
DEFAULT_QUALITY, FF_DONTCARE, "arabic transparent bold" );
dc.SelectObject(&fntArab);
dc.TextOut(30,90, (CString)"hahah");
CDialog::OnPaint();
}
}
M.A. Shah
Computer Science Student - Penn State University
|
|
|
|
|
I thought I might have to do something like that, but I was trying to avoid it . Thanks for your help.
If I write code in my sleep, does that make me brilliant, or just a lazy programmer?
My articles
www.stillwaterexpress.com
BlackDice - the programmer formerly known as bdiamond
|
|
|
|
|
Is there any algorithm who find a double character in a string as for example (two spacebars,two semicolons )and delete one of them?Please tell me where can I find this algorithm...Thank you
|
|
|
|
|
Have you looked at CString::Replace() ?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
hi,
I want to add Custom Explorer Bar to Internet Explorer using C++.Can any body tell me how am I going to do that?
Thanks in advance..
|
|
|
|
|
pubududilena wrote:
I want to add Custom Explorer Bar to Internet Explorer using C++.Can any body tell me how am I going to do that?
Please Look at MFC/C++-->InTernet Section, you will found tons of example implementing that
-----------------------------
"I Think It Will Help"
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
When i import both libraries in Pocket PC project i get some redefinition errors:
<br />
error C2011: '_Collection' : 'struct' type redefinition<br />
error C2011: 'DataTypeEnum' : 'enum' type redefinition<br />
error C2011: 'Properties' : 'struct' type redefinition<br />
error C2011: 'Property' : 'struct' type redefinition<br />
how can be used both of them and avoid conflicts?
were rgrtgrtvrtrt rtrtb brt tyuhjghj hbhbnh hnjm 1234567?
|
|
|
|
|
Why do you need to import both libraries?
Surely adoxce31.dll extends adoce31.dll and therefore you do not need to import adoce31.dll!?
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fruity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Walliams (Little Britain)
|
|
|
|