Article View: borland.public.cppbuilder.nativeapi
Article #8084Help needed in Type Casting
From: FireHead
Date: Mon, 22 Nov 2004 00:57
Date: Mon, 22 Nov 2004 00:57
297 lines
9242 bytes
9242 bytes
Hello Borland.COM
I am writing Win32API based application.
The source code is as follows:
//----------- ============================== -------------------------//
#include <windows>
struct Text_Fields
{
HWND hF; //First Name
HWND hL; // Last Name
HWND hNak; //Nakshatram
HWND hDOB; //Date of Birth
HWND hPOB; //Place of Birth
void Widget(HWND arg_hwnd,HINSTANCE hinst,int iCmdShow)
{
hF=0;hL=0;hNak=0;hDOB=0;hPOB=0;
hF=CreateWindowEx(WS_EX_LEFT,"static","First
Name:",SS_LEFT|WS_VISIBLE|WS_CHILD,10,10,100,20,
arg_hwnd,NULL,hinst,NULL);
hL=CreateWindowEx(WS_EX_LEFT,"static","Last
Name:",SS_LEFT|WS_VISIBLE|WS_CHILD,10,40,100,20,
arg_hwnd,NULL,hinst,NULL);
hNak=CreateWindowEx(WS_EX_LEFT,"static","Nakshtra:",SS_LEFT|WS_VISIBLE|WS_CHILD,10,70,100,20,
arg_hwnd,NULL,hinst,NULL);
hDOB=CreateWindowEx(WS_EX_LEFT,"static","Date Of
Birth:",SS_LEFT|WS_VISIBLE|WS_CHILD,10,100,100,20,
arg_hwnd,NULL,hinst,NULL);
hPOB=CreateWindowEx(WS_EX_LEFT,"static","Place of
Birth:",SS_LEFT|WS_VISIBLE|WS_CHILD,10,130,100,20,
arg_hwnd,NULL,hinst,NULL);
ShowWindow(hF,iCmdShow);
UpdateWindow(hF);
ShowWindow(hL,iCmdShow);
UpdateWindow(hL);
ShowWindow(hNak,iCmdShow);
UpdateWindow(hNak);
ShowWindow(hDOB,iCmdShow);
UpdateWindow(hDOB);
ShowWindow(hPOB,iCmdShow);
UpdateWindow(hPOB);
}
};
struct Input_Fields
{
HWND hF; //First Name
HWND hL; // Last Name
HWND hNak; //Nakshatram
HWND hDOB; //Date of Birth
HWND hPOB; //Place of Birth
void Widget(HWND arg_hwnd,HINSTANCE hinst,int iCmdShow)
{
hF=0;hL=0;hNak=0;hDOB=0;hPOB=0;
hF=CreateWindowEx(WS_EX_LEFT|WS_EX_CLIENTEDGE,"edit","",SS_LEFT|WS_VISIBLE|WS_CHILD,110,10,200,20,
arg_hwnd,NULL,hinst,NULL);
hL=CreateWindowEx(WS_EX_LEFT|WS_EX_CLIENTEDGE,"edit","",SS_LEFT|WS_VISIBLE|WS_CHILD,110,40,200,20,
arg_hwnd,NULL,hinst,NULL);
hNak=CreateWindowEx(WS_EX_LEFT|WS_EX_CLIENTEDGE,"edit","",SS_LEFT|WS_VISIBLE|WS_CHILD,110,70,200,20,
arg_hwnd,NULL,hinst,NULL);
hDOB=CreateWindowEx(WS_EX_LEFT|WS_EX_CLIENTEDGE,"edit","",SS_LEFT|WS_VISIBLE|WS_CHILD,110,100,200,20,
arg_hwnd,NULL,hinst,NULL);
hPOB=CreateWindowEx(WS_EX_LEFT|WS_EX_CLIENTEDGE,"edit","",SS_LEFT|WS_VISIBLE|WS_CHILD,110,130,200,20,
arg_hwnd,NULL,hinst,NULL);
ShowWindow(hF,iCmdShow);
UpdateWindow(hF);
ShowWindow(hL,iCmdShow);
UpdateWindow(hL);
ShowWindow(hNak,iCmdShow);
UpdateWindow(hNak);
ShowWindow(hDOB,iCmdShow);
UpdateWindow(hDOB);
ShowWindow(hPOB,iCmdShow);
UpdateWindow(hPOB);
}
};
struct Navigation{
HWND hF;
HWND hL;
HWND hP;
HWND hN;
HWND hAbout;
HWND hQuit;
void Widget(HWND arg_hwnd,HINSTANCE hinst,int iCmdShow){
hF=0;hL=0;hP=0;hN=0;hAbout=0;
hF=CreateWindowEx(WS_EX_LEFT,"button","|<
Begin",SS_CENTER|WS_VISIBLE|WS_CHILD|BS_DEFPUSHBUTTON,350,10,80,20,
arg_hwnd,NULL,hinst,NULL);
hL=CreateWindowEx(WS_EX_LEFT,"button","<
Prev",WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON,350,32,80,20,
arg_hwnd,NULL,hinst,NULL);
hP=CreateWindowEx(WS_EX_LEFT,"button","Next
>",WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON,350,54,80,20,
arg_hwnd,NULL,hinst,NULL);
hN=CreateWindowEx(WS_EX_LEFT,"button","End
>|",WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON,350,76,80,20,
arg_hwnd,NULL,hinst,NULL);
hAbout=CreateWindowEx(WS_EX_LEFT,"button","About",WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON,350,98,80,20,
arg_hwnd,NULL,hinst,NULL);
hQuit=CreateWindowEx(WS_EX_LEFT,"button","Quit",WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON,350,120,80,20,
arg_hwnd,NULL,hinst,NULL);
ShowWindow(hF,iCmdShow);
UpdateWindow(hF);
ShowWindow(hL,iCmdShow);
UpdateWindow(hL);
ShowWindow(hP,iCmdShow);
UpdateWindow(hP);
ShowWindow(hN,iCmdShow);
UpdateWindow(hN);
ShowWindow(hAbout,iCmdShow);
UpdateWindow(hAbout);
ShowWindow(hQuit,iCmdShow);
UpdateWindow(hQuit);
}
};
struct Signal_Window{
void destroy(){PostQuitMessage(WM_QUIT);}
};
struct Signal{
Text_Fields* pText;
Input_Fields* pInput;
Navigation* pNav;
struct Signal_Window* pWnd;
int Run(){
MSG msg;
while(GetMessage(&msg,NULL,0x00,0x00)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
//--- Methods ----//
LRESULT CALLBACK Events(HWND handle,UINT message,WPARAM wparam,LPARAM
lparam)
{
switch(message)
{
case WM_DESTROY:
pWnd->destroy();
break;
}
return DefWindowProc(handle,message,wparam,lparam);
}
}; // --- Signals ---//
struct Main_Window{
//--- Attribute --//
HWND hwnd;
struct Signal *slots;
struct Cmd_Args
{
HINSTANCE hinst;
HINSTANCE hprev;
LPSTR lpsCmdLine;
int iCmdShow;
const char *title;
const char *class_name;
}cli;
//--- Constructor --//
void Constructor(const char *title,HINSTANCE hinst,HINSTANCE
hprev,LPSTR lpsCmdLine,int iCmdShow ){
hwnd=0;
cli.hinst=hinst;
cli.hprev=hprev;
cli.lpsCmdLine=lpsCmdLine;
cli.iCmdShow=iCmdShow;
cli.title = TEXT(title);
}
//--- Destroyer --//
void Destructor(){
}
bool InitInstance(const char* class_name){
WNDCLASSEX wnd;
WNDPROC wfn = &slots->Events;
cli.class_name =TEXT(class_name);
wnd.cbSize=sizeof(wnd);
wnd.style = CS_HREDRAW|CS_VREDRAW;
wnd.lpfnWndProc = *wfn;
wnd.hInstance = cli.hinst;
wnd.hIcon = NULL;
wnd.hCursor = NULL;
wnd.cbClsExtra = 0;
wnd.cbWndExtra = 0;
wnd.hbrBackground=reinterpret_cast<HBRUSH>(COLOR_APPWORKSPACE);
wnd.lpszMenuName = NULL;
wnd.lpszClassName = cli.class_name;
wnd.hIconSm = NULL;
if(!RegisterClassEx(&wnd))
return TRUE;
else
return FALSE;
}
BOOL Create(void){
hwnd =
CreateWindowEx(WS_EX_LEFT,cli.class_name,cli.title,WS_VISIBLE|WS_CAPTION|WS_TILED|WS_SYSMENU|WS_GROUP,
CW_USEDEFAULT,CW_USEDEFAULT,450,200,NULL,NULL,cli.hinst,NULL);
if(!hwnd){
MessageBoxEx(hwnd,"Entry interface failed.","Error",
MB_OK+MB_ICONERROR,LANG_ENGLISH);
return TRUE;
}
ShowWindow(hwnd,cli.iCmdShow);
UpdateWindow(hwnd);
return FALSE;
}
};
//--------- Driver Module
------------------------------------------------------//
int far PASCAL WinMain(HINSTANCE hinst,HINSTANCE hprev,char*
lpsCmdLine,int iCmdShow)
{
Signal_Window sw;
Main_Window mw;
Signal slots;
//slots.pWnd = 0;
slots.pText = 0;
slots.pInput = 0;
slots.pNav = 0;
mw.slots = 0;
slots.pWnd = &sw;
mw.slots = &slots;
short valid=TRUE;
mw.Constructor("Family Nakstram",hinst,hprev,lpsCmdLine,iCmdShow);
valid=mw.InitInstance("Main_Window");
if(valid==FALSE){if(mw.Create()==TRUE){return TRUE;}}
Text_Fields text_fields;
Input_Fields input_fields;
Navigation nav;
slots.pText = &text_fields;
slots.pInput = &input_fields;
slots.pNav = & nav;
slots.pText->Widget(mw.hwnd,hinst,iCmdShow);
slots.pInput->Widget(mw.hwnd,hinst,iCmdShow);
slots.pNav->Widget(mw.hwnd,hinst,iCmdShow);
return slots.Run();
}
//----------- ============================== -------------------------//
As you can see that I have function called LRESULT CALLBACK Events(....)
which globally located.
I have function called InitInstance which is part of Main_Window structure.
Where I declare WNDCLASSEX wnd
and then I declare the expression
as << wnd.lpfnWndProc = & sig.Events; >> I get a error type casting in
the following:
Cannot convert 'long (_stdcall *(_closure)(HWND__*,unsigned
int,UINT,long))(HWND__* hwnd,unsigned int,UINT,long)' to 'long
(_stdcall *)(HWND__* hwnd,unsigned int,UINT,long)' in function struct
MainWindow::InitInstance(const char*)
Can someone tell me how do I fix this problem.
I could have just the MainWindow::Initinstance to a static function but
I dont want to that; and I want to create too many global variables.
This is my version OOP programming in C.
Technical Details
Message-ID:
<41a13964@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!proxad.net!194.117.148.138.MISMATCH!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,874f410c864356cd,start X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Mon, 22 Nov 2004 11:57:37 +1100 From: FireHead <satishA82@linuxmail.org> User-Agent: Mozilla Thunderbird 0.9 (Windows/20041103) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.nativeapi Subject: Help needed in Type Casting Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 202.78.34.89 Message-ID: <41a13964@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1101085028 202.78.34.89 (21 Nov 2004 16:57:08 -0700) Lines: 297 Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!proxad.net!194.117.148.138.MISMATCH!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail