Thread: Something wrong with PUSHBUTTON

  1. #1
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584

    Something wrong with PUSHBUTTON

    I just programmed the Child Window BS_PUSHBUTTON. Well, my problem is that when I move around the main window, it "disappears". And then when I wanted to test out the WM_COMMAND message I processed it like this:

    Code:
    case WM_COMMAND:
        MessageBox(NULL, TEXT("Test"), TEXT("Test"), MB_OK);
        return 0;
    And nothing happened. Can you answer my questions and solve my problems? Thanks!

    --Garfield
    1978 Silver Anniversary Corvette

  2. #2
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,227
    well some code might be nice...

    Be sure you ddidn't do soemthing stupid I once did, and put the createwindow() in WM_PAINT....I did that once...baffled me for a while until I realized I had typed "PAINT" instead of "CREATE"...oh well

    But CODE, garfield. Code. How can we solve your problems with a vague description and nothing more?

  3. #3
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Umm...this is the code. I had deleted some parts of it and then I just quickly put some of the code back in (I think I might have some parameters of CreateWindow wrong -- but that's not the initial problem).

    Code:
    /****************************************************
    ****	FirstButton -- an example to create child****
    ****	window controls starting with the button ****
    ****************************************************/
    
    #include <windows.h>
    
    /***************************************************
    ****	Function Prototypes:					****
    ****		- WndProc : main window procedure	****
    ***************************************************/
    
    LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
    
    /***************************************************
    ****	Globals/Constants:						****
    ****	hInst : Global type HINSTANCE			****
    ****	NUM : Constant number of buttons		****
    ***************************************************/
    
    #define NUM 1
    HINSTANCE hInst;
    
    /***************************************************
    ****	Main Code Section/Functions/Definitions:****
    ****		- WinMain							****
    ****		- WndProc : main window procedure	****
    ***************************************************/
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int nCmdShow)
    {
    	HWND			hwnd;
    	WNDCLASS		wc;
    	MSG				msg;
    	TCHAR			szClassName[] = TEXT("MainWindow");
    
    	wc.cbClsExtra = 0;
    	wc.cbWndExtra = 0;
    	wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
    	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    	wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    	wc.hInstance = hInstance;
    	wc.lpfnWndProc = WndProc;
    	wc.lpszClassName = szClassName;
    	wc.lpszMenuName = NULL;
    	wc.style = CS_HREDRAW | CS_VREDRAW;
    
    	if(!RegisterClass(&wc))
    	{
    		MessageBox(NULL, TEXT("Error registering window!"), szClassName, MB_ICONEXCLAMATION | MB_OK);
    		return 0;
    	}
    
    	hInst = hInstance;
    
    	hwnd = CreateWindow(szClassName, TEXT("Main Window"),
    						WS_OVERLAPPEDWINDOW,
    						CW_USEDEFAULT, CW_USEDEFAULT,
    						CW_USEDEFAULT, CW_USEDEFAULT,
    						NULL, NULL, hInstance, NULL);
    
    	ShowWindow(hwnd, nCmdShow);
    	UpdateWindow(hwnd);
    
    	while(GetMessage(&msg, NULL, 0, 0))
    	{
    		TranslateMessage(&msg);
    		DispatchMessage(&msg);
    	}
    
    	return msg.wParam;
    }
    
    /***************************************************
    ****	WndProc : main window procedure			****
    ***************************************************/
    
    LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    	static HWND hwndButton;
    	HDC			hdc;
    	static int	cyChar, cxChar;
    
    	switch(message)
    	{
    	case WM_CREATE:
    		cxChar = LOWORD(GetDialogBaseUnits());
    		cyChar = HIWORD(GetDialogBaseUnits());
    
    	hwndButton = CreateWindow("button", TEXT("firstbutton"),
    		WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
    		cxChar, cyChar, 20 * cxChar, 7 * cyChar / 4,
    		hwnd, (HMENU) 1, hInst, NULL);
    
    	return 0;
    
    	case WM_SIZE:
    		return 0;
    
    	case WM_PAINT:
    		return 0;
    
    	case WM_COMMAND:
    	MessageBox(NULL, TEXT("Test"), TEXT("Test"), MB_OK);
    	return 0;
    
    	case WM_DESTROY:
    	PostQuitMessage(0);
    	return 0;
    
    	default:
    		break;
    	}
    	return DefWindowProc(hwnd, message, wParam, lParam);
    }
    Garfield
    1978 Silver Anniversary Corvette

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    421
    here's your mistake:

    case WM_PAINT:
    break;

    not

    case WM_PAINT:
    return 0;

    good luck!
    U.
    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

  5. #5
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    ::slaps face:: I should have known that! Of course, I'm processing the WM_PAINT method with just returning without processing. I should pass it on to DefWindowProc. Thanks, dude!
    1978 Silver Anniversary Corvette

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Also watch that you have given the button an ID# of one.

    I would use more descriptive ID's, especially when you need more controls.

    ie
    #define IDB_BUTTON1 10001
    and use this as the HMENU cast.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  7. #7
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Okay. Thanks, guys!
    1978 Silver Anniversary Corvette

  8. #8
    Registered User
    Join Date
    Dec 2001
    Posts
    421
    no problem.

    By the way, are you the dude that's helping Oskilian out on Aurora?
    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

  9. #9
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Yeah, Uraldor, I am. Go to osky's board so we can talk. He might have started a thread, but I'm not sure. Well anyway, we have to sort this out and assign jobs to each other.

    If you get a minute, can you PM me your e-mail address, Uraldor?

    --Garfield
    1978 Silver Anniversary Corvette

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Debugging-Looking in the wrong places
    By JaWiB in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-03-2003, 10:50 PM
  2. Confused: What is wrong with void??
    By Machewy in forum C++ Programming
    Replies: 19
    Last Post: 04-15-2003, 12:40 PM
  3. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM
  4. What's wrong with this resource file?
    By -leech- in forum Windows Programming
    Replies: 2
    Last Post: 09-13-2002, 07:53 PM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 01:04 PM