|
I am trying to create an ActiveX control (mediaplayer9.0 to be more specific) over document/view architecture. I have created the same application on VC++6.0. Its working fine.
But as soon as I port the same application from VC++6.0 to VC.Net and tries to run the application, it gives an error in call to GetParent() function as this function checks for ASSERT(::IsWindow(m_hWnd)). m_hWnd handle is assigned inside CreateControl() call, which is happening perfectly fine with VC++6.0.
I debugged the application in more detail for CreateControl() call in both VC++6.0 and VC.Net and found that in VC.Net:
1. COleControlSite::XOleIPSite::OnInPlaceActivateEx() function is getting called and assigning the (mediaplayer) control to be windowless.
In parallel to this VC++6.0 calls:
1. COleControlSite::XOleIPSite::OnInPlaceActivate(), which is doing nothing but returning "OK".
In addition to above inside CreateControl() VC.Net calls:
1. COleControlSite::AttachWindow(), which actually assigns the handle to “m_hWnd”. This is failing in VC.Net but working perfectly ok with VC++6.0 and that’s the reason why control is working fine with VC6.0 and not with VC.Net.
So my question is can anyone let me know why the behavior (which is leading to error) is changing in VC.Net.
FYI: .Net/VC7/atlmfc/src/mfc/occsite.cpp (This is the path for OnInPlaceActivateEx() and AttachWindow() functions).
Thanks,
Ajit
Amol Chavan
Persistent System Pvt. Ltd.
Member of Technical Staff
Bhageerath,402
Senapati Bapat Road,
Pune 411 016, India.
|
|
|
|
|
I wanna hook a certain window and coded as below but it didn't work!
please check my code.
In control dialog project..
BOOL (*install_hook)(HWND, HWND, DWORD);<br />
m_inst_hooker_dll = LoadLibrary("Hooker_dll.dll");<br />
if(m_inst_hooker_dll == NULL)<br />
{<br />
AfxMessageBox("Hooker_dll.dll was not found!");<br />
PostQuitMessage(0);<br />
return;<br />
}<br />
<br />
install_hook = (BOOL (*)(HWND, HWND, DWORD))GetProcAddress(m_inst_hooker_dll, "install_hook");<br />
<br />
DWORD process_di = 0;<br />
DWORD id = GetWindowThreadProcessId(edit, &process_di);<br />
<br />
if(!install_hook || !(*install_hook)(this->GetSafeHwnd(), edit, id))<br />
{<br />
AfxMessageBox("Fail to intall the Hooker,");<br />
PostQuitMessage(0);<br />
return;<br />
}<br />
'edit',found by FindWindow, the window handle of the external process which will be hooked, has a valide value. I verificated the value by sending a certail message.(It worked!)
In hook_dll project..
<br />
#include "stdafx.h"<br />
#pragma data_seg(".HKT")<br />
HINSTANCE g_module = NULL;<br />
HHOOK g_hook = NULL;<br />
HWND g_msg_destination = NULL;<br />
HWND g_hooked_window = NULL;<br />
#pragma data_seg()<br />
#pragma comment(linker, "/SECTION:.shared, RWS")<br />
<br />
BOOL APIENTRY DllMain( HANDLE hModule, <br />
DWORD ul_reason_for_call, <br />
LPVOID lpReserved<br />
)<br />
{<br />
switch (ul_reason_for_call)<br />
{<br />
case DLL_PROCESS_ATTACH:<br />
g_module = (HINSTANCE)hModule;<br />
break;<br />
<br />
case DLL_PROCESS_DETACH:<br />
UnhookWindowsHookEx(g_hook);<br />
break;<br />
}<br />
return TRUE;<br />
}<br />
<br />
LRESULT CALLBACK proc(int nCode, WPARAM w_param, LPARAM l_param)<br />
{<br />
if(nCode >= 0)<br />
{<br />
static char buf[256];<br />
int n;<br />
<br />
n = ::SendMessage(g_hooked_window, WM_GETTEXT, 256, (LPARAM)buf);<br />
buf[n] = 0;<br />
::SendMessage(g_msg_destination, WM_SETTEXT, 0, (LPARAM)buf);<br />
}<br />
<br />
return ::CallNextHookEx(g_hook, nCode, w_param, l_param);<br />
}<br />
<br />
extern "C" __declspec(dllexport)BOOL install_hook(HWND dest_window, HWND hooked_window, DWORD thread_id)<br />
{<br />
if(!hooked_window) return FALSE;<br />
g_msg_destination = dest_window;<br />
g_hooked_window = hooked_window;<br />
g_hook = ::SetWindowsHookEx(WH_GETMESSAGE, proc, (HINSTANCE)g_module, thread_id);<br />
return TRUE;<br />
}
It seems that my hook-procedure was not inserted to the hook chain. and If I set the thread_id = 0, as global hook, It works well.
Please answer me.
|
|
|
|
|
Code delete all child Values and keys of a particular key
DWORD dwReturn = SHDeleteKey(hKey,sKeyName);
if(dwReturn != ERROR_SUCCESS)
{
return FALSE;
}
else
{
HKEY hChildKey = NULL;
if(RegCreateKey(hKey,sKeyName,&hChildKey) == ERROR_SUCCESS)
{
return TRUE;
}
else
{
return FALSE;
}
}
|
|
|
|
|
Nope. SHDeleteKey will fail on NT where there are sub keys or values. See MSDN
this is how i do it
void
VPropertyRegistryPersister::DeleteRegKey(HKEY parentKey, LPCTSTR path)
{
DWORD index = 0;
DWORD nameBuffSize = MAX_PATH;
TCHAR nameBuff[MAX_PATH];
FILETIME lastWriteTime;
HKEY key = OpenKey(parentKey, path);
long result;
while((result = RegEnumKeyEx(key, index, nameBuff, &nameBuffSize,
NULL, NULL, NULL, &lastWriteTime)) != ERROR_NO_MORE_ITEMS)
{
RegistryException::VerifyAndThrow(result, "RegEnumKeyEx");
result = RegDeleteKey(key, nameBuff);
RegistryException::VerifyAndThrow(result, "RegDeleteKey");
index++;
nameBuffSize = MAX_PATH;
}
RegCloseKey(key);
RegDeleteKey(parentKey, path);
}
|
|
|
|
|
Josh Gray wrote:
Nope. SHDeleteKey will fail on NT where there are sub keys or values. See MSDN
funny it work perfectly on XP (haven't tried it on NT)
MSDN doesn't say anything about SHDeleteKey
all it says is
Deletes a subkey and all its descendants. The function will remove the key and all of the key's values from the registry.
Clickity[^]
|
|
|
|
|
wierd. In my installed version of MSDN at the very bottom it says
Windows 95: This function deletes a subkey and all its descendants.
Windows NT: The specified key must not contain any subkeys.
|
|
|
|
|
I actually had previously used it to do console applications on Visual C++ but never used MFC before. I had a problem; I was told to set a 10 by 10 area by using Matrix in MFC coding and use it to check whether the image has any little "black spots". If it does, I have to set these small little "black spots" of the image from "255" or anything else to zero. The codings must be in a function.
I did it but there were some problems with the codes. It does not work!!
Pls do kindly reply. I needed this asap. Thanks!
Below are the codes:
<br />
void CMediVisionView::MatrixImage()
{ <br />
int i, n, refer;<br />
<br />
if(no_of_rows==512 && no_of_cols==512){<br />
<br />
refer = 0;<br />
<br />
n = 0;<br />
for(i=0; i<512-5; i++)<br />
{<br />
if (image512[n]==0 && image512[n+1]==0 && image512[n+2]==0 && image512[n+3]==0 && image512[n+4]==0 && image512[n+5]==0 && image512[n+6]==0 && image512[n+7]==0 && image512[n+8]==0 && image512[n+9]==0){<br />
<br />
if(image512[n]==0 && image512[n+512]==0 && image512[n+(512*2)]==0 && image512[n+(512*3)]==0 && image512[n+(512*4)]==0 && image512[n+(512*5)]==0 && image512[n+(512*6)]==0 && image512[n+(512*7)]==0 && image512[n+(512*8)]==0 && image512[n+(512*9)]==0){<br />
<br />
if(image512[n+9]==0 && image512[n+512+9]==0 && image512[n+(512*2)+9]==0 && image512[n+(512*3)+9]==0 && image512[n+(512*5)+9]==0 && image512[n+(512*6)+9]==0 && image512[n+(512*7)+9]==0 && image512[n+(512*8)+9]==0 && image512[n+(512*9)+9]==0){<br />
<br />
if(image512[n+(512*9)]==0 && image512[n+(512*9)+1]==0 && image512[n+(512*9)+2]==0 && image512[n+(512*9)+3]==0 && image512[n+(512*9)+4]==0 && image512[n+(512*9)+5]==0 && image512[n+(512*9)+6]==0 && image512[n+(512*9)+7]==0 && image512[n+(512*9)+8]==0 && image512[n+(512*9)+9]==0){<br />
<br />
image512[(n+512)+1]=0;<br />
image512[(n+512)+2]=0;<br />
image512[(n+512)+3]=0;<br />
image512[(n+512)+4]=0;<br />
image512[(n+512)+5]=0;<br />
image512[(n+512)+6]=0;<br />
image512[(n+512)+7]=0;<br />
image512[(n+512)+8]=0;<br />
<br />
<br />
image512[n+(512*2)+1]=0;<br />
image512[n+(512*2)+2]=0;<br />
image512[n+(512*2)+3]=0;<br />
image512[n+(512*2)+4]=0;<br />
image512[n+(512*2)+5]=0;<br />
image512[n+(512*2)+6]=0;<br />
image512[n+(512*2)+7]=0;<br />
image512[n+(512*2)+8]=0;<br />
<br />
image512[n+(512*3)+1]=0;<br />
image512[n+(512*3)+2]=0;<br />
image512[n+(512*3)+3]=0;<br />
image512[n+(512*3)+4]=0;<br />
image512[n+(512*3)+5]=0;<br />
image512[n+(512*3)+6]=0;<br />
image512[n+(512*3)+7]=0;<br />
image512[n+(512*3)+8]=0;<br />
<br />
<br />
<br />
image512[n+(512*4)+1]=0;<br />
image512[n+(512*4)+2]=0;<br />
image512[n+(512*4)+3]=0;<br />
image512[n+(512*4)+4]=0;<br />
image512[n+(512*4)+5]=0;<br />
image512[n+(512*4)+6]=0;<br />
image512[n+(512*4)+7]=0;<br />
image512[n+(512*4)+8]=0;<br />
<br />
<br />
<br />
image512[n+(512*5)+1]=0;<br />
image512[n+(512*5)+2]=0;<br />
image512[n+(512*5)+3]=0;<br />
image512[n+(512*5)+4]=0;<br />
image512[n+(512*5)+5]=0;<br />
image512[n+(512*5)+6]=0; <br />
image512[n+(512*5)+7]=0;<br />
image512[n+(512*5)+8]=0;<br />
<br />
<br />
<br />
image512[n+(512*6)+1]=0;<br />
image512[n+(512*6)+2]=0;<br />
image512[n+(512*6)+3]=0;<br />
image512[n+(512*6)+4]=0;<br />
image512[n+(512*6)+5]=0;<br />
image512[n+(512*6)+6]=0;<br />
image512[n+(512*6)+7]=0;<br />
image512[n+(512*6)+8]=0;<br />
<br />
<br />
<br />
image512[n+(512*7)+1]=0;<br />
image512[n+(512*7)+2]=0;<br />
image512[n+(512*7)+3]=0;<br />
image512[n+(512*7)+4]=0;<br />
image512[n+(512*7)+5]=0;<br />
image512[n+(512*7)+6]=0;<br />
image512[n+(512*7)+7]=0;<br />
image512[n+(512*7)+8]=0;<br />
<br />
<br />
image512[n+(512*8)+1]=0;<br />
image512[n+(512*8)+2]=0;<br />
image512[n+(512*8)+3]=0;<br />
image512[n+(512*8)+4]=0;<br />
image512[n+(512*8)+5]=0;<br />
image512[n+(512*8)+6]=0;<br />
image512[n+(512*8)+7]=0;<br />
image512[n+(512*8)+8]=0;<br />
<br />
refer = 0;<br />
n++;<br />
refer++;<br />
}<br />
}<br />
}<br />
}<br />
}<br />
}<br />
<br />
}<br />
<br />
|
|
|
|
|
This is weird code, dude.
pohcb_sonic wrote:
n= (512-(Rectn_y+1))*512 + Rectn_x;
refer = 0;
n = 0;
Do you mean to set n twice ?
pohcb_sonic wrote:
n++;
refer++;
You can use the comma operator to make your loop look like this:
for(i=0; i<507; i++, n++, refer++)
pohcb_sonic wrote:
refer = 0;
n++;
refer++;
This means that refer will always equal 1, because you set it to 0, THEN increment it. Why ?
From what I can see, your loop sets all values to 0, but only if all values are already zero. Why ?
Is this a real image, or just a 2 dimensional array ?
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
gday all,
Can anyone help me out with the formatting withing a list box?? At the moment i am just using m_permList.AddString() to add items to the list box but even if i put a formatted string with \t etc between words it will only give one space between words?? Thanks
Steve
|
|
|
|
|
The list box must have been created with the LBS_USETABSTOPS style.
Try to use m_permList.SetTabStops(...).
Or see more on:
http://www.codeguru.com/Cpp/controls/controls/lists,treesandcombos/article.php/c2325/
|
|
|
|
|
I will create an ActiveX in our project, it is a telnet logon terminal, we want it just like a true terminal in webbrowser. it means some accelerator keys will be used, such as ctrl+e, ctrl+f. but these keys are captured by webbrowser whatever the focus in ActiveX or not, I want catch these keys, can it be realized? thanks.
|
|
|
|
|
I am a beginning programmer, so everything is still fairly fuzzy. Is there a means to pass a variable or variables to a fucntion called by a thread? Are the variables passed via the thread call or some more round about way????
David
|
|
|
|
|
ZeroGs wrote:
Is there a means to pass a variable or variables to a fucntion called by a thread?
There's always at least one thread per process, so a function is always called in the context of a thread. A function call is a function call, no matter where its called from.
A function has a signature, or prototype, that defines how it is to be called, the number and types of variables it expects, and the value, if any, it returns.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
what exactly do you mean Zero??
are you creating a thread and trying to pass function parameters to the function your using to create the thread??
or are you calling another function from inside the function used for the thread start??
Steve
|
|
|
|
|
Hi,
In our app here @ work I can call a function from inside the main thread or from another thread started by the main thread.
If you're inside your own thread there are no worries. If you want to call your function from another thread it crashes (or at least here it did ) You should pass the instance of your class to the thread and when you want to call your function from that thread post a message to your class saying you want to execute that function.
I'm not sure this is the way to go, but it works. The program doesn't crash anymore (jeej )
You can look things up at CP or MSDN or google.
The reason for this I THINK, is that the threads work on a different part of memory or something like that.
Good luck.
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix
|
|
|
|
|
I am studing C++ and the textbook says every class should have a public destructor. OK, I accept that, but the wizard generated code always has a private: destructor and the other examples in the text have a virtual private: destructor.
So what is the value of a public destructor? Is it just the freedom to 'delete' where and when as desired?
|
|
|
|
|
The textbook is wrong. The destructor is called by the class, not by the client, and so does not need to be public. You also don't need a destructor unless your class has objects it needs to clean up in there. An empty constructor and destructor are provided for you without you having to specify them.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Thank you. That make perfect sense.
|
|
|
|
|
Christian Graus wrote:
The destructor is called by the class, not by the client, and so does not need to be public.
No sir, I'm sorry, but you are wrong. In order to delete an object, the destructor must be visible in the scope in which it's being deleted. If it's a private destructor, then only code belonging polymorphically* to the class (including friend s) can delete the object. And the client does call the destructor, although implicitly by using ::operator delete , class::operator delete or simply letting the stack object go out of scope. You can call the destructor explicitly, which is a must, if you deal with exotic memory allocations such as in embedded systems where objects are supposed to be in fixed memory locations. Actually, it's not all that exotic. STL does it everywhere under the hood. I.e.: X* x = (X*)malloc(sizeof(X)); new (x) X; x->~x(); free(x); is equivalent to X* x = new X; delete x; (Just make sure you have included <memory> and is using std::new as the "compiler new" may not support the placement new syntax. G++ doesn't for some reason )
Moreover, you cannot instantiate an object on the stack, whose destructor is not visible in the current scope. This is one way to force the programmer to use the heap.
*If you have a public virtual destructor in a base class, and the subclass has hidden it, you can delete the object through the base class' interface. However, making a previously public destructor private doesn't make much sense IMO, so it's a moot point dragging the polymorphic case into the picture.
--
Arigato gozaimashita!
|
|
|
|
|
Dagnamit. I googled for that answer, and spent a fair amount of time reading, too. I'm not saying you are wrong, just that I've been cheated by the web, again.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Is there any way to tell if the user has clicked on the button or the item in a ctreectrl.
I want to limit expansion of the tree to only the button and use overwrite the single click of an item to do something else besides expand the tree.
I have been watching the on_notify but it doesn't seem to make a distinction.
Thanks
|
|
|
|
|
"Is there any way to tell if the user has clicked on the button or the item in a ctreectrl."
Yes, there is. Use HitTest() to determine which item was hit.
"I want to limit expansion of the tree to only the button and use overwrite the single click of an item to do something else besides expand the tree."
Couldn't get what you are saying. Can u explain it a little bit.
Imagine that you are creating a fabric of human destiny with the object of making men happy in the end, giving them peace and rest at last, but that it was essential and inevitable to torture to death only one tiny creature..and to found that edifice on its unavenged tears, would you consent to be the architect on those conditions? Tell me, and tell me the truth!
-Fyodor Dostoevsky, The Brothers Karamazov
|
|
|
|
|
I am writing a script that allows for nodes on tree to be transferred to another tree. They are side by side in a dialog box.
What I want is the tree to expand and collapse when the +/- button is pressed and when the node receives a single-click to simply highlight and when the node is double-cliked to then move the node to the other tree.
Right now the +/- button, single-click and double click all expand the tree plus carryout the above mentioned functionality. It is too confusing for end-users. Even I hate it.
So I am looking for a way to caught the above mention three clicks and then parse them as needed. Basically pass the +/- click on to expand/collapse the tree and do nothing with the single and double click.
Do you have any examples of code were I can caught the expand/collapse action. I have tried a TVN_ITEMEXPANDING on_notify and on_notify_reflect in both the parent dialog box and the cmytreeview class to no avail. It doesn't seem to catch the event. I have doubled checked to make sure that I have all of the includes and base classes.
Any help and examples would be appreciated
|
|
|
|
|
Cedar Sith wrote:
I want to limit expansion of the tree to only the button and use overwrite the single click of an item to do something else besides expand the tree.
For this you can handle the TVN_ITEMEXPANDING message.
[EDIT]Sorry, I didn't properly read your request. I guess the most first thing that comes to mind is to set an explicit mouse click flag (when you do your button HitTest()). This would probably let your program know whether the expansion was due to a mouse action, or a keyboard action.[/EDIT]
I Dream of Absolute Zero
|
|
|
|
|
I'm experienced with MFC/C++, but new to the VBA world, and I've been charged with writing a MFC app that can be controlled by (possibly user-written) VBA scripts, just as the bigtime MS apps are.
I've gotten the VBA SDK, and I followed the documentation to the point where I can make a MFC app that can call up the VBA IDE and a macro dialog using APC. But there, the documentation appears to end, there is apparently nothing that tells me how to hook up the functionality inside my app to run outside VB files.
That is, if I have a class in my C++ app: CMyDoc::Foo(int x), what do I need to do so that I can write a VB file that says something like:
for x = 1 to 5
mydoc.Foo(x)
next
and get it to run?
|
|
|
|
|