-
August 19th, 2013, 04:23 PM
#1
[RESOLVED] the hidecaret() function isn't ok?
what i need for hide the caret?
Code:
bool GetCaretVisible()
{
return blCaretVisible;
}
void SetCaretVisible(bool Visible)
{
if (Visible==true)
{
ShowCaret(hwnd());
}
else
{
HideCaret( hwnd());
}
}
__declspec ( property ( put = SetCaretVisible, get = GetCaretVisible ) ) bool CaretVisible ;
the caret isn't hided, i test the GetLastError() and gives me 0(zero). so what i need for hide the caret?
(more 1 property for my class)
-
August 19th, 2013, 04:35 PM
#2
Re: the hidecaret() function isn't ok?
At this rate, I might as well just post you my console class! As per other thread, when dealing with the console, you use console handles and not window handles and you do things the console way not the window way!
Code:
//Turn cursor on
DWORD CursorOn(HANDLE sout)
{
CONSOLE_CURSOR_INFO cur;
if (!GetConsoleCursorInfo(sout, &cur)) {
return (GetLastError());
}
cur.bVisible = TRUE;
return (!SetConsoleCursorInfo(sout, &cur) ? GetLastError() : 0);
}
//Turn cursor off
DWORD CursorOff(HANDLE sout)
{
CONSOLE_CURSOR_INFO cur;
if (!GetConsoleCursorInfo(sout, &cur)) {
return (GetLastError());
}
cur.bVisible = FALSE;
return (!SetConsoleCursorInfo(sout, &cur) ? GetLastError() : 0);
}
//Get cursor size
DWORD GetCursorSize(HANDLE sout, DWORD& size)
{
CONSOLE_CURSOR_INFO cur;
if (!GetConsoleCursorInfo(sout, &cur)) {
return (GetLastError());
}
size = cur.dwSize;
return (0);
}
//Set cursor size
DWORD SetCursorSize(HANDLE sout, DWORD size)
{
CONSOLE_CURSOR_INFO cur;
if (!GetConsoleCursorInfo(sout, &cur)) {
return (GetLastError());
}
cur.dwSize = size;
return (!SetConsoleCursorInfo(sout, &cur) ? GetLastError() : 0);
}
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
August 19th, 2013, 04:45 PM
#3
Re: the hidecaret() function isn't ok?
Originally Posted by 2kaud
At this rate, I might as well just post you my console class! As per other thread, when dealing with the console, you use console handles and not window handles and you do things the console way not the window way!
Code:
//Turn cursor on
DWORD CursorOn(HANDLE sout)
{
CONSOLE_CURSOR_INFO cur;
if (!GetConsoleCursorInfo(sout, &cur)) {
return (GetLastError());
}
cur.bVisible = TRUE;
return (!SetConsoleCursorInfo(sout, &cur) ? GetLastError() : 0);
}
//Turn cursor off
DWORD CursorOff(HANDLE sout)
{
CONSOLE_CURSOR_INFO cur;
if (!GetConsoleCursorInfo(sout, &cur)) {
return (GetLastError());
}
cur.bVisible = FALSE;
return (!SetConsoleCursorInfo(sout, &cur) ? GetLastError() : 0);
}
//Get cursor size
DWORD GetCursorSize(HANDLE sout, DWORD& size)
{
CONSOLE_CURSOR_INFO cur;
if (!GetConsoleCursorInfo(sout, &cur)) {
return (GetLastError());
}
size = cur.dwSize;
return (0);
}
//Set cursor size
DWORD SetCursorSize(HANDLE sout, DWORD size)
{
CONSOLE_CURSOR_INFO cur;
if (!GetConsoleCursorInfo(sout, &cur)) {
return (GetLastError());
}
cur.dwSize = size;
return (!SetConsoleCursorInfo(sout, &cur) ? GetLastError() : 0);
}
thanks.
maybe you like these line(the last line):
Code:
bool GetCaretVisible()
{
return blCaretVisible;
}
void SetCaretVisible(bool Visible)
{
if (Visible==true)
{
CursorOn(handle());
}
else
{
CursorOff(handle());
}
blCaretVisible=Visible;
}
__declspec ( property ( put = SetCaretVisible, get = GetCaretVisible ) ) bool CaretVisible ;
thanks for all
-
August 19th, 2013, 09:30 PM
#4
Re: the hidecaret() function isn't ok?
Originally Posted by Cambalinho
thanks.
maybe you like these line(the last line):
Code:
__declspec ( property ( put = SetCaretVisible, get = GetCaretVisible ) ) bool CaretVisible ;
thanks for all
What's that? That line is not C++, and it certainly has nothing to do with the Windows API (the topic of this forum).
Regards,
Paul McKenzie
-
August 20th, 2013, 02:43 AM
#5
Re: the hidecaret() function isn't ok?
Originally Posted by Paul McKenzie
What's that? That line is not C++, and it certainly has nothing to do with the Windows API (the topic of this forum).
Regards,
Paul McKenzie
i think is C++
is for transform that 2 subs in properties
see that 2 subs?
GetCaretVisible() and SetCaretVisible(bool Visible). they are overloading subs, but the line:
Code:
__declspec ( property ( put = SetCaretVisible, get = GetCaretVisible ) ) bool CaretVisible ;
'transform' that 2 sub in 1 property: CaretVisible .
now is more easy to use:
Code:
Console a;
a.CaretVisible=false;
Sleep= 5000; //wait 5 seconds
a.CaretVisible=true;
a.Read(); //wait until press any key;)
is more easy to use... that's why i share
(but, of course, we can use that 2 subs too(GetCaretVisible() and SetCaretVisible(bool Visible)).
thanks for all
-
August 20th, 2013, 04:23 PM
#6
Re: the hidecaret() function isn't ok?
Originally Posted by Cambalinho
i think is C++
is for transform that 2 subs in properties
That last line of code is not C++, and it has nothing to do with the Windows API.
Regards,
Paul McKenzie
-
August 20th, 2013, 04:30 PM
#7
Re: the hidecaret() function isn't ok?
Originally Posted by Paul McKenzie
That last line of code is not C++, and it has nothing to do with the Windows API.
Regards,
Paul McKenzie
so isn't compatible with Dev C++\ANSI?
-
August 21st, 2013, 10:20 AM
#8
Re: the hidecaret() function isn't ok?
Originally Posted by Cambalinho
so isn't compatible with Dev C++\ANSI?
Dev C++ is not a C++ compiler. It is an integrated development environment. It uses an old version of gcc as the compiler (3.x).
Second, that code is not ANSI C++, unless you can create some sort of tricky macros to get that line of code to compile. If you want proof, try to create a small program and get that line to compile here:
http://www.compileonline.com/compile_cpp_online.php
Regards,
Paul McKenzie
-
August 21st, 2013, 10:25 AM
#9
Re: the hidecaret() function isn't ok?
Originally Posted by Paul McKenzie
Dev C++ is not a C++ compiler. It is an integrated development environment. It uses an old version of gcc as the compiler (3.x).
Second, that code is not ANSI C++, unless you can create some sort of tricky macros to get that line of code to compile. If you want proof, try to create a small program and get that line to compile here:
http://www.compileonline.com/compile_cpp_online.php
Regards,
Paul McKenzie
like you understand my experience with C++ isn't the best. so i can't create that line easly
maybe i can with temples, but i don't know how
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|