Thread: Using a image like a button

  1. #1
    Banned
    Join Date
    Oct 2004
    Posts
    250

    Using a image like a button

    Im trying to use a bitmap image as a button but when i click on the image it doesnt do anything

    Code:
    #include <windows.h>
    #include "resource.h"
    
    LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
    {
    	switch (message)
    	{
    	case WM_CLOSE:
    		EndDialog(hwnd,true);
    		break;
    	case WM_COMMAND:
    		switch (LOWORD(wParam))
    		{
    		case START_IMAGE:
    			MessageBox(NULL,"Message","Message",MB_OK);
    			break;
    		}
    		break;
    	}
    
    	return false;
    }
    
    int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,
    				   LPSTR lpCmdLine,int nCmdShow)
    {
    	DialogBox(hInstance,MAKEINTRESOURCE(IDD_DIALOG1),NULL,DLGPROC(WndProc));
    	return true;
    }
    It compiles with no error's..... im using the Picture control wich comes with MFC

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Perhaps you are referring to the 'picture' control available from the dialog editor toolbar? If that's the case, and given the winapi nature of your code, then you're probably not using mfc at all....

    Some clarification on your behalf would be helpful.

    >>Im trying to use a bitmap image as a button but when i click on the image it doesnt do anything<<

    Then use an owner drawn button control. Since it's already a button control it will send BN_CLICKED notifications to its parent window as expected. All you'd need to do is handle the WM_DRAWITEM message to render the button up and button down visual states.

    msdn: Owner drawn buttons

    If you still prefer to go down to static control route then you'll either have to subclass the control and handle mouse up and down messages to simulate button behaviour or enable mouse message handling by giving it the SS_NOTIFY style; you'd still need to simulate button behaviour.

    You might also find it useful to review previous threads on this board that you have initiated regarding WM_COMMAND control notification message handling.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem reading tiff image files?
    By compz in forum C++ Programming
    Replies: 9
    Last Post: 10-30-2009, 04:17 AM
  2. Remove Image for button
    By franse in forum C++ Programming
    Replies: 3
    Last Post: 12-17-2008, 06:15 PM
  3. C Programming 2d Array Question
    By jeev2005 in forum C Programming
    Replies: 3
    Last Post: 04-26-2006, 03:18 PM
  4. Button Displaying Image
    By mrafcho001 in forum Windows Programming
    Replies: 4
    Last Post: 12-03-2005, 02:14 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM