PDA

Click to See Complete Forum and Search --> : Icon?


prog_tom
Sep 1st, 2001, 06:26 PM
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

abdul
Sep 1st, 2001, 07:12 PM
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)


wc.hIcon = MAKEINTRESOURCE(THEICONNAME);
wc.hIconSm = MAKEINTRESOURCE(THEICONNAME);

Megatron
Sep 1st, 2001, 07:47 PM
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.

SteveCRM
Sep 1st, 2001, 08:50 PM
Megatron:

Doesn't work for me

prog_tom
Sep 1st, 2001, 10:12 PM
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:

//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"?

crptcblade
Sep 1st, 2001, 10:20 PM
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.

abdul
Sep 1st, 2001, 10:22 PM
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:


char edtext[100];
GetDlgItemText(hwnd, TEX1, edtext, GetWindowTextLength(GetDlgItem(hwnd, TEX1)) + 1);
MessageBox(NULL,edtext,"The text",MB_OK);

abdul
Sep 1st, 2001, 10:22 PM
Originally posted by crptcblade


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

Yes:D

prog_tom
Sep 2nd, 2001, 01:24 AM
Yeah I removed:

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...

abdul
Sep 2nd, 2001, 05:56 AM
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:


//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(hwnd, TEX1), 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(hwnd, TEX1), 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(wOldProc, hwnd, msg, wParam, lParam);
}