|
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
|
|
|
|
|
|
If i can understand your question i use InstallShield the part of Visual Studio and its help but as i said before the my probem is having .ocx .dll to know if these files are already registered in that machine or not.
Sorry for telling my story anew.
Alexander
|
|
|
|
|
Hi,
If I understand your question correctly, what you need to do is create a "Component" specifically for these shared self-registering files. If you select the Component in InstallShield, and look at its properties, you will find one for "Overwrite". What you need to do is select the criteria for overwrite. Usually, you will probably want to choose "Overwrite files BY VERSION THEN DATE" with both the NEWER options as well. This means the install will only ever overwrite these files if they have a higher version than the currently installed ones.
The self-registering bit is a whole other kettle of fish. You need to create a "File Group" for self-registering files as well (basically, the Component I mentioned above will contain this "File Group"). If you view the File Group properties, there is a self-registering option which will allow you to mark all of the files in this File Group as self-registering.
So, if you create a Component and File Group as described, Installshield SHOULD check the version of existing OCX and DLL files, overwrite them if your installer's files have a higher version, and then register them. Note that if a program on the install machine is using one of these registered files, you will get the "You need to reboot your machine..." message once the install is finished, and Installshield will register these files after the restart.
Hope this helps.
------------------------
Derek Waters
derek@lj-oz.com
|
|
|
|
|
After years of default Msdev looking I have completely reworked its toolbar and menu, added a lot of tool found here and added several custom icon.
Now how can I save all this modification in order to restore after an (eventual) crash or to restore on another computer to have exactly the same environnement ?
Thanks for any help I searched but didn't found anything on this.
|
|
|
|
|
Save the following keys under HKCU\Software\Microsoft\Devstudio\6.0 - Debug, Format, General, Keyboard, Layout, Text Editor, Tools.
--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 read on your page that you studied french about 6 years so:
Ce n'est pas tres pratique mais ca peux servir
dommage que microsoft n'aie pas inclu la possibilité
de sauver la configuration.
en tout cas Merci beaucoup.
hope you didn't forget your curse.
For my part I studied german about 6 years and I can't remember one word... mhhh perhaps "ja" ?
|
|
|
|
|
Does anyone know how to get the user's group name for the
current user with Visual C++ in WinNT?
plz
Jancsi
|
|
|
|
|
Take a look at NetUserGetGroups() in your doc's.
Ben Burnett
---------
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
The following proc should find the record(contract)in db based on type(takes the position in the file and compare to the Type in the db).Proc. should return contract for use in different proc.
Please help...I can't understand why it's not working.
dbproc_get1 ->connection to SQL
int find_record()
{dbcmd (dbproc_get1, "select contract from type");
dbfcmd(dbproc_get1,"where type = %d",Type);
// Send the command to SQL Server and start execution.
dbsqlexec (dbproc_get1);
// Process the results.
if (dbresults (dbproc_get1) == SUCCEED)
{dbbind (dbproc_get1, 1, INTBIND, 0, (BYTE *) &contract);
while (dbnextrow (dbproc_get1) != NO_MORE_ROWS)
return(1);
}
|
|
|
|
|