|
paintMemory is a memory DC.
Let do an example. I implement the following:
painMemory.FillSolidRect(0,0,BitmapWidth,BitmapHeight(),RGB(255,0,0));
::TransparentBlt(pDC->GetSafeHdc(),m_upperLeftX, 0,BitmapWidth,0,BitmapHeight,
paintMemory.GetSafeHdc(),0,0,BitmapWidth,BitmapHeight,RGB(0,0,0));
// At this point I see the overlay image is red.
// Then next is try to clear this overlay painMemory from red to RGB(0,0,0)
painMemory.FillSolidRect(0,0,BitmapWidth,BitmapHeight(),RGB(0,0,0));
::TransparentBlt(pDC->GetSafeHdc(),m_upperLeftX, 0,BitmapWidth,0,BitmapHeight,
paintMemory.GetSafeHdc(),0,0,BitmapWidth,BitmapHeight,RGB(0,0,0));
// At this point I still see the overly image is red instead of black
I need solution for this ASAP. Thanks
|
|
|
|
|
Are you drawing to the screen? Is this code in a WM_PAINT message handler (OnPaint())?
You can't erase - you need to redraw what was "underneath" the red.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Yes, I draw to the screen. I add WM_PAINT message handler OnPaint() as you suggested as shown
CMyView::OnPaint()
{
CPaintDC dc(this); // device context for painting
OnPrepareDC(&dc);
OnDraw(&dc);
}
And OnDraw(CDC pDC) I have GDI method to draw image on screen that always works.
After I implement OnPaint(). It still doesn't redraw image underneath the red.
Please Help!
|
|
|
|
|
I didn't suggest anything - I was asking.
You don't need an OnPaint override in a view since there's OnDraw().
You do, however, need to draw whatever you want to appear.
You can't draw something to the screen and then erase it, expecting to see
what was underneath it.
It's up to you to redraw the window without the overlay.
You can force a window to repaint by invalidating a portion (or all)
of the window with one of the Invalidate___() methods/APIs.
That will cause your OnDraw() to be called, where you can draw
whatever you want to appear on the window.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I want to convert a unsigned char string to other character set char string.
In UNIX,there have iconv() such functions to do the task,but how to do it in Windows,Especially using VC?
Thanks.
GOOD LUCK.
|
|
|
|
|
|
Because that,I want to output any language not only English.
When I output English,it works well but if the string contains another language,like Chinese,it does not work well.The output is wrong.
Thanks.
|
|
|
|
|
I'm timing a threading utility that pushes a bunch of work to the thread pool, executes the work, and then figures out how much time it has taken overall. The concept is really simple. That said, when I run the tests regularly in release mode with /O2 enabled, the time either takes 0.25s or 0.33s, and it randomly alternates between the two. Now, if I add a printf() statement right when the thread pool is shutting down, printing the number of work units that each thread has completed, the timing result is always 0.25s -- and by always, I mean 100%. It will never be 0.33s. In fact, I tried replacing this printf() statement with one that simply prints out "WTF?", and the result is the same (the time always ends up being 0.25s and never 0.33s). This makes me think that there is something with console operations that is changing the innards of my timing, however, I have no clue what it is.
For reference, I am using Visual C++ 2005, and QueryPerformanceCounter() / GetTickCount() to do my timing (I've used both, and they both give me these kinds of different results).
Anyone know what's going on?
EDIT: I forgot to mention one important thing. Here is how my timing works:
#1: Initialize thread pool
#2: Get count of start time
#3: Queue and process work
#4: Get count of end time
#5: Release thread pool
Now, we can truly understand the hilarity of these results, as the printf() statement, within the release of the thread pool, is not even within the count of the start and end! It's as if something I am doing in the future is changing the result of what is happening now.
|
|
|
|
|
Maybe overwritting your stack at some point ?
Put some Sleep calls to make the execution times longer see if they follow the time you set
|
|
|
|
|
I will give this a try.
Thanks.
|
|
|
|
|
Hi,
I believe when a thread does not have any sychronization objects associated with it, the OS kernel will yield and pre-empt the thread in a semi-random way, based on a priority-driven, preemptive scheduling algorithm. However once a thread has created a synchronization object the OS kernel begins to internally use this object as a reference point for yeilding process time. So by simply having created a synchronization object within a thread, the quantum timeslices should indeed become more uniform.
http://msdn2.microsoft.com/en-us/library/ms686364.aspx[^]
Maybe when your application is opening STD_INPUT_HANDLE or STD_OUTPUT_HANDLE an internal synchronization object is being created and causing the uniform quantum slices. This is just purely a guess.
It should also be noted that when using QueryPerformanceCounter on a multiprocessor computer that in order to retrieve the most accurate timestamp you should set the threads affinity mask to a single processor using SetThreadAffinityMask.
Best Wishes,
-Randor (David Delaune)
|
|
|
|
|
Thanks for the reply. Your explanation sounds plausible, although there doesn't seem like a way for me to confirm this. I am pretty sure this has nothing to do with multiprocessors and QueryPerformanceCounter() as there is a lot of info that suggests the use of /pmtimer in the C:/boot.ini file to fix incorrect timing results. I'm also unsure as to how well using SetThreadAffinityMask() works for timing, as I don't believe it provides any guarantees, only a suggestion. In another application that I was developing, using SetThreadAffinityMask() before calling QPC still gave me some timing results that were off, on 32-bit Windows XP (64-bit Windows XP, however, didn't have any such issues).
|
|
|
|
|
I want to export some functions from an executeable file. How to do it.....
In exe export function like below, and add .def file add foo to exports.
<br />
__declspec(dllexport) int __stdcall foo(int i, int j)<br />
{<br />
return i+j;<br />
}<br />
In another exe file invoke function like this:
<br />
typedef int (__stdcall *FOO)(int, int);<br />
<br />
HMODULE hModule = LoadLibrary("C:\\Export.exe");<br />
if (hModule != NULL)<br />
{<br />
FOO pFun = (FOO)GetProcAddress(hModule, "foo");<br />
if (pFun != NULL)<br />
{<br />
TRACE("%d\n", pFun(1, 3));<br />
}<br />
}<br />
I Got an "Access Violation" error.
Hongjun Ge
|
|
|
|
|
you can't.
(not safely, anyway)
|
|
|
|
|
But he has an export table, right?
AFAIK, it is perfectly possible, albeit not very common. From MSDN[^]:
LoadLibraryEx Function
Maps the specified executable module into the address space of the calling process. The executable module can be a .dll or an .exe file.
|
|
|
|
|
hmmm...
perhaps i was mistaken.
|
|
|
|
|
Nemanja Trifunovic wrote: LoadLibraryEx Function
But the OP is still using LoadLibrary and not LoadLibraryEx
|
|
|
|
|
|
You may want to know the difference in accessing a function from a .exe and a .dll. Dlls run in the same process space where your calling application runs. So you can call functions just like that!
| |
| Dll |
| |
^
|
|
v
|calling|
| EXE |
| |
But to call a function in an exe, you cannot access it straight unless you have a function like LoadLibraryEx because it runs in a different address space. You need to "marshal" the calls if in different spaces. But as pointed up Nemanja, LoadLibrary should be able to do that.
| | Marshal/LLEx |calling|
|exe|<------------>| EXE |
| | | |
|
|
|
|
|
You mentioned on dllexport with declspec.
If you are exporting functions from Exe, I dont think dllexport will work. As this is only just for DLLs not for EXE. I dont know for exporting functions from exe what convention is used?
|
|
|
|
|
glitteringsound wrote: I dont know for exporting functions from exe what convention is used?
You can always do something like this:
<br />
#define EXEEXPORT __declspec(dllexport)<br />
<br />
void EXEEXPORT MyExportFunction() {<br />
<br />
}<br />
<br />
|
|
|
|
|
i would like to create a toolbar which is docked to the left side of the SDI window but which has two column instead of one which is the default. What i already know is:
1. Derive a class from toolbar
2. Include a handler for WM_SIZEPARENT, which is MFC's private message.
3. Overwrite the virtual functions CalcDyanamicLayout and CalcFixedLayout in my derived class.
4. Write code in CalcDynamicLayout and CalcFixedlayout to set the flags of each button in the toolbar.
5. Use my derived Toolbar to replece the original toolbar.
I need help in 3 and 4 especially 4. I am also getting some kind of error when i close my application. Anyone who can help me out would be great. If you have better idea, please advise so.
Mark
|
|
|
|
|
You shouldn't need step 2.
I personally use a CControlBar with CToolbars embedded (members of the
control bar).
Here's 3 reasons why...
In the CControlBar class Calc____Layout() override(s) I can return a CSize
that has the appropriate dimensions to fill a side of the parent frame window.
In the CControlBar class Calc____Layout() override(s) I can resize the embedded
toolbar(s) to force it to wrap the rows/columns of buttons into multiple rows or
columns (depending on orientation).
With CControlBa, it's easy to mix toolbars and any other windows/controls and wrap them
all nicely in one bar docked to the frame.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I got your idea. But i am not sure if i can not do it the way i am doing it. That is derive my class directly from CToolBar. I think you are saying that derive my class from CControlBar, which has CMyToolBar class embedded in it which is more flexible.
I would need CControlBar the way you described it as an option bar in my application which will be horizonal. My vertical bar needs not to be moved and will be fixed. Depening on which button you press in ver bar, the right option bar should show. It is more like adobe photoshop type application that i am trying to develop.
You said i do not need step 2. That is using WM_SIZEPARENT. Is that what you really meant. Please explain a little. And thanks for the help.
Mark
|
|
|
|
|
Hi all, im trying to make an application that requires me to use the API WinMain() and it just so happens i need to use argv and argc. Problem is that WinMain takes 4 arguments in it and doesnt have room for argc/argv[]. So i looked up the issue and as it turns out MS didnt allow the usage for whatever reason (which really isnt important to me because i need to make it work.) So i figured if i cant put it in the calling function then make it apart of a if statement. So this is what i did.
<br />
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd){<br />
string file2="C:\\Debug\\test.exe";<br />
<br />
if(__argv[0] == file2){<br />
ofstream file;<br />
file.open("test.txt");<br />
file << "Sponcer brought to you by - Subway! Eat Fresh! :) " << endl;<br />
file.close();<br />
system(buffer);<br />
exit(1);<br />
}<br />
else{<br />
Sleep(1000);<br />
exit(1);<br />
}<br />
return 0;<br />
}<br />
And it works. But my problem is that i dont want to have to specify the name of the program and file path etc etc. Thats what argv[0] is for. So what im trying to do is this....
Use argv within the WinMain function so that i can print out file/path info. That way i can work my way around other problems. Thanx in advance!
|
|
|
|
|