CDC::DrawText
The syntax
int DrawText( const CString& str, LPRECT lpRect, UINT nFormat );
We dont know the width and height of the rectangle where the text to display, so that the lpRect is empty
Then how calculate the text area ?
It is simple,
Eg:
CRect rcText( 0, 0, 0 ,0 );
dc.DrawText( csText, &rcText, DT_CALCRECT );
dc.DrawText( csText, &rcText, DT_CENTER );
The first DrawText fills rcText with required value, ie the hight of the text, width of the text.
Call next DrawText, then the text will display.
The return of the DrawText is the height of the text. But we also have to calculate the width of the text. So the above method is easy to use.
Get Icon of a process
Use ExtractIconEx function to get icon of a process. It will return both small and large icon of the specified process.
::ExtractIconEx( szProcessName, 0, &hSmallIcon, &hLargeIcon, 1 ) ;
You must destroy all icons extracted by ExtractIconEx by calling the DestroyIcon function.
Why this program is not crashing up?
class Test
{
private:
int m_Data;
void Disp( int n)
{
int i = n + 100;
cout << “Data = ” << i;
}
};
int main()
{
Test* t = 0;
t->Disp( 100 );
}
What is the output of this function? Will it crash?
This program outputs Data = 200 Why?
Normally we think program will crash if function call with a null pointer. But if you know the internal working of member function call, it will easy to catch my words.
As you all know, there is only one definition of member function in memory. All the instance of the class uses this memory.
t->Disp( 100 ) will replaced by compiler as Test::Disp( Test* this, int n ) ( Note that every non static member function will have “this” pointer to refer the calling object itself ).
Then this is null pointer and n is 100. Inside the Disp function we just manipulate data that don’t depends the class. So there is no chance for crash.
But if we call member data inside the Disp function, the scene will change, this->m_Data surely crash the program.
Windows Handle
In windows OS, every resource is an “object” identified and referenced by handle of type HANDLE.
In 32 bit machine, it is a 32 bit value. HANDLE is just a typedef of void pointer.
This type is declared in WinNT.h as typedef PVOID HANDLE;
Usually, the HANDLE is wrapped in an instance of a class. CWnd is a good example; it contains HWND which is a handle to a window. Here CWnd brings the object oriented concept. For exapmle to show a window,
pWnd->ShowWindow( SW_SHOW ); this is exactly same as ::ShowWindow( pWnd->m_hWnd, SW_SHoW );
Kernal objects must be manipulated by HANDLES contains:
files, thread, memory,events,mutexes,semaphores,pipes,processes
Hello world!
Welcome to WordPress.com. This is your first post. Edit or delete it and start blogging!
-
Archives
- September 2008 (1)
- August 2008 (4)
- July 2008 (5)
-
Categories
-
RSS
Entries RSS
Comments RSS