Any ideas how to use SetParent()?
The following doesn't seem to work:
fhWnd = FindWindow(_T("Notepad"), NULL);
hWnd = CreateWindowEx(WS_EX_TOPMOST , _T("test"), _T("test"),
WS_POPUP,
20, 20, 400, 400, NULL, NULL, hInst, NULL);
SetParent(hWnd, fhWnd);
DWORD style = GetWindowLong(hWnd, GWL_STYLE);
style = style & ~(WS_POPUP);
style = style | WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
SetWindowLong(hWnd, GWL_STYLE, style);
SetWindowLong(fhWnd, GWL_STYLE, GetWindowLong(fhWnd, GWL_STYLE) | WS_CLIPCHILDREN);
With the above code I have to move the parent window out of the screen and back in again in order to see what's draw on the child window.
Any idea what I am doing wrong?
Related
I want make a hidden window visible.
HWND hWnd = FindWindow(NULL, "MyWindowName");
ShowWindow(hWnd, SW_SHOW);
The window is found, but nothing happens. It remains hidden.
What am I doing wrong?
If it matters, the application is made using MFC and it has the following method overwritten:
void CMyClass::OnWindowPosChanging(WINDOWPOS* lpwndpos)
{
lpwndpos->flags &= ~SWP_SHOWWINDOW;
CDialog::OnWindowPosChanging(lpwndpos);
}
I did it.
Apparently you need to modify some flags.
long style= GetWindowLong(hWnd, GWL_STYLE);
style |= WS_VISIBLE;
SetWindowLong(hWnd, GWL_STYLE, style);
SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
And it works.
As the title says, I can't get it working. The button works and looks like normal...
HWND hWndButtonGetRes = CreateWindowEx(NULL,
"BUTTON",
"Get Results",
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
50,
220,
100,
24,
hwnd,
(HMENU)IDC_MAIN_BUTTON,
GetModuleHandle(NULL),
NULL);
SendMessage(hWndButtonGetRes, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)myBitmap);
Edit:
The bitmap is being loaded this way:
myBitmap = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(BM))
where BM is
BM BITMAP DISCARDABLE "bitmap.bmp"
#define BM 1
I am running Windows 7 64.
I have Created an Edit window.
I want one string to be displayed in one line and the other string to be displayed on the other line, but the code I am executing only displays the second string. below is my code snippet:
hWndEdit = CreateWindow("EDIT", // We are creating an Edit control
NULL, // Leave the control empty
WS_CHILD | WS_VISIBLE | WS_HSCROLL |
WS_VSCROLL | ES_LEFT | ES_MULTILINE |
ES_AUTOHSCROLL | ES_AUTOVSCROLL,
10, 10,1000, 1000,
hWnd,
0,
hInst,NULL);
SetWindowText(hWndEdit, TEXT("\r\nFirst string\r\n"));
SetWindowText(hWndEdit, TEXT("\r\nSecond string"));
OUTPUT:
You are only seeing the last line because SetWindowText() replaces the entire contents of the window in one go.
If you want to display both lines at one time, simply concatenate them together in a single call to SetWindowText():
SetWindowText(hWndEdit, TEXT("\r\nFirst string\r\n\r\nSecond string"));
On the other hand, if you want to insert them at different times, you have to use the EM_SETSEL message to place the edit caret at the end of the window and then use the EM_REPLACESEL message to insert text at the current caret position, as described in this article:
How To Programatically Append Text to an Edit Control
For example:
void AppendText(HWND hEditWnd, LPCTSTR Text)
{
int idx = GetWindowTextLength(hEditWnd);
SendMessage(hEditWnd, EM_SETSEL, (WPARAM)idx, (LPARAM)idx);
SendMessage(hEditWnd, EM_REPLACESEL, 0, (LPARAM)Text);
}
.
AppendText(hWndEdit, TEXT("\r\nFirst string\r\n"));
AppendText(hWndEdit, TEXT("\r\nSecond string"));
hWndEdit = CreateWindow("EDIT", // We are creating an Edit control
NULL, // Leave the control empty
WS_CHILD | WS_VISIBLE | WS_HSCROLL |
WS_VSCROLL | ES_LEFT | ES_MULTILINE |
ES_AUTOHSCROLL | ES_AUTOVSCROLL,
10, 10,1000, 1000,
hWnd,
0,
hInst,NULL);
SetWindowText(hWndEdit, TEXT("\r\nFirst string\r\n\r\nSecond string"));
or
SetWindowText(hWndEdit, TEXT("\r\nFirst string\r\n"));
char* buf = malloc(100);
memset(buf, '\0', 100);
GetWindowText(hWndEdit, (LPTSTR)buf, 100);
strcat(buf, "\r\nSecond string");
SetWindowText(hWndEdit, (LPTSTR)buf);
My code as follow, but the background doesn't transparent also.. What should i do ?
QAxWidget *flash = new QAxWidget(0,0);
flash->resize(200,200);
flash->setControl(QString::fromUtf8("{d27cdb6e-ae6d-11cf-96b8-444553540000}"));
flash->dynamicCall("LoadMovie(long,string)",0,"D:/test.swf");
flash->dynamicCall("WMode", "transparent");
flash->show();
By the way,,In Qt , is there a another way to show swf ? Thank you....
add
flash->setAutoFillBackground(true)
if the movie has a transparent background, you should see widget's original backgorund
try this code
QAxWidget *flash = new QAxWidget(0, 0);
flash->resize(500, 400);
HWND hWnd = (HWND)flash->winId();
LONG lStyle = ::GetWindowLong(hWnd, GWL_STYLE);
lStyle &= ~(WS_CAPTION | WS_THICKFRAME | WS_MINIMIZE | WS_MAXIMIZE | WS_SYSMENU);
::SetWindowLong(hWnd, GWL_STYLE, lStyle);
LONG lExStyle = ::GetWindowLong(hWnd, GWL_EXSTYLE);
::SetWindowLong(hWnd, GWL_EXSTYLE, lExStyle|WS_EX_LAYERED|WS_EX_TOPMOST|WS_EX_TRANSPARENT);
typedef int (WINAPI* LPFUNC)(HWND, COLORREF , BYTE, DWORD);
HINSTANCE hins = ::LoadLibraryW(L"User32.DLL");
if(!hins)
return ;
LPFUNC func2 = (LPFUNC)GetProcAddress(hins,"SetLayeredWindowAttributes");
if(!func2)
return ;
COLORREF clrMask = RGB(255,255,255);
func2(hWnd, clrMask, 0, LWA_COLORKEY);
FreeLibrary(hins);
flash->setControl(QString::fromUtf8("{d27cdb6e-ae6d-11cf-96b8-444553540000}"));
flash->dynamicCall("LoadMovie(long,string)", 0, "d:/9023.swf");
flash->dynamicCall("WMode", "transparent");
flash->show();
show activex with transparent background.
I have a richedit control on a dialog. I want to populate the richedit control with a string. The richedit control itself displays properly. But I don't know how to populate the richedit control with a string. I took a guess at it below, in the resource.rc code.
In main.cpp, I have:
case IDC_BUT_ABOUT:
{
HINSTANCE hRichEdit;
hRichEdit = LoadLibrary("RICHED32.DLL");
DialogBox( hInst, MAKEINTRESOURCE(IDD_ABOUT), hDlgWnd,(DLGPROC)InitAbout );
//ShowWindow(hDlgWnd, SW_SHOWNORMAL);
return TRUE;
}
break;
In resource.rc, I have:
IDD_ABOUT DIALOGEX 0, 0, 206, 136
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "About"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
PUSHBUTTON "Close",IDCANCEL,77,115,50,14
CONTROL "",IDC_RICHEDIT21,"RichEdit20W",ES_AUTOHSCROLL | ES_READONLY | WS_BORDER | WS_TABSTOP,36,53,130,46
END
string rt = "{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Arial;}{\f1\fnil\fprq2\fcharset0 Biondi;}}{\colortbl ;\red255\green0\blue0;}\viewkind4\uc1\pard\f0\fs20\par\cf1\f1 hello\cf0\f0 \ul some text here\par}";
this.IDC_RICHEDIT21.Rtf = rt;
But this apparently isn't even close to how I should put text from a string into a rich edit control?
Try EM_SETTEXTEX or EM_STREAMIN.