Click to See Complete Forum and Search --> : Newbe question
Kitu
December 18th, 2004, 09:57 AM
I’m rather new to Windows programming and would need a bit of help. I know how to create basic child windows and stuff. Anyway I’m trying to make a program, where you could press the button with letter on it and it would print the letter into textbox (I’m actually planning to make all letters there Russian, so it would be possible to write shorter text in Russian without having to install Russian language module)
Well, Everything was fine until the part where the letter should appear to textbox, the way I though it should works didn’t, so I would be happy, if anyone would give me the syntax how to do something like that.
Thanks,
Kitu.
NoHero
December 18th, 2004, 10:01 AM
Please post your code, because we may can find the mistake in it.
This will print the entire text that is displayed on the IDC_BUTTON into IDC_EDITBOX,
Kitu
December 18th, 2004, 10:20 AM
Hi,
Thanks for answering so quickly! =)
I may post the code, but that would be no use, that the thing is not in, that theres problem with code, it was that my syntanx was wrong. Anyways thanks for posting that, but as I already mentioned in my previous post, I’m Win32 beginner, so could you please tell, that does that identifyer hDlg stand for (and how to declaree it)
Thanx,
Kitu
NoHero
December 18th, 2004, 10:36 AM
Yes I may correct your code and/or modify it :)
As you run your dialog (with either DialogBox or CreateDialog) you specified a application defined DialogProc that handles all messages that comes in for your dialog. In this function you have some parameters:
The first paramater hDlg is from type HWND. This is a handle with which windows recognizes your dialog box. msg is the message that should be handled. All windows messages start with WM_. So you might take a look at these in the MSDN - because there are a ton of messages that could be handled. The other two paramters are additional paramters and their meaning that differ from message to message.
In your case you want to handle the button pressed. To do this you have to handle the WM_COMMAND message. The lowest word of the wParam paramaters tells you which control caused this message and the highest word what event has been occured.
LRESULT WINAPI DlgProc ( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch ( msg )
{
case WM_COMMAND:
{ // Let's say your button has an ID of IDC_BUTTON
if ( LOWORD(wParam) == IDC_BUTTON )
{ // Now do something here
}
}
break;
}
return 0;
}
TCHAR is just a type that can either handle Ansi strings or - if you want to use Unicode - unicode strings. If you define a _UNICODE macro before you include the windows header you will use unicode strings.
The first function 'GetDlgItemText' retrieves the text of a specified control. The control is recognized by the HWND-handle of the parent (hDlg) and it's ID. szStr will now contain the string of how you labeld your button.
SetDlgItemText is the opposite of GetDlgItemText it lets you set the text of a specified control. The control is also recognized - as mentioned above - by the HWND handle of the parent and the controls ID.
You can set IDs in the resource editor. And you need to include the automatically created header file "resource.h".
Kitu
December 18th, 2004, 11:39 AM
Thanx!
NoHero
December 18th, 2004, 01:25 PM
Thanx!
You are welcome ... :wave:
Kitu
December 20th, 2004, 06:19 AM
Well, I’m officially a hopeless n00b. I read your text and it made sense, but I didn’t have time to actually test it. Now I got the time and I just cant get it to compile no matter what I try. Maybe its just cause of my stupid programming style…Anyway here’s the last compiling source (that consists only of GUI)
Well, that was the last place I saw message "0 errors, 0 warnings". When I tried to add the LRESULT WINAPI DlgProc function after fnMessageProcessotr (Well, that might have been the mistake, but I don’t know much more about that than I know about location of Bil Laden) I got error: "error C2601: 'DlgProc' : local function definitions are illegal"
I’m very thankful, that you took your time to help a beginner, but looks like beginner turned out to be just anther dumbuser…I would be as thankful, if anyone would explain me how to actually use it…
NoHero
December 20th, 2004, 09:16 AM
This error occures in the following circumstances:
* You havn't closed the last bracket for example:
int main ( void )
{
// You haven't closed it here so You will get an error
void _error ( const char* err )
{
}
* If you try to declare a function into a function. This is not legal in C. But legal in Pascal.
Please post the code that caused the error.
You are very welcome. Everybody - me too - had to start from scratch. ;)
Sef
December 23rd, 2004, 04:51 PM
[QUOTE=NoHero]Now I will explain you the following code:
TCHAR szStr[100] = _T("");
NoHero
December 24th, 2004, 05:54 AM
Of course. Sorry for forgeting this. I am not perfect either ;)
But thank you for correcting me.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.