How to run WndProc?

Blitz3D Forums/Blitz3D Programming/How to run WndProc?

amitjf(Posted 2008) [#1]
Hello, I tried to embed a blitz3d program I wrote, in a c# program I wrote. I've done that by using the SetParent API, and giving the handle of a panel/other control. Now, I want the two program to send some text to each other, using the SendMessage API, but to recieve it, I need to catch it through the WndProc function. I know how to do that in c#, but I dont know how to do it blitz3d?
Please Help, Thanks in advance.


amitjf(Posted 2008) [#2]
Anyone? I'm waiting about a day and a half already, and no reply...


Kev(Posted 2008) [#3]
you need to subclass blitz3d's own winproc. its the way i done it while writing winblitz3d.


markcw(Posted 2008) [#4]
I was going to reply yesterday but then I didn't know what to say. Now I can say:

"you need to subclass blitz3d's own winproc."

Maybe some relevant code would help.

Edit: have a look at the code here:
http://www.blitzbasic.com/Community/posts.php?topic=48244


Rroff(Posted 2008) [#5]
I'd have thought it would have been simpler just to create a local TCP connection between the 2 apps... pretty much everyone now will have networking installed.


Kev(Posted 2008) [#6]
maybe i should of explained a little, but did not have the time. still dont sorry! heres a stripped down version of my main WB3D_InitializeGUI() function for you to look over.

look into SetWindowsHookEx() functions to get even more events from the api.

BBDECL HWND BBCALL API_InitializeGUI(HWND runtimewindow_Name,int x,int y,int width,int height){

         
        runtimewindow = runtimewindow_Name;
        
        if(!runtimewindow){
                MessageBox(0,"Error","API_InitializeGUI",MB_OK);
        }    
              


        lpOLDblitzproc = (WNDPROC) SetWindowLong(runtimewindow,GWL_WNDPROC,(LONG)GLOBAL_HOOKED_WINPROC);

        lpInst = (HINSTANCE)GetModuleHandle(0);
        if(!lpInst){
                MessageBox(0,"lpInst error","lpInst handle",MB_OK);
        }
            
        // get blitz window style, add clip children style, so that controls are not blitted over
        long winstyle = GetWindowLong(runtimewindow,GWL_STYLE);
        SetWindowLong(runtimewindow,GWL_STYLE,winstyle | WS_CLIPCHILDREN);


        
        gKBHook = SetWindowsHookEx(WH_GETMESSAGE,GLOBAL_HOOKED_MESSAGE_WINPROC,0,GetWindowThreadProcessId(runtimewindow,NULL));
        wpBHook = SetWindowsHookEx(WH_CALLWNDPROC,GLOBAL_HOOKED_MESSAGE_WINPROC_2,0,GetWindowThreadProcessId(runtimewindow,NULL));
        HookRET = SetWindowsHookEx(WH_CALLWNDPROCRET,GLOBAL_HOOKED_MESSAGE_WINPROC_RET,0,GetWindowThreadProcessId(runtimewindow,NULL));

                     
        HDWP r = BeginDeferWindowPos(1);
        HDWP t = DeferWindowPos(r,runtimewindow,0,x,y,width,height,SWP_FRAMECHANGED | SWP_SHOWWINDOW | SWP_NOZORDER );
        EndDeferWindowPos(r);

 
        // get the window class name of the runtime window
        if(!GetClassName(runtimewindow, szClassName, nMaxCount)){
                MessageBox(NULL,"CLASS NAME ERROR","ERROR: Blitz Class Name",MB_OK);
                return FALSE;
        }else{
                      
                if(!GetClassInfoEx(GetModuleHandle(0), szClassName,&wc)){
                        MessageBox(NULL,"CLASS NAME ERROR","ERROR: Blitz Class Info",MB_OK);
                        return FALSE;
                }else{

                        // set window background.
                        SetClassLong(runtimewindow, GCL_HBRBACKGROUND, (LONG) GetSysColorBrush(COLOR_BTNFACE));
                                                
                        // set window icon
                        SetClassLong(runtimewindow, GCL_HICON, (LONG) LoadIcon(lpInst, IDI_APPLICATION));
                                                                       
                        // set window cursor
                        SetClassLong(runtimewindow, GCL_HCURSOR, (LONG) LoadCursor(NULL, IDC_ARROW));

                        // set window winproc
                        SetClassLong(runtimewindow, GCL_WNDPROC,(long)GLOBAL_HOOKED_WINPROC);

                                                          
                        WINPROC_CHANGED = 1;
                         
                                        
               }

         }

                                
        return runtimewindow;
        
}




markcw(Posted 2008) [#7]
I was just about to post exactly what Kev posted, glad I don't have to now. ;)


amitjf(Posted 2008) [#8]
thank you very much, ill try to implement some of these codes, but I must to tell that I am very ashamed that I didn't thought about the TCP connection idea, but after thinking about it, it may cause some problems so ill kip the API idea.
I never wrote an external DLL for Blitz, and if I got it right I should write this code on a DLL. So first:what does this means:"BBDECL HWND BBCALL ", and second, after compiling this DLL, How do I use it in blitz?
thank you


Kev(Posted 2008) [#9]
amitjf

see blitz userlib specs, theres also an example of a vc++ .dll and blitz .decls

http://www.blitzbasic.com/sdkspecs/sdkspecs.php