|
I agree - Automation is a way. BUT don't forget COM - it's much easier and less complicated then the snippets.
COM hides all the details.
If you are interested - contact me for an example using COM.
Regards
Michael Mogensen.
mm it-consult dk.
|
|
|
|
|
Michael Mogensen wrote:
Automation is a way. BUT don't forget COM - it's much easier and less complicated...
Automation and COM are not mutually exclusive. Remember that Automation is a technology based on the Component Object Model, that enables interoperability among components such as ActiveX. It makes it possible for one application to manipulate objects implemented in another application, or to "expose" objects so they can be manipulated by another.
|
|
|
|
|
|
thank you,
I will this method then I will get back to you, If i get any more doubts.
thanks for the attention and the time you spared for me.
bye
harinath
Harinath Reddy
HOneywell Technology Solutions Lab,
Bangalore,
India-560076
harinath@vandemataram.com
|
|
|
|
|
Hi,
Is there any way in which I could get all the controls that exist in a Dialog?
I went through most of the functions in CDialog and CWnd but couldn't find any.
Thanks in advance,
Melwyn
|
|
|
|
|
This is how we have to do.
Read it, understand it and learn your self.
CWnd *pWnd = m_pPropertySheet->GetWindow(GW_CHILD);
CWnd *pWnd1 = NULL;
CWnd *pWnd2 = NULL;
CString cstrCaption;
while(pWnd) //get all the controls on the property sheet
{
pWnd->GetWindowText(cstrCaption);
if( _T("OK") == cstrCaption ) //get one with caption "OK"
pWnd1 = pWnd;
if( _T("Cancel") == cstrCaption )//get one with caption 'Cancel"
pWnd2 = pWnd;
pWnd = pWnd->GetNextWindow(); //go to next control
}
if( pWnd1)
{
pWnd1->DestroyWindow(); //remove OK button
}
if( pWnd2)
{
pWnd2->DestroyWindow(); //remove Cancel button
}
m_bOKCancelRemoved = TRUE;
Harinath Reddy
HOneywell Technology Solutions Lab,
Bangalore,
India-560076
harinath@vandemataram.com
|
|
|
|
|
A little more friendly answer would be to look at the EnumChildWindows function. Let's say that you need to grey out all items on the dialog except the cancel button. This code would do that:
CMyDialog::DisableAllControls()
{
EnumChildWindows(GetSafeHwnd(),MyDisableProc,this);
}
// this is a static member fcn
BOOL CMyDialog::MyDisableProc(HWND hWnd, LPARAM lParam)
{
- CMyDialog *pDlg = (CMyDialog *)lParam;
-
- if (::GetDlgCtrlID(hWnd) != IDCANCEL)
- ::EnableWindow(hWnd,FALSE);
-
- return TRUE;
}
|
|
|
|
|
Hi basementman,
Thanks for giving me an alternative solution.
Your example makes it very clear.
Any idea how EnumChildWindows()is different from a GetWindow()+FindWindow() loop?
Thanks and Regards,
Melwyn
|
|
|
|
|
Hi Harinath,
Thanks for the reply.
It has solved my problem.
I guess the code you posted is a snippet from one of your projects. I was wondering is there any reason why you went with the GetWindow(GW_CHILD), GetNextWindow() loop rather than EnumChildWindow() function?
Regards,
Melwyn
|
|
|
|
|
I have create/selected a font, now depend on different situation i have to rotate the text accordingly, is there a function that can just rotate the text without going into creating a new font?
|
|
|
|
|
You need to create a new font and set the LOGFONT's lfEscapement value to the rotation required prior to creating the font. See the sample below:
// helper text-drawing function
void DrawOrientedText(CDC *pDC, CRect oR, short iOrientation, CString cText, LPLOGFONT lpLF, UINT iFlags/*=DT_CENTER*/,BOOL bSuppressSpace/*=FALSE*/)
{
CFont *pOldFont;
CFont oFont;
short iOldEscapement;
BOOL bExtruded = FALSE;
BOOL bRecessed = FALSE;
BOOL bHeavy = FALSE;
CString cDrawText;
if (iFlags & DRAW_EXTRUDED)
bExtruded = TRUE;
if (iFlags & DRAW_RECESSED)
bRecessed = TRUE;
if (iFlags & DRAW_HEAVY)
bHeavy = TRUE;
iFlags &= ~(DRAW_EXTRUDED|DRAW_RECESSED|DRAW_HEAVY);
if (bSuppressSpace)
cDrawText = cText;
else
cDrawText = CString(" ")+cText+CString(" ");
if (lpLF)
{
iOldEscapement = (short)lpLF->lfEscapement;
lpLF->lfEscapement = 0;
if (iOrientation == iORIENT_90)
lpLF->lfEscapement = 900;
if (iOrientation == iORIENT_270)
lpLF->lfEscapement = 2700;
oFont.CreateFontIndirect(lpLF);
pOldFont = pDC->SelectObject(&oFont);
lpLF->lfEscapement = iOldEscapement;
}
short iOldBkMode = pDC->SetBkMode(TRANSPARENT);
if (iOrientation == iORIENT_NORM || iOrientation == iORIENT_TB)
{
if (iOrientation == iORIENT_TB)
{
CString cTempText = cDrawText;
short iLen = cTempText.GetLength();
cDrawText = "";
char caChar[4];
caChar[1] = 13;
caChar[2] = 10;
caChar[3] = 0;
for (int iLup = 0; iLup < iLen; iLup++)
{
caChar[0] = cTempText[iLup];
if (caChar[0] == 13 || caChar[0] == 10)
caChar[0] = ' ';
cDrawText += CString(caChar);
}
}
if (iOrientation == iORIENT_TB || cDrawText.Find("\n") > -1)
iFlags |= DT_WORDBREAK;
else
iFlags |= DT_SINGLELINE;
iFlags |= DT_NOPREFIX;
if (bExtruded || bRecessed)
DrawTextSpecial(pDC,cDrawText,oR,iFlags,bExtruded,bRecessed,bHeavy);
pDC->DrawText(cDrawText,cDrawText.GetLength(),&oR,iFlags);
}
else
{
short iFontAdj = 5; // default to 10pt
if (lpLF)
iFontAdj = abs(lpLF->lfHeight) / 2;
if (iOrientation == iORIENT_270)
iFontAdj = (-iFontAdj) + 1;
else
iFontAdj -= 1;
short iX = oR.left + (oR.Width() / 2) - 1 + iFontAdj;
short iY = oR.top + (oR.Height() / 2);
short iOldAlign = pDC->SetTextAlign(TA_CENTER|TA_BASELINE);
if (bExtruded || bRecessed)
TextOutSpecial(pDC,cDrawText,iX,iY,bExtruded,bRecessed,bHeavy);
pDC->TextOut(iX, iY, cDrawText);
pDC->SetTextAlign(iOldAlign);
}
if (lpLF)
pDC->SelectObject(pOldFont);
pDC->SetBkMode(iOldBkMode);
}
|
|
|
|
|
I have to create a class which can manage multiple print jobs (adding jobs, deleting, enumerating etc.).
I have to use multi-threading also.
Can you please suggest what kind of data structure i should use? Any do-s and donts?
Any other suggestions and help would be greatly appreciated.
Thanks,
Stilgar.
|
|
|
|
|
How can I copy a pointer to an item of an array pointer such as below?
<br />
ClassA *ptr = new ClassA[5];<br />
ClassA *ptr1 = somePointerOFClassA;<br />
ClassA *ptr2 = somePointerOFClassA;<br />
ptr[0] = ptr1;
&(ptr[1]) = ptr2;
What should I do?
|
|
|
|
|
ptr[0] is an actual object, not a pointer to an object. Therefore, it needs to be assigned the value of ptr1, not the address of ptr1.
ptr[0] = *ptr1;
|
|
|
|
|
The array pointer declaration could be:
ClassA **ptr = new ClassA*[5]; Then use ptr[i] = ClassAPtr.
rechi
|
|
|
|
|
If you want an array of pointers then do like this
ClassA *ptr[5];
ClassA *ptr1 = somePointerOFClassA;
ClassA *ptr2 = somePointerOFClassA;
and now
ptr[0]=ptr1;
jhaga
|
|
|
|
|
the line
ClassA *ptr = new ClassA[5];
defines an array of 5 ClassA objects, not an array of 5 ClassA pointers.
If you want an array of 5 ClassA pointers, your declaration will have to be:
ClassA **ptr = new ClassA*[5];
and then you will be able to execute the following code (or similar):
<br />
ClassA *ptr1 = somePointerOFClassA;<br />
ClassA *ptr2 = somePointerOFClassA;<br />
<br />
ptr[0] = ptr1;<br />
ptr[1] = ptr2;<br />
Now, coming back to your previously mentioned code block.Unfortunately, once you have defined an array as you have :
ClassA *ptr = new ClassA[5];
You cannot actually change the address of an element within that array, ie, you cannot do this:
&ptr[0] = ptr1
Hope this helps some.
Cheers,
Peter
-------------------------------------------
99 little bugs in the code, 99 little bugs,
Fix 1 bug, recompile....
101 little bugs in the code...
|
|
|
|
|
I have a VB6 (WebClass) application that, from time to time, is failing to create some random COM object (it's not always the same component). From FileMon and RegMon traces I suspect that the error occurs on CoCreateInstance, but I have no access to the HRESULT of CoCreateInstance on VB, so I have no clue of what is the problem.
Does anyone know if is there some application that hooks on CoCreateInstance and allows me to know the HRESULT it is returning?
My latest article: GBVB - Converting VB.NET code to C#
|
|
|
|
|
Hi all,
I'm trying to find and load a resource from another application. Here's the code I'm using:
HINSTANCE hToDLL;
HRSRC hsrc;
hsrc = FindResource(GetModuleHandle(app),icon,RT_ICON);
where app = "someapp.exe" and
icon = "IDI_ICON3"
This ALWAYS returns a NULL pointer, so it's always failing and the GetLastError always gives me a:
1813 The specified resource type cannot be found in the image file. ERROR_RESOURCE_TYPE_NOT_FOUND
Now I know the resource exists in the application I'm trying to get at, so what am I doing wrong?? Do I need to call LoadLibrary first? I don't think I should have to.
Any insights, help, suggestions, comments are greatly appreciated. Thanks!
Dan
|
|
|
|
|
The GetModuleHandle() function retrieves a module handle for the specified module if the file has been mapped into the address space of the calling process. Had you checked the return value of it, rather than immediately calling FindResource(), this might have been evident.
|
|
|
|
|
DavidCrow wrote:
The GetModuleHandle() function retrieves a module handle for the specified module if the file has been mapped into the address space of the calling process. Had you checked the return value of it, rather than immediately calling FindResource(), this might have been evident.
Gotcha,
I understand now, but then what do I need to do to map the file into the address space? Call LoadResource?
Thanks!
Dan
|
|
|
|
|
HMODULE hModule;
HRSRC hResource;
hModule = LoadLibrary(...);
if (NULL != hModule)
{
hResource = FindResource(hModule, ...);
if (NULL != hResource)
{
LoadResource(hResource, ...);
}
FreeLibrary(hModule);
}
|
|
|
|
|
Thanks,
I'll try that and report back
|
|
|
|
|
Since the module is an EXE, you may want to use the LoadLibraryEx() function instead, passing LOAD_LIBRARY_AS_
DATAFILE for the Flags parameter. This will prevent any calls to unresolved externals (like DllMain) and prevent the loader from loading any dependent dlls that the EXE imports.
|
|
|
|
|
Ok,
I'm further in my understanding, but still no further in a solution. Here's what I have now:
HMODULE hModule;
HRSRC hResource;
sprintf(buff,"%s.exe",app);
hModule = LoadLibraryEx(buff,NULL,LOAD_LIBRARY_AS_DATAFILE);
if (NULL != hModule){
hResource = FindResource(hModule,"IDI_ICON3",RT_ICON);
if (NULL != hResource) {
IUXLogData("the resource exists\n",TRACE1);
//LoadResource(hResource, ...);
} else if ( NULL == hResource ) {
sprintf(buff,
"the %s app is not up to date with error %d\n",
app,
GetLastError());
IUXLogData(buff,IUX_ERROR);
}
FreeLibrary(hModule);
}
I'm still getting an 1814 error though. Still unsure why I am. Is the "IDI_ICON3" or the RT_ICON the wrong stuff? the ICON resource for my test is IDI_ICON3 and I'm sure its in the app I'm trying to open, so I'm confused as to why I'm seeing this.
Any suggestions, insight, comments are greatly appreciated
Thanks!
Dan
|
|
|
|
|