What control are you using ? It's hard to know what's available to you in C, in C++ I am certain the textbox has properties and probably a selection changed event.
Why would you choose to learn C ? It's not used for much of anything, and certainly not for writing windows programs.
I picked C because it is a good starting position. Complicated enough to get an understanding of the inner workings but avoids the complications of objects. Stromcodes tutorial is next on my agenda I am sure there is a way to do it in C something using the EM_GETSEL and comparing the WPARAM and LPARAM to see if they are equal, which they should be if no text is selected ( WPARAM and LPARAM should both return the cursor position if no text is selected ). C++ is on my horizon, but I have no interest in C# at this point in time.
Your reasoning is faulty. C++ is far more useful than C, and C will only teach you how to write BAD C++ code. Far better to avoid anything that looks like C, and learn C++. C# is more useful for windows programming, but it's not related to C or C++ at all, so if you want to learn a harder language, C++ is the one to learn, and C is only going to teach you how to do things badly.
That might be true... Using C++ may be a better idea... Like I said in the title I am a noob when it comes to Windows programming. Although, using the Windows API system calls I doubt that the coding is much different for instance:
void DoFileClose( HWND hwnd, LPSTR szFileName )
{
// Variable Declaration
HWND hEdit = GetDlgItem(hwnd, IDC_MAIN_EDIT);
if(SendMessage( hEdit, EM_GETMODIFY, 0, 0 ) == TRUE )
{
if( MessageBox( hwnd, "File has been changed.\nSave it now?", "Confirm Close",
MB_ICONQUESTION | MB_YESNO ) == IDYES )
{
SendMessage( hwnd, WM_COMMAND, ID_FILE_SAVE, 0);
}
}
for( int i = 0; i != sizeof(szFileName); i++ )
{
szFileName[i] = '\0';
}
SetDlgItemText( hwnd, IDC_MAIN_EDIT, "" );
SendMessage( hEdit, EM_EMPTYUNDOBUFFER, 0, 0 );
SendMessage( hEdit, EM_SETMODIFY, 0, 0 );
SetFocus( hEdit );
return;
}
Would this be coded any different in c++ and btw I think the whole ++ is a really bad joke :)
Would this be coded any different in c++ and btw I think the whole ++ is a really bad joke.
What's a bad joke ? C++ is C plus object orientation. Yes, the C++ code would look a lot different. Any code that uses handles and calls non class methods, is probably bad code in C++.
The fact is that most people who learn C++, learn C first, and as a result, they write bad C++ code. Learning C++ first and going back to learn C, makes more sense, because you learn how to do it right first, then learn how to live with the limitations of C.
C++ is the superset to C in C and C++ the ++ Means incriment by one which to me is just a really, really bad joke.
Well, I guess it was meant as a pun, but it's not inaccurate. It's not brilliant humour, but it told people what they were getting, when the language was new, and C was the main language used for systems programming :-)
Its still used in almost everything Unix. I'll start Stromcode tomorrow but I am already a thousand lines into this so I am kinda antsy to finish it. Want to see crap code, this is what I have so far for testing for selection and no it doesnt work:
WPARAM wPar;
LPARAM lPar;
SendMessage(hEdit, EM_GETSEL, wPar, lPar );
if( wPar == lPar )
{
EnableMenuItem( hMenu, ID_EDIT_COPY, MF_BYCOMMAND | MF_GRAYED );
}
else
{
EnableMenuItem( hMenu, ID_EDIT_COPY, MF_BYCOMMAND | MF_ENABLED );
}
DWORD Check;
Check = SendMessage(hEdit, EM_GETSEL, NULL, NULL );
if( HIWORD(Check) == LOWORD(Check) )
{
EnableMenuItem( hMenu, ID_EDIT_COPY, MF_BYCOMMAND | MF_GRAYED );
}
else
{
EnableMenuItem( hMenu, ID_EDIT_COPY, MF_BYCOMMAND | MF_ENABLED );
}
This is the code that finally worked it wasn't the returning lParam or wParam that contained the cursor position it was the hi and lo value of the DWORD returned.
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)