CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2005
    Posts
    2

    WndProc in wrapped class problem

    I have wrapped up a window in a class, but WndProc has to be a static function of the class. But what if I want to make use of a variable from that class in the function.

    Example. I have a member varaible called hInst. It is the HINSTANCE you get when you start a win application. but since WndProc is static I can't use normal member variables. So I thought I had to make the member variable static too. But that didn't help (Well it is probably my fault, because I am pretty sure it whould work. Here is a snapshot of the code. I guess I am messing up the function definition or something? Or any other advice?

    .h file

    Code:
    class Device{
    
    
    public:
    	Device();
    	~Device();
    
    
    private:
    	static LRESULT WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );
    	static HINSTANCE hInst;	    					// Hinstance to our window
    
    };
    .c file

    Code:
    LRESULT CALLBACK Device::WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){
    
    	static 	PAINTSTRUCT	paintstruct;
    
    	switch (message){
    
    		//This is sent following WM_NCCREATE -- we can assume our window is up
    		//If it gets this far
    		case WM_CREATE:{
    			CreateWndControls(hwnd, hInst);
    			FillControls();
    			break;
    		}
    Cheers,

    RyanJ
    __________________

  2. #2
    Join Date
    Mar 2005
    Location
    Canada Alberta
    Posts
    80

    Re: WndProc in wrapped class problem

    In C, you merely shoot yourself in the foot.

    In C++, you accidentally create a dozen instances of yourself and shoot them all in the foot. Providing emergency medical care is impossible, because you can't tell which are bitwise copies and which are just pointing at others and saying, "That's me, over there."

  3. #3
    Join Date
    May 2005
    Posts
    2

    Re: WndProc in wrapped class problem

    Quote Originally Posted by barrensoul

    Right, I will read through that,

    Thanks,

    RyanJ

  4. #4
    Join Date
    Mar 2004
    Location
    (Upper-) Austria
    Posts
    2,899

    Re: WndProc in wrapped class problem

    And you are sure your compiler takes the C file and treats its contents as C++ source? I think this might also be a problem. If you have changed that behaviour you should better go and rename it to .cc or .cpp instead because it is more segnificant either for you and the other programms and for the compiler which language it contains.
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured