how to change window's start button text? problem with my program
-
Im using MFC to make dailog based program. I have one button that will change my start button text to "TEST" after click. my program crash after I clicked on the button here is the code for the button. void CStart_Button_ChangerDlg::OnText() { HWND starthandle; CWnd StartButton; CWnd* Window = CWnd::FindWindow("Shell_TrayWnd",""); starthandle = FindWindowEx(NULL,NULL,"Button",""); StartButton.m_hWnd=starthandle; StartButton.SetWindowText("TEST"); StartButton.SendMessage(WM_SETTEXT,0,0); //SendMessage (StartButton, WM_SETTEXT, 0); }
-
Im using MFC to make dailog based program. I have one button that will change my start button text to "TEST" after click. my program crash after I clicked on the button here is the code for the button. void CStart_Button_ChangerDlg::OnText() { HWND starthandle; CWnd StartButton; CWnd* Window = CWnd::FindWindow("Shell_TrayWnd",""); starthandle = FindWindowEx(NULL,NULL,"Button",""); StartButton.m_hWnd=starthandle; StartButton.SetWindowText("TEST"); StartButton.SendMessage(WM_SETTEXT,0,0); //SendMessage (StartButton, WM_SETTEXT, 0); }
-
Im using MFC to make dailog based program. I have one button that will change my start button text to "TEST" after click. my program crash after I clicked on the button here is the code for the button. void CStart_Button_ChangerDlg::OnText() { HWND starthandle; CWnd StartButton; CWnd* Window = CWnd::FindWindow("Shell_TrayWnd",""); starthandle = FindWindowEx(NULL,NULL,"Button",""); StartButton.m_hWnd=starthandle; StartButton.SetWindowText("TEST"); StartButton.SendMessage(WM_SETTEXT,0,0); //SendMessage (StartButton, WM_SETTEXT, 0); }
Mouse_103 wrote: ...change my start button text to "TEST"... See here on how to do this. Mouse_103 wrote: starthandle = FindWindowEx(NULL,NULL,"Button",""); StartButton.SetWindowText("TEST"); Should be:
starthandle = FindWindowEx(Window->GetSafeHwnd(),NULL,"Button",NULL);
::SetWindowText(starthandle, "TEST");However, this will not work as intended as the Start button's text is not drawn in the normal fashion.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
-
Mouse_103 wrote: ...change my start button text to "TEST"... See here on how to do this. Mouse_103 wrote: starthandle = FindWindowEx(NULL,NULL,"Button",""); StartButton.SetWindowText("TEST"); Should be:
starthandle = FindWindowEx(Window->GetSafeHwnd(),NULL,"Button",NULL);
::SetWindowText(starthandle, "TEST");However, this will not work as intended as the Start button's text is not drawn in the normal fashion.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
--------------------Configuration: Start_Button_Changer - Win32 Debug-------------------- Compiling... Start_Button_ChangerDlg.cpp C:\-= My Stuff =-\Start_Button_Changer\Start_Button_ChangerDlg.cpp(186) : error C2660: 'SetWindowTextA' : function does not take 2 parameters Error executing cl.exe. Start_Button_Changer.exe - 1 error(s), 0 warning(s)
-
--------------------Configuration: Start_Button_Changer - Win32 Debug-------------------- Compiling... Start_Button_ChangerDlg.cpp C:\-= My Stuff =-\Start_Button_Changer\Start_Button_ChangerDlg.cpp(186) : error C2660: 'SetWindowTextA' : function does not take 2 parameters Error executing cl.exe. Start_Button_Changer.exe - 1 error(s), 0 warning(s)
The compiler is telling you exactly what the problem is. You are trying to use
CWnd::SetWindowText()
which does not take 2 parameters.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
-
The compiler is telling you exactly what the problem is. You are trying to use
CWnd::SetWindowText()
which does not take 2 parameters.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
I got it working now now Im trying to get working with the user defined edit box. I use control CEdit for the edit box. void CStart_Button_ChangerDlg::OnText() { HWND hWnd; RECT rc; if (hWnd = FindWindowEx(NULL, NULL, "Shell_TrayWnd", NULL)) { ::GetWindowRect(hWnd, &rc); if (hWnd = FindWindowEx(hWnd, NULL, "Button", NULL)) { /* CEdit* text = (CEdit*)GetDlgItem(IDC_EDIT1); CString gettext; text->GetWindowText(gettext); */ CString starttext; m_text.GetWindowText(starttext); ::SendMessage(hWnd, WM_SETTEXT, 0, (LPARAM)(LPTSTR) TEXT(starttext)); } } } compile error: Compiling... Start_Button_ChangerDlg.cpp C:\-= My Stuff =-\Start_Button_Changer2\Start_Button_ChangerDlg.cpp(199) : error C2440: 'type cast' : cannot convert from 'class CString' to 'char *' No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called Error executing cl.exe. Start_Button_Changer.exe - 1 error(s), 0 warning(s)
-
I got it working now now Im trying to get working with the user defined edit box. I use control CEdit for the edit box. void CStart_Button_ChangerDlg::OnText() { HWND hWnd; RECT rc; if (hWnd = FindWindowEx(NULL, NULL, "Shell_TrayWnd", NULL)) { ::GetWindowRect(hWnd, &rc); if (hWnd = FindWindowEx(hWnd, NULL, "Button", NULL)) { /* CEdit* text = (CEdit*)GetDlgItem(IDC_EDIT1); CString gettext; text->GetWindowText(gettext); */ CString starttext; m_text.GetWindowText(starttext); ::SendMessage(hWnd, WM_SETTEXT, 0, (LPARAM)(LPTSTR) TEXT(starttext)); } } } compile error: Compiling... Start_Button_ChangerDlg.cpp C:\-= My Stuff =-\Start_Button_Changer2\Start_Button_ChangerDlg.cpp(199) : error C2440: 'type cast' : cannot convert from 'class CString' to 'char *' No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called Error executing cl.exe. Start_Button_Changer.exe - 1 error(s), 0 warning(s)