|
Whilst testing some code from the framework I have been working on in various Win32 platforms I came across a rather odd bug.
Lets say we have the following:
HBITMAP hbmpOrig = getImageListHBMP()
where hbmpOrig represents the HBITMAP to a properly created bitmap image in memory
Now I want to make a copy of the handle, and according to MSDN there is a nice function called CopyImage that does just this.
So I do the following:
HBITMAP hbmpCopy = (HBITMAP)CopyImage( hbmpOrig, IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG );
Now according to the MSDN that I have at home (which is the Oct 98 MSDN that comes with VC6):
<quote>
CopyImage
<snip>
...
fuFlags
<snip>
LR_COPYRETURNORG Creates an exact copy of the image, ignoring the cxDesired and cyDesired parameters.
This is why I used the LR_COPYRETURNORG - to make a copy of the image.
The behavior on Win2000 (all sp versions), WinXP, Win98 (and presumably on 95 and ME as well) is to create a new HBITMAP value - just like the docs say.
However on Win NT4 it returns a the original value!! So this is a problem that was in the framework. One of the guys helping out on the project posted this problem to a newsgroup (or list, or whatever) on MSDN and this is what a Microsoft eng replied as :
>
> I don't think I understand - the docs for LR_COPYRETURNORG state
> that you will get back the original if it meets the criteria. Since
> you're asking for 0 width and height, the only way the original
> wouldn't satisfy your request is if it's a different bit depth.
>
> The difference in behavior is either a bug in NT4, or due to the
> color depth in which you're running on the various machines. Either
> way, you could very easily create your own CopyImage() which creates
> a new bitmap and uses BitBlt() to copy the image from source to target.
Sure enough I checked on the latest MSDN docs for this and they read:
<quote>
CopyImage
<snip>
...
fuFlags
<snip>
LR_COPYRETURNORG
Returns the original hImage if it satisfies the criteria for the copy—that is, correct dimensions and color depth—in which case the LR_COPYDELETEORG flag is ignored. If this flag is not specified, a new object is always created.
WTF ! This is the behaviour on WinNT4 but NO OTHER system performs like this!!! Which is correct ? Do we just use 0 ?
So I am curious - has anyone else ran into this before ? Is there a workable solution or do we just end up writing our own version of CopyImage? This is just so incredibly annoying. Actually it is a lot more than that but I am going to refrain from a stream of expletives...sigh.
Thanks in advance !
¡El diablo está en mis pantalones! ¡Mire, mire!
|
|
|
|
|
I'd say write your own. I know that TransparentBlt also has trouble, quite a few people have ended up using my version and it's solved their problems with it. It seems Microsoft are not infallible
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
|
|
|
|
|
Hi,
I create a Dialog box with some controls.
I would like to use my Dialog box for another application in VC++.
How can I do for import this dialog with all controls ?
Best Regards
youssef
|
|
|
|
|
Do you mean import? One solution is to import the dialog box class in the new project. Export the dialog box template and import it in the new project.
If you meant controlling the dialog box in another program, then you should consider other solutions including file-mapping, namepipe, Winsock, and COM.
Kuphryn
|
|
|
|
|
When I go to the dialog box that I want to export, the context menu can't display Export but only import.
youssef
|
|
|
|
|
i have an MDI application with 2 views .
Initially in the App class I do the following :
CMultiDocTemplate* pDocTemplate;<br />
pDocTemplate = new CMultiDocTemplate(<br />
IDR_MDI2TYPE,<br />
RUNTIME_CLASS(CMDI2Doc),<br />
RUNTIME_CLASS(CChildFrame),
RUNTIME_CLASS(CPersonalityGenerator1View));<br />
AddDocTemplate(pDocTemplate);<br />
<br />
<br />
secondTemplate = new CMultiDocTemplate(<br />
IDR_MDI2TYPE,<br />
RUNTIME_CLASS(CMDI2Doc),<br />
RUNTIME_CLASS(CChildFrame),
RUNTIME_CLASS(View1));
// I DO NOT ADD THIS SECOND TEMPLATE
On a New document I do the following :
if (!CDocument::OnNewDocument())<br />
return FALSE;<br />
<br />
CMDI2App *myApp=(CMDI2App *)AfxGetApp();<br />
CMainFrame *mnd= (CMainFrame *)(myApp->m_pMainWnd);<br />
CFrameWnd *allotedFrameWnd;<br />
allotedFrameWnd=myApp->secondTemplate->CreateNewFrame(this,0);<br />
myApp->secondTemplate->InitialUpdateFrame(allotedFrameWnd,this, TRUE);<br />
allotedFrameWnd->SetActiveWindow();<br />
allotedFrameWnd->ShowWindow(SW_HIDE);
I am suppressing this second View by hiding it AND i display the first view . This is what i want initially !
Now I need to activate this view on an On Button Event from the Toolbar
In the active View i am trying to do something as :
<br />
void CFirstView::OnSwitchView()<br />
{<br />
<br />
POSITION pos = this->GetDocument()->GetFirstViewPosition();<br />
<br />
CView *v2 = this->GetDocument()->GetNextView(pos);<br />
<br />
v2->GetActiveWindow();<br />
<br />
v2->GetParentFrame()->ShowWindow(SW_SHOW);<br />
}
I find that the views are not getting switched . I observe no change . Please help
|
|
|
|
|
I'm looking for an explanation of how to detect an idle period within an application and close dialogs and log off the application if the idle period is exceeded.
I have information on how to detect the application idle time by using Paul D.'s IdleUI DLL from Feb. 2000 MSJ, but I'm curious how to find a modal dialog that is currently displayed and close it. Will I have to send a user windows message to the dialog and write a message loop for the dialog to get it?
Any one of a number of modal dialogs in the app can be displayed when the idle time is exceeded and I can't seem to figure out how to notify these dialogs that they should close. Also, will I even get system hook notifications in the main app if a modal dialog is currently displayed?
Thanks...
|
|
|
|
|
Do you have control of the dialog boxes? Call its destroy function, DestroyWindow(), or post a WM_DESTROY message.
Kuphryn
|
|
|
|
|
I have an Application in Vc++ . From this application I want to invoke another Application .
Imagine invoking Notepad to view a file .
How do I do this ?
|
|
|
|
|
_spawn, CreateProcess, WinExec and ShellExecute are all popular methods.
-c
A conclusion is simply the place where someone got tired of thinking.
|
|
|
|
|
For a command line:
Use system if you want the command line interpreter to handle it.
Use ShellExecute/ShellExecuteEx if you want the Windows shell to handle it.
Use CreateProcess if you want Windows to handle it.
|
|
|
|
|
I try to write a program to talk to a external device via com port1. I use WriteFile() to send the ascii command: I verified to see that the ASCII command that I send out does go out to the port. I checked the correct configuration for the port(baudrate,stopbit...). But the devide still does not respond. However, the device is responding when I use windows hyperterminal to send the exact ascii command. Does anyone know why?
Does hyperterminal terminate the stream it sends out with a special ascii value that my program doesn't ?
Please help!
Thanks, peter.
|
|
|
|
|
Nope. After setting up the DCB with SetCommState and the timeouts with
SetCommTimeouts, sending out the commands via WriteFile should be enough.
Hook up COM1 to COM2 via a null-modem cable. Connect to COM2 via terminal emulator (Hyperterm or whatever.) and pretend you are the device. Connect your program to COM1 and check out what is being sent.
|
|
|
|
|
Hi, I'm looking for a MFC/Vis C++ example of a rotary dial control. I located one in the CP archives, but thought there were others.
http://www.codeproject.com/miscctrl/rotary.asp
Any help?
Thanks,
Johnny
|
|
|
|
|
you could try this[^]
Error 4711: Signature expired
|
|
|
|
|
I liked this one:
http://www.marvgolden.com/health-safety/relief_bands.htm
-- seriously though, was looking for a quick one that you might know about.
|
|
|
|
|
Thats what I call a "reusable component"
Error 4711: Signature expired
|
|
|
|
|
hi
i am using EnumPrinters() function in my project. this is working fine. in msdn help they given if EnumPrinters() successfully executed it returns nonzero value otherwise zero value. but i am getting zero value for successful working of EnumPrinters(). so which one is right please clarify my doubt
thank you
|
|
|
|
|
Try to catch a CDBException like this:
try
{
}
catch (CDBException* e)
{
AfxMessageBox (e->m_strError);
e->Delete ();
}
It may give you useful information
Best regards,
Alexandru Savescu
P.S. Interested in art? Visit this!
|
|
|
|
|
Does anyone know what is the preferred what to pass variables to a function ? Assuming the value does not need to change.
For example I was just recently old that
foo( long val ) was preferable to
foo (const long& val )
Isn't the second form more efficient ? I had always thought this, plus the use of "const" clearly marking something as not changing. Any thoughts welcome here
¡El diablo está en mis pantalones! ¡Mire, mire!
|
|
|
|
|
const reference is what is favoured by the 'gurus', like Scott Myers and the like.
in case of a long int, it may make no big difference, but when you have to transfer an object of several hundreds of bytes, things are different.
As for the const, it simply is a good habit, giving the compiler the opportunity to assist you in adhering to your own guidelines.
|
|
|
|
|
The const is important for the optimizer. It allows the caller more freedom to optimize since it knows the callee won't change the value.
However, for small values that can normally be passed on the stack, using a const reference will slow things down. So for ints, longs, etc..., don't use a const reference. Just pass the value normally.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
For built-in types, there is no copy constructor that may cause unwanted side-effects when passing by value. For user defined types, there may be side effects when (if it is even possible to) passing by value which invokes the copy constructor. That's why passing by reference is generally better for user-defined types-- you're just passing the ability to access the same object instead of a copy of the object. (and if you will make no changes, pass a reference to the object as const.)
|
|
|
|
|
Hmmmmm - the copy constructor that you are talking about would be called buggy here.
Either it does its work flawlessly or it is impossible to call (private).
|
|
|
|
|
That is not necessarily true.
A copy constructor can have unwanted side
effects that are not bugs.
Take for example, auto_ptr.
Its copy constructor will pass ownership
to the copy being passed to the function
in question. Upon return, the original
auto_ptr will no longer point to a valid
object, it having been destroyed when the
function's copy of the auto_ptr deleted
the object. This is almost certainly not
what the designer of that function nor its
user would desire.
|
|
|
|