|
Hi Dave,
Thank-you for your response. I think I'm getting it.
zdisplay() is clearly a worker thread since it is so-started by AfxBeginThread().
I assumed (badly) that since OnUpdateDialog() function (the intensive processing) was started from a message sent BY the zdisplay() function that it too was of the 'worker' variety.
Clearly you are correct, but what tells you that OnUpdateDialog() is considered a 'main' thread rather than a 'worker' thread?
Sorry for all the dumb questions.
Thank-you very much,
Robert
|
|
|
|
|
Windows are associated with the thread in which they are created. When you send or post a message to a window handle, it will be processed by the thread that owns that window (which may be the same thread). In addition, since worker threads do not have a message pump, they cannot process any messages.
Take a look through some of the thread articles, particularly the ones talking about worker threads vs. user interface threads if you are interested.
Dave
|
|
|
|
|
Hi Dave,
Thanks again. I wrote a quick little test program to experiment with this and it works just like you indicated - no surprize.
I found PostMessage() in the Win32 SDK and will implement that as well. It looks like it takes the same parameters.
Thanks for helping me through this. I'm an old C warhorse and C++ and MFC are new to me.
|
|
|
|
|
|
who used visual basic knows that it has a holly function :
DoEvents()
it processes events while working !
int i=0;
while(1)
{
i++;
DoEvents();
}
this is the C++ version :
bool DoEvents()
{
MSG msg;
while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) == TRUE)
{
if (GetMessage(&msg, NULL, 0, 0) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
return TRUE;
}
}
return 0;
}
//rate me or hate me
I am the mighty keeper of the book on knowledge . Contact me to get your copy .
|
|
|
|
|
Thanks TomKat!
|
|
|
|
|
Ok, it may seem like a stupid question, but i feel like i'm going nutts here.
I bought this book on Java, and i was reading some till i came accross this table with data types and their size in bits. Now, assuming (since Java seems to be derived from C) the main data types are the same as in C, a char would be 8 bits right? 1 byte... It's what i always thought though, cause when i open a file in my HEX editor i get one byte per character in the ASCII table.
But what do i see in my (btw reasonably cheap) book??? A char is 16 bits or 2 bytes in size!!!!!!!?????
Am i going nutts (which is most probable), is this a printing error in my book, or does the fact that it says UNICODE behind the char in my book have something to do with it (which i doubt)..?
WHAT IS THE SIZE OF A CHAR IN C IN BYTES OR BITS??? I seek redemption from this insanity erghh i'll quit now lol
Kuniva
--------------------------------------------
|
|
|
|
|
An ASCII character is 8 bits or 1 byte long.
Kuphryn
|
|
|
|
|
WOOHO THANK U SOOOO MUCH!
Kuniva
--------------------------------------------
|
|
|
|
|
A char variable in Java is 2 bytes. A char in variable C/C++ is one byte. This is related to the character encodings the languages use. Unicode characters are 2 bytes each.
--Mike--
THERE IS NO THERE IS NO BUT THERE IS
MAGIC PIXIE DUST BUSINESS GENIE CODE PROJECT
Homepage | RightClick-Encrypt | 1ClickPicGrabber
|
|
|
|
|
A CHAR is 8 bits SIGNED.
If you need to handle binary data, use UNSIGNED CHAR.
|
|
|
|
|
http://www.codeproject.com/string/CPPStringGuide1.asp -Give s an comprehensive overview of strings ,character
|
|
|
|
|
There's no iterator for stack ( as far as MSDN is concerned )
Is there a way to traverse the stack ?
Thanks.
Max.
Maximilien Lincourt
For success one must aquire one's self
|
|
|
|
|
One solution is a while loop and check the status of the stack via empty().
Kuphryn
|
|
|
|
|
Maximilien wrote:
There's no iterator for stack
That's right. Because you're only allowed to look at the top element.
If you *must* use a stack (rather than a list or deque) and *must* traverse it, you can always derive from std::stack and then access the underlying data container (yuk )
You should save yourself and your company years of grief by shooting yourself through the head immediately. Believe me, in the long run it'll turn out better for everyone. - Tyto (at arstechnica)
Awasu 1.0[^]: A free RSS reader with support for Code Project.
|
|
|
|
|
ok.. i am getting closer and closer to almost having something that almost works..
i have an example of a function that interacts with vb, and it modifies a variable that comes in by making it backwards before returning.. all i am trying to do is be able to set the value of the variable before returning.. the variable is of type BSTR, and i am getting nowhere.. here is an example of modifying the string which works:
void __stdcall FindBankName(LPSTR strFilename, LPSTR strRoutingNumber, BSTR a)
{
int i, iLen;
BSTR b;
LPSTR pA, pB;
iLen = lstrlen( (LPCSTR) a );
b = SysAllocStringLen( NULL, iLen );
pA = (LPSTR)a;
pB = (LPSTR)b + iLen -1;
for ( i = 0; i < iLen; i++ )
*pB-- = *pA++;
pA = (LPSTR)a;
pB = (LPSTR)b;
for ( i = 0; i < iLen; i++ )
*pA++ = *pB++;
SysFreeString( b );
} here is an example of one of the many many unsuccessful tries which doesn't work:
void __stdcall FindBankName(LPSTR strFilename, LPSTR strRoutingNumber, BSTR a)
{
a = SysAllocString ( "Woop Howdi Bob!" );
}
my main purpose here is to be able to set a variable of type BSTR equal to a character array i have..
like:
char szBuffer[60];
thanks a ton fer everyones help..
still a newb.. cut me some slack :P
-dz
|
|
|
|
|
void __stdcall FindBankName(LPSTR strFilename, LPSTR strRoutingNumber, BSTR a){
a = SysAllocString ( "Woop Howdi Bob!" );
}
First, it's wrong and going to leak memory.
void __stdcall FindBankName(LPSTR strFilename, LPSTR strRoutingNumber, BSTR *a)
{
*a = SysAllocString ( "Woop Howdi Bob!" );
}
|
|
|
|
|
I am not sure, but according to VC++ source codes, BSTR is actualy an LPWSTR which is by turn a pointer to WCHAR or wide charater type that's used in UNICODE. That means you may use wide charater functions to set its value.
For example, to set the BSTR a paramter that you have in your code we may do this:
int len = wcslen(a);
if(len >= wcslen(L"Testing"))
wcscpy(a, L"Testing");
This code is to change an existing BSTR variable but if you are making new one then SysAllocString() should be used.
if your string is ANSI then you must convert it first to UNICODE. If you are using VC++7 then the easiest way is to use CStringW, for e.g.:
char buff[] = "Test";
CStringW strw(buff);
wcscpy(a, strw);
Otherwise you should use MultiByteToWideChar() to convert.
|
|
|
|
|
Hi all. I've created a list view with a bunch of columns. My problem is that when the view comes up, the columns aren't expanded so you can see and/or read what they are. Here's how I'm inserting the columns:
pcol.mask = LVCF_TEXT;
pcol.fmt = LVCFMT_CENTER;
pcol.cx = strlen(column_header[index]) * CHAR_PIXEL_WIDTH;
pcol.pszText = column_header[index];
pcol.cchTextMax = COLUMN_WIDTH;
ListView_InsertColumn(hListView,0,&pcol);
And here is how I am inserting into the list view:
// Insert the name into the list
lvItemList.mask = LVIF_TEXT;
lvItemList.iItem = itemIndex;
lvItemList.iSubItem = 0;
lvItemList.pszText = app;
lvItemList.cchTextMax = 128;
// Insert the item into the list
ListView_InsertItem(hListView,&lvItemList);
Nothing fancy going on here just using the normal LV_ITEM and LVITEM structures, and there's no extra funny stuff going into the LPARAM. So my question is what am I doing wrong here? I thought that by specifying the pcol.cx value to the width that I wanted, the width would be automatically setup for me, but that does not seem to be the case.
Any comments are appreciated.
Thanks!
|
|
|
|
|
i've never used that method of creating lists.. but ive used bunches of them and have always specified the widths of the columns.. here is how i do mine.. dunno if it'll help er not..
void CTopView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
ListView_SetExtendedListViewStyleEx(m_lstReportList.GetSafeHwnd(), NULL, LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES);
m_lstReportList.InsertColumn(0, "Form", LVCFMT_LEFT, 55);
m_lstReportList.InsertColumn(1, "Description", LVCFMT_LEFT, 238);
m_lstReportList.InsertColumn(2, "Period", LVCFMT_LEFT, 70);
}
still a newb.. cut me some slack :P
-dz
|
|
|
|
|
dazinith wrote:
i've never used that method of creating lists.. but ive used bunches of them and have always specified the widths of the columns.. here is how i do mine.. dunno if it'll help er not..
Yeah, I've used that method in other applications and it works like a charm, but this application is written in Win32, not MFC.
thanks though.
Gotta work with what ya got in this case. Anyone else have a suggestions?
|
|
|
|
|
Actually,
Your replay gave me an idea. I checked the MFC code realizing that MFC is just an OO implementation of Win32, and Looked into the InsertColumn. That told me everything I needed to know, which happened to be me forgetting to add the LVCF_WIDTH to the item mask. that took care of my problem.
Thanks!
|
|
|
|
|
I don't know if I understand your question correctly. You want to set the width of the columns, so that the column text prefectly fits in? You could try GetTextExtentPoint32 to set the width directly to the width of your string.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
I have a Formview class and I'm trying to display a message box when the user hits the X to close the form. If I do the processing in OnDestroy, the message box doesn't show up until after the form has closed.
How can I show this messagebox before the form goes away? I tried to catch a WM_CLOSE or WM_DESTROY message with PreTranslateMessage, but neither seem to work.
|
|
|
|
|
Interesting. Add some breakpoints in OnClose(). What gets called when you exit the program?
Kuphryn
|
|
|
|