|
Mark Salsbery wrote: TVN_GETDISPINFO
"Requests that a tree-view control's parent window
provide information needed to display or sort an item."
You shouldn't be inserting items in response to this notification.
You also shouldn't be calling GetSelectedItem().
The TVN_ITEMEXPANDING notification is maybe a better place to insert
the child items.
Thanks a lot,finally i've figure out the problem. Here is my solution
void CMutiTreeCtrl::PopulateTree()
{
TV_INSERTSTRUCT itInsert = {0};
CString strText;
strText = _T("Start");
itInsert.item.pszText = const_cast<LPTSTR>((LPCTSTR)strText);
itInsert.item.state = TVIS_BOLD;
itInsert.item.mask = TVIF_CHILDREN | TVIF_HANDLE | TVIF_TEXT |
TVIF_STATE | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
itInsert.item.stateMask = TVIS_BOLD | TVIS_STATEIMAGEMASK;
itInsert.item.cChildren = I_CHILDRENCALLBACK;
itInsert.hParent = hRoot;
HTREEITEM hItem = this->InsertItem(&itInsert);
UpdateWindow();
}
void CMutiTreeCtrl::OnTvnItemexpanding(NMHDR *pNMHDR, LRESULT *pResult)
{
CWaitCursor curWait;
SetRedraw(FALSE);
LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);
HTREEITEM hItem = pNMTreeView->itemNew.hItem;
HTREEITEM hRemove = this->GetChildItem(hItem);
while(hRemove)
{
ctlTree.DeleteItem(hRemove);
hRemove = this->GetChildItem(hItem);
}
CString strText = _T("This is the Child Item which is dynamiclly inserted");
AddMySubItems(hItem, strText);
SetRedraw(TRUE);
Invalidate();
*pResult = 0;
}
void CMutiTreeCtrl::OnGetdispinfo(NMHDR* pNMHDR, LRESULT* pResult)
{
TV_DISPINFO* pTVDispInfo = (TV_DISPINFO*)pNMHDR;
pTVDispInfo->item.cChildren = 1;
*pResult = 0;
}
HALLELUJAH! Hallelujah! Hallelujah! Hallelujah!
|
|
|
|
|
Hello,
I am writing a BlackJack type program to learn C++/.NET. I'm, trying to raise an event from Shoe Class (DealtCutCard Event) which is used by Dealer Class. Dealer sets a flag and at the apprpriate time raises a DealerShuffles Event which the Shoe Class uses.
This code won't compile, the error is in the Shoe.h:
"improper syntax for specifying event in __hook/__unhook" line 25
"improper syntax for specifying event in __hook/__unhook" line 25
"improper syntax for specifying event in __hook/__unhook" line 25
If I comment out #include "Dealer.h" and the __hook init function this will compile, but now I can only raise events from Shoe it won't recieve events from Dealer.
How can I both call and handle events from between the same two classes?
BTW - note i NEED "Shoe.h" in Dealer because there are functions in Dealer that reference Shoes.
Using .NET 2003
Also, I tried substituting #include "Dealer.h" with class Dealer; as a predeclaration but that didn't work.
Dealer.h
#pragma once
#include "Bettor.h"
#include "Hand.h"
#include "Shoe.h"
#ifndef DEALER_H
# define DEALER_H
[event_source(native)]
[event_receiver(native)]
class Dealer
{
public:
__event void DealerShuffles(void);
Dealer(Shoe*);
void InitShoeEvents(Shoe* pSource){
__hook(&Shoe::DealtCutCard, pSource, &Dealer::ReadyToDeal);};
};
#endif
Shoe.h
#pragma once
#ifndef SHOE_H
# define SHOE_H
#include "Dealer.h"
[event_receiver(native)]
[event_source(native)]
class Shoe
{
public:
void Shuffle(void);
void InitDealEvents(Dealer* pSource){
__hook(&Dealer::DealerShuffles, pSource, &Shoe::Shuffle);};
__event void DealtCutCard(void);
};
#endif
|
|
|
|
|
I'm currently coding a server and accepting incoming connections using the CAsyncSocket class under Vista.
Things are working fine but now I would like to be able to resolve the dotted IP address CAsyncSocket::GetPeerName() returns into a nice human readable name so users can easily identify connections rather than remembering strings of numbers (dotted ip's). Can someone point me to the API which will help me do that. Spent a while searching but everything talks about going the other way, that is name->dotted ip, not dotted ip->name.
Thanks!
|
|
|
|
|
jbem wrote: ...I would like to be able to resolve the dotted IP address CAsyncSocket::GetPeerName() returns into a nice human readable name...
Which of the two GetPeerName() methods are you using? Have you tried gethostbyaddr() ?
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
Thanks I missed the gethostbyaddr(). I used getnameinfo() since gethostbyaddr is deprecated and it worked out fine. Thanks for your help!
|
|
|
|
|
hi to all
i want to store some string datas in a CString or similar variable
and i need a int variable also
this is a global hook dll and i want to update this variables at runtime
and all applications should access to this variables which load this dll
simly : i can say this dll will be a bridge between applications
which load this dll
i have found the following sample but i could not
write a working one from it
application exits with crash always
note: the following sample copied from a C project
and my dll is a MFC/C++ dll
thank you
#pragma data_seg(".shared")
#pragma comment(linker, "/section:.shared,rws")
HHOOK g_hHook = 0;
HWND g_hwndNotify = 0;
BOOL g_FirstInstance = FALSE;
UINT g_nButtonCmdId[MAX_TITLE_BUTTONS] = { 0 };
UINT g_nButtonResId[MAX_TITLE_BUTTONS] = { 0 };
int g_nButtonCount = 0;
WCHAR g_szBlackList[MAX_BLACKLIST][64] = { 1 };
LONG g_nBlackListLen = 0;
#pragma data_seg()
|
|
|
|
|
I have code which worked under VC6 and now failing under VS2005 (additional change was moving portions to a dll from a lib, but pretty sure this not affecting things)
I have an out-of-process COM server, which constructs a CWnd in the constructor of the CComCoClass templated object. The intent is for this CWnd to receive messages posted from a thread (created in a linked dll) to track external state. (why is it a CWnd? because the primary recipient of the dll's state messages is a windows app)
The CWnd seems to construct fine, but the thread goes quiescent. I don't think that the thread has a message loop.
Question: how to I get the CWnd into a messagepump? a) Can I change the CWnd creation? b) Can I force the linkage of the Cwnd into the PreTranslate tree? c) Do I have to punt the CWnd and go to a GUI thread (which seems to be effectively duplicating much of what just creating a CWnd should do for me, and forces me to add to the dll a parallel notification list)?
Messages sent from the posting dll thread can be received at the COM object's message loop (via PostThreadMessage), so I'm confident the switch from VC6 to VS2005 is the culprit not the change from LIB to DLL, especially since PostMessage works in the primary application.
class ATL_NO_VTABLE CServer:
public CComObjectRootEx<ccomsinglethreadmodel>,
public CComCoClass<cserver,>,
public IDispatchImpl<iserver,>
{
...
class wndHook : public CWnd{
public:
wndHook(){}
afx_msg LPARAM Message(WPARAM, LPARAM);
DECLARE_MESSAGE_MAP()
}*pWnd;
}
CServer::CServer(){
...
pWnd = new wndHook();
if (!pWnd->CreateEx(0, NULL, _T("HOOK"), WS_CHILD,
CRect(0,0,0,0), CWnd::GetDesktopWindow(), 0, NULL)){
TRACE0("Failed to create hook window\n");
}
GetDLL()->AddToNotificationList(ENUM_VAL, pWnd);
}
BEGIN_MESSAGE_MAP(CServer::wndHook, CWnd)
ON_MESSAGE(WM_APP, CServer::wndHook::Message)
END_MESSAGE_MAP()
void DLL::Post(WORD mID, long val)
{
...
::PostMessage([element in list]->GetSafeHwnd(), WM_APP, mID, val);
}</ccomsinglethreadmodel>
|
|
|
|
|
|
First of all, this sounds like a Design and Architecture question so the VC++/MFC forum probably isn't the best place to get the answer you require.
Second of all, what I suggest is that you load the ActiveX controls as they are needed, as as you state it could all become a big mess, and this will significantly help performance when the control needs to be loaded.
As you have 20 of these controls then this sounds like a pretty good model, however have you taken the client's screen resolution into account? It depends on the size of the controls, but if you plan to place 10 of these on the screen in two rows then the page may not display as you want it to.
Regards,
--Perspx
"The Blue Screen of Death, also known as The Blue Screen of Doom, the "Blue Screen of Fun", "Phatul Exception: The WRECKening" and "Windows Vista", is a multi award-winning game first developed in 1995 by Microsoft" - Uncyclopedia
Introduction to Object-Oriented JavaScript
|
|
|
|
|
Thanks, PerspX, for your prompt reply and comments/suggestion. I'm moving from here. I did remove the message but i guess I can't remove the entire thread...
|
|
|
|
|
Regarding design - layout, have you considered grouping the controls and putting individual groups on Tab-ed pages (CPropertySheet/CPropertyPage)?
Regarding usage/active controls - as a suggestion, you might want a common look for all "screens" by having individual controls occupy same position per each "screen". You can assign variables to the controls, access the position of the controls (with CRect() and ClientToScreen() type functions), and then swap/enable/show controls using these reference points.
I recently used a collapse/expand class that I got from CP - it is rather slick and uses reference points on a dialog to show only upper/full dialog dimensions when needed (Michael Walz, Expanding and Collapsing dialogs)
|
|
|
|
|
Thanks very much for your detailed reply, john. I can't use tabbed pages because, you see, I'm simulating a control panel for a small factory with LED's, switches, etc, plus some custom controls so I need to offer the whole view to the user.
It's a clever idea that you've given, proposing to use the same dialog boxes but swapping controls. But, unfortunately, the layout of the main screen is such that it's not possible to have a common look for all the smaller screens. I'm stuck with having ten different dialog boxes.
My next question is, how can I be notified of mouse pointer position and state of the mouse buttons when moving on a bitmap? All I want to do is to highlight the square which the mouse is currently in, and be notified when and where the user clicks.
[SOLVED] Got my answer from another thread... Visual C++ ain't that hard folks
Thanks again,
Henry.
|
|
|
|
|
in C++ if i have the following string literal:
"Hello"
The compiler represents this as
{'H', 'e', 'l', 'l', 'o', '\0'}
If I were to expand that out to wide chars, for the special case of a string literal in code, I do not need to call MultiByteToWideChar do I? I can just insert 0s to fill in the gap, so "Hello" becomes:
{'H', '\0', 'e', '\0', 'l', '\0', 'l', '\0', 'o', '\0', '\0', '\0'}
I ask this because with Visual C++ wchar_t is always (so far as I know) a 16bit character, which works very nicely with the rest of the OS since it's Unicode support is built with 16bit code points/characters. On other systems (specifically unix based ones) wchar_t is frequently a 32 bit value which is NOT what I want when dealing with string support. This causes translation issues when you write L"Hello" on those systems, and if you simply leave it as "Hello" (ansi), then the string thinks it needs to translate from ascii to unicode, which is big performance hit. So for string literals I thought I might make a simple class that just expands the ansi string literal to a 16 bit version. Something like :
String s = SL("Hello");
Where String is a unicode UTF16 based string class, and "SL" is a StringLiteral class that just expands out the string literal.
Does this make any sense, or have I twisted my head into a moebius strip over nothing?
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
Save an Orange - Use the VCF!
VCF Blog
|
|
|
|
|
Yeah, if the compiler has no built-in way of representing a string of 16-bit quantities, then you'd need a class to handle that conversion for you.
You could also do:
unsigned char str[] = {'H', '\0', 'e', '\0', 'l', '\0', 'l', '\0', 'o', '\0', '\0', '\0'}; but that's a whole lot of typing and the SL("hello") version is far easier to read.
|
|
|
|
|
|
i have a program to connect the system with mobile via bluetooth serial connection and when it comes to read method it just stops.
and the read methos is
<br />
bool ReadPort()<br />
{<br />
long int dwSize = 0;<br />
bool hResult = false;<br />
std::string sb = "";<br />
DWORD dwEventMask;<br />
<br />
if(!SetCommMask(hComm, EV_RXCHAR)) <br />
{ <br />
return hResult;<br />
}<br />
<br />
if(WaitCommEvent(hComm, &dwEventMask, NULL)) <br />
{<br />
char szBuf[1024];<br />
DWORD dwIncommingReadSize;<br />
<br />
do<br />
{<br />
if(ReadFile(hComm, &szBuf, 1024, &dwIncommingReadSize, NULL) != 0)<br />
{<br />
if(dwIncommingReadSize > 0)<br />
{<br />
dwSize += dwIncommingReadSize;<br />
sb.append(szBuf);<br />
}<br />
hResult = true;<br />
}<br />
<br />
else<br />
{<br />
unsigned long error = ::GetLastError();<br />
hResult = false;<br />
printf("the error while reading error is %dl\n", error);<br />
break;<br />
}<br />
} while(dwIncommingReadSize > 0);<br />
<br />
*readData = new char[dwSize];<br />
strcpy(*readData, sb.c_str());<br />
return hResult;<br />
}<br />
else<br />
{<br />
return hResult;<br />
}<br />
<br />
}<br />
the program just goes to wait mode in the WaitCommEvent function, even when i send a file via bluetooth from my mobile it does'nt reads and while iam sending the file the bluetooth pops the message that PIM transfer is happining, how to send file serial so that my read function should read the data and store in a file......
|
|
|
|
|
Hi,
I am developing a VC++ 6 (MFC) project in which i need to print reports with the data from sqlserver.
As a first go, I taught of using CrystalReprts. I had found many C++/VC++ samples on how to display a existing report on the dialog, but i am not able to find any C++/VC++ samples on how to print the report by using the data from sql server.
If any one has a sample or document, Please share with me.
Thanks,
Krish
|
|
|
|
|
CrystalReports comes with a number of useful functions to deal with reports. Try to search help on it. Although I did some reports in VS2003 and 2008, I'm sure there is such a possibility in VC++6 provided you have CR properly installed.
|
|
|
|
|
Hi All,
I am using a thread to do a work that is to write a file from a device. After the writing reaches to 100 MB I want to close the window and stop the thread. Stopping thread seems to be working but the window is not closed and it is showing error sometimes. But while using a button event the same code works.
void TestDlg::CloseRecord()
{
m_staGradient12.SetWindowTextA("Status:Stopped");
if(hRecording)
{
SuspendThread(hRecording);
DWORD lpExitCode;
GetExitCodeThread(hRecording,&lpExitCode);
TerminateThread(hRecording,lpExitCode);
CloseHandle(hRecording);
CloseHandle(file_rec);
hRecording = NULL;
file_rec = NULL;
OnCancel();
}
}
DWORD WINAPI Recording(LPVOID pParam)
{
TestDlg* pTSRecording = (TestDlg*)pParam;
fptr1 = fopen(def_filename,"w");
while(::WaitForSingleObject(pTSRecording->file_rec,0)==WAIT_TIMEOUT)
{
pTSRecording->ReceiveData(pbuff);
fwrite(pbuff,1,sizeof(pbuff),fptr1);
CFile file(def_filename,CFile::shareDenyNone|CFile::modeRead);
int x = file.GetLength();
file.Close();
if(x>=a)
{
fclose(fptr1);
a=0;
pTSRecording->CloseDevice();
break;
}
}
pTSRecording->CloseRecord();
return 0;
}
|
|
|
|
|
bhanu_8509 wrote: CFile file(def_filename,CFile::shareDenyNone|CFile::modeRead);
int x = file.GetLength();//for getting the length of the file after every succesive write
file.Close();
Doing this just to get the file's size is awfully expensive in terms of disk I/O. Why not just keep track of how much data is written, like:
x += fwrite(pbuff, 1, sizeof(pbuff), fptr1);
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
Why are you using TerminateThread when you already appear to have a signalling mechanism in place with pTSRecording->file_rec ? To quote MSDN:
TerminateThread is a dangerous function that should only be used in the most extreme cases. You should call TerminateThread only if you know exactly what the target thread is doing, and you control all of the code that the target thread could possibly be running at the time of the termination. For example, TerminateThread can result in the following problems:
If the target thread owns a critical section, the critical section will not be released.
If the target thread is allocating memory from the heap, the heap lock will not be released.
If the target thread is executing certain kernel32 calls when it is terminated, the kernel32 state for the thread's process could be inconsistent.
If the target thread is manipulating the global state of a shared DLL, the state of the DLL could be destroyed, affecting other users of the DLL.
Since you have an event already and your thread's while loop is testing the event's state, simply signal the event in your CloseRecord function and then WaitForSingleObject (hRecording) . This will neatly and completely and correctly shut down your thread. TerminateThread can mess up a system so much, it could be the reason your window won't close since the window and thread are interacting with each other.
Judy
|
|
|
|
|
Thanks for your advice Judy.
JudyL_FL wrote: Since you have an event already and your thread's while loop is testing the event's state, simply signal the event in your CloseRecord function and then WaitForSingleObject (hRecording). This will neatly and completely and correctly shut down your thread
Please kindly tell me how to proceed the above. I am new to threads. Please...
|
|
|
|
|
|
In addition to David's and JudyL_FL's replies...
bhanu_8509 wrote:
OnCancel();
I'm surprised you even get that far...
You probably have more than one thread started so the first one is able to suspend the second and continue, or something like that.
You're calling CloseRecord() inside the context of your thread and the first thing you do is suspend the thread.
The thread stops its execution right there and cannot continue if the handle provided is the one of the thread and it looks like you believe it is.
If you manage to get further you kill the thread inside the context of your thread by calling TerminateThread() , which is always a bad call.
And so on...
bhanu_8509 wrote:
while(::WaitForSingleObject(pTSRecording->file_rec,0)==WAIT_TIMEOUT)
This doesn't make any sense at all. This assumes the pTSRecording->file_rec is a valid handle, otherwise you'll get WAIT_FAILED as return value and exit the while-loop.
If it is a valid handle you check whether the handle is in a signalled state and if it isn't you continue immediately. It would be the same to have while(bContinue) instead, where bContinue would be a volatile declared boolean set to false when the thread should stop.
Think real hard whether you need a worker thread at all.
Consider overlapped I/O.
If you still think you need a secondary thread, read this[^].
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Hi all,
I have any string in given format:: "string1-string2 string3"
i want to fetch string1 that is comes before sign "-",so please tell me how can i do this?
is solve when i use findstring function.
please help me.
if possible please explain with example.
thanks in advance.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|