|
Seems theres no dummies steps out there for me..
Heres what I do:
1) On dialog view I click on the main form, in messages I goto WM_KEYDOWN, type in method name OnKeyDown and push enter.
2) In the OnKeyDown method I type in
AfxMessage("key pressed");<br />
SetWindowText("New Text");<br />
None of these changes occur when I press a key.
What basic thing am I missing?
And when overriding methods such as OnOk, do I just use the add function wizard and do it as a protected method in my code?
Thanks,
Brian
|
|
|
|
|
Hi
Actually the problem is when the dialog box is displayed it must have focus on any of the control. And when you press any key the WM_KEYDOWN goes to that control. If there are no control in your dialog box then your code will work.
Now what you can do to get that message is make the controls notify to the parent. But if there are lots of control you have to do it for each, and so its not a good idea.
Better you handle at PreTranslateMessage or WM_COMMAND to do your needs.
Regards
Anil
|
|
|
|
|
thanks, I used the PreTranslateMessage method you mentioned, and looked at the following site for how to basic steps to override http://support.microsoft.com/default.aspx?scid=kb%3BEN-US%3B817372[^]
then use
<br />
if (pMsg->message == WM_KEYDOWN){<br />
if(pMsg->wParam == VK_RETURN){<br />
return true;<br />
}<br />
}<br />
inside the new method.
thanks,
Brian
|
|
|
|
|
Hallo to all,
is there anyone who works with Dialogs and modless windows in DLL over MFC? How can I handle the right resources? What kind of DLL is to use? If it is possible, I want to use a Win32-Project with MFC as Console-App. Is it possible?
Thank you
Meinhard
|
|
|
|
|
Hi
What I got from your question is that you want to develop a DLL which supports Dialog box and it can be used in console and other application.
If it is so then it is possible. Use class wizard (MFC AppWizard (dll) ) to create your DLL. you can create dialog bos and all you want like MFC applicatin, and also you can use this DLL in console application.
Regards
Anil
|
|
|
|
|
Hi Anil,
I tried to do so, but if I want to acces it from the app like
CDialogXX m_dialogXX;
m_diologXX.create(ID_SOURCE, NULL); // ID_Source is a resource of the DLL
// but #defined in both identical.
the AFX_FindResource()-Function will abort.
TRhats my problem.
Thank you for helping
Regards
Meinhard
|
|
|
|
|
I am hosting the WebBrowser control in an application I wrote for a Windows CE .Net device. The control works properly and I am capturing events from the DWebBrowserEvents2 interface. So far, so good. I receive the DocumentComplete and NavigateComplete2 events whenever a navigation is performed. However if an error occurs (for example: Page not found, Incorrect Syntax, etc) the NavigateError event never seems to fire. Has anyone else had this issue when implementing the webbrowser control on CE?
Any help would REALLY be appreciated, as this is somewhat of a show stopper for now. If I need to elaborate or give some example code please let me know.
Thanks,
Dan
|
|
|
|
|
Hi
i display in an edit control Lat/long information. Unfortunately the degrees sign is not displayed in certain language locales. The problem is, as i can know , that the font used by those systems does not contain the degrees sign. A solution is to remove it, is there anything else i can do?
Thanks in advance for any help
George
George
|
|
|
|
|
Show it as an image?
Distribute and use a unicode font that does have it?
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Hi,
I wrote a DLL which works fine if I just include the header file and the lib file in the code that uses this DLL.
However, when I try to call functions from the DLL the program crash and complain about calling conventions that do not match.
Here is the bare minimum:
******* DLL Code ****
Header:
<br />
typedef void (__stdcall *PF_SPCMCOMM_CALLBACK)(char *,pack_data *);<br />
SPCMCOMM_API int InitilizeConnection(char *appname,PF_SPCMCOMM_CALLBACK pfn);<br />
CPP file:
<br />
SPCMCOMM_API int InitilizeConnection(char *appname,PF_SPCMCOMM_CALLBACK p_cbfn)<br />
{<br />
.....<br />
}<br />
*** Client Code ***
Header file:
static void __cdecl SpcmCallBack (char *payload,pack_data *pd);
CPP file:
<br />
HISNT spcm_hInst =LoadLibrary (__TEXT("SpcmComm.dll"));
<br />
if (spcm_hInst)<br />
{<br />
PF_SPCMCOMMINIT initspcm;
initspcm = (PF_SPCMCOMMINIT) GetProcAddress spcm_hInst, "InitilizeConnection");<br />
if (initspcm)<br />
{<br />
int result=initspcm ("TestAlertUUT",(PF_SPCMCOMM_CALLBACK)SpcmCallBack);<br />
}<br />
|
|
|
|
|
does the library implementation have something like this in it ?
extern "C"
{
}
This needs to be around the prototype of InitilizeConnection in the header file and around its implementation in the .CPP file.
|
|
|
|
|
Thanks, I will try that and let you know.
In any case, what is the logic behind it and why does it work when I use the dll implicitly.
|
|
|
|
|
//int result=initspcm ("TestAlertUUT",(PF_SPCMCOMM_CALLBACK)SpcmCallBack);
aha! this is a callback function so the calling convention of both function has to be same
but ",(PF_SPCMCOMM_CALLBACK)SpcmCallBack is _cedel
where as initspcm is _stdcall.
never say die
|
|
|
|
|
Shay Harel wrote: typedef void (__stdcall *PF_SPCMCOMM_CALLBACK)(char *,pack_data *);
Shay Harel wrote: static void __cdecl SpcmCallBack (char *payload,pack_data *pd);
These two must have the same calling convention - __stdcall and __cdecl are not compatible.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
VC6, MFC
I'm trying to print the contents of a CScrollView. The text displays correctly (font and size) in the view, but when I try to print, it's REEEEAL small.
I'm not using the view's built-in procedures (OnBeginPrinting, etc). Instead, I'm displaying the CPrintDlg, retrieving the DC of the selected printer, and managing the printing myself.
Can anyone tell me why the printed text is super-small?
------- sig starts
"I've heard some drivers saying, 'We're going too fast here...'. If you're not here to race, go the hell home - don't come here and grumble about going too fast. Why don't you tie a kerosene rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
-- modified at 15:11 Thursday 9th February, 2006
|
|
|
|
|
See if this helps.
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
|
|
|
|
|
Nope.
here's my code:
LRESULT CPatientInfoView::OnCBPrint(WPARAM wParam, LPARAM lParam)
{
CPrintDialog dlg(FALSE);
if (dlg.DoModal() != IDOK)
{
return 1L;
}
HDC hDC = dlg.GetPrinterDC();
if (hDC == NULL)
{
return 1L;
}
CDC printerDC;
printerDC.Attach(hDC);
DOCINFO docinfo;
memset(&docinfo, 0, sizeof(docinfo));
docinfo.cbSize = sizeof(docinfo);
docinfo.lpszDocName = _T("TRIAD Patient Info Report");
if (printerDC.StartDoc(&docinfo) < 0)
{
AfxMessageBox(_T("Printer wouldn't initalize"));
}
else
{
CalcPrintedPageHeight(&printerDC);
int nLinesPrinted = 0;
do
{
nLinesPrinted = PrintPage(&printerDC, nLinesPrinted);
} while (nLinesPrinted > 0);
printerDC.EndDoc();
}
return 1L;
}
BOOL CPatientInfoView::BuildReportFont(CFont* pFont)
{
int nFontSize = -12;
CString sFontName = _T("Courier");
return pFont->CreateFont(nFontSize, 0,0,0, FW_NORMAL, 0,0,0, DEFAULT_CHARSET,
OUT_CHARACTER_PRECIS, CLIP_CHARACTER_PRECIS, DEFAULT_QUALITY,
DEFAULT_PITCH | FF_DONTCARE, sFontName);
}
int CPatientInfoView::PrintPage(CDC* pDC, int nStartLine)
{
if (pDC->StartPage() < 0)
{
MessageBox(_T("Could not start page"));
return pDC->AbortDoc();
}
int nCount = m_saLines.GetSize();
if (nCount <= 0)
{
return -10;
}
if (nStartLine >= nCount)
{
return -11;
}
TRACE("DrawOnDevice()\n");
m_nDocHeight = 0;
CRect screenRect;
CFont* pOldFont = NULL;
CFont docFont;
BuildReportFont(&docFont);
pDC->SelectObject(&docFont);
CString sText = "";
CString sTemp = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
int nLineHeight = pDC->GetTextExtent(sTemp).cy + 2;
int nTabWidth = 25;
int nYPos = 5;
int nXPos = 5;
pDC->SetBkColor(RGB(255,255,255));
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(RGB(0,0,0));
int i = 0;
for (i = nStartLine; i < nCount; i++)
{
nYPos += (DrawLine(pDC, nXPos, nYPos, m_saLines.GetAt(i)) * nLineHeight);
if (nYPos > m_nPageHeight - nLineHeight)
{
break;
}
}
pDC->SelectObject(pOldFont);
pDC->EndPage();
if (i >= nCount -1)
{
return -12;
}
return i;
}
void CPatientInfoView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
TRACE("OnPrepareDC()\n");
if (!pDC->IsPrinting())
{
SetScrollSizes(MM_TEXT, CSize(1000, m_nDocHeight));
CScrollView::OnPrepareDC(pDC, pInfo);
}
else
{
CScrollView::OnPrepareDC(pDC, pInfo);
}
}
void CPatientInfoView::CalcPrintedPageHeight(CDC* pDC)
{
CDC *pCurrentDC = GetDC();
if (!pCurrentDC)
{
return;
}
pDC->SetMapMode(MM_TEXT);
CSize szPaperPPI (pDC->GetDeviceCaps(LOGPIXELSX), pDC->GetDeviceCaps(LOGPIXELSY));
CSize szScreenPPI(pCurrentDC->GetDeviceCaps(LOGPIXELSX), pCurrentDC->GetDeviceCaps(LOGPIXELSY));
int nLeftMargin = 0;
int nRightMargin = 0;
int nHeaderHeight = 0;
int nFooterHeight = 0;
int nGap = 0;
CFont prnFont;
BuildReportFont(&prnFont);
CFont *pOldFont = pDC->SelectObject(&prnFont);
CSize charSize = pDC->GetTextExtent(_T("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSATUVWXYZ"),52);
charSize.cx /= 52;
int nMargins = (nLeftMargin + nRightMargin) * charSize.cx;
CSize szPaperSize = CSize(pDC->GetDeviceCaps(HORZRES), pDC->GetDeviceCaps(VERTRES));
CSize szLogicalPageSize = CSize(szScreenPPI.cx * szPaperSize.cx / szPaperPPI.cx * 3 / 4,
szScreenPPI.cy * szPaperSize.cy / szPaperPPI.cy * 3 / 4);
m_nPageHeight = szLogicalPageSize.cy -
(nHeaderHeight + nFooterHeight + 2 * nGap) *
charSize.cy;
m_nPageWidth = szLogicalPageSize.cx -
(nLeftMargin + nRightMargin + 2 * nGap);
pDC->SetWindowExt (szLogicalPageSize);
pDC->SetViewportExt(szPaperSize);
pDC->SetWindowOrg (nLeftMargin * charSize.cx, 0);
pDC->SelectObject(pOldFont);
}
------- sig starts
"I've heard some drivers saying, 'We're going too fast here...'. If you're not here to race, go the hell home - don't come here and grumble about going too fast. Why don't you tie a kerosene rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
John Simmons / outlaw programmer wrote: int nFontSize = -12;
This is gonna make a font that's 12 pixels high on the screen, but twelve ridiculously little dots high on any modern printer.
So, the solution is to down-grade your printer. I'll sell you my old Epson 9-pin, if you can find a ribbon for it...
|
|
|
|
|
That means your DC's mapping mode isn't set correctly. If you try to use the mapping mode you use for the screen, the output comes out smaller because the printer's DPI is a lot higher than the screen's.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
|
|
|
|
|
I just don't get it...
I changed the font creation code and it's printing the right siZe text, but now, it's not printing on the whole page.
------- sig starts
"I've heard some drivers saying, 'We're going too fast here...'. If you're not here to race, go the hell home - don't come here and grumble about going too fast. Why don't you tie a kerosene rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
As a final act of desperation, I looked on CodeGuru and found a class that works almost perfectly, I had to fix a last-page footer placement problem and add code for breaking long lines on word or character boundaries, but other than that, it was fairly straightforward (despite the fact that the guy used foreign words for some of the variables).
------- sig starts
"I've heard some drivers saying, 'We're going too fast here...'. If you're not here to race, go the hell home - don't come here and grumble about going too fast. Why don't you tie a kerosene rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Petzold introduced a technique for achieving true WYSIWYG printing way back in the late '80s. I used it in about 1993 with good results. Unfortunantly, I no longer have that code, or the book. The technique was called 'logical twips' and involved a formuila for adjusting the mapping mode to work for both the screen and the printer device context.
The "Logical Twips" Mapping Mode [^]
When I discussed mapping modes in Chapter 11, you might have thought the
MM_TWIPS mapping mode would be used by programs that make heavy use of
formatted text. In this mapping mode, logical units are in terms of 1/20
point. However, you probably won't want to use MM_TWIPS for the video
display, because the mapping mode is based on real inches rather than
logical inches. As a result, your program won't be able to equate the
correct point sizes (8, 10, 12, 14, 18, and 24) of the available screen
fonts to their heights in MM_TWIPS units.
You'll be better off if you define your mapping mode based on the
logical-pixels-per-inch dimensions available from GetDeviceCaps. I call this
the "Logical Twips" mapping mode; here's all you need to set it:
SetMapMode (hdc, MM_ANISOTROPIC) ;
SetWindowExt (hdc, 1440, 1440) ;
SetViewportExt (hdc, GetDeviceCaps (hdc, LOGPIXELSX),
GetDeviceCaps (hdc, LOGPIXELSY)) ;
Because the pixels-per-logical-inch values are always divisors of 1440, the
scaling factor for this mapping mode is an integer. With this mapping mode
set, if you want to request a font with 12-point line spacing (as we'll do
shortly), you can specify the height of the font as 240 (12 times 20)
logical units.
If you select a font into your device context and call GetTextMetrics to
obtain the dimensions of the font, you can calculate the type size in points
by using the formula:
(tm.tmHeight - tm.tmInternalLeading) / 20
The line spacing in points is equal to:
tm.tmHeight / 20
For some smaller fonts on low-resolution devices, the size and spacing of
the type might actually involve a fraction of a point--for example, 8-point
type with 8.5-point line spacing. To round to the nearest integer point
size, you might instead want to use the formulas:
(tm.tmHeight - tm.tmInternalLeading + 10) / 20
and:
(tm.tmHeight + 10) / 20
We'll use the "Logical Twips" mapping mode in the JUSTIFY program toward the
end of this chapter.
Once again, remember that the discrepancy between logical inches and real
inches occurs only for the display. If you use the "Logical Twips" mapping
mode with a printer, you'll simply duplicate the MM_TWIPS mapping mode.
"You get that which you tolerate"
-- modified at 19:55 Thursday 9th February, 2006
|
|
|
|
|
I have a modeless dialog with some controls. How to disable this dialog with all controls?
Best regards,
Eugene Pustovoyt
ICQ UIN: 161325180
|
|
|
|
|
Do something like this:
BOOL b = EnumChildWindows( hWndDlg, EnumFunc, NULL );
BOOL CALLBACK EnumFunc( HWND hwnd, LPARAM lParam )
{
EnableWindow( hwnd, FALSE );
}
Andy
Human beings were not meant to sit in little cubicles staring at computer screens all day, filling out useless forms and listening to eight different bosses drone on about about mission statements. -- Peter Gibbons
|
|
|
|
|
Are you wanting to disable all of the controls on the dialog, or the dialog itself?
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
|
|
|
|
|