|
Honnestly, I would advise you not to write a macro for this. In general, using macro (in this particular case) makes the code harder to read. Here, it doesn't really have any additional value (except that you don't have to type the assignment).
Anyway, if you really want to do something like that, the macro would be:
#define DELETE(ptr) delete ptr; ptr = NULL;
|
|
|
|
|
Thanks a lot.
But why should not write a macro in this case,well I have read on Net also that we should not write a Macro for deleting.But I did'nt come accros any good reason.Will you please provide me one.
|
|
|
|
|
Because macros can have unforeseen consequences - consider this:
#define DELETE(ptr) delete ptr; ptr = NULL;
if (myPtr->DeleteMe()) DELETE(myPtr);
That's translated by the pre-processor to
if (myPtr->DeleteMe()) delete myPtr; myPtr = NULL;;
So myPtr will be set to NULL even if it shouldn't be deleted...
There are ways around that, but I'd rather write this:
template<class _Ty>
inline void Delete(_Ty*& ptr)
{
delete ptr;
ptr = 0;
}
because it's not messing around with the program text - it doesn't rely on pre-processor magic.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
like this?
#define MyDelete(_ptr) if (_ptr) {delete _ptr; _ptr=NULL;}
|
|
|
|
|
hi guys i and bard...i want to do a braille programming using visual C++..
firstly...the key that input was S,D,F,J,K,L...how can i set the input from keyboard...
example like> if i push the input from keyboard letter SDF is for image 1, S for image 2,SDFJKL for image 3 or etc...
example>the sentences was
'saya suka makan'
s=image 1
a=image 2
y=image 3
a=image 1
s=image1
u=image 4
k=image 5
a=image 2
m=image7
a=image 2
k=image 5
a=image 2
n=image 8
display look like,
image 1,image2,image3,image1 ,image 0,image1,image 4,image5,image6,image0,image7,image2,image5,image2,image8
*image 0 for the space.
i wanted to put just 20 image on row...every time finish, i can reset the image...
please guys help me! email me..hightemperature@yahoo.com
|
|
|
|
|
mr bard2 wrote: i want to do a braille programming using visual C++..
As far as I know, Braille is for blind people. So, replacing the text with images won't solve anything.
Anyway, your question is really vague because we don't know anything of your project: are you using MFC ? Where do you want to display those figures ? Directly on the dialog, in a specific control, ... ?
|
|
|
|
|
i wanted the display on the screen like this...
http://lookpic.com/i/990/Q8s8GvYz.jpeg
could every help me...please...
|
|
|
|
|
Are you wanting to paint bitmaps onto the screen or will the program create the image dynamically? If the former then just use the BitMap functions to load and display each image on the screen as required. If the latter then there will be some more code required to calculate where to paint your dots. In either case there are many tutorials on CP about displaying/creating images to the screen.
|
|
|
|
|
Hello all..
I'm making an application which terminate other processes in different way, i.e using TerminateProcess, WM_CLOSE, WM_QUIT, SC_CLOSE.
Now i'm able to terminate process in all the way, But i need bit explanation in WM_CLOSE, WM_QUIT and SC_CLOSE.. How exactly it closes other process?? I believe there are two conditions which need to be fulfilled.
1> The target process has at least one window.
2> The target process doesn't handle the WM_CLOSE, WM_QUIT, SC_CLOSE message.
So i'm doing this to enumerates all top level windows, In LPARAM i'm passing the pid of the target process..
EnumWindows((WNDENUMPROC)Enum_Terminate_Process, (LPARAM) aiPID[i]);
And in Enum_Terminate_Process, I'm doing something like this..
BOOL CALLBACK Enum_Terminate_Process(HWND hWnd, LPARAM lParam)
{
DWORD dwID;
GetWindowThreadProcessId(hWnd, &dwID);
if(dwID == (DWORD)lParam)
{
char Title[MAX_PATH];
Title[0] = 0;
GetWindowText(hWnd, Title, sizeof(Title));
if(IsWindowEnabled(hWnd) && Title[0]!= 0 && Proc_Argument[0]!= 0)
{
if(strcmp(Proc_Argument , "-wmc") == 0)
SendMessage(hWnd, WM_CLOSE, 0, 0 );
else if(strcmp(Proc_Argument , "-wmq") == 0)
PostMessage(hWnd, WM_QUIT, 0, 0);
else if(strcmp(Proc_Argument, "-scl") == 0)
PostMessage(hWnd, WM_SYSCOMMAND,SC_CLOSE,0);
else
MessageBox(NULL,"Invalid Arguments", "Error", MB_OK);
}
}
return TRUE;
}
So i need to know whether i'm doing right?
Thanks All..
modified on Monday, September 7, 2009 4:39 AM
|
|
|
|
|
gothic_coder wrote: So i need to know whether i'm doing right?
The above looks fine, so yes you are doing it right. However, it is up to the receiving process to decide how it handles these messages, so you need to check that those processes will terminate correctly on receipt of whichever message they are sent.
|
|
|
|
|
Alright.. Thanks for confirming
|
|
|
|
|
No, it's wrong, ... in particular WM_CLOSE.
|
|
|
|
|
|
Check his post history. He does not have the capability to explain, only criticize.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hi all,
i m using SDI application,
i m using worker thread for loading records in ListControl.
here i m using a modeless dialog box ,i create and display the modeless dialog before Starting the thread and hide it at end of thread.
I m start thread at OnInitialUpdate function of Formview.
my problem is that when modelss dialog box hide now the main window lost the focus.
i m use SetFocus function but its not working.
void CFormView::OnInitialUpdate()
{
CMainFrame *pMainFrame=(CMainFrame*)AfxGetMainWnd();
if(Main_View->m_pmodeless)
{
m_pmodeless->SetForegroundWindow();
m_pmodeless->ShowWindow(SW_SHOW);
pMainFrame->EnableWindow(0);
m_pmodeless->EnableWindow(0);
}
else
{
m_pmodeless = new CModeless_dlg
m_pmodeless->Create(CModeless_dlg::IDD,0);
m_pmodeless->ShowWindow(SW_SHOW);
pMainFrame->EnableWindow(0);
m_pmodeless->EnableWindow(0);
}
AfxBeginThread(Initial_Thread,NULL,THREAD_PRIORITY_HIGHEST,0,0,NULL);
}
m_pmodeless->ShowWindow(SW_HIDE);
CMainFrame *pMainFrame=(CMainFrame*)AfxGetMainWnd();
pMainFrame->EnableWindow(1);
pMainFrame->SetFocus();
please tell me how can i setfocus on main window of sdi.
thanks in advance.
To accomplish great things, we must not only act, but also dream;
not only plan, but also believe.
|
|
|
|
|
"_$h@nky_" wrote: i m using worker thread for loading records in ListControl.
That's probably a bad idea to start with - you should only access windows from a UI thread, unless you're posting messages to the window from hte non-UI thread.
And that's also the basic reason why the SetFocus in the thread function isn't effective - as the documentation[^] says:
The window must be attached to the calling thread's message queue
Try posting a custom message to the main window at the end of the thread, indicating that the thread is finished. The main frame can handle that by dismissing the progress dialog and retrieving the focus.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Which is the right way to do and why?
TCHAR *gClassName = 0;
bool CreateCabinetMainWindow(const TCHAR* classname)
{
DeleteCabinetMainWindow( );
gClassName = (TCHAR*)classname;
}
OR
const TCHAR *gClassName = 0;
bool CreateCabinetMainWindow(const TCHAR* classname)
{
DeleteCabinetMainWindow( );
gClassName = classname;
}
Thanks in advance,
Nandu
|
|
|
|
|
Second option makes more sense.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Second one. If you're declaring gClassName as mutable, then assigning an immutable string pointer to it is a bad idea. If you try to write to gClassName, then you could easily get an access violation if you'd called CreateCabinetMainWindow like this:
if (CreateCabinetMainWindow(_T("MyClass"))) { .... };
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
|
I have an EXE file and i want to list all the strings from the String Table of the EXE
The exe is the compiled CPP file like the one present in the Debug folder
How do i display all the strings that are present??
|
|
|
|
|
If it's just the string table you're after, load the exe into Visual Studio - you can view its resources there.
Otherwise, a nice utility called strings[^] will show you all the strings embedded in an executable.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Actually we have to write our code which will take an EXE as input and display all the strings present in that EXE.
What are the ways to do that?
|
|
|
|
|
If it's string tables in the resources, then EnumResourceNames[^] can tell you all the string tables present in a module, FindResource[^] can get you handles for those resources, which you can then access using LoadResource[^] and LockResource[^].
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thanks for the reply
The documentation of MSDN about FindResource is not that clear,so am having problem in that.
What is the parameter lpName ([in] Specifies the name of the resource) ?
|
|
|
|
|