sham_ibmgs
asked on
wndclass and registerclass()
Hello
In the following code, registerclass(wndclass) is called, what exactly are we doing in this call conceptually? am new to GUI application!!!!!!!!!
typedef struct tagAPPINFO {
INT iVersion;
INT iFiller;
HWND hAppInst;
INT iAppType;
HWND hWndFrame;
HWND hWndMDIClient;
HWND hWndToolbar;
HWND hWndStatbar;
UINT uMemBlocks;
UINT uMemBlockSize;
char szAppName [MAXOBJNAME + 2];
char szFileName [FILENAME_LENGTH + 2];
char szHelpFile [PATHNAME_LENGTH + 2];
char szPathName [PATHNAME_LENGTH + 2];
BOOL bDeltaMode;
char szSysPathName[PATHNAME_LEN GTH + 2];
} APPINFO;
int WINAPI TNGMain (LPSTR lpszCmdLine, ULONG TNGContext, int nCmdShow, HWND hParent)
{
/* clear application information structure */
memset (&appInfo, '\0', sizeof (APPINFO));
/* save instance handle in structure */
hAPPINST = hResourceModule;
hWndParent = hParent;
/* set other application information in structure */
appInfo.iVersion = iVERSION;
appInfo.uMemBlocks = NUMMEMBLOCKS;
appInfo.uMemBlockSize = MEMBLOCKSIZE;
strncpy(appInfo.szAppName, szAPPNAME, MAXOBJNAME);
strcpy(appInfo.szFileName, szFILENAME);
strcpy(appInfo.szHelpFile, sz2DHELPFILE);
/* register window classes if this is the first instance */
if (!RegisterClasses (hAPPINST))
return FALSE;
.
.
.
}
static BOOL PASCAL RegisterClasses (hInstance)
HANDLE hInstance;
{
WNDCLASS wndclass;
SetFunctionName (RegisterClasses);
/* register class for frame window */
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = GRFFrameWndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon (hInstance, "GrafBASEIcon");
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = appInfo.szFileName;
if (!RegisterClass (&wndclass))
return FALSE;
/* register class for MDI child windows */
/* wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS; */
wndclass.style = CS_DBLCLKS;
wndclass.lpfnWndProc = GRFChildWndProc;
wndclass.hIcon = LoadIcon (hInstance, "CALOGOICON");
wndclass.lpszClassName = szWndClass;
wndclass.lpszMenuName = NULL;
return (RegisterClass (&wndclass));
}
Regards
Sham
In the following code, registerclass(wndclass) is called, what exactly are we doing in this call conceptually? am new to GUI application!!!!!!!!!
typedef struct tagAPPINFO {
INT iVersion;
INT iFiller;
HWND hAppInst;
INT iAppType;
HWND hWndFrame;
HWND hWndMDIClient;
HWND hWndToolbar;
HWND hWndStatbar;
UINT uMemBlocks;
UINT uMemBlockSize;
char szAppName [MAXOBJNAME + 2];
char szFileName [FILENAME_LENGTH + 2];
char szHelpFile [PATHNAME_LENGTH + 2];
char szPathName [PATHNAME_LENGTH + 2];
BOOL bDeltaMode;
char szSysPathName[PATHNAME_LEN
} APPINFO;
int WINAPI TNGMain (LPSTR lpszCmdLine, ULONG TNGContext, int nCmdShow, HWND hParent)
{
/* clear application information structure */
memset (&appInfo, '\0', sizeof (APPINFO));
/* save instance handle in structure */
hAPPINST = hResourceModule;
hWndParent = hParent;
/* set other application information in structure */
appInfo.iVersion = iVERSION;
appInfo.uMemBlocks = NUMMEMBLOCKS;
appInfo.uMemBlockSize = MEMBLOCKSIZE;
strncpy(appInfo.szAppName,
strcpy(appInfo.szFileName,
strcpy(appInfo.szHelpFile,
/* register window classes if this is the first instance */
if (!RegisterClasses (hAPPINST))
return FALSE;
.
.
.
}
static BOOL PASCAL RegisterClasses (hInstance)
HANDLE hInstance;
{
WNDCLASS wndclass;
SetFunctionName (RegisterClasses);
/* register class for frame window */
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = GRFFrameWndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon (hInstance, "GrafBASEIcon");
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = appInfo.szFileName;
if (!RegisterClass (&wndclass))
return FALSE;
/* register class for MDI child windows */
/* wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS; */
wndclass.style = CS_DBLCLKS;
wndclass.lpfnWndProc = GRFChildWndProc;
wndclass.hIcon = LoadIcon (hInstance, "CALOGOICON");
wndclass.lpszClassName = szWndClass;
wndclass.lpszMenuName = NULL;
return (RegisterClass (&wndclass));
}
Regards
Sham
ASKER
Why are we running RegisterClass() with wndclass as parameter?
Regards
Sham
Regards
Sham
"wndclass" is the structure where you define all the window class behavior ( for example the background color).
RegisterClass registers in the system the "wndclass" that you have defined.
RegisterClass registers in the system the "wndclass" that you have defined.
You can sort of think as RegisterClass as the definition of an *object's class* definition in an OO language.
The WNDCLASS defines this template, RegisterClass let's the system know about it once you've defined it, and the WndProc defines the behaviour of objects of that type - think of it as a single parameterised method definition.
Once you've registered a class, you can then create as many instances of objects of that class using CreateWindow etc.
The WNDCLASS defines this template, RegisterClass let's the system know about it once you've defined it, and the WndProc defines the behaviour of objects of that type - think of it as a single parameterised method definition.
Once you've registered a class, you can then create as many instances of objects of that class using CreateWindow etc.
ASKER
@peet: definition of an object's class definition?
Regards
Sham
Regards
Sham
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Done
Like in a language like C++ ..
class Foo
{
public:
Foo();
}
So now you can have any number of Foos
Foo a;
Foo b;
etc.
The WNDCLASS is very similar in so many ways.
WNDCLASS definition somewhat analogous to ...
class appInfo_szFileName
{
public:
// No constructor - handled by WM_CREATE and CreateWindow().
long GRFFrameWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
}
So now you can ...
HWND hWnd = CreateWindow(appInfo_szFil eName, ...)
CreateWindow's creating a appInfo_szFileName type window and returning a polymorphic pointer to it here.
// Single method that handles all message traffic for objects of type appInfo_szFileName
//
HWND appInfo_szFileName::GRFFra meWndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
}
Hope this hasn't confused more than it's helped??
class Foo
{
public:
Foo();
}
So now you can have any number of Foos
Foo a;
Foo b;
etc.
The WNDCLASS is very similar in so many ways.
WNDCLASS definition somewhat analogous to ...
class appInfo_szFileName
{
public:
// No constructor - handled by WM_CREATE and CreateWindow().
long GRFFrameWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
}
So now you can ...
HWND hWnd = CreateWindow(appInfo_szFil
CreateWindow's creating a appInfo_szFileName type window and returning a polymorphic pointer to it here.
// Single method that handles all message traffic for objects of type appInfo_szFileName
//
HWND appInfo_szFileName::GRFFra
{
}
Hope this hasn't confused more than it's helped??
class
It really pi***s me off when someone asks an additional question, and you answer it - just to find they've already accepted a solution!
http://msdn.microsoft.com/en-us/library/ms632596(VS.85).aspx