|
I have mvc++ 6.0. I have a SDI CDialog. I click on the date time picker icon and presto, I have a date time picker. I then go to class wizard and add the member variable m_datetime to IDC_DATETIMEPICKER and I change it from 'type' to 'control' so that I have declared in my header file
CDateTimeCtrl m_datetime;
When I compile the program, I get the error:
'CDateTimeCtrl' missing storage class or type specifiers
and it's referring to line that I have declared CDateTimeCtrl. I don't understand what I am doing wrong. It is my understanding the msvc++ 6.0 has the header file CDateTimeCtrl. So why do I need to enter it?
Please, any response any one can give me will be greatly appreciated.
Sincerely,
Danielle
|
|
|
|
|
You need to #include <afxdtctl.h>
|
|
|
|
|
This might be an OLE control, in which case you need to make sure you have the line
#include <afxctl.h>
in your stdafx.h file.
Otherwise, it might require the
#include <afxcmn.h>
line added to your stdafx.h file.
The build goes a lot faster if you do not include these header files if you are not using any of those controls in your project, so they are not in the stdafx.h by default.
|
|
|
|
|
I need to get a CWnd * to the window that has the focus (even if outside of my application), check to see if its a CEdit, and then do some Stuff. I have tried many thorough tests with CWnd's GetFocus(), GetForegroundWindow(), etc, and have not succeeded. It seems I can get a pointer to the CEdit's framework but not the CEdit itself. I am checking to see if its a CEdit by getting the class name and comparing to "EDIT".
Is there a better way to do this? Any help is appreciated.
|
|
|
|
|
Hello,
I've been trying to use CMap to create a hashing table of pointers to elements based on a class that specifies an unique coordinate.
Class CPonto (translates to CPoint) has 3 members: x,y,z of type UINT, and my CMap member should be able to give me a pointer to the object CMyObject if there is any at [x,y,z], or NULL if not.
Each unique coordinate refers to only one CMyObject, or NULL if it isn't ocupied.
I have declared my CMap member variable as follows:
[ccode]
#include <afxtempl.h>
CMap<cponto,cponto&,cmyobject*,cmyobject*> myWorld;
[/ccode]
However compilers generates:
[b]. D:\Program Files\DevStudio\VC\MFC\include\afxtempl.h(129) : error C2440: 'type cast' : cannot convert from 'class CPonto' to 'unsigned long'
. No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called[/b]
which jumps to a line containing
[ccode]
return ((UINT)(void*)(DWORD)key) >> 4;
[/ccode]
and it seems to my that my key has to be a sizeof() 4-bytes variable, which isn't explained by MSDN.
My main question is: Is it possible to have CPonto as KEY and ARG_KEY type? How?
Thinking of what error says: "No user-defined-conversion operator available that can perform this conversion"... Does it mean i can do that (programatically specify an automatic operator that converts CPonto to DWORD)? How?
Note: UINT types for CPonto members x,y,z could be of type BYTE, so it would fit in 3 of the 4 byte of DWORD, still, i don't know if CPonto's definition correctly aligns these members, but anyway, i bet it can be done, so i'm asking here. Also, i'm trying to use CMap to avoid certain limitations I have with other ways, mainly the resources needed only to reach a coordinate like (100,100,100) - memory - ie, there is no sense in using an UINT to store a XYZ coordinate like (500,500,500) if most of the times user can't reach it, right? I think that with CMap it would be possible.
If you can be of any help... Thanks in advance,
|
|
|
|
|
Hello, Nuno!
See: http://home.socal.rr.com/samhobbs/VC/Collections.html
That might help you. The importnat hting is that instead of:
CMap myWorld;
you probably need something like:
CMap <dword, dword,="" cmyobject,="" cmyobject&=""> myWorld;
Does that look like what you want?
I prefer to use typedefs, so I would do that this way:
typedef CMap <dword, dword,="" cmyobject,="" cmyobject&=""> CMyObjectMap;
CMyObjectMap m_MyObjectMap;
Yes, I think that you are correct that default hash keys are four bytes, because someone in the CodeGuru forum said that, but when I asked him where in the documentation it says that he said he did not want to answer my question because I had given him a negative rating for saying that he was not spamming CodeGuru with a message about the CodeProject web site.
|
|
|
|
|
Hey! I know I did the first reply correctly; it must have gotten messed up by this CodeProject thingee. I sure miss the CodeGuru's preview feature. I took advantage of it often.
I will do my post again and this time I will be sure to copy the password number for fixing this one.
Ok, I got the same result this time that I got the first time. The problem seems to be the brackets used as delimiters for STL. So in the code below use a less-than-symbol ("<") instead of "{" and use a greater-than-symbol (">") instead of "}". This CodeProject forum software seems to exclude text between the "angle" brackets.
So what I meant to say is that instead of:
CMap myWorld;
you probably need something like:
CMap {DWORD, DWORD, CMyObject, CMyObject&} myWorld;
Does that look like what you want?
I prefer to use typedefs, so I would do that this way:
typedef CMap {DWORD, DWORD, CMyObject, CMyObject&} CMyObjectMap;
CMyObjectMap myWorld;
|
|
|
|
|
Eheheh, i couldn't avoid laughing
It's weird indeed, since it's a programmers forum.
Anyway, i think you missed my point (probably as a consequence). My problem is that i need CMap capabilities but with a KEY larger than sizeof(DWORD).
I'm actually digging your suggestion and MSDN CTypedPtrMap. My first choice was that last, but once again, MSDN makes it sound something it seems it's not. I really couldn't think of any application that would need to get a pointer based on a string or something like that, but PERHAPS it would fit my case.
Is there any way to transform 3 UINT in a CString object so that memory is correctly aligned without using string-formatting and string-parsing routines? I'm trying to ask if is there a way to accomplish something like this:
char buffer[sizeof(UINT)*3];
memcpy(buffer,&m_uintarray,sizeof(UINT)*3);
?
Once again, Sam, thank you very much!
|
|
|
|
|
If you do not have to remove items from this list too frequently, then you could use an AVL tree or a binary tree or a ternary search tree.
These types of items do not have a limit on the key length.
You might find some examples of these tree types on CodeProject or on CodeGuru.
I recall seeing an AVL example on CodeGuru before.
|
|
|
|
|
Yes, I missed your point. I got confused by the part that says "UINT types for CPonto members x,y,z could be of type BYTE, so it would fit in 3 of the 4 byte of DWORD". So I am still a little confused, but I guess the important thing is that you want to be able to use CMap with a key that is more than 4 bytes in size.
I did some more searching and found MS KB article Q158541 ("PRB: C2440 Error When Using CMap and User Defined Key Type"). I think that is relevant.
See: http://support.microsoft.com/support/kb/articles/q158/5/41.asp for the online copy of the article.
|
|
|
|
|
Hi again Sam,
MS KB suggests exactly what i said i could do if i declared CPonto members as BYTE's, and that i already did.
After digging some more, i guess one possible solution would be using a CString as the key and use CMapStringToPtr, something like that:
CString key;
CPonto point(1,2,3);
key.Format("%d%d%d",CPonto.x,CPonto.y,CPonto.z);
// now call CMapStringToPtr.SetAt()
Anyway, thank you all who tried to help.
|
|
|
|
|
Hello,
I´d like to use a Toolbar in my MFC Program which is the same as the INternet Explorer/ VC++6.0 use. Where can I find Information? The normal Menus via the API (CreateManu etc.) are only flat, but I want this cool bevel effect.
Sebastian
|
|
|
|
|
Sebastian,
There is a demo project on this site and on codeguru. Your looking for 'hot tool bar'. I think the article was written by Kirk Stowell, if I remember correctly.
Email me if you can't find it.
Sincerely,
Erich J. Ruth
|
|
|
|
|
How do I print a dialog box?
|
|
|
|
|
Best thing to do is a screen grab.
void CMachine::PrintWindow()
{
// show options
CMyPrintDialog PrintDlg(
FALSE,
PD_ALLPAGES | PD_USEDEVMODECOPIES | PD_NOPAGENUMS | PD_NOSELECTION |
PD_DISABLEPRINTTOFILE,
this);
int Response = 0;
Response = PrintDlg.DoModal();
if (Response == IDOK)
{
// get printer dc
HDC hPrinterDC =(HDC) 0;
hPrinterDC = PrintDlg.m_pd.hDC;
ASSERT(hPrinterDC != NULL);
CDC PrinterDC;
BOOL IsAttached = FALSE;
IsAttached = PrinterDC.Attach(hPrinterDC);
ASSERT(IsAttached);
// Set landscape
LPDEVMODE pDevMode = PrintDlg.GetDevMode();
pDevMode->dmFields |= DM_ORIENTATION;
pDevMode->dmOrientation = DMORIENT_LANDSCAPE;
PrinterDC.ResetDC(pDevMode);
// attempt to set abort procedure
int SetAbortProcStatus = 0;
// SetAbortProcStatus = PrinterDC.SetAbortProc( &AbortProc );
// attempt to start print job
DOCINFO DocInfo;
DocInfo.cbSize = sizeof(DOCINFO);
DocInfo.lpszOutput = NULL;
DocInfo.lpszDocName = "PDMW Windows Screen Print";
int StartDocStatus = 0;
StartDocStatus = PrinterDC.StartDoc(&DocInfo);
// if abort procedure set and print job started
if (SetAbortProcStatus >= 0 && StartDocStatus >= 0)
{
// start page
VERIFY(PrinterDC.StartPage() > 0);
// get the screen dc
HDC hScreenDC =(HDC) 0;
hScreenDC = ::GetDC(NULL);// CDC
ASSERT(hScreenDC != NULL);
CDC ScreenDC;
VERIFY(ScreenDC.Attach(hScreenDC));
// create screen device dependent (dd) bitmap
CRect tmp;
GetWindowRect(tmp);
// ClientToScreen(tmp);
// tmp.top -= ::GetSystemMetrics(SM_CYCAPTION);
int ScreenWidth = tmp.Width();// - ::GetSystemMetrics(SM_CXEDGE) * 4;// 0;
// ScreenWidth = ScreenDC.GetDeviceCaps( HORZRES );
int ScreenHeight = tmp.Height();// + ::GetSystemMetrics(SM_CYCAPTION);// - ::GetSystemMetrics(SM_CYEDGE) * 4;
//- ::GetSystemMetrics(SM_CYCAPTION);// 0;
// ScreenHeight = ScreenDC.GetDeviceCaps( VERTRES );
CBitmap ScreenBitmap;
VERIFY(ScreenBitmap.CreateCompatibleBitmap(
&ScreenDC,
ScreenWidth,
ScreenHeight
));
// copy image to screen dd bitmap
CDC MemDC;
VERIFY(MemDC.CreateCompatibleDC(&ScreenDC));
CBitmap* pOldBitmap = NULL;
pOldBitmap = MemDC.SelectObject(&ScreenBitmap);
ASSERT(pOldBitmap != NULL);
VERIFY(MemDC.BitBlt(
0,
0,
ScreenWidth,
ScreenHeight,
&ScreenDC,
tmp.left,
tmp.top,
SRCCOPY
));
// create device independent (di) bitmap
const int BitCount = 24;
long ImageSize = 0;
ImageSize =((((ScreenWidth * BitCount) + 31) & ~31) >> 3)
* ScreenHeight;
BYTE* pBitmapBits = NULL;
pBitmapBits = new BYTE[ImageSize];
ASSERT(pBitmapBits != NULL);
// copy image from screen dd bitmap to di bitmap
BITMAPINFO BitmapInfo;
BitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
BitmapInfo.bmiHeader.biWidth = ScreenWidth;
BitmapInfo.bmiHeader.biHeight = ScreenHeight;
BitmapInfo.bmiHeader.biPlanes = 1;
BitmapInfo.bmiHeader.biBitCount = BitCount;
BitmapInfo.bmiHeader.biCompression = BI_RGB;
BitmapInfo.bmiHeader.biSizeImage = ImageSize;
BitmapInfo.bmiHeader.biXPelsPerMeter = 0;
BitmapInfo.bmiHeader.biYPelsPerMeter = 0;
BitmapInfo.bmiHeader.biClrUsed = 0;
BitmapInfo.bmiHeader.biClrImportant = 0;
memset(&BitmapInfo.bmiColors[0], 0, sizeof(RGBQUAD));
VERIFY(GetDIBits(
ScreenDC.m_hDC,
(HBITMAP) ScreenBitmap,
0,
ScreenHeight,
(LPVOID) pBitmapBits,
&BitmapInfo,
DIB_RGB_COLORS
));
VERIFY(ScreenBitmap.DeleteObject());
VERIFY(MemDC.DeleteDC());
ScreenDC.Detach();
// if bitmap selection succeeded
if (pOldBitmap != NULL)
{
// copy di bitmap to printer
int PrinterWidth = 0;
PrinterWidth = PrinterDC.GetDeviceCaps(HORZRES);
int PrinterHeight = 0;
PrinterHeight = PrinterDC.GetDeviceCaps(VERTRES);
if (PrintDlg.m_bCheckFullPage)
{
VERIFY(StretchDIBits(
PrinterDC.m_hDC,
0,
0,
PrinterWidth,
PrinterHeight,
0,
0,
ScreenWidth,
ScreenHeight,
(LPVOID) pBitmapBits,
&BitmapInfo,
DIB_RGB_COLORS,
SRCCOPY
) != GDI_ERROR);
}
else
{
CString strFactor;
int dFactor;
// PrintDlg.m_EditMagnifyCtrl.GetWindowText(strFactor);
strFactor = PrintDlg.GetFactorText();
if (strFactor.IsEmpty())
dFactor = 1;
else
{
dFactor = atoi(strFactor);
if (dFactor < 1)
dFactor = 1;
}
VERIFY(StretchDIBits(
PrinterDC.m_hDC,
(PrinterWidth - ScreenWidth * dFactor) / 2,
(PrinterHeight - ScreenHeight * dFactor) / 2,
ScreenWidth * dFactor,
ScreenHeight * dFactor,
0,
0,
ScreenWidth,
ScreenHeight,
(LPVOID) pBitmapBits,
&BitmapInfo,
DIB_RGB_COLORS,
SRCCOPY
) != GDI_ERROR);
}
// finish the print job
VERIFY(PrinterDC.EndPage() >= 0);
VERIFY(PrinterDC.EndDoc() >= 0);
}
// else could not select bitmap
else
{
// abort job
VERIFY(PrinterDC.AbortDoc() >= 0);
AfxMessageBox("Could Not Print--Memory Error Possible.");
}
// clean up
delete pBitmapBits;
}
// else job cannot be started
else
{
// attempt to abort job
PrinterDC.AbortDoc();
AfxMessageBox("Cannot Start Print Job.");
}
// clean up
PrinterDC.Detach();
VERIFY(DeleteDC(hPrinterDC));
}
}
BOOL CALLBACK CMachine::AbortProc(HDC hdc, int iCode)
{
MSG msg;
while (!bUserAbort && PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (!hDlgPrint || !::IsDialogMessage(hDlgPrint, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
if (iCode > 0)
bUserAbort = 1;
return !bUserAbort;
}
|
|
|
|
|
I have implemented an interface using ATL(in-proc server). In one of the interface methods, I display a modal dialog. The dialog is written in MFC. When this interface method and hence when the dialog class' DoModal() is called, there is a line of code in MFC libraries, that calls AfxGetInstanceHandle(). The function AfxGetInstanceHandle() ASSERTs if a variable by name afxCurrentInstanceHandle is not NULL. Unfortunately this variable is NULL. AfxGetInstanceHandle() is supposed to return the handle of the EXE. Am I doing things right?
|
|
|
|
|
At the beginning of the method, put this line:
AFX_MANAGE_STATE(AfxGetStaticModuleState());
to have MFC init its state information for your DLL. You need to do this in every exported function that can be called from outside the DLL.
|
|
|
|
|
I added this line as the first statement of the exported function (in my case an interface method). Unfortunately, I get a linker error that _DllMain@12 is already defined. DllMain is automatically generated for me when I added this ATL object to the project and is where I load the resource DLL for this component. But the linker includes mfcs42ud.lib as well where there is a second definition of DllMain. Moreover I guess that AFX_MANAGE_STATE is for REGULAR DLLs only. What do I do now?
|
|
|
|
|
|
How would I get an event for a key-stroke like ALT+SHIFT+CTRL+L even while the capture isn't on my program? Many programs (such as ICQ) do things like this.
|
|
|
|
|
Look up the RegisterHotKey() API.
|
|
|
|
|
I have a program which will generate Images of different objects on the screen.If you choose a menu item (RSC,Folder for example) you are promted to enter a few parametrs related to the object.(Length,Width,Depth and flute)
Since all of the objects need the same info I want to use one single dialog.However Each object manipulates the info in different ways..With a single dialog and hence a single
"Render" button how can I determine Which object the dialog was called for in my OnRender Function...Is what Im trying to do possible???It has to be this is C++ ).
Any suggestions or hints would be greatly appreciated...
Thanks for the time
J.Prisco
|
|
|
|
|
Make a base class for all the objects.
Put a member variable in it to represent the current ype.
Make an enumeration for all your types.
Derive all your 'object' classes from this base type.
Use the value of the 'type' data item to let your OnRender code know what was selected.
The diaog can also use that 'type' variable to know what controls to display to user, or else how to limit the data ranges where user might be entering numbers.
You could do the saem thing with C structures, always make the first element of the object structures this type.
Then if you have a pointer to some of this memory, you can cast the pointer to this 'type' variable and access the data structure's object type.
|
|
|
|
|
Although this sounds good Im still not to clear on how this is done..Thanks for the hint Ill investigate it further..
|
|
|
|
|
I assume that you have one menu item for each object that you want to display. I also assume that each kind of display object is being abstracted as a class and all these classes have a common base class. In the menu handler for each of these menu items, you would probably instantiate an object of the dialog class and call its DoModal(). You can pass a 'C++ object' of the appropriate object to be displayed to the dialog's constructor. In the dialog's OnRender() method, you can call the Render() method of these objects, provided the Render() method of the base class is virtual.
|
|
|
|
|