|
In fact, NT has two versions of FindWindow (as well as other API functions). FindWindowW uses Unicode, FindWindowA uses ASCII.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
I've been having a problem recently that has really been bugging me; for some reason, when I use printf or cout, the output will not appear on the console - I assume this is because stdout is not being flushed. Any idea why this is? I don't want to have to call fflush(stdout) after every printf!
|
|
|
|
|
Stdout is normally line-buffered, so end your printfs with \n. When printing to cout, add a "cout << endl" to get a newline.
--Mike--
http://home.inreach.com/mdunn/
A recent survey reports that 1/4 of all internet users in England surf for porn.
The other 3/4 just didn't want to admit it.
|
|
|
|
|
I was already doing this - it's not working.
|
|
|
|
|
I am using CListBox::SetTopIndex() to make sure I can view the last entry in a list box. I would like the view to adjust so the last entry is shown about half way between the top of the bottom of the list box control. I created a quick formula to do this, however, I found that using SetTopIndex() will make the last entry visible, but no matter what I put as the index for SetTopIndex(), it always puts the last entry at the bottom of the list box control. Visible yes, what I want, no.
Any ideas?
Thanks
John
|
|
|
|
|
Do I understand correctly, you want the last item entered into a list box to be displayed centered vertically? There are no other entries in the list box below this one?
If this is what I understand then you can't. What you may have to do is add empty strings to pad the listbox and move the item up.
|
|
|
|
|
Dumb question.. If I have a dialog type application called "A".. and I create dialog box "B" within the same app. I then create a member variable for "B" in "A"s Class how can I update a control on "A" from "B".. for example lets say I have a listbox on dialog "A" and I input a string into an edit box on dialog "B" from "B" I want to add the item to the listbox on "A" with out actually pulling the string from "A" and inserting it.. can this done or do I have to update the variable and add it while in "A"?
Any help would be greatly appreciated.
Rob Jones
|
|
|
|
|
You could do that with ::SetDlgItemText(..)
Or eaven send a window message to a control
|
|
|
|
|
Hi,
I currently have a bitmap that is being held in a CDC and I would like to get a peice of that bitmap and save it to another bitmap. For instance, let's say that I have a bitmap that is 100 x 100 pixels. I want to select region 25, 25, 50, 50 copy it to another DC I guess? and then save it out to another .bmp file.
Does anyone know how to do this? I have the coordinates of what I want to copy to the new bitmap but don't know how to do it.
Thanks for any help you can provide,
Craig
|
|
|
|
|
Create a new CBitmap of the size you want, a new CDC to hold the CBitmap, and then use BitBlt to copy across the section you want.
Christian
Secrets of a happy marriage #27:
Never go to bed if you are mad at each other. It's more fun to stay up and fight.
|
|
|
|
|
Hi Christian,
Here is what I've got so far:
CDC dcMemory;
dcMemory.CreateCompatibleDC(&dc);
COXDIB imagePiece;
imagePiece.CreateEmptyDIB(1, 55, 50);
CBitmap* pOldBitmap = imagePiece.MakeBitmap(&imagePiece, &dcMemory, CSize(55, 50));
dc.BitBlt(0, 0, 55, 50, &dcMemory, x, y, SRCCOPY);
CFile imageFile("c:\\temp\\imageManip\\testResult.bmp", CFile::modeCreate|CFile::modeWrite);
imagePiece.Write(&imageFile);
dcMemory.SelectObject(pOldBitmap);
When I look at the image that I created it is just all black, nothing else.
Am I on the right track?
Thanks,
Craig
|
|
|
|
|
What is a C0XDIB ? I assume a DIBSection wrapper ? x and y are valid values ? I can't comment on what you're doing wrong, but as therest looks fine I'd assume it's in the section:
COXDIB imagePiece;
imagePiece.CreateEmptyDIB(1, 55, 50);
CBitmap* pOldBitmap = imagePiece.MakeBitmap(&imagePiece, &dcMemory, CSize(55, 50));
if x and y are good values, because I have no idea what the syntax for this class you're using is. I'd bet on the last line if I had to make a guess, but only because CreateEmtyDIB is obviously working ;0
Christian
Secrets of a happy marriage #27:
Never go to bed if you are mad at each other. It's more fun to stay up and fight.
|
|
|
|
|
ok, so let's say I try something like this:
CDC dcMemory;
dcMemory.CreateCompatibleDC(&dc);
dc.BitBlt(0, 0, 55, 50, &dcMemory, x, y, SRCCOPY);
CBitmap bitmap;
CFile imageFile("c:\\temp\\imageManip\\testResult.bmp", CFile::modeCreate|CFile::modeWrite);
imageFile.Close();
Given that, how would I copy the dcMemory into the new CBitmap? After that, how do I write out the CBitmap to a file?
Sorry for such basic questions,
Craig
|
|
|
|
|
The way you were trying - by calling CreateBitmap on the bitmap, with the bits per pixel of the old bitmap and the size you want. Select it into a new DC and call BitBlt, just like you were doing.
For saving, if you don't want to use GDI+, there is a recent submission to this site that saves bitmaps in multiple formats.
Christian
Secrets of a happy marriage #27:
Never go to bed if you are mad at each other. It's more fun to stay up and fight.
|
|
|
|
|
Thanks Christian, I'll give it a try.
|
|
|
|
|
Hi, in my program I have two classes, say A and B. In class A I need to use B's functions, while in B I need to use A's. If in A I include B.h and in B I include A.h the compiler will complain. How can I make it work?
|
|
|
|
|
Include the files in the .cpp file. Or, if you need to declare an instance of A in B and B in A, then in one of them include in the .cpp file and in the header just put a dummy declaration, for example in B.h you might put
class A();
A m_MyA;
and include the *real* A.h in B.cpp.
Christian
Secrets of a happy marriage #27:
Never go to bed if you are mad at each other. It's more fun to stay up and fight.
|
|
|
|
|
I would like to know, how to get the directory where the application is installed.
I tried to use _getcmd but this doesn't works correctly.
Thanks for your help!
|
|
|
|
|
char szAppName[2000];
char szDrive[200];
char szDir[200];
memset(szAppName, 0, 2000);
memset(szDrive, 0, 200);
memset(szDir, 0, 200);
::GetModuleFileName(AfxGetInstanceHandle(), szAppName, 2000);
_splitpath(szAppName, szDrive, szDir, NULL, NULL);
|
|
|
|
|
The best way to do this is to get the folder from the application .EXE path.
To do that, you need to use the Win32 API GetModuleFileName(). That API will return the complete pathname of the calling process' EXE. Unfortunately, it can return an 8.3 style filename and can mangle your directory names. I've included a Win95 safe short->long pathname conversion function ( Win95 doesn't support this ). Finally, once you have a nice looking path, you chop off the .EXE name path off with another funciton I've included GetPathOnlyFromPathname.
CString MyPath =
GetPathOnlyFromPathname(GetLongPathname(GetAppPathname()));
where you have the following 3 utility functions:
CString GetAppPathname(void);
CString GetLongPathname(const CString & ShortPathname);
CString GetPathOnlyFromPathname(const CString & PathName);
// returns the full pathname of the application
CString CVChatApp::GetAppPathname(void)
{
char szAppPath[2048];
GetModuleFileName(NULL, szAppPath, sizeof(szAppPath));
return (GetLongPathname(szAppPath));
}
The GetModuleFileName call will return an 8.3 style pathname to the EXE. You may want to convert that into a long filename so the directory name doesn't get mangled:
// convert a short DOS type 8.3 pathname to a Long Filename is the
// version of Windows support the export of the "GetLongPathName" API ( Win95 doesn't )
CString GetLongPathname(const CString & ShortPathname)
{
CString FullPath;
// Win95 doesn't have the GetLongPathName function,
// so we need to check the dll to see if it exists to avoid
// a fatal run-time error.
// Also, note that the name of the function as specified in the DLL
// is different than the called name, due to UNICODE macro preprocessors
// AND, I think GetLongPathName is a pascal-style called function, so
// have to add __stdcall (__cdecl is the default, which is buggy)
HMODULE hm;
hm = GetModuleHandle("kernel32.dll");
typedef unsigned long (__stdcall *PFI)(LPCTSTR lpszShortPath, LPTSTR lpszLongPath, DWORD cchBuffer);
PFI pGetLongPathName;
FARPROC pTemp;
pTemp = GetProcAddress(hm, "GetLongPathNameA");
char strLongName[MAX_PATH];
strcpy(strLongName, "");
if (pTemp != NULL)
{
DWORD dw;
pGetLongPathName = (PFI)pTemp;
dw = (*pGetLongPathName)(ShortPathname, strLongName, MAX_PATH);
}
else
{
strcpy(strLongName, ShortPathname);
}
FullPath = strLongName;
return FullPath;
}
and you'll need one other function:
CString GetPathOnlyFromPathname(const CString & PathName)
{
CString PathOnly = PathName;
// ReverseFind the first '\'
int iFound = PathOnly.ReverseFind('\\');
if(iFound != -1)
{
PathOnly = PathOnly.Left(PathOnly.ReverseFind('\\'));
// put a trailing '\' on if the last char is a ':'
if(PathOnly.GetAt(PathOnly.GetLength()-1) == ':')
PathOnly += "\\";
}
else
{
PathOnly.Empty();
}
return(PathOnly);
}
Hope this helps...
|
|
|
|
|
Hi there I was wondering how you can increment an ActiveX version automatically after every build.
I was also wondering how you can access the version information provided under resources in Visual C++.
thanks
|
|
|
|
|
Hello,
I want to create a control which basically encompasses MS Word/ MS Project.
Basically my application needs a dialog box where it has a button and MS word window (The entire window along with menus and toolbars) in it.
How should I go about.
I tried the standard OLE method. Added MSWORD9.olb type library into the project and got its associated class. Then I created an object of application class and instantiated it. Added a document and finally made it visible.
Then I tried getting handle to the word window and tried making it a child window of the control. But this doesnt seem to work (I basically cant move the window into the control).
I am sure this is a wrong way of doing it. Can anyone tell me how should I create such a control.
Thanks
Arvind
The following is a snippet of code I added in the control's OnDraw Function.
COleVariant vTrue((short)TRUE), vFalse((short)FALSE), vOpt((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
_Application oWordApp; // this is part of MSWORD9.olbDocuments oDocs;
_Document oDoc;
oDocs = oWordApp.GetDocuments();
oDoc = oDocs.Add(vOpt, vOpt, vOpt, vOpt);
m_bFirstTime = FALSE;
oWordApp.SetVisible(TRUE);
m_szDocName = oDoc.GetName();// this will set the value for the member variable m_hWordWindow
::EnumChildWindows(NULL, WndProc,(LPARAM) this);
::SetParent(m_hWordWindow, m_hWnd);
::GetWindowLong(m_hWordWindow,nIndex);
::SetWindowLong(m_hWordWindow,GWL_STYLE,nIndex&(~WS_CAPTION|WS_TABSTOP|~WS_POPUP));
GetClientRect(&rWndRect);
ScreenToClient(&rWndRect);
ClientToScreen(&rWndRect);
::SetWindowPos (m_hWordWindow,NULL,rWndRect.left,rWndRect.top, (rWndRect.right-rWndRect.left),(rWndRect.bottom-rWndRect.top), SWP_NOACTIVATE|SWP_SHOWWINDOW|SWP_DRAWFRAME);
::MoveWindow(m_hWordWindow,rWndRect.left,rWndRect.top, (rWndRect.right-rWndRect.left),(rWndRect.bottom-rWndRect.top), TRUE);
Can Someone Tell me where I have gone wrong and what I should do. Any help would be greatly appreciated.
Thanks
|
|
|
|
|
I am currently having problems with the CSocket Class. My main problem is that when I call the Accept(), function my program will crash. I believe I am using all the correct parameters. Even in sample programs that I have downloaded it does the same thing, I was wondering if perhaps it had to do with me using Win2k. Any help will be Greatly Appreciated.
-Aaron
|
|
|
|
|
Here is a sample of code I'm using and it works fine.. I am all so running windows 2k pro.. so I doubt that the OS is the problem.. If this doesnt help, I could email you the whole project I made and you can try to run it on your pc to rule out OS or what not..
void CChatDlg::OnAccept()
{
if(m_bConnected)
{
//create a rejection socket
CAsyncSocket sRjctSock;
//Acept using the rejection socket
m_sListenSocket.Accept(sRjctSock);
//Close the socket
sRjctSock.Close();
}
else
{
//Accept the connection request
m_sListenSocket.Accept(m_sConnectSocket);
//Mark the socket as connected
m_bConnected = TRUE;
UpdateData(FALSE);
}
}
Hope this helps..
Rob Jones
|
|
|
|
|
Hi!
I need to create installation program for a few applications with dependency
between them(one application run another etc.)
Between files i should install there are some .ocx(ActiveX) or even
COM objects that i should register in the registry of local machine.
I'am trying to use InstallShield of the Visual Studio but i do not
understand how can i know(maybe there are some functions available in script) if the specified .ocx or .dll is already registered on that machine or not. This deal seems me to be confusing(I'am not familiar so good with registry).
Could somebody help me.
Thank you.
Alexander
|
|
|
|
|