Thanks, I can print from my service now. But there's still a problem.
After calling ImpersonateLoggedOnUser(), I call PrintDlg() to display Print Dialog Box. And I can only print if hwndOwner of PRINTDLG structure is set to NULL. If hwndOwner is set to the Handle of parent window, there's no printer to select in the Print Dialog Box and this dialog box is the dialog box of the function PrintDlgEx(). Quite weird!
I assume with 'parent window' you suppose the window created by your service, that belongs to the SYSTEM context/process and may annul the previous impersonation.
Try FindWindow("Progman", "Program Manager") as owner, that's an unique valid window of logged on users desktop.
I am drwaing images on a view So I develped a owner draw control to darw images.
I also need to draw blue order around on mouse hover So I am also drwing. But I am facing some flickering issue How can I reduce it?
You might also try handling WM_ERASEBKGND. Do nothing in the handler and return a non-zero value. This will prevent the view window being flood-filled with the window class brush color just before each call to WM_PAINT.
The other key is using some double-buffering scheme. Draw your content on an off-screen bitmap and then blit that to your view, rather than drawing in the view itself.
Flicker occurs when there are intermediate pixels on the screen. Example: draw a blue,filled rectangle, then draw a non-rectangle bitmap over that. The blue pixels 'under' the bitmap cause the effect. There are 2 solutions: 1) avoid the drawing of unneeded pixels by making your algorithm better (and faster) or using regions (see winapi documentation), 2) draw everything in a buffer (memory DC) and transfer that to the screen. This is called 'double buffering'.
The first solution is most of the times too difficult to implement, so solution 2 is widely used, although it is actually slower.
Good day . Though this question is not relevant to MFC or Win32 but to do with VB generic behavior =>
I have a outlook plugin ( COM plugin ) developed in VB 6.0 . We have an external application which uses the outlook addin to get the contact details from outlook. The problem is here =>
We create a new application object and free it as below =>
Set gApp = New Outlook.Application
Set gApp = Nothing
After this code is executed when we click on outlook application it says "Operation failed" . It looks like the outlook application object is not well freed by the statement Set gApp = Nothing . But I checked by adding the line below to ensure if the gApp is really free or not .
If gApp is Nothing
Then Log("gApp is free")
Log ( "gApp is not free")
Even after this check it shows gApp is free which does not seem to be the case .
What can I further do to make sure the object is really made NULL !!!!
dealing with outlook is especially difficult.
first you need to attempt to connect to running instance and if successfull set a flag.
if not current instance create one.
do your stuff.
then if you connected to running instance just free your stuff and go bye bye.
if you created an instance call close on it and then go bye bye.
NEVER call close on an instance you didnt create.
What I found, was that Outlook 2007, was unfriendly. It is a single instance multi process application that needs to be specifically closed. If you start it, you close it, if you dont specifically close an instance you started it sits in running processes until you log off. If you dont start it, you dont close it, but you do release all instances of objects you created. Maybe this is because I dont have the latest VS. But I dont see how that would affect the Outlook object model.
normally when u create project in Visual studio ,and after debugging it (ofcourse in debug mode) , when u close the app, Visual studio will shows any unfreezed memory in the output window( ALT+CTRL+ O).
sometimes this information is sufficient to detect the memory leak(depends on codes and the persons knowledge)
if u r trying to find memory leak and vs's output is not sufficient try using boundsckecer or similar softwares ( http://en.wikipedia.org/wiki/BoundsChecker) . Boundschecker is not free.
visual leak detector is a free one(http://www.codeproject.com/KB/applications/visualleakdetector.aspx)
How to let the code be more elegant? Just too much delete.
BTW, while not to deal the exception in side the function, try catch finally can't be used.
char * buf = new char;
I think what I need is something like constructor and destructor, but for a function.
By overriding operator() of a class may solve some problem, but the function it hard to be re-entrantable, and other misc problems.
Most of the cases the function should be short, so this couldn't be a problem, but in some rare case, it has to deal a lot of data,
and the function looks very long.