Results 1 to 10 of 10

Thread: Icon?

  1. #1

    Thread Starter
    Fanatic Member prog_tom's Avatar
    Join Date
    May 2001
    Location
    Los Angeles and Little Rock
    Posts
    810

    Post Icon?

    Does anyone know how to change the Icon of the EXE? i mean everytime I compile it, the Icon is the same old DOS ICON

    prog_tom
    JOIN THE REVOLUTION!!!! Dual T3 backedup science community.
    http://physics.sviesoft.com/forum

  2. #2
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    You can load the icon from a resource file and then change the following lines for your window class structure:
    (I assume that you have an icon called "THEICONNAME" in the resource file. And I also assume that the window cass structure is declared as wc)

    PHP Code:
       wc.hIcon MAKEINTRESOURCE(THEICONNAME);
       
    wc.hIconSm MAKEINTRESOURCE(THEICONNAME); 
    Baaaaaaaaah

  3. #3
    Megatron
    Guest
    If it's a console app, then just add an icon to the project, and that will be the icon that the EXE will use.

  4. #4
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    Megatron:

    Doesn't work for me

  5. #5

    Thread Starter
    Fanatic Member prog_tom's Avatar
    Join Date
    May 2001
    Location
    Los Angeles and Little Rock
    Posts
    810

    Post Not what I meant

    Hi Abdul, I meant the Icon displayed on the EXE file. Not in the program... Also Megatron, I'm creating a Win32 App. Not Console.
    Please have a look at this code:
    Code:
    //Sviesoft Corporation(r)
    //Copyright(c) 1999 - 2001
    //All Rights Reserved
    //
    //Thanks to God, my Mom and the people
    //that have supported me all these years
    //
    //God Bless you all, Amen
    
    #include <windows.h>
    const char tzID[]="myWindowClass";
    HINSTANCE hInst;
    #define BUT1 1
    #define TEX1 2
    LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam){
    	switch(msg){
    	case WM_CREATE:
    		CreateWindowEx(NULL,"edit","",WS_CHILD|WS_VISIBLE,100,40,80,20,hwnd,(HMENU)TEX1,hInst,NULL);
    		CreateWindowEx(NULL,"button","Submit",WS_CHILD|WS_VISIBLE,100,100,80,20,hwnd,(HMENU)BUT1,hInst,NULL);
    		break;
    	case WM_COMMAND:
    		switch(LOWORD(wParam)){
    		case BUT1:
    			MessageBox(hwnd,"You clicked","",0);
    			return 0;
    			break;
    		case TEX1:
    			MessageBox(hwnd,"Type in your name","",0);
    			return 0;
    			break;
    		}
    	case WM_CLOSE:
    		DestroyWindow(hwnd);
    		break;
    	case WM_DESTROY:
    		PostQuitMessage(0);
    		break;
    	default:
    		return DefWindowProc(hwnd,msg,wParam,lParam);
    	}
    	return 0;
    }
    int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow){
    	WNDCLASSEX tz;
    	HWND hwnd;
    	MSG Msg;
    
    	tz.cbSize=sizeof(WNDCLASSEX);
    	tz.style=0;
    	tz.lpfnWndProc=WndProc;
    	tz.cbClsExtra=0;
    	tz.cbWndExtra=0;
    	tz.hInstance=hInstance;
    	tz.hIcon=LoadIcon(NULL,IDI_APPLICATION);
    	tz.hCursor=LoadCursor(NULL,IDC_ARROW);
    	tz.hbrBackground=(HBRUSH)(COLOR_WINDOW+8);
    	tz.lpszClassName=tzID;
    	tz.lpszMenuName=NULL;
    	tz.hIconSm=LoadIcon(NULL,IDI_APPLICATION);
    	if(!RegisterClassEx(&tz)){
    		return 0;
    	}
    	hwnd=CreateWindowEx(WS_EX_CLIENTEDGE,tzID,"Welcome!",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,500,300,NULL,NULL,hInstance,NULL);
    	if(hwnd==NULL){
    		return 0;
    	}
    	ShowWindow(hwnd,nCmdShow);
    	UpdateWindow(hwnd);
    	while(GetMessage(&Msg,NULL,0,0)){
    		TranslateMessage(&Msg);
    		DispatchMessage(&Msg);
    	}
    	return Msg.wParam;
    }
    When I click on the "edit"(TextBox), it pops out MessageBox twice. How to change it to once? Do you know how to get the Text in the "edit"?

    prog_tom
    JOIN THE REVOLUTION!!!! Dual T3 backedup science community.
    http://physics.sviesoft.com/forum

  6. #6
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091

    Re: Not what I meant

    Originally posted by prog_tom
    Hi Abdul, I meant the Icon displayed on the EXE file. Not in the program...
    it should do it for both, it does for me.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  7. #7
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    you have

    return 0;
    break;

    at the end of each case statement. Try erasing one of those lines and then see if you get two messages.

    Try the following code that shows a messagebox with the editbox text in it:

    PHP Code:
    char edtext[100];
            
    GetDlgItemText(hwndTEX1edtextGetWindowTextLength(GetDlgItem(hwndTEX1)) + 1);
            
    MessageBox(NULL,edtext,"The text",MB_OK); 
    Baaaaaaaaah

  8. #8
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827

    Re: Re: Not what I meant

    Originally posted by crptcblade


    it should do it for both, it does for me.
    Yes
    Baaaaaaaaah

  9. #9

    Thread Starter
    Fanatic Member prog_tom's Avatar
    Join Date
    May 2001
    Location
    Los Angeles and Little Rock
    Posts
    810

    Post Both?

    Yeah I removed:
    Code:
    return 0;
    break;
    But each time I clicked Either Button or Edit, it will pop up expressions for both.
    I only want like one for one...

    prog_tom
    JOIN THE REVOLUTION!!!! Dual T3 backedup science community.
    http://physics.sviesoft.com/forum

  10. #10
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    that is wierd. I only get two message boxes with the editbox. I don't know if there is any other way to do so without subclassing the editbox. I think that you are getting two message boxes because of one "Down" and one "Up" event on the editbox.

    Here is the subclassing thing that only shows one messagebox when the mouse is down:

    PHP Code:
    //Sviesoft Corporation(r)
    //Copyright(c) 1999 - 2001
    //All Rights Reserved
    //
    //Thanks to God, my Mom and the people
    //that have supported me all these years
    //
    //God Bless you all, Amen

    #include <windows.h>
    const char tzID[]="myWindowClass";
    HINSTANCE hInst;
    WNDPROC wOldProc;
    #define BUT1 1
    #define TEX1 2
    LRESULT CALLBACK SubClassText(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);
    LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)

    {
        switch(
    msg){
        case 
    WM_CREATE:
            
    CreateWindowEx(WS_EX_CLIENTEDGE,"edit","",WS_CHILD|WS_VISIBLE,100,40,80,20,hwnd,(HMENU)TEX1,hInst,NULL);
            
    CreateWindowEx(NULL,"button","Submit",WS_CHILD|WS_VISIBLE,100,100,80,20,hwnd,(HMENU)BUT1,hInst,NULL);
            
    wOldProc = (WNDPROC)SetWindowLong(GetDlgItem(hwndTEX1), GWL_WNDPROC, (LONG)SubClassText);
            break;
        case 
    WM_COMMAND:
            switch(
    LOWORD(wParam)){
            case 
    BUT1:
                
    MessageBox(hwnd,"You clicked","",0);
                return 
    0;
            case 
    TEX1:
                
                return 
    0;
            }
            return 
    0;
        case 
    WM_CLOSE:
            
    SetWindowLong(GetDlgItem(hwndTEX1), GWL_WNDPROC, (LONG)wOldProc);
            
    DestroyWindow(hwnd);
            break;
        case 
    WM_DESTROY:
            
    PostQuitMessage(0);
            break;
        default:
            return 
    DefWindowProc(hwnd,msg,wParam,lParam);
        }
        return 
    0;
    }
    int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow){
        
    WNDCLASSEX tz;
        
    HWND hwnd;
        
    MSG Msg;

        
    tz.cbSize=sizeof(WNDCLASSEX);
        
    tz.style=0;
        
    tz.lpfnWndProc=WndProc;
        
    tz.cbClsExtra=0;
        
    tz.cbWndExtra=0;
        
    tz.hInstance=hInstance;
        
    tz.hIcon=LoadIcon(NULL,IDI_APPLICATION);
        
    tz.hCursor=LoadCursor(NULL,IDC_ARROW);
        
    tz.hbrBackground=(HBRUSH)(COLOR_WINDOW+8);
        
    tz.lpszClassName=tzID;
        
    tz.lpszMenuName=NULL;
        
    tz.hIconSm=LoadIcon(NULL,IDI_APPLICATION);
        if(!
    RegisterClassEx(&tz)){
            return 
    0;
        }
        
    hwnd=CreateWindowEx(WS_EX_CLIENTEDGE,tzID,"Welcome!",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,500,300,NULL,NULL,hInstance,NULL);
        if(
    hwnd==NULL){
            return 
    0;
        }
        
    ShowWindow(hwnd,nCmdShow);
        
    UpdateWindow(hwnd);
        while(
    GetMessage(&Msg,NULL,0,0)){
            
    TranslateMessage(&Msg);
            
    DispatchMessage(&Msg);
        }
        return 
    Msg.wParam;
    }
    //--------------------------------------------------------------------------------

    LRESULT CALLBACK SubClassText(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
    {
        switch(
    msg)
        {
        case 
    WM_LBUTTONDOWN:
            
    MessageBox(NULL,"You clicked to editbox","Hi",MB_OK);
            return 
    0;
        }
        return 
    CallWindowProc(wOldProchwndmsgwParamlParam);

    Baaaaaaaaah

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