CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Apr 2009
    Posts
    1,355

    [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)

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    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)

  3. #3
    Join Date
    Apr 2009
    Posts
    1,355

    Re: the hidecaret() function isn't ok?

    Quote Originally Posted by 2kaud View Post
    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

  4. #4
    Join Date
    Apr 1999
    Posts
    27,449

    Re: the hidecaret() function isn't ok?

    Quote Originally Posted by Cambalinho View Post
    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

  5. #5
    Join Date
    Apr 2009
    Posts
    1,355

    Re: the hidecaret() function isn't ok?

    Quote Originally Posted by Paul McKenzie View Post
    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

  6. #6
    Join Date
    Apr 1999
    Posts
    27,449

    Re: the hidecaret() function isn't ok?

    Quote Originally Posted by Cambalinho View Post
    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

  7. #7
    Join Date
    Apr 2009
    Posts
    1,355

    Re: the hidecaret() function isn't ok?

    Quote Originally Posted by Paul McKenzie View Post
    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?

  8. #8
    Join Date
    Apr 1999
    Posts
    27,449

    Re: the hidecaret() function isn't ok?

    Quote Originally Posted by Cambalinho View Post
    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

  9. #9
    Join Date
    Apr 2009
    Posts
    1,355

    Re: the hidecaret() function isn't ok?

    Quote Originally Posted by Paul McKenzie View Post
    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
  •  





Click Here to Expand Forum to Full Width

Featured