|
I used Paul DiLascia's class for this:
http://www.microsoft.com/msj/1099/c/c1099.aspx
"Opinions are neither right nor wrong. I cannot change your opinion of me. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
The CRT sets up the __argc and __argv variables for you, which have the same contents as argc /argv in a console mode app.
--
I'm Michael Dunn and I approve this post.
Vote Trogdor in oh-four!
|
|
|
|
|
My process use COMCTL32.dll and COMCTL32.DLL use USER32.DLL, I want to hook APIs in USER32.DLL, how can I do this?? Demo source code is welcome.
|
|
|
|
|
Hi All
i have a modeless dialog which i use as a wait screen.
this appears ontop of a dialog that is called
for example you click "Ok" the wait dialog appears
then once the function is completed the modless(wait) dialog disappear,
my problem is, if the user clicks away from the modless dialog, although
its still there focus can go somewhere else
how can i set the focus, on the modless dialog so that i cant click elsewhere
and that the modless dialog stays in focus until it disapears
ta
si
|
|
|
|
|
I think you want a modal dialog. Try looking into CWnd::DoModal()
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
|
|
|
|
|
There are several possible solutions. One solution is to handle the different window focus messages and process them according.
Kuphryn
|
|
|
|
|
Hi All
i have a modeless dialog which i use as a wait screen.
this appears ontop of a dialog that is called
for example you click "Ok" the wait dialog appears
then once the function is completed the modless(wait) dialog disappear,
my problem is, if the user clicks away from the modless dialog, although
its still there focus can go somewhere else
how can i set the focus, on the modless dialog so that i cant click elsewhere
and that the modless dialog stays in focus until it disapears
ta
si
|
|
|
|
|
I have an edit control that is placed inside a custom popup window that I wrote. The popup appears, and then transfers fopcus to the edit control. When the user hits an Esc or Tab key something makes the computers internal speaker "beep", I presume through a call to Beep(). Is there any way to prevent this, as it's really annoying.
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
|
|
|
|
|
ESC and TAB are handled by the default Dialog Procedure, and the beeping usually indicates something is wrong with the styles set for the popup window (don't ask me what's valid and what not, though...)
we are here to help each other get through this thing, whatever it is Vonnegut jr. boost your code || Fold With Us! || sighist | doxygen
|
|
|
|
|
Hello guys,
I used to print the content of a RichEditText control with following code.
But now I would like to print it in landscape and with paper specifications (12cm x8.5cm).
All articles I read are talking about the famous DEVMODE, but I have no clue how to insert this DEVMODE in my existing code.
Can you hep me ?
Thanks in advance
DD
void CTestRichEditText::OnPrint()
{
// lance l'interface pour l'imprimante
CPrintDialog printDialog(false);
bool bShowPrintDialog = TRUE; //FALSE lance directement l'impression
if (bShowPrintDialog)
{
int r = printDialog.DoModal();
if (r == IDCANCEL)
return;
}
else
{
printDialog.GetDefaults();
}
// recently added to try to print in landscape on special paper
DEVMODE *MyPrintMode;
MyPrintMode = printDialog.GetDevMode();
MyPrintMode->dmFields |= DM_ORIENTATION | DM_PAPERSIZE | DM_PAPERLENGTH | DM_PAPERWIDTH;
MyPrintMode->dmOrientation = DMORIENT_LANDSCAPE;
MyPrintMode->dmPaperSize = 0;
MyPrintMode->dmPaperLength = 120;
MyPrintMode->dmPaperWidth = 85;
// end of new added code
HDC hPrinterDC = printDialog.GetPrinterDC();
FORMATRANGE fr;
int nHorizRes = GetDeviceCaps(hPrinterDC, PHYSICALWIDTH),
nVertRes = GetDeviceCaps(hPrinterDC, PHYSICALHEIGHT),
nLogPixelsX = GetDeviceCaps(hPrinterDC, LOGPIXELSX),
nLogPixelsY = GetDeviceCaps(hPrinterDC, LOGPIXELSY);
LONG lTextLength; // Longueur total du document
LONG lTextPrinted; // Longueur du document edite
// Ensure the printer DC is in MM_TEXT mode.
SetMapMode ( hPrinterDC, MM_TEXT );
// Rendering to the same DC we are measuring.
ZeroMemory(&fr, sizeof(fr));
fr.hdc = fr.hdcTarget = hPrinterDC;
// Set up the page.
fr.rcPage.left = fr.rcPage.top = 0;
fr.rcPage.right = (nHorizRes/nLogPixelsX) * 1440;
fr.rcPage.bottom = (nVertRes/nLogPixelsY) * 1440;
// Set up 1" margins all around.
fr.rc.left = fr.rcPage.left + 570; // 1440; // 1440 TWIPS = 1 inch.
fr.rc.top = fr.rcPage.top + 570; 1440;
fr.rc.right = fr.rcPage.right - 570; // 1440
fr.rc.bottom = fr.rcPage.bottom - 570; // 1440
// Default the range of text to print as the entire document.
fr.chrg.cpMin = 0;
fr.chrg.cpMax = -1;
// Set up the print job (standard printing stuff here).
DOCINFO di;
ZeroMemory(&di, sizeof(di));
di.cbSize = sizeof(DOCINFO);
di.lpszDocName = "(Untitled)";
// Do not print to file.
di.lpszOutput = NULL;
// Start the document.
StartDoc(hPrinterDC, &di);
// Find out real size of document in characters.
lTextLength = m_RichTextCtrl.SendMessage ( /*hRTFWnd,*/ WM_GETTEXTLENGTH, 0, 0 );
// do {
// Start the page.
StartPage(hPrinterDC);
// Print as much text as can fit on a page. The return value is
// the index of the first character on the next page. Using TRUE
// for the wParam parameter causes the text to be printed.
#ifdef USE_BANDING
lTextPrinted = m_RichTextCtrl.SendMessage(/*hRTFWnd,*/
EM_FORMATRANGE,
FALSE,
(LPARAM)&fr);
SendMessage(hRTFWnd, EM_DISPLAYBAND, 0, (LPARAM)&fr.rc);
#else
lTextPrinted = m_RichTextCtrl.SendMessage(/*hRTFWnd,*/
EM_FORMATRANGE,
TRUE,
(LPARAM)&fr);
#endif
// Print last page.
EndPage(hPrinterDC);
// If there is more text to print, adjust the range of characters
// to start printing at the first character of the next page.
if (lTextPrinted < lTextLength) {
fr.chrg.cpMin = lTextPrinted;
fr.chrg.cpMax = -1;
}
// Tell the control to release cached information.
SendMessage(/*hRTFWnd,*/ EM_FORMATRANGE, 0, (LPARAM)NULL);
EndDoc (hPrinterDC);
DeleteDC(hPrinterDC);
// recently added to try to print in landscape on special paper
GlobalUnlock(MyPrintMode);
// end of new added code
}
|
|
|
|
|
Something like this should get you away ...
Do this to prepare the printer DC before you start printing. (pDC is a pointer to the printer DC).
CString csPrinterName = printDialog->GetDeviceName();
_TCHAR *szPrinterName = csPrinterName.GetBuffer(0);
DWORD dwRet;
HANDLE hPrinter;
if (!OpenPrinter(szPrinterName, &hPrinter, NULL))
return;
LPDEVMODE lpDevMode;
dwRet = DocumentProperties(m_hWnd, hPrinter, szPrinterName, NULL, NULL, 0);
lpDevMode = (LPDEVMODE)malloc(dwRet);
dwRet = DocumentProperties(m_hWnd, hPrinter, szPrinterName, lpDevMode, NULL, DM_OUT_BUFFER);
if (dwRet != IDOK)
{
free(lpDevMode);
ClosePrinter(hPrinter);
return;
}
if ((lpDevMode->dmFields & DM_ORIENTATION))
lpDevMode->dmOrientation = DMORIENT_LANDSCAPE;
dwRet = DocumentProperties(m_hWnd, hPrinter, szPrinterName, lpDevMode, lpDevMode, DM_IN_BUFFER|DM_OUT_BUFFER);
ClosePrinter(hPrinter);
if (dwRet != IDOK)
{
free(lpDevMode);
return;
}
pDC->ResetDC(lpDevMode);
free(lpDevMode);
The opinions expressed in this communication do not necessarily represent those of the author (especially if you find them impolite, discourteous or inflammatory).
|
|
|
|
|
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
|
|
|
|
|