|
I am having a problem using print and printpreview in a FormView.
If I build using MFC as a shared dll, all works as it should.
If I build using MFC as a static library, I get an error when the print function tries to create the dialog to show print status. Apparently when
Create(CPrintingDialog::IDD, pParent);
gets called in the CPrintingDialog contructor,
if (!_AfxCheckDialogTemplate(lpszTemplateName, FALSE))<br />
{<br />
ASSERT(FALSE);
PostNcDestroy();
return FALSE;<br />
}
in CDialog::Create fails because there isn't a valid document template name. Is this the document template name of my form view or one created by MFC for the print dialog? How do I make sure it gets set? I need to compile using MFC as a static library due to installation on other Windows versions.
Ed
|
|
|
|
|
I want to set the transparency (SetLayeredWindowAttributes(...))of my dialog. One option is to LoadLibrary, i did, and it was successful.
But I want to do this the primitive way: Project>Setting>Link>Object/Library module
"C:\Program Files\Microsoft Visual Studio\VC98\Lib\User32.lib"
"C:/Program Files/Microsoft Visual Studio/VC98/Lib/User32.lib"
"User32.lib"
User32.lib (without quotation)
none worked. I didnt get any compiler error but the compiler does not recognise SetLayeredWindowAttributes(...) for one reason or another...
Help! feel like an idiot.
norm
|
|
|
|
|
If you want to use the lib file then you need the latest header files, you must download the lastest Platform SDK from http://MSDN.microsoft.com
Btw actually it's enough to include User32.lib (without quotation) to your project settings, although it should be included by default
modified 12-Sep-18 21:01pm.
|
|
|
|
|
i think u're right... i searched winuser.h and it's not even there.
and MSDN didnt mention that u need the latest version for this sh*t..
thanks anyway. got my hands on Platform SDK Build2601 August 2001 Edition.
norm
|
|
|
|
|
(Not 100% sure) Try definining the macros _WIN32_WINNT and WINVER as 0x0500 before any inclusion (or preferrably on the preprocessor editbox in the project settings).
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
thanks!
but, is this what u mean?
#define _WIN32_WINNT
#define WINVER 0x0500
norm
|
|
|
|
|
#define _WIN32_WINNT 0x0500
#define WINVER 0x0500
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I am still getting the error:
Compiling...
DeleteThisProjectDlg.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\DeleteThisProject\DeleteThisProjectDlg.cpp(123) : error C2065: 'SetLayeredWindowAttributes' : undeclared identifier
Error executing cl.exe.
I have already:
1. installed August 2001 Build 2601 SDK
2. #define _WIN32_WINNT 0x0500
#define WINVER 0x0500
3. #include "winuser.h"
4. import User32.lib
Project>Setting>Link>Object/Library Modules>
I've added User32.lib in the text box with NO QUOTATION MARK.
5. These are the only code i added to this simple MFC dialog app:
BOOL CDeleteThisProjectDlg::OnInitDialog()
{
...
... wizard generated code
...
// TODO: Add extra initialization here
# define LWA_COLORKEY 1
# define LWA_ALPHA 2
# define WS_EX_LAYERED 0x80000
SetWindowLong (this->m_hWnd, GWL_EXSTYLE, GetWindowLong (this->m_hWnd, GWL_EXSTYLE) |WS_EX_LAYERED/*|WS_EX_TOOLWINDOW*/ );
SetLayeredWindowAttributes(this->m_hWnd, RGB(0,0,0), 240, LWA_ALPHA); //QUESTION: Intellisence dont give you this API from the list?? ::SetLayeredWindowAttributes doesnt work neither?
...
...
...
return TRUE; // return TRUE unless you set the focus to a control
}
norm
|
|
|
|
|
Try defining the macros into the project settings, Go to Project->Settings->C/C++->Preprocessor definitions, and insert there the following
,_WIN32_WINNT=0x0500,WINVER=0x0500 Good luck!
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Quote:
" Project->Settings->C/C++->Preprocessor definitions, and insert there the following,_WIN32_WINNT=0x0500,WINVER=0x0500"
just tried. didnt work unfortunately. THe compiler is still bitching that it doesnt understand SetLayeredWindowAttributes(..)
btw, #define precompiler directive does the same does it not?
I found on my machines that there's a total of four User32.lib:
1. C:\Program Files\Microsoft SDK\lib
2. C:\Program Files\Microsoft SDK\lib\IA64
3. C:\Program Files\Microsoft Visual Studio\VC98\Lib
4. C:\Program Files\Microsoft Visual Studio.NET\VC7\PlatformSDK\lib
I'm also suspecting that #include "winuser.h" is including the wrong version...
anyway, it's 5am here now. will get back to this tomorrow.
nite
norm
|
|
|
|
|
I have checked and there're three winuser.h on my system. So, I #include the version that has defined SetLayeredWindowAttribute as follows (dialog class cpp file):
#define _WIN32_WINNT 0x0500
#define WINVER 0x0500
#include "C:\Program Files\Microsoft SDK\Include\WinUser.h" //I double checked. SetLayeredWindowAttributes is declared in this file. For some strange reason, Intellisense doesnt seems to register this???
And I am still getting this compiler error:
Compiling...
DeleteThisProject.cpp
DeleteThisProjectDlg.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\DeleteThisProject\DeleteThisProjectDlg.cpp(128) : error C2065: 'SetLayeredWindowAttributes' : undeclared identifier
Generating Code...
Error executing cl.exe.
Since it's a compiler error, can I safely conclude that it has nothing to do with library file user32.lib? But how can this happen? I openned the header file and I search for the API and there it is the declaration of the API is sitting right in front of me: SetLayeredWindowsAttributes(..)
norm
|
|
|
|
|
How to output string into a file? My part of code is below:(Look at the last line, it is not ok.)
// Open the file ready write
if((pOutputFileStream = fopen(csFilePath, "w")) != NULL)
bStatus = TRUE;
// Otherwise output message to the console window.
else
{
printf("The output %s file is not available!", csFilePath);
bStatus = FALSE;
}
if (bStatus)
{
// STL string.
string str = vNode.back ();
cout << str << endl;
//
// this line is not ok.
//
fprintf(pOutputFileStream, "%s", str.substr);
}
Thanks.
mIchAel Liu
__________________________________________________________
The secret of business is to know something that nobody else knows.
|
|
|
|
|
Use C++ instead of C. Longer reply in ATL/WTL/STL.
I should add that if you're stuck with C files, you can use the c_str() function of a std::string to get a const char *.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
??
Is it bad to do a SendMessage() to the main application from a UI thread? Does the thread hang until a response is made? Could I get deadlocks etc..
|
|
|
|
|
SendMessage() sends a message to the target window synchronously - i.e. it waits for the message to be processed before returning. Consequently, it is inherently dangerous to use SendMessage() to send messages between threads. It blocks the sending thread until the message is processed, and so if the target thread then does something that requires a response from the first thread, deadlock will occur. It is possible to design your application in such a way to ensure this will not happen, but it is generally not the preferred option. Generally you should use PostMessage() or PostThreadMessage() to communicate betweeen UI threads.
Dave
|
|
|
|
|
The reason I ask is because I was using PostMessage but the thread would exit before the lParam value (CString) could be read by the main app.. I assumed that if I used SendMessage the UI thread would wait until the main app read the message..
|
|
|
|
|
You should create the CString (or whatever data structure) on the heap instead:
CString* pStrResponse = new CString( "My string" );
if ( !::PostThreadMessage( dwMainThread, myResponseThreadMessage, wParam, reinterpret_cast<LPARAM>( pStrResponse ) ) )
delete pStrResponse; // Only delete it if the post failed
Then in the main thread
LRESULT CMyApp::OnThreadResponse(WPARAM wParam, LPARAM lParam)
{
CString* pStr = NULL;
try
{
pStr = reinterpret_cast<CString*>( lParam );
// Do something with it
}
catch ( ... )
{
ASSERT( FALSE );
}
delete pStr; // Make sure we delete this even if an exception occurs
}
Dave
|
|
|
|
|
Dave, u da man!
Tnx..
|
|
|
|
|
take a look at SendMessageTimeout()
From MSDN:
SendMessageTimeout
The SendMessageTimeout function sends the specified message to a window or windows. The function calls the window procedure for the specified window and, if the specified window belongs to a different thread, does not return until the window procedure has processed the message or the specified time-out period has elapsed. If the window receiving the message belongs to the same queue as the current thread, the window procedure is called directly — the time-out value is ignored.
CPUA 0x5041
Sonork 100.11743 Chicken Little
"So it can now be written in stone as a testament to humanities achievments "PJ did Pi at CP"." Colin Davies
Within you lies the power for good - Use it!
|
|
|
|
|
Hello All,
Have a question about declaring an abstract base class in a .dll. Basically, we have something like this, in a header file of a regular win32 .dll":
class DLL_API IMyClass
{
public
virtual int DoSomething()=0;
}
which resolves to something like dllimport in the client code. If the client of this .dll is another .dll, I get an LNK2001, an unresolved external for a default constructor. Why would I need a constructor, you can't use new on an interface class.
Anyway, what's the appropriate way to do something like this? Make an abstract base class available to client code, while hiding the implementation. What does the dllimport attribute really mean for a type that is abstract, anyway? Is it even relavent? Taking off the DLL_API macro thingy from the class gets rid of the LNK error.
Thanks,
aaron
|
|
|
|
|
If using pure abstract classes, dllimport makes no sense at all, and you can safely omit it. As for the particular problem you were experiencing, probably the client DLL is "seeing" the DLL which holds IMyClass with dllexport , as DLL_API resolves to import/export depending on the _DLL macro (I guess). The default ctor, as you correctly point out, is never explicity called, but it does get called for classes derived from IMyClass .
Going the way of exporting classes through an abstract base, omit import/export qualifiers for IMyClass and declare a couple of functions like this:
IMyClass * DLL_API CreateMyClass();
DLL_API DestroyMyClass(IMyClass *); You might be tempted to omit DestroyMyClass and use delete instead: this is a bad idea, since you're likely to run into incompatibility problems between the versions of the C run-time library used by the various components of the program.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
OK, thanks, that makes sense. In this instance, most of the stuffin the .dll is created through a sort of factory, so most of the interfaces the client actually sees, he didn't get by calling new himself.
|
|
|
|
|
How does this work? Even for other Icons on the desktop ,what steps are involved for creating a customized MyAppIcon>Right Click>Properties> MyPopUpMenu ??
I have tried looking around, no luck thanks
Joe
"You can't throw yourself a parade every time you win, and you can't bury yourselves when you lose."-Levon Kirkland Philadelphia Eagles
|
|
|
|
|
Check out the msdn article # Q236312 -- I've used something similar to what's in the Driller sample to disable the rt-click menu. I think this article also shows you how to override it or create your own.
Chris
"No one goes to hell because of their sin, but because of rejecting God's method of salvation: His Son's life for yours..."
"It does not take a majority to prevail ... but rather an irate, tireless minority, keen on setting brushfires of freedom in the minds of men." --Samuel Adams
|
|
|
|
|
Thanks, I'll check it out
|
|
|
|