Re: Another Hook question
Most likely you are not missing anything in your code.
You have to remember that hook dll is inserted into each running process address space; therefore OutputDebugString will not serve as good indicator of reaching parts of code.
Your string output goes to another procedd and since you are not debugging it you won’t see the output.
Run your program and then using another instance of VS, connect to the IE process. After connecting set your hook and try to invoke a print dialog. You will see your messages now.
On the other hand, preventing dialog from appearing and replacing by another will not do you any good. You may try to subclass dialog window and set printing parameters you need when dialog initializes. I will try to do that when the time permits.
Let us know how did it go.
Re: Another Hook question
Thank you very much because I am still trying my hand at this and not having any success. I will try the advice that you just gave me though.
Re: Another Hook question
I finally have it kind of working with a few minor problems that I'll probably ask about in the morning. For now (11:27 P.M.) It's time to go to bed.
I think that I didn't have my call to SetWindowsHookEx coded properly is what was causing the main part of the problem.
Thank you all for your help and your patience.
Pat
Re: Another Hook question
OK... I determined that most of my problem was getting caused by the way I was trying to debug. M break points and debug strings were not getting hit or triggered by anything outside of my test application.
I also at one time had the 3rd argument of SetWindowsHookEx set to the hinstance of the test application.
Now, there are some other things I need to address.
I am finally able to trap the WH_CREATEWND message and get the text from the new dialog. I am filtering for that and then calling my own modified Page Setup dialog box.
If I just leave it at that, this gets triggered at least 7 times and if I try to return 1 from my CBTProc, I get an error.
Is there a different way I should be doing this?
Re: Another Hook question
Quote:
Originally Posted by patrickmoe
OK... I determined that most of my problem was getting caused by the way I was trying to debug. M break points and debug strings were not getting hit or triggered by anything outside of my test application.
That is exactly what I have stated. You are trying to debug code injected into another process.
Quote:
Originally Posted by patrickmoe
I also at one time had the 3rd argument of SetWindowsHookEx set to the hinstance of the test application.
Not good.
Quote:
Originally Posted by patrickmoe
I am finally able to trap the WH_CREATEWND message and get the text from the new dialog.
.
.
.
Is there a different way I should be doing this?
Yes. IN a hook procedure while processing HCBT_CREATEWND code, window is not created yet.
You can either subclass dialog and check window text in WM_CREATE handler but it is easier to retrieve pointer to a CREATESTRUCT. For HCBT_CREATEWND code lParam is a pointer to the CBT_CREATEWND structure that in turn has a member of the CREATESTRUCT. lpszName member of create structure carries the name if the window. Use this for comparison.
Quote:
Originally Posted by patrickmoe
If I just leave it at that, this gets triggered at least 7 times and if I try to return 1 from my CBTProc, I get an error.
I am not sure why and withour seeing youe code I am not able to voice any comments.
Quote:
Originally Posted by patrickmoe
I am finally able to trap the WH_CREATEWND message and get the text from the new dialog. I am filtering for that and then calling my own modified Page Setup dialog box.
I am still not sure what you are trying to accomplish but most likely that will not work. Since you are failing original dialog’s creation, invoking application will receive an error.
If you want to replace certain values you would have to be able to modify original dialog’s PAGESETUPDLG members and that is not easy if not impossible.
Can you tell me what is it that you are trying to do?
Re: Another Hook question
My ultimate goal here is to catch the creation of the Page Setup dialog and prevent it from happening and display a modified Page Setup dialog with a couple of button on it either removed or disabled.
I'm doing that like this.
Code:
void ShowModifiedDialog()
{
PAGESETUPDLG psd;
DialogCreated = TRUE;
memset(&psd, 0, sizeof(psd));
psd.lStructSize=sizeof(psd);
psd.Flags=PSD_DISABLEPRINTER;
PageSetupDlg(&psd);
}
Here is the CBTProc from my DLL.
Code:
LRESULT CALLBACK CBTProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if(nCode<0)
return CallNextHookEx(g_hHook, nCode, wParam, lParam);
if(nCode==HCBT_CREATEWND)
{
HWND hwnd=(HWND)wParam;
CBT_CREATEWND *ccw=(CBT_CREATEWND *)lParam;
CHAR szClassName[255];
GetClassName(hwnd, szClassName, 255);
if(!lstrcmp(szClassName, "#32770") && !lstrcmp(ccw->lpcs->lpszName, "Page Setup"))
{
// Show custom dlg
ShowModifiedDialog();
return 0;
}
}
CallNextHookEx (g_hHook, nCode, wParam, lParam) ;
return 0;
}
Coded this way, my modified dialog DOES get displayed but..... After closing it, I wind up back inside the 'if(!lstrcmp(szClassName, "#32770") && !lstrcmp(ccw->lpcs->lpszName, "Page Setup"))' test 6 or 7 more times and getting an equal amount of custom dialogs displayed.
I'm not sure that I really need to be displaying my own dialog at all like I am in the ShowCustomDialog function. If there is a way to modify the properties of the original dialog that I trapped in the first place, I'd rather just do that.
Re: Another Hook question
So.... Is it possible to stop the original Page Setup dialog from getting created and open a freah one that has some flags set in the PAGESETUPDLG structure that gets sent to it?
Am I going about this the wrong way? Should I be modifying the dialog that was originally caled to open?
Shoud I subclass it? If so, how do you go about subclassing a dialog box that is getting created by a different application?