|
Try with ShowWindow(SW_HIDE) instead.
Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
|
|
|
|
|
Like someone else said you should use ShowWindow. But, to be precise, it's the WS_VISIBLE style you'd want to remove: ModifyStyle( WS_VISIBLE, 0, 0 );
Joel Lucsy (jjlucsy@ameritech.net)
|
|
|
|
|
I keep receiving an error when i am working with my .rc and resource.h saying that they have been modified outside of visual studio, and asking if i want to reload them.. i am the only person using the software, or editing the files, and it just asked me the same thing and reloaded them a few minutes ago.. i keep getting this error about reloading the resource, what could cause this? i think this may somehow be related to my other main problem i posted last night.
which can be found here:
http://www.codeproject.com/script/comments/forums.asp?forumid=1647&fr=26#xx252677xx[^]
any ideas on either thing? .net is actin real screwy..
-dz
|
|
|
|
|
Chances are it is your AV software getting in the way. This has been a problem long before .NET.
Tim Smith
"Programmers are always surrounded by complexity; we can not avoid it... If our basic tool, the language in which we design and code our programs, is also complicated, the language itself becomes part of the problem rather that part of the solution."
Hoare - 1980 ACM Turing Award Lecture
|
|
|
|
|
welp i've disabled it, but how could this cause the problem? does NAV actually scan .h or .rc files?
thanks for the suggestion, hopefully thats it..
-dz
|
|
|
|
|
I get this in VS.NET occasionally and I don't run AV software... I'll see if I can dupe it.
I'd tell all my friends
But they'd never believe me
They'd think that I'd finally lost it completely.
|
|
|
|
|
I try to scroll a MFC rich edit control to the last line but it seems that i don't understand the LineScroll method's behaviour.
Do you know how to properly use it?
rechi
|
|
|
|
|
Hi,
I have a class
class CTestDlg : public CDialog , public D360::CController
{
which I want to respond to messages like
BEGIN_MESSAGE_MAP(CTestDlg, CDialog)
ON_MESSAGE(OLDA_WM_BUFFER_DONE, OnBufferDone)
END_MESSAGE_MAP()
This worked when the CTestDlg class only inherited from CDialog, but now I get the following compilation error
error C2440: 'type cast' : cannot convert from 'int (__thiscall CTestDlg::*)(unsigned int,long)' to 'long (__thiscall CWnd::*)(unsigned int,long)'
Pointers to members have different representations; cannot cast between them
I don't know much about the D360::CController class, it was supplied with some hardware.
Any suggestions would be appreciated.
Will
|
|
|
|
|
Do you really have to derive from D360::CController? Are there any CController virtual functions you are overriding?
Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
|
|
|
|
|
As far as I can tell, yes I do have to derive from D360::CController - it is doing something I don't understand with ATL to interface with the hardware. The only example code the company sent me used multiple inheritance.
Is this a general problem with ON_MESSAGE and multiple inheritance, or just a strange quirk of the classes I am trying to inherit from?
Will
|
|
|
|
|
Will Woods wrote:
Is this a general problem with ON_MESSAGE and multiple inheritance, or just a strange quirk of the classes I am trying to inherit from?
Well, the MFC wasn't designed with multiple inheritance in mind. This means that you can't have your object derived from CCoolWnd and COtherWnd. OTOH, you can derive your object from CWnd (or CView, CDialog, or any other MFC window class) and non-MFC class[es]. In such case you just have to make sure that MFC class is first in the base classes list. I've used this approach in many MFC-based projects.
So one possible reason for your problems would be CController deriving from some MFC class. Can you have a look on the D360 docs?
Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
|
|
|
|
|
Problem solved - I had declared the callback functions to return bool (as 'required' by some other hardware drivers) - changing the return type to LRESULT fixed the problem.
I wonder why this compiled ok (I just checked it, it does) before I added the second inheritance??
Thanks for your help.
Will
|
|
|
|
|
I am reading a book on the GDI and have noticed that the author deletes an object before reusing it but do not delete it before restoring the 'Old Object'. Why is this? Is it good practise to delete the object anyway, after reselecting the 'Old Object'?
|
|
|
|
|
If object is selected into device context, the call to DeleteObject fails.
So, if you don't select 'old' object or any other existing object of given type, you'll get GDI memory leak.
Your other option is to destroy DC first; this will release all objects. However, this isn't always possible. For example, CView::OnDraw method gets the DC as parameter and you shouldn't destroy this context.
Another solution could be using SaveDC and RestoreDC functions.
Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
|
|
|
|
|
But is there a good reason why the author is not deleting his objects after reselecting the 'OldObject'(by this I mean the windows pen or font that was being used before my program started creating objects)? Does selecting the 'OldObject' automatically delete the existing object? Or is he a nitwit ?;P and I do have to delete any object I create regardless of whether I Reselect the 'OldObject'
|
|
|
|
|
Anonymous wrote:
But is there a good reason why the author is not deleting his objects after reselecting the 'OldObject'
It depends. If he's using MFC, then CPen/CBrush/CFont destructor will call DeleteObject. Since object isn't selected anymore, the DeleteObject will succeed.
He also may be using global variables or class members with lifetime longer than piece of code in which he's using GDI objects
But - if he's running on raw Win32 API and there are no DeleteObject calls for local objects created with CreatePen/Brush/Font etc., then he is a nitwit indeed. BTW: who's 'the author'?
Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
|
|
|
|
|
He is using MFC and since chances that I'm the nitwit is rather big, and he has a great sense of humour, I will refrain from mentioning any names. Thanks for the answer it was just what I needed to know
|
|
|
|
|
I want to use CreateThread() function, and i have created a ThreadFunc. The problem is, that i want this ThreadFunc to be placed within a calss (i don't want it to be a global function).
member function is defined as follows:
<br />
unsigned long __stdcall ThreadFunc(void * Parameter);<br />
And i try to do a conversion to:
<br />
LPTHREAD_START_ROUTINE TS;<br />
Both:
<br />
TS=ThreadFunc;<br />
And:
<br />
TS=CMyDialog::ThreadFunc;<br />
Report as follows:
error C2440: '=' : cannot convert from
'unsigned long (__stdcall CMyDialog::*)(void *)'
to
'unsigned long (__stdcall *)(void *)'
First conversion works when ThreadFunc is not a class member, but both fails when it is a class member.
How to make this conversion?
Railgun is like a Gilette Mach 3 - it does the job with one, easy stroke.
|
|
|
|
|
If you insist on member function, you must make it a static one. Also, if you use CreateThread, you may hit problems with C++ runtime. Use _beginthread[ex]; these functions call CreateThread for you.
Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
|
|
|
|
|
Adding to what Tomasz said, use only the _beginthreadex(do not use _beginthread or CreateThread) or AfxBeginThread in MFC, these 2 functions create the necessary TIB(Thread Information Block) that is necessary to the C/C++ runtime could correctly dispose and control the Thread specific data.
Cheers,
Joao Vaz
And if your dream is to care for your family, to put food on the table, to provide them with an education and a good home, then maybe suffering through an endless, pointless, boring job will seem to have purpose. And you will realize how even a rock can change the world, simply by remaining obstinately stationary. - Shog9
|
|
|
|
|
Thank you for an advise.
Using static function was the key problem. Now it works fine.
By the way - what kind of runtime problems may occur when using CreateThread?
I've been using this one many times, and never had problems with managing threads.
[ CoY0te ]
Railgun is like a Gilette Mach 3 - it does the job with one, easy stroke.
|
|
|
|
|
Check this article for discussion of CreateThread vs AfxBeginThread vs _beginthreadex:
http://www.microsoft.com/msj/defaulttop.asp?page=/msj/archive/S39CD.htm[^]
Heer's an interesting excerpt:
Don't create threads with the C runtime functions beginthread or beginthreadex if the threads will access any MFC objects. The framework uses CWinThread to manage thread-specific data. You should use AfxBeginThread to start your threads (or call the CWinThread constructor and its CreateThread method). CWinThread::CreateThread eventually calls beginthreadex after taking care of some setup and synchronization
Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
|
|
|
|
|
Even while thread functions follow the calling conventions of a standard C function and therfore have to be static functions, it is not impossible to create a thread directly in a member function. The key to do this is utilizing adapter objects, that translate the C-stylish callback into a call to a member function.
This is explained in detail in the article Use member functions for C-style callbacks and threads - a general solution. Using the techiques described there, creating threads becomes real fun:
#include "stdafx.h"
#include "win_adapter.h"
class Test
{
public:
virtual DWORD ThreadStart( LPCTSTR pszName )
{
printf( " Hello, I'm a Thread and my name is: %s\n", pszName );
return 0;
}
};
void main()
{
Test test;
LPCTSTR pszThreadName = "Joe, the funny thread";
HANDLE hThread = win::beginthreadex( &test, &Test::ThreadStart, pszThreadName );
WaitForSingleObject( hThread, INFINITE );
CloseHandle( hThread );
}
Of course this makes live and code a lot nicer, because you don't have to write all those static wrappers including ugly casts and so on. And the best thing is, that all you need to use it is to include one single header file! No CPP file to add to your project, no libs, no interface or class to derive from, no structural dependencies at all.
(Ehm, yes... I am a bit proud about this piece of code )
--
Daniel Lohmann
http://www.losoft.de
(Hey, this page is worth looking! You can find some free and handy NT tools there )
|
|
|
|
|
Daniel Lohmann wrote:
no interface or class to derive from, no structural dependencies at all.
So why Test::ThreadStart is virtual? Please note that I haven't read your article yet. Can you explain in 25 words or less?
Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
|
|
|
|
|
Tomasz Sowinski wrote:
So why Test::ThreadStart is virtual? Please note that I haven't read your article yet. Can you explain in 25 words or less?
Ehm, just to show that it is possible to use even virtual functions as thread starters. However, it does not have to be virtual. It just a member function.
(Oh, sorry, that's about 33 words )
--
Daniel Lohmann
http://www.losoft.de
(Hey, this page is worth looking! You can find some free and handy NT tools there )
|
|
|
|