|
Hello guys!I've been coding MFC apps for 3 months now,and i recently encountered the situation below:
I have a Dialog window (class CControlPanelDlg) and a picture control object called m_pcTest(of type CStatic).I have created a structure called "Bitmap" that contains the following array : CBitmap Icon[4].I've created 4 bitmap images and loaded them into Icon(Using LoadBitmap(IDB_IMAGE_ID) method).I want to change the image that m_pcTest shows each time i click a Button within the window(using m_pcTest.SetBitmap(Bitmap.Icon[0])).So far so good.The image changes.Then i created a thread,that it's thread function calls another function located inside CControlPanelDlg.cpp,the same function i use to change the image shown in m_pcTest every once i click the button.While in Debug mode,i noticed that when the program jumps inside the function that change images (m_pcTest.SetBitmap(Bitmap.Icon[0])),the variable m_pcTest has the following value:
m_pcTest={CStatic hWnd=???}. When the program passes the line that contains the breakpoint,it throws a nasty Access Violation!I tried calling tha function from within the thread function with different ways,like:
((CControlPanelDlg*)AfxGetApp()->m_pActiveWnd)->ChangeImage();
p_ControlPanelDlg ->ChangeImage();
(p_ControlPanelDlg ---> external pointer to CControlPanelDlg dialog class)
The variable m_pcTest is public.Am i doing something wrong?Did i forget to declare something?Or i declared it in the wrong way?Please help.I know i'm new to MFC,and you probably going to ask yourself "why this young lad bothers himself with threads so early"? The answer is i'm in love with MFC and i've learned so much within those 3 months(mostly Serial Communication,Database projects) and i needed to learn how to change bitmaps while other code was executing.I tried to do this with timers but as long as my code enters a loop,ChangeImage()could not be called until code execution continued beyond the loop.I tried UpdateData(FALSE)from inside the loop,but nothing happend.So i needed a co-process,a thread.I would appreciate it if someone of you code gurus out there could help.Thank GOD that "The Code Project" exists as my homepage...
Lefteris_RG3120
Control Systems & Software Engineer
-- modified at 8:23 Monday 29th August, 2005
|
|
|
|
|
Instead of directly calling ChangeImage from your worker thread, you need to make the CDialog's m_hWnd available to the thread (when you create it) and then use it to post a private message from the worker thread back to the dialog. Use a handler for that message in the CDialog to call ChangeImage.
Hope that helps,
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
char v1[12]= "CodeProject";
char v2[5];
strncpy(v2,v1,sizeof(v2));
AfxMessageBox(v2);
Now what will u get, don't test it in ur IDE.. just hav a luk n tell..
answer this , i'll tell u what i actually need..
Thanks n regards,
V
|
|
|
|
|
here again, i see you don't take care to the trailing null character...
you should have written
strncpy(v2, v1, sizeof(v2)-1);
v2[sizeof(v2) - 1] = '\0';
this way, it will display Code
the other way to use strcpy() and strncpy() properly is to use pure pointers variables :
char v[12] = "CodeProject";
char* pc = NULL;
strcpy(pc, v);
TOXCCT >>> GEII power [toxcct][VisualCalc]
-- modified at 8:36 Monday 29th August, 2005
|
|
|
|
|
I guess, you meant v2[sizeof(v2) - 1] = '\0'; ?
We can do no great things, only small things with great love. - Mother Theresa
|
|
|
|
|
yes, sorry for the mistake...
it's fixed now
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
thatz nice tox.. thank u so much
thanx,
V
|
|
|
|
|
toxcct wrote:
char v[12] = "CodeProject";<br />
char* pc = NULL;<br />
strcpy(pc, v);
Doesn't this lead to a runtime error? Here you try to copy string v to the address NULL...
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
To get "Code" you need a terminating NULL:
char v1[12]= "CodeProject";
char v2[5];
strncpy(v2, v1, sizeof(v2) - 1);
v2[sizeof(v2) - 1] = 0;
Regards
We can do no great things, only small things with great love. - Mother Theresa
|
|
|
|
|
thankx buddy
V
|
|
|
|
|
Hello,
I try to write a program that uses http tunneling. But behind a proxy it won't work. Of course i can get the proxy settings from registry but the username and passowrd aren't stored, so if i want to connect i need to know the username and password. How can i get them?
One more information: the program is in vc++ and the iexplorer must start before it. So the user is authenticated.
Robi75
|
|
|
|
|
your program will have to ask for those 2 infos to the user to store them... (that's what happens for example when you configure other programs for a proxy connection...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Thanks, I thought its possible to get the username and pass somehow at code level but I came to the conclusion that it is impossible after reading related topics on the net.
Thanks anyway,
Rob
|
|
|
|
|
I am using DOC/View facilities.
1. When a make a preview, there is not a preview toolbar; i don't found a mean to print from there, What to do ?
2. When i close my preview windows, the program is broken down, why ? and what to do ?
I learn my self
|
|
|
|
|
I am using Doc/View facilities,
1. When make preview, there is not a preview toolbar where i can print,etc.. . What to do ?
2. When I close my preview windows my program broken down, Why ?
I learn my self
|
|
|
|
|
Please, Write How you are using Preview?
And How you close Preview if there is no toolbar?
|
|
|
|
|
From ClassWizard, I generate my OnFilePrint PreView fonction like below. When i am in this view like i am using DOc/View facility, i clic File/printpreview menu, the preview screen is shown but without preview boxes and when i close, the program broken down
void impression::OnFilePrintPreview()
{
// TODO: Add your command handler code here
CFormView::OnFilePrintPreview();
}
|
|
|
|
|
So I had some problems like yours.
Try to invoke DoPrintPreview in your OnFilePrintPreview.
|
|
|
|
|
From CFormView, DoPrintPreview is unknow fonction. How can I call it.
Would you like to give me an example please
I learn my self
|
|
|
|
|
How can i read a MS word doc file and even content of the table of the file. Or can any one refer any link.
Thanks
Masum
|
|
|
|
|
Hello Friends,
I want to create ODBC DSN dynamically, so I am using SQLConfigDataSource() function. for this reason i had included the odbcinst.h file also. But when tried to execute the program, i am getting a linker error as
unresolved external symbol _SQLConfigDataSource@16.
If i don't include the odbcinst.h file, then getting that SQLConfigDataSource undeclared identifier.
Please help how can i create the DSN dynamically.
Thanks in advance.
Neelesh K J Jain.
|
|
|
|
|
In VC++,does anyone know how to convert a UTF-8 string into a Shift-JIS string? Thanks.
|
|
|
|
|
|
Is there any Win32 or MFC API to retrieve the Available COM ports in a PC.
Thank you
laiju
|
|
|
|
|