|
Hello,
Thanks for your answer but I have some additionnal questions for you :
1) compared to my code, what do you mean by "before you start printing" ? at which moment exactly should I do this ?
2) is the way I set my paper length and height ok?
3) I tried to insert your code in mine, just before my "HDC hPrinterDC = printDialog.CreatePrinterDC();" line and I get the following compil errors : OpenPrinter, DocumentProperties and ClosePrinter are considered as undeclared identifiers ... Do I need an special include or what ?
4) pDC is a pointer to the printer DC ? How do I get this ?
5) "// add in here any other changes to the DEVMODE you need"
something like :
lpDevMode->dmPaperSize = 0;
lpDevMode->dmPaperLength = 120;
lpDevMode->dmPaperWidth = 85;
and what about the dmFields ?
Thanks in advance for extra explanations
DD
|
|
|
|
|
My answer was intended to set you on the right track so that you could solve the problem for yourself and learn something aliong the way. I did not and do not intend to write the code for you.
However...
1) "before you start printing" means beofre you start outputting anything to the printer DC.
3) The code is intended to prepare the printer DC so include it AFTER you create the printer DC.
Work out the rest for yourself. Don't be afraid to press F1 occasionally and read the documentation. It takes a little longer the first time but you will have learned something instead of blindly using code you don't understand.
The opinions expressed in this communication do not necessarily represent those of the author (especially if you find them impolite, discourteous or inflammatory).
|
|
|
|
|
Hello,
<<my answer="" was="" intended="" to="" set="" you="" on="" the="" right="" track="" so="" that="" could="" solve="" problem="" for="" yourself="" and="" learn="" something="" aliong="" way.="">>
If I asked you for more details, it is simply because I don't see any link between your code and mine and, as it is, it does not help me at all. I don't see how I can use it. Evermore, I received compilation errors.
<>
It is not what I expected from you, I just need some explanations that I could understand and, if possible, linked to the code I wrote . This will probably help me to understand this function usage
<<1) "before you start printing" means before you start outputting anything to the printer DC.>>
Is this answer supposed to help me ... really ??
<<work out="" the="" rest="" for="" yourself.="">>
Work is what I am doing almost every nights until 2am when I write my (quite big) application after my normal work day. I can't offer me the luxury to loose 2 days in searching and trying without success.
<<don't be="" afraid="" to="" press="" f1="" occasionally="" and="" read="" the="" documentation.="">>
I spend 2 days to "play" with MSDN documentation and search thru codeproject and codeguru articles to find a basic article that explains how to use this DEVMODE easily in a context that matches my type of program. I also wrote a lot of code to try it. Ok. I can retrive the current DEVMODE, but when I change the content, how do I precise that I want to use it ?? ResetDC is a CDC method, I have no CDC, just a HDC, so ... And it is because I did not find the correct way to use it, that I finally post my question ...
<<it takes="" a="" little="" longer="" the="" first="" time="" but="" you="" will="" have="" learned="" something="" instead="" of="" blindly="" using="" code="" don't="" understand.="">>
I am trying to find a solution that suits my code, I am not copying your code without trying to understand it, it is not very funny.
Nevertheless, thanks for your time and your example I can't understand.
DD
|
|
|
|
|
I have set up an application hook procedure. This hook is looking for WM_INITMENUPOPUP, WM_MEASUREITEM and WM_DRAWITEM messages so that I can make all menus shown by the application ownerdrawn.
The hook does catch these as required, but its the actual processing of the message I am having trouble with.
For example. My WM_MEASUREITEM handler correctly measures the menu item and returns the correct size, yet when I get to the WM_DRAWITEM message to draw it, the size comes through as 12 * 16, which is the default size of a menu item which has not been measured (not processed WM_MEASUREITEM).
It looks like I cannot modiy the MEASUREITEM struct members in the hook procedure and have the application use these values.
I have tried both the WH_CALLWNDPROC and WH_CALLWNDPROCRET hook methods for before/after porcessing of the message, but regardless the system is not using the sizes I measure for the items.
Anyone know of this problem or how to get around it? The docs on hooks are pretty sparse.
I would also like to know whether is possible from within the hook procedure to stop the application processing the message as I have already done the work in the hook procedure.
If you vote me down, my score will only get lower
|
|
|
|
|
Are you assigning lpMeasureItemStruct->itemHeight the new height?
void CMyView::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct)
{
...
...
...
lpMeasureItemStruct->itemHeight = nNewHeight;
...
...
...
}
|
|
|
|
|
Yes I am. I TRACE out the values in the hook function after the OnMeasureItem() has been called. This is a variation of my owner drawn menu plug-in article so I know all the measureitem/draw item stuff works. I am just chaning it from a plug in to a hook so that it will work for all standard WIN32 programs.
If I get it working it will become another article.
Here is some of the code:
LRESULT CALLBACK CODMenu::HookFunction(int code, WPARAM wParam, LPARAM lParam)
{
CWPSTRUCT * cwpStruct = (CWPSTRUCT*)(lParam);
ASSERT(m_activeObject != NULL);
switch (cwpStruct->message)
{
case WM_MEASUREITEM:
{
LPMEASUREITEMSTRUCT lpMIS = (LPMEASUREITEMSTRUCT)(cwpStruct->lParam);
m_activeObject->OnMeasureItem(cwpStruct->wParam, lpMIS);
TRACE("Measure Item is %1d by %1d\n", lpMIS->itemWidth, lpMIS->itemHeight);
}
break;
case WM_DRAWITEM:
{
m_activeObject->OnDrawItem(cwpStruct->wParam, (LPDRAWITEMSTRUCT)(cwpStruct->lParam));
TRACE("WM_DRAWITEM\n");
}
break;
}
return ::CallNextHookEx(m_hookHandle, code, wParam, lParam);
}
LRESULT CALLBACK CODMenu::HookFunctionAfter(int code, WPARAM wParam, LPARAM lParam)
{
CWPRETSTRUCT * cwpretStruct = (CWPRETSTRUCT*)(lParam);
ASSERT(m_activeObject != NULL);
switch (cwpretStruct->message)
{
case WM_INITMENUPOPUP:
{
m_activeObject->OnInitMenuPopup(CMenu::FromHandle((HMENU)cwpretStruct->wParam), LOWORD(cwpretStruct->lParam), (BOOL)HIWORD(cwpretStruct->lParam));
TRACE("WM_INITMENUPOPUP\n");
}
break;
case WM_MEASUREITEM:
{
LPMEASUREITEMSTRUCT lpMIS = (LPMEASUREITEMSTRUCT)(cwpretStruct->lParam);
TRACE("After Measure Item is %1d by %1d\n", lpMIS->itemWidth, lpMIS->itemHeight);
}
break;
}
return ::CallNextHookEx(m_hookHandleAfter, code, wParam, lParam);
}
And the TRACE output is
WM_INITMENUPOPUP
Measure Item is 99 by 19
Warning: unknown WM_MEASUREITEM for menu item 0xE100.
After Measure Item is 0 by 16
Measure Item is 116 by 19
Warning: unknown WM_MEASUREITEM for menu item 0xE101.
After Measure Item is 0 by 16
Measure Item is 66 by 19
Warning: unknown WM_MEASUREITEM for menu item 0xE102.
After Measure Item is 0 by 16
Measure Item is 102 by 19
Warning: unknown WM_MEASUREITEM for menu item 0xE103.
After Measure Item is 0 by 16
Measure Item is 94 by 19
Warning: unknown WM_MEASUREITEM for menu item 0xE104.
After Measure Item is 0 by 16
Measure Item is 0 by 3
Warning: unknown WM_MEASUREITEM for menu item 0x0000.
After Measure Item is 0 by 16
Measure Item is 111 by 19
Warning: unknown WM_MEASUREITEM for menu item 0xE107.
After Measure Item is 0 by 16
Measure Item is 110 by 19
Warning: unknown WM_MEASUREITEM for menu item 0xE109.
After Measure Item is 0 by 16
Measure Item is 110 by 19
Warning: unknown WM_MEASUREITEM for menu item 0xE106.
After Measure Item is 0 by 16
Measure Item is 0 by 3
Warning: unknown WM_MEASUREITEM for menu item 0x0000.
After Measure Item is 0 by 16
Measure Item is 93 by 19
Warning: unknown WM_MEASUREITEM for menu item 0xE110.
After Measure Item is 0 by 16
Measure Item is 0 by 3
Warning: unknown WM_MEASUREITEM for menu item 0x0000.
After Measure Item is 0 by 16
Measure Item is 56 by 19
Warning: unknown WM_MEASUREITEM for menu item 0xE141.
After Measure Item is 0 by 16
Draw Item is 12 by 16
WM_DRAWITEM
Draw Item is 12 by 16
WM_DRAWITEM
Draw Item is 12 by 16
WM_DRAWITEM
Draw Item is 12 by 16
WM_DRAWITEM
Draw Item is 12 by 16
WM_DRAWITEM
Draw Item is 12 by 16
WM_DRAWITEM
Draw Item is 12 by 16
WM_DRAWITEM
Draw Item is 12 by 16
WM_DRAWITEM
Draw Item is 12 by 16
WM_DRAWITEM
Draw Item is 12 by 16
WM_DRAWITEM
Draw Item is 12 by 16
WM_DRAWITEM
Draw Item is 12 by 16
WM_DRAWITEM
Draw Item is 12 by 16
WM_DRAWITEM
If you vote me down, my score will only get lower
|
|
|
|
|
To stop further processing of the message, have your hook procedure return 1 (one) instead of calling CallNextHook
LRESULT CALLBACK MyHook(int nCode, WPARAM wp, LPARAM lp)
{
...
return 1;
}
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
Hi PJ,
I have tried what you suggested. It does stop any further hook procedures being called, but it does not stop the target window from processing the message which is what I really need to do in this case.
If I can do this, then it should clear up my main problem which is that the hook intercept WM_MEASUREITEM and returns the size of the menu item in the LPMEASUREITEMSTRUCT object. The thing is, the CWnd default handler gets a different LPMEASURITEM struct pointer to the hook procedure which means that in effect what I return in the hook is ignored.
If I can suppress the target window processing WM_MEASUREITEM then I think it would accept the values returned by the hook and fix my problem.
Cheers for any sugesstions
If you vote me down, my score will only get lower
|
|
|
|
|
According to MSDN, you can not modify the messages via the WH_CALLWNDPROC and WH_CALLWNDPROCRET hooks. I have used the method I suggested (return 1) in my CWindowScroller[^] class to supress user input, so I just assumed it should work for you also.
Have you tried using the WH_MSGFILTER hook instead? According to MSDN you can change things via this hook.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
I have tried WH_GETMESSAGE, but it doesn't get the WM_DRAWITEM and WM_MEASUREITEM messages.
I eneded up going with a combination hook/WndProc replacement technique which works correctly.
I should get an article up in the next few days about a new ownerdrawn menu method using 2 lines of code. An include and declaration of an object.
Thanks for the help.
If you vote me down, my score will only get lower
|
|
|
|
|
You solved your problem, so this post is probably useless, but I have to answer anyway.
From my understanding of MSDN, WH_GETMESSAGE monitors messages posted to the message queue and is called whenever the GetMessage or PeekMessage functions are called. What is probably happening is that the WM_DRAWITEM and WM_MEASUREITEM messages are never posted to the queue, but rather sent directly via the SendMessage function. The WH_MSGFILTER hook is supposed to work with menus, among others, but I do not know if it catches those two messages.
Looking forward to the article.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
I posted it last night, so should be found on the front page.
If you vote me down, my score will only get lower
|
|
|
|
|
Hello!
I'm playing around with Windows disk-quotas, using the IDiskQuotaControl interface. On lokal machine it works fine, but I also would like to get quotas of remote machines. Is there any way to initialize the IDiskQuotaControl-object for a remote path? For a lokal path I do it this way:
hr = pIDiskQuotaControl->Initialize("c:\\", true);
Any help with this would be great.
Thank you,
Markus
|
|
|
|
|
I would imagine you could use something like:
hr = pIDiskQuotaControl->Initialize("\\\\machine\\c$", true); I've not tried this but if it fails, you'll at least know of a way that does not work.
"Opinions are neither right nor wrong. I cannot change your opinion of me. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Very good idea, I tried it and it returns 123, this is ERROR_INVALID_NAME, but this brought me to
hr = pIDiskQuotaControl->Initialize("\\\\machine\\c:\\", true);
, which returns 5, ERROR_ACCESS_DENIED. Another tip I got was to run it as a domain admin, perhaps this it work then.
Thanks for your help!
|
|
|
|
|
hi all,
How do I add chart to my visual C++ Program?
can any body please help me....?
thanks in advance..
|
|
|
|
|
|
Just wanted to use the Clipboard within my application.
I did download Tom Archers example from the Code Project, but it failed to build with error:-
SimpleTextTransfer error LNK2019: unresolved external symbol ?0CRect@@QAE@XZ referenced in function "public: void __thiscall CDragListBox::DrawSingle(int)" (?DrawSingle@CDragListBox@@QAEXH@Z)
Also if I just want to Copy/Paste text from a listCtrl is it that complicated?
Any comments please.
|
|
|
|
|
I am currently writing an installer (using the Windows Installer Setup Project from VC .net) and need to install along with the package a couple of Command Line tools. I would like to update the windows PATH environment variable at install / uninstall time.
Does anyone know the "Correct" way of doing this, rather than just hacking about with the registry.
Thanks
Dave
|
|
|
|
|
Try this:
TCHAR tszBuf[MAX_PATH];
GetEnvironmentVariable("PATH", tszBuf, MAX_PATH);
Maybe not the best way, but at least better than reading it directly from the registry
Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
(doesn't work on NT)
|
|
|
|
|
Hi
I have a threaded app which can have many threads running (number not known until runtime). Each thread needs to use shared resource so I lock with WaitOnSingleObject and pass a handle to a mutex. The handle is a global variable assigned with CreateMutex so all threads have access to it and this method works fine.
Whilst one thread has access to the shared resource, other threads are sitting INFINITE at the WaitOnSingleObject. Do these threads get access on a first come first served basis or is there a possibility that a thread could constantly be shoved to the back of the queue by others threads pushing in?
Which leads me onto a second question - can you give a thread higher priority (easily) ?
Cheers
Angel1058
*********************************************
The sooner you fall behind, the longer you have to catch up.
|
|
|
|
|
The queue to get access to the mutex is on a first-in, first-out basis. So the first thread to wait on the mutex will get access to it when it is released, regardless of thread priority.
Mike
|
|
|
|
|
The scheduler makes no promises, except that it will be "fair to all threads" (which is enough for your case).
Also, there are substantial differences in the scheduler implementation between 9x and NT platforms.
we are here to help each other get through this thing, whatever it is Vonnegut jr. boost your code || Fold With Us! || sighist | doxygen
|
|
|
|
|
can't find sources for ShellIconChanger.zip FILE
|
|
|
|
|
|