|
What in the world could cause me to be unable to draw to a blood PICTURE CONTROL?
|
|
|
|
|
Since you are drawing in the dialog windows WM_PAINT handler, when the child window (picture control) gets its WM_ERASEBKGND and WM_PAINT message later causes it to erase the image drawn.
you can do,
1. Why don't you set the Bitmap for the picture control at the time of resource editing or dynamically SetBitmap() and allow the picture control to draw in its way.
2. you may subclass the picture control and draw on its paint handler.
3. you actually don't need a picture control if you are drawing the image, remove the picture control and draw the image on the WM_PAINT handler of the dialog as you are doing now, only difference is you don't want to acquire the DC of Picture control but use the dialogs DC and draw where you want in the dialog (where the picture control is supposed to place)
4. Try set the Transparent style to the picture control in the resource editor
|
|
|
|
|
What does the transparent property do?
I can't do it by resource editing. Whenever I draw on a picture control I never see anything.
I will try SetBitmap tomorrow.
Is there a tutorial on doing the subclassing on the picture control?
|
|
|
|
|
There's not really a "picture control" - it's just a static control
with the SS_BITMAP style. If you're ok with the way the static control
draws its bitmap then you should just be using the static control that way
instead of doing the drawing yourself.
If you need to draw yourself, then you should be doing so in the control's
WM_PAINT handler. The symptoms seem to indicate you're drawing a bitmap
"underneath" (in the z-order) another control - that means you've got the
wrong HWND
Also make sure you handle WM_PAINT properly (for any window). If the invalid
region of the window being painted isn't marked valid after painting, then you get
recurring calls to WM_PAINT - bad for performance! Use BeginPaint() and EndPaint()
in your WM_PAINT handlers (and the DC it provides) and the invalid region updating
will be taken care of by the system.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I know I can use a SendMessage command to a static control to tell it to change its bitmap.
But how do I load a bitmap from a file that's a gif or jpeg or png? Or just from a file in general.
Is there a way to use GDI+ to do this? I can create a bitmap with gdi plus (that's what I'm doing now) but I don't know how to use that in
for SendMessage().
Edit I've tried setting the image with
<br />
SendMessage(GetDlgItem(hwnd,IDC_PICTURE),STM_SETIMAGE,IMAGE_BITMAP, (LPARAM)&srcBitmap);<br />
The srcBitmap variable is a valid bitmap object. Is that not the correct way to do it?
Because at the moment, whenever I set it by clicking on the control, it erases itself and it still gray.
modified on Saturday, May 3, 2008 1:54 PM
|
|
|
|
|
You can't send a Gdiplus::Bitmap to the control....you need to use Bitmap::GetHBITMAP() to
create an HBITMAP to send to the static control.
HBITMAP hbm;<br />
srcBitmap.GetHBITMAP(Color::Black, &hbm);<br />
SendMessage(GetDlgItem(hwnd,IDC_PICTURE), STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hbm);
Mark
Mark Salsbery
Microsoft MVP - Visual C++
modified on Saturday, May 3, 2008 2:24 PM
|
|
|
|
|
Hi,
Actually i reading one file and list all file details in TreeCtrl and finally i select one thing from the list.
The file contains two details as Name and Category,the file looks like
Name Category
DT002 UNIT OPERATIONS
IND01 CUSTOMS
CRD01 UNIT OPERATIONS
ECH01 CUSTOMS
So, I have to list the details as follow
UNIT OPERATIONS (Parent)
DT001 (child of UNIT OPERATIONS)
CRD01 (child of UNIT OPERATIONS)
CUSTOMS (Parent)
IND01 (child of CUSTOMS )
ECH01 (child of CUSTOMS )
When i made TreeCtrl, what it displays like...
all the things displayed as in file.
UNIT OPERATIONS
DT001
CUSTOMS
IND01
UNIT OPERATIONS
CRD01
CUSTOMS
ECH01
So pls help me.
I have to find the parent items in TreeCtrl and i have to add appropriate name (child) to that
category. Pls help me to sort out the problem????
Anu
|
|
|
|
|
Do you have a problem reading from the file or constructing the tree control or populating it?
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
I read from file and made the Treectrl. But i have to populate it na good manner.
In a single parent i have to place three or four child item.
But now i got tree list as
THree child item have the seperate parent item,but all this parent item are same.
Anu
|
|
|
|
|
Anu_Bala wrote: THree child item have the seperate parent item,but all this parent item are same.
What could that possibly mean? Can you just show your code?
While posting a query, please keep the scope narrow as possible and explain *only* the part where you face a problem, along with relevant source code, if any. This would help you get an accurate and fast answer. You've been long enough here to know it though.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
for(int k=0 ; k<pCustInfo->oCustDet.iNoOfModels;k++)
{
HTREEITEM hTree, hModel;
oModel = new SModelInfo;
pCustInfoFile->Read(oModel,sizeof(SModelInfo));
hTree = m_ModelTree.InsertItem(oModel->stModels, TVI_ROOT); ///THIS IS PARENT ITEM
hModel = m_ModelTree.InsertItem(oModel->stModelName, hTree); //THIS IS CHILD ITEM
}
By this coding, i add every same parent and child item in line by line.
But i need all child items from the samr parent in single list.
In codeproject, is any provision to add some image, then i will add screenshot of my treectrl dialog.
Anu
|
|
|
|
|
This code works for me to get two root items with two branch items for each root:
HTREEITEM hRoot, hBranch;
hRoot = m_Tree.InsertItem("Root item 1", TVI_ROOT);
hBranch = m_Tree.InsertItem("Branch of Root 1", hRoot, TVI_LAST);
hBranch = m_Tree.InsertItem("Branch of Root 1", hRoot, TVI_LAST);
hRoot = m_Tree.InsertItem("Root item 2", TVI_ROOT);
hBranch = m_Tree.InsertItem("Branch of Root 2", hRoot, TVI_LAST);
hBranch = m_Tree.InsertItem("Branch of Root 2", hRoot, TVI_LAST);
Note: Please enable the following from the Tree Control properties: Has buttons, Has lines, Lines as root.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
Hello,
i created a shell extension for my program but i cannot delete them? Whats going wrong there? Hope someone can help me. Thanks !
<br />
HKEY key;<br />
DWORD res;<br />
<br />
<br />
RegCreateKeyEx(HKEY_CLASSES_ROOT,L"CPACK\\shell\\Extract with CPACK\\command",0,NULL,REG_OPTION_NON_VOLATILE,0xF003F,NULL,&key,&res);<br />
wchar_t *data = L"C:\\cpack.exe e %1";<br />
RegSetValueEx(key,L"",0,REG_SZ,(LPBYTE)data,(DWORD)(lstrlen(data)+1)*sizeof(TCHAR));<br />
RegCloseKey(key);<br />
<br />
RegCreateKeyEx(HKEY_CLASSES_ROOT,L".cpack",0,NULL,REG_OPTION_NON_VOLATILE,0xF003F,NULL,&key,&res);<br />
data = L"CPACK";<br />
RegSetValueEx(key,L"",0,REG_SZ,(LPBYTE)data,(DWORD)(lstrlen(data)+1)*sizeof(TCHAR));<br />
RegCloseKey(key);<br />
<br />
<br />
RegDeleteKey(HKEY_CLASSES_ROOT,L"CPACK");<br />
bye,
gabbana
|
|
|
|
|
You cannot delete a registry key if subkeys exist.
If you were successful with creating the key and subkeys then you should be able to delete them as well. RegDeleteKey will fail with ERROR_ACCESS_DENIED if a subkey exists. You need to implement a recursive deletion[^].
Best Wishes,
-David Delaune
|
|
|
|
|
ahh okay now it works fine. Thanks.
|
|
|
|
|
gabbana wrote: Whats going wrong there?
What's going on is that you are not checking for errors. From MSDN:
If RegDeleteKey() fails, the return value is a nonzero error code defined in Winerror.h. You can use the FormatMessage() function with the FORMAT_MESSAGE_FROM_SYSTEM flag to get a generic description of the error.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
|
A Visual C++ program of mine has been suffering from an ailment that it did not have under Borland C++ on my old PC: ignoring the keyboard, unprogrammed bell beeping when I press a keyboard key. I may have tracked it down, all or partly.
It has an array char KEYS[256] which is used as a boolean array to keep track of which keyboard keys are up and which are down. When I switch away from the program using alt-tab, this seems to happen: Alt down: is recorded. Tab down: the program loses the foreground. Alt up and tab up: not recorded by my program. So, when my program gets the foreground back, it thinks that the alt key is still down.
What I want to do is to trap any system message that says "This program is about to lose the foreground", so I can set to 0 the variable KEYS[VK_MENU] and any other KEYS elements that are so affected.
VK_MENU is the virtual key number of the ALT key.
|
|
|
|
|
You can probably use the WM_KILLFOCUS[^] message to detect when your window loses the keyboard focus.
You could also possibly use WM_ACTIVATE[^] to detect when your application has been activated or inactivated.
Best Wishes,
-David Delaune
|
|
|
|
|
Thanks. I found that:
case WM_KILLFOCUS: for(i=0;i<256;i++) KEYS[i]=0; goto DEF; seems to make dialog boxes misbehave.
case WM_ACTIVATE: for(i=0;i<256;i++) KEYS[i]=0; goto DEF; seems so far to work OK.
|
|
|
|
|
I have a Windows service in which I need to stop worker threads from my main thread. I am trying to use events to do this but I am stumped on why it is not working. Each class that runs a worker thread creates a stop event and a response event. When I need to stop the worker thread I call into the threads class and set the event. However, instead of the worker thread detecting that the event has been set and stopping gracefully, it just disappears. Why?
What is the best method for stopping a worker thread from the main thread?
Re-posted from the C# forum.
|
|
|
|
|
This should work quite well. I do it all the time. Something else is wrong.
Of course, your thread must periodically be 'waiting'on the event. If you require a polled approach because your thread is always working and does not return to check for the 'main event' too often, then you can use InterLockedIncrement and InterlockedCompareExchange on a control variable.
|
|
|
|
|
I appreciate any help. I have posted my code below:
<br />
void CFileChangeEvent::stopProcessThread()<br />
{<br />
TRACE( "> > > > CFileChangeEvent::stopProcessThread() entered - Event handles < %X, %X >, Event ID < %s >\n",<br />
m_hProcessStopEvent, m_hProcessRespEvent, getIdentifier() );<br />
<br />
::SetEvent( m_hProcessStopEvent );<br />
}<br />
<br />
UINT CFileChangeEvent::MultiFileProcessThread( LPVOID lpParam )<br />
{<br />
CFileChangeEvent* pEvent = (CFileChangeEvent*)lpParam;<br />
<br />
CFlightDataHandler* pFlightDataHandler = NULL;<br />
CLogWriter* pLogWriter = NULL;<br />
HANDLE hProcessStopEvent = pEvent->getProcessStopEvent();<br />
HANDLE hProcessRespEvent = pEvent->getProcessRespEvent();<br />
<br />
try<br />
{<br />
CDataMovement* pDataMovement = pEvent->getDataMovementParent();<br />
CLogWriter* pLogWriter = pDataMovement->getLogWriter();<br />
pFlightDataHandler = new CFlightDataHandler( pLogWriter );<br />
<br />
HRESULT hRes = ::CoInitialize(NULL);<br />
<br />
CString strInboxPath( pDataMovement->getInboxPath() );<br />
vector<CString> vecFifFiles = UtilK::findAllFiles( "*.fif", strInboxPath );<br />
<br />
int nLen = strInboxPath.GetLength() + 1;<br />
vector<CString>::iterator iterFile = vecFifFiles.begin();<br />
CString strFile = *iterFile;<br />
CString strLastPath = (*iterFile).Mid( 0, strFile.Find( "\\", nLen ) );<br />
<br />
int nFileCount = 0;<br />
bool bCancelled = false;<br />
for( ; iterFile != vecFifFiles.end() && ! bCancelled; iterFile++ )<br />
{<br />
CString strPath = UtilK::getFsPart( *iterFile, UtilK::FsPath );<br />
pFlightDataHandler->importRawFlightData( strPath );<br />
<br />
DWORD dwWaitStatus = ::WaitForSingleObject( hProcessStopEvent, 1 ); <br />
if ( dwWaitStatus == WAIT_FAILED )<br />
bCancelled = true;<br />
else if ( dwWaitStatus == WAIT_OBJECT_0 )<br />
bCancelled = true;<br />
}<br />
}<br />
catch( CMultiLevelException e )<br />
{<br />
CString strMsg;<br />
strMsg.Format( "importVARFile() failed - error description is %s", e.getUserMessage() );<br />
<br />
TRACE( "> > > > CFileChangeEvent::MultiFileProcessThread() exception < %s >\n", strMsg );<br />
if ( pLogWriter )<br />
pLogWriter->writeEntry( "CFileChangeEvent", CLogWriter::LE_OPERATION_FAILED, strMsg );<br />
}<br />
catch(...)<br />
{<br />
CString strMsg( "importVARFile() failed with unexpected exception" );<br />
TRACE( "> > > > CFileChangeEvent::MultiFileProcessThread() exception < %s >\n", strMsg );<br />
if ( pLogWriter )<br />
pLogWriter->writeEntry( "CVarFileEvent", CLogWriter::LE_OPERATION_FAILED, strMsg );<br />
}<br />
<br />
if ( pFlightDataHandler )<br />
delete pFlightDataHandler;<br />
<br />
CFileChangeEvent::setProcessCompleted();<br />
<br />
TRACE( "> > > > CFileChangeEvent::MultiFileProcessThread() exiting\n" );<br />
<br />
::CoUninitialize();<br />
<br />
if ( hProcessStopEvent )<br />
::CloseHandle( hProcessStopEvent );<br />
<br />
if ( hProcessRespEvent )<br />
{<br />
::SetEvent( hProcessRespEvent );<br />
::CloseHandle( hProcessRespEvent );<br />
}<br />
<br />
::AfxEndThread( 0 );<br />
<br />
return 1;<br />
}<br />
|
|
|
|
|
A couple things I see going on here.
1. You should verify pFlightDataHandler got created before using it.
2. I am assuming that the calls to getProcessStopEvent and getProcessRespEvent actually open a handle, otherwise, when you close them at the end of your thread, you have closed them off for the 'parent' as well.
3. It is not necessary to call AfxEndThread if you are going to exit the thread via its return. Just return the value 0 at end of thread function to accomplish same result.
4. I am assuming that pLogWriter's writeEntry will not throw exceptions, otherwise, you could just flag a problem in your exception handling code and then write to log after leaving the exception.
5. I would consider moving the CoInitialize ahead of your main try block, since the CoUninitialize is already outside of it.
6. If the pFlightDataHandler is a 'risky' object, consider putting its delete in a try/catch block.
7. Why not wait for 0 milliseconds, as per MSDN The function returns if the interval elapses, even if the object's state is nonsignaled. If dwMilliseconds is zero, the function tests the object's state and returns immediately. Then I think it might not even suspend your thread if the system is not busy.
Otherwise, I am not sure why you would have a problem, unless one of your obejcts is bad, as there are a couple other retrieval functions there where the pointers are not verified against NULL.
|
|
|
|
|
I've installed "Visual C++ 2008 feature pack", but the documents couldn't be updated.
The documents are already on www.msdn.com[^], any way to make it local?
|
|
|
|
|