Pelles C forum
C language => Expert questions => Topic started by: tbohon on April 14, 2010, 08:22:13 PM
-
This is my first Windows program in Pelles C so I'm still learning (a lot) ...
I have a simple dialog defined which has two buttons and a text box. From the .rc file the buttons are named as follows:
IDOK is labeled 'Generate'
4005 is labeled 'Exit'
The text box is named 4003 Text.
What I'm trying to get it to do is display a message in the Text box when the 'Generate' button is clicked and exit the application when the 'Exit' button is clicked. So far I have the 'Exit' button working just fine but I'm rapidly running out of ideas (and obviously a deep enough understanding) of how to get the 'Generate' button to place the text message (a simple 'Hello there!') in the text box.
Here is what I think is the relevant part of the generated code - maybe someone can gently point the way?
case WM_COMMAND:
switch (GET_WM_COMMAND_ID(wParam, lParam))
{
/*
* TODO: Add more control ID's, when needed.
*/
case IDOK:
break;
case 4005:
EndDialog(hwndDlg, TRUE);
return TRUE;
}
break;
I'm also curious how one goes about changing the '4003' and '4005' into something equally meaningful to the compiler and yours truly ... when I click the dropdown in the resource window I only have 3 choices with no apparent way to add something (like, e.g., btnGenerate or btnExit) to remind me what it does.
Thanks as always in advance.
Tom
-
I'm also curious how one goes about changing the '4003' and '4005' into something equally meaningful to the compiler and yours truly
The way I do it is to manually change the .h and .rc files.
So in the .h file,
#define ID_EXIT 4005 // EXIT button
#define ID_GENERATE 4004 // OK button
#define ID_TEXT 4003 // Text Box
And in the .rc file make the changes to reflect what you've done in the .h file.
The Generate button becomes ID_GENERATE, the text box becomes ID_TEXT and the Exit button becomes ID_EXIT.
For example.
CONTROL "Generate", ID_GENERATE, "Button", BS_DEFPUSHBUTTON|WS_TABSTOP, 56, 76, 40, 24
This will send "Hello" to the text box.
case WM_COMMAND:
switch (GET_WM_COMMAND_ID(wParam, lParam))
{
case ID_GENERATE:
SetWindowText(GetDlgItem(hwndDlg, ID_TEXT), "Hello");
break;
case ID_EXIT:
EndDialog(hwndDlg, TRUE);
return FALSE;
}
break;
John
-
Great, John - thanks a million! Makes perfect sense once explained.
Appreciate it!!!
Tom