|
Thanks for this info..
You must fill the cell rect with the background color before drawing the text.
SetBkColor(lpCD->nmcd.hdc, GetBkColor());
ExtTextOut(lpCD->nmcd.hdc, 0, 0, ETO_OPAQUE, &iR, NULL, 0, NULL);
but may function looks like this
fillrect(); //i am using this to fill out the specific rect
settextcolor(); //then I set the text color
Drawtext() //then I draw the text
(1)
if use ExtTextOut then there is no need to drawtext?
ExtTextOut(lpCD->nmcd.hdc, 0, 0, ETO_OPAQUE, &iR, Buffer, strlen(Buffer), NULL);
(2)
i used SetBkColor(lpCD->nmcd.hdc, GetBkColor(..)); nothing happened, i do not set a bk color in my listview, i did set a row color manually... so If I do SetBkColor(lpCD->nmcd.hdc, RGB(255,0,0)); the whole list bk changed to red?
maybe the method i use is wrong..
|
|
|
|
|
My example code is those used by CDC::FillSolidRect() . It will erase the cell using the actual background color of the HDC which can be set to the default returned by CListView::GetBkColor() or any other you are specifying (e.g. a row specific color).
You may of course use ExtTextOut() to print the cell text parts with different colors when adjusting the rect.
When using CListView::SetBkColor() this will set the default color for the list. When calling ::SetBkColor(HDC) , this specifies the color for the drawing functions using the HDC.
If you change the background color (or the text color) of the HDC, you should restore it to the original value that is returned by the first set call. Restoring the colors may be omitted when all cells are owner drawn.
|
|
|
|
|
OMG man (After all that Time) I finally got what I am looking for thanks so much..
those info helped me a lot
|
|
|
|
|
I have not tried using direct drawing code such as you do, but maybe this MSDN sample[^] will help.
Use the best guess
|
|
|
|
|
Hi
I am getting the above mentioned error when clearly DebugString is a member of _DEBUG_EVENT
My declaration of DEBUG_EVENT is as follows
DEBUG_EVENT debug_event;
|
|
|
|
|
If you check the documentation for the structure[^] you will see that DebugString is part of the union u . So to address this item you should code:
debug_event.u.DebugString;
debug_event->u.DebugString;
Use the best guess
|
|
|
|
|
I'm sorry yes you are
Right
|
|
|
|
|
Hello,
I have a problem with my Progress Bar in MFC, C++
Indeed, I want display progress bar in CList Ctrl. I use the class CProgressCtrl.
And I want to move this prograss bar if my scroll bar move. I use MoveWindow(...), RedrawWindow(...) functions.
It runs in mode Debug but in mode Release, it doesn't run, i've got an error with MoveWindow function because in this function, the program doesn't know the m_Wnd and m_pCtrlSite
Help me
|
|
|
|
|
I want to record d3d games. Now I can get data from backbuffer and save it.
The programe is when the game resize the window, I should strech it.
The following is my steps:
IRefPtr<ID3D10Texture2D> texture;
HRESULT hRes = m_pDXGISwapChain->GetBuffer(0, __uuidof(ID3D10Texture2D),
reinterpret_cast<void**>(IREF_GETPPTR(texture,ID3D10Texture2D)));
if (FAILED(hRes))
{
return hRes;
}
hRes = pDevice->CreateTexture2D(&desc, NULL, IREF_GETPPTR(textureDest,ID3D10Texture2D));
if (FAILED(hRes))
{
return hRes;
}
pDevice->CopySubresourceRegion(textureDest, 0, 0, 0, 0, texture, 0, &sourceRegion);
Everything is ok, but as i say, when the game change size, i must stretch the Texture2D for get the whole picture. The CopySubresourceRegion() cant do it. And i dont find anyother way to do it.
Thanks for any advices. I am a newer for directx.
I am a rookie boy, if you help me, i will become a man.
|
|
|
|
|
I think the D3D10LoadTexureformTexure() will be the right answer. But it is very slow.It is not a best answer but a right one.
|
|
|
|
|
Hi everyone.
Recently i'm working on a project which is to record games. Some trouble comes to me, for d3d10 and d3d11. I can hook the Present() through IDXGISwapChain:
PFN_D3D10_CREATE_DEVICE_AND_SWAP_CHAIN1 pDirect3DCreate10 = (PFN_D3D10_CREATE_DEVICE_AND_SWAP_CHAIN1)GetProcAddress("D3D10CreateDeviceAndSwapChain1");
if (pDirect3DCreate10 == NULL)
{
return false;
}
IDXGISwapChain * pSwapChain;
ID3D10Device1 * pDevice;
HRESULT hRet = pDirect3DCreate10(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0, D3D10_FEATURE_LEVEL_9_1,
D3D10_1_SDK_VERSION, &swapChainDesc, &pSwapChain, &pDevice);
if (FAILED(hRet))
{
return false;
}
UINT_PTR* pVTable = (UINT_PTR*)(*((UINT_PTR*)pSwapChain));
m_nDX10_Present = pVTable[8];
m_nDX10_ResizeTarget = pVTable[14];
Using VTable to get the address. And I can save backbuffer. But when change game's size, the game will crash. It seems change size wouldn't go to ResizeTarget(). So I want to ask:
1. When the game change size for d3d10_1.dll, what does he do, and what should I do?
2. There is other question, when the game exit, what should i do. i want to stop my project when the game is exit.
Thanks for any advices. I'm a newer in directx. There are so many publishs for directx, i.e d3d9, d3dx9_43, d3d10, d3d10_1, d3d11, d3d11_1 and so on.
modified 19-Jul-13 0:53am.
|
|
|
|
|
I find when resize game's window it will call IDXGISwapChain()->ResizeBuffers(). I can hook ResizeBuffers(). And it also crash(the game is stablish, cant move any more.).I dont konw what should i do? please help!
|
|
|
|
|
Hello,
I am trying to call a GUI function from a worker thread in a Doc/View application in MFC in VS2008. It was working fine on XP 32bit, but throws error in Windows 7 32bit.
I am calling the following function within a worker thread-
parent->UpdateAllViews(NULL);
The error that it throws is at Line 900 in wincore.cpp which is
ASSERT(pMap != NULL);
Also my other function which was working fine under XP is giving fatal error
AfxGetMainWnd()->PostMessage(WM_CLOSE, 0, 0);
The above function is also called in the same worker thread.
Any suggestions/ideas?
thanks
PKNT
|
|
|
|
|
Every normal gui framework is single threaded that means: you can access gui related data and functions only from the gui thread (that is the main thread in case of MFC). Its only blind luck that your app worked on WinXP most of the time. Multithreaded programs become quite non-deterministic and the same is true for the occurrence/reproduction of their bugs. Now you are "lucky" that you have a quite reliable repro case for your bug that was a bug even on WinXP!
1. AfxGetMainWnd() is a gui related call so I would call it only from the main/gui thread. Call AfxGetMainWnd() from the gui thread when you create the worker thread and pass the window pointer to the thread as a CreateParam. Since SendMessage() and PostMessage() are thread safe WinAPIs the same is true for the SendMessage() and PostMessage() methods of the window.
2. On the worker thread use the PostMessage() or SendMessage() method on the window pointer you received as a ThreadCreateParam. PostMessage(WM_CLOSE, 0, 0) should work if you use directly the window pointer without AfxGetMainWnd().
3. To call UpdateAllViews() do the following: Define your own window message. Either WM_APP+(0..1000 or whatever) or WM_USER+... Then use again PostMessage() on the window pointer to post your own window message. In the message map of your window receive your user defined message with ON_MESSAGE(WM_MYMESSAGE, OnMyMessageMethod). Your OnMyMessageMethod() will be called from the gui thread so it will be safe to call UpdateAllViews() from there. Use PostMessage() instead of SendMessage() if you don't want the worker thread to block until the end execution of OnMyMessageMethod() on the gui thread.
BTW: Here is the implementation of AfxGetMainWnd() of VS2010:
_AFXWIN_INLINE CWnd* AFXAPI AfxGetMainWnd()
{ CWinThread* pThread = AfxGetThread();
return pThread != NULL ? pThread->GetMainWnd() : NULL; }
If your worker thread was created with non-mfc api then this AfxGetMainWindow() returns NULL always if called from your worker thread.
|
|
|
|
|
Passing a window pointer between threads is not a good idea in MFC.
Instead, you must pass the window handle behind the pointer.
You can convert the handle to a pointer using the CWnd::FromHandle static method.
Rest of the things are spot on.
|
|
|
|
|
If you can guarantee that the lifetime of the window spans that of the worker thread activity (and it does since it is the main window) then its OK to pass the pointer but it has no advantage over your solution because PostMessage and SendMessage is available in both cases.
|
|
|
|
|
Thanks for your reply. Probably I should show how I am currently defining my thread and how I am using it.
Declaration:
static DWORD WINAPI ThreadProcess(LPVOID pParam);
Definition:
DWORD WINAPI CMainDoc::ThreadProcess(LPVOID pParam)
{
CMainDoc *parent = (CMainDoc *)pParam;
while(TRUE) {
switch(::WaitForSingleObject(2, parent->m_eMsg, FALSE, INFINITE)) { case WAIT_OBJECT_0:
parent->UpdateAllViews(NULL);
break;
case WAIT_OBJECT_1: pObject->PostMessage(WM_CLOSE, 0, 0);
break;
}
}
Now if I do the way you suggested, do I need to send the handle returned from AfxGetMainWnd() along with a pointer to the document in 'pParam'?
PKNT
|
|
|
|
|
If you don't call MFC functions from your worker thread (its best not to call them) then its OK to go with non MFC threads so the kind of your thread doesn't matter. As I see you have already used up your pParam to send the doc pointer. You can send any number of parameters to your thread this way:
struct MyThreadParamStruct
{
CMainDoc* parent;
CWnd* mainwnd;
};
void StartThreadTask()
{
MyThreadParamStruct* thread_param = new MyThreadParamStruct;
CreateThread(..., thread_param, ...)
...
}
DWORD WINAPI CMainDoc::ThreadProcess(LPVOID pParam)
{
std::unique_ptr<MyThreadParamStruct> thread_param((MyThreadParamStruct*)pParam);
...
}
|
|
|
|
|
Looks like std::unique_ptr is not defined in VS2008. I got it working using standard form like
ThreadNetMsgParamStruct *pThreadParams = (ThreadNetMsgParamStruct *)pParam;
But the problem is, a CDocument class can not process windows messages. Is there any other straight forward way to replicate UpdateAllViews() command without calling it directly?
thanks
PKNT
|
|
|
|
|
unique_ptr is like std::auto_ptr (its younger brother in stl). It deletes the pointer automatically when it goes out of scope (in this case at the end of the function or if you return from the func). The struct instance must be deleted otherwise you cause a memory leak. You have to send a message to a window and not to a document object. If you can't solve the problem using the info I provided (theory + 90% of the code needed) then either ask a colleague to do it for you or start learning about multithreading+gui and their relationship.
|
|
|
|
|
Kiran Satish wrote: I am trying to call a GUI function from a worker thread... Bad idea. See here for why.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Just dont do it. Think of your thread as being in a different process, how would you communicate between them? With PostMessage and SendMessage. So create some custom IDs, handle them in your main window proc and post or send using those IDs from the thread.
You have to keep it clean on Windows, you cant bodge stuff. It might work for a bit, but eventually it will break.
|
|
|
|
|
Thanks, that's exactly how I did it over the weekend and it works well.
PKNT
|
|
|
|
|
Hi there,
Is there a way to disallow users from pasting anything to CEdit box control?
Right now they can right click and select the PASTE menu option.
And also do a Control + V.
How to disable this?
please give some sample code.
Thanks in advance.
|
|
|
|
|