|
Damn! I just realised that in my example, the call to "do_stuff" should have been in Base's constructor, not in Derived's.
I still don't care though.
----------------
Blaster
Computer game programmer and part time human being
http://www.blastersoft.com
|
|
|
|
|
At this time I have a window in which i draws and saves screen window as bmp.
But i want to draw shapes on a window that is hidden.
I am confused that with which device context i should draw.
It will be great if u guide me on this problem.
|
|
|
|
|
dont use a window device context as such
create a memdc compatible with the window dc bitmap and draw there
"even if my world is weird its my world" biz stuff about me
|
|
|
|
|
Yes u r right
but when creating memDC using CreateCompatibleDC(....
In parameters of this function device context with which drawing is done is also given.
So what device context shold be the parameter.
As
I am creating memDc in constructor of my view class
and getting devicecontect as
CDC *pDC=GetDC(); //step1/
//doing drawing with this pdc as pDC->Rectangle(....
//after this
CDC memDC;
memDC.CreateCompatibleDC(pDC);
//and then saving window image as bmp
but i am getting an empty image in bmp file.
If i use
HDC hdc=::GetDC(NULL) in place of step1
i get figures drawn but also the desktop imageis also painted.
So which device context should be used in step1.
Thanks for ur answer
|
|
|
|
|
mkashifkkj wrote:
So which device context should be used in step1.
The screen DC, GetDC(0), will do just fine.
|
|
|
|
|
I do a lot of drawing on "imaginary" surfaces.
You could always try something like this:
<br />
BITMAP bm;<br />
GetObject(hBmp, sizeof(BITMAP), &bm);<br />
<br />
BITMAPINFO bmInfo;<br />
memset(&bmInfo.bmiHeader, 0, sizeof(BITMAPINFOHEADER));<br />
bmInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);<br />
bmInfo.bmiHeader.biWidth = bm.bmWidth;<br />
bmInfo.bmiHeader.biHeight = bm.bmHeight;<br />
bmInfo.bmiHeader.biPlanes = 1;<br />
bmInfo.bmiHeader.biBitCount = 24;<br />
<br />
HDC TmpDC = CreateCompatibleDC(NULL);<br />
<br />
BYTE *pbase;<br />
HBITMAP TmpBmp = CreateDIBSection(TmpDC &bmInfo, DIB_RGB_COLORS, (void**)&pbase, 0, 0);<br />
<br />
HGDIOBJ TmpObj = SelectObject(TmpDC, TmpBmp);<br />
<br />
HDC dcBmp = CreateCompatibleDC(TmpDC);<br />
SelectObject(dcBmp, hBmp);<br />
<br />
BitBlt(TmpDC, 0, 0, bm.bmWidth, bm.bmHeight, dcBmp, 0, 0, SRCCOPY);<br />
<br />
<br />
<br />
DeleteDC(dcBmp);<br />
<br />
DeleteObject(hBmp);<br />
hBmp = TmpBmp;<br />
SelectObject(TmpDC, TmpObj);<br />
DeleteDC(TmpDC);<br />
|
|
|
|
|
If I use InsertMenu and
BOOL InsertMenu( UINT nPosition, UINT nFlags, UINT nIDNewItem = 0, LPCTSTR lpszNewItem = NULL );
and do it in a loop which sticks in an incremented integer i (5000, 5001, 5002, etc) in the nIDNewItem position, then when I address this item in the future say using RemoveMenu(), then since I didnt put in something like ID_MYITEM, but a number instead, can I just say RemoveMenu(5001, MF_BYCOMMAND) ? Even though I didnt have a value like ID_MYITEM for that menu item?
When you add menu items dynamically , does it make entries in the resource.h file temporarily, and deletes them when the program is done?
Appreciate your help,
ns
|
|
|
|
|
Those ID_MYITEM s are just mnemonics for plain numbers. I.e. if resource.h contains
#define ID_MYITEM 5000 then ID_MYITEM is replaced by 5 before before compilation; it is just convenient notation. resource.h is not changed in any manner when running the program. So to sum it up, it is OK to add items the way you are doing without resorting to any macros defined in resource.h .
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Ok,
I've been reading up like crazy, and I really still don't understand the benefits of using a ReBar Vs. using a bunch of ToolBars. You still have to use the toolbars anyways and then add them to the Rebar, so what is the whole point of a rebar?
And can you have more than 1 rebar?
Any insights on this matter are extremely helpful. Thank you.
Dan Willis
|
|
|
|
|
Hi,
In ReBar you can use controls like ComboBox, EditBox, ..., Also ReBar supports various features like Bitmap background. See Hotbar for an example!
A. Riazi
|
|
|
|
|
The ReBar control (which can contain multiple bars) has different layout rules than normal MFC toolbars - ReBars cannot be floated, can overlap, and move immediately when dragged. IMHO, they are generally more difficult for users to lose or accidentally close than toolbars, but if you need the cabability to drag from one side of the window to another or to float, you'll need to implement the functionality yourself or use normal toolbars.
---
Shog9
I see the way the salesmen stare into the sun
I stood and watched them as they fell off one by one...
|
|
|
|
|
Does anyone know of a good way to replace a running executable file.
Specifically, I have a piece of client software that I want to be able to update from the server. I need some sort of mechanism to replace the executable file while it is running. Obviously, I can readily download a new binary from the server without any problems, the question is how to get it executing?
I had considered the idea of using a little proxy program with this algorithm:
If filename2 is newer than filename1 then
copy filename2 to filename1
end if
execute filename1
Using an algorithm like that, filename1 is the standard executable file for my software, and an update is simply copied to filename 2. That means that next time the proxy program is run (which is always when you start the software) it auto updates.
However, there are a few problems with this, such as the hit on startup, and the fact that you have to restart before getting the new updated software.
Does anyone have a better approach to this?
(Oh, BTW, excuse the VB in the algorithm above, I switch between so often that I forget where I am sometimes!!)
Thanks for your help
|
|
|
|
|
Hi,
Like you I want to write an application to transfer a file on the net (or LAN). Is it possible to share your file transfer code to me?
Thanks a lot, A. Riazi
|
|
|
|
|
This is what I would do:
1. When the program (filename1) starts up, it checks if there's a newer version of itself available.
2. If so, it runs another small (invisible) program, passing it the process ID (GetCurrentProcessId) as a command-line parameter. Then it exits.
3. The small program then takes the process ID and retrieves the process handle for it (OpenProcess).
4. It then waits for the process to finish (WaitForSingleObject).
5. Once that happens, it copies the new version of the program (filename2), runs it, and exits.
Regards,
Alvaro
All you need in this life is ignorance and confidence, and then success is sure. -- Mark Twain
|
|
|
|
|
There's multiple ways to do this:
1. There's a wait for reboot option in MoveFileEx
MoveFileEx(src, dst, MOVEFILE_DELAY_UNTIL_REBOOT|MOVEFILE_REPLACE_EXISTING);
2. Download the update exe and run it. The update exe can post a message to the current application telling it to quit. Once it has exited then you can replace it with the update.
Todd Smith
|
|
|
|
|
Am I in much danger doing this? I wanted to see the TRACE
results w/o attaching a debugger, so I did this:
#ifdef _DEBUG
{
typedef BOOL (WINAPI* ISDEBUGGERPRESENT)();
ISDEBUGGERPRESENT pIsDebuggerPresent=(ISDEBUGGERPRESENT)GetProcAddress(GetModuleHandle("KERNEL32.DLL"),"IsDebuggerPresent");
if (pIsDebuggerPresent && !pIsDebuggerPresent())
{
ASSERT(!afxDump.m_pFile);
CString DumpFilename;
DumpFilename.ReleaseBuffer(::GetModuleFileName(0,DumpFilename.GetBuffer(MAX_PATH),MAX_PATH)?-1:0);
DumpFilename+=".TRACE-DUMP.TXT";
afxDump.m_pFile=new CFile(DumpFilename,CFile::modeWrite|CFile::modeCreate|CFile::shareDenyWrite);
}
}
#endif
I feel uneasy about it. Besides the problem of a debugger attaching to
the process later on, it may step on other dependencies of which I am
unaware. Is there a simple tool instead that will serve to receive and
display the TRACE messages?
|
|
|
|
|
|
Hello everyone.
I'm new to C++ and I can't get this to work.
Please let me know if I'm doing something wrong besides my problem
I can not update two fields in FoxPro database
it gives me an error "Can't update. Database or object is read-only"
This is how it goes:
CDaoDatabase* pDatabase = new CDaoDatabase;
pDatabase->Open("C:\\Work\\UpdateDBF\\INPUT", //path only!
TRUE, //exclusive?
FALSE, //read only?
"FoxPro 3.0;"); //connect string
CDaoRecordset rsCUST(pDatabase);
rsCUST.Open(dbOpenDynaset, "SELECT Custnum, noemail, norent FROM [CUST.dbf]");
rsCUST.MoveFirst(); //move to the beginning so we start from the begin
rsCUST.FindFirst( "Custnum = " + strCustNum );// strCustNum is a number i pull from a text file
if (rsCUST.IsEOF != 0){//if found the record
oleTemp.ChangeType( VT_BOOL );
oleTemp.boolVal = true;
try {
// this is where it fails
// the error i get is "Can't update. Database or object is read-only"
rsCUST.SetFieldValue("noemail", oleTemp);
rsCUST.SetFieldValue("norent", oleTemp);
}
catch(CDaoException* e){
TCHAR szCause[255];
CString strFormatted = _T("The data file could not be updated because of this error: \n");
e->GetErrorMessage(szCause, 255);
strFormatted += szCause;
AfxMessageBox(strFormatted, MB_OK | MB_ICONEXCLAMATION);
}
catch (...) {
TRACE ( "*** Unhandled Exception ***" );
}
} //if (rsCUST.IsEOF != 0){
If any one know please let me know
Thank you in advance.
ilya
iluha
|
|
|
|
|
I'm looking for an example of how to change images in a CListView. The items in my list can be edited, once edited I want to change the image so the user has a visual clue that the item has been modified. When the document is saved, the orignal image will be restored.
An example of this capability is Microsofts Visual Source Safe (VSS). When you check out a file, its image (file icon) gets a red check-mark and red border. When the file is checked in, the check-mark and border are removed.
I've experimented with I_IMAGECALLBACK, but it seems the callback only happens once when the item is inserted in the list control.
I've read a little about image overlays in MSDN, but I can't find enough information to make an attempt at using them. I'm not even sure if it's the appropriate solution.
Any help is much appreciated.
Marc
|
|
|
|
|
Use LVITEM structure with SetItem member function.
It's very easy!
A. Riazi
|
|
|
|
|
Hi everybody!
I have an exe projekt, and i want to load a child dialog from an dll.
The child dialog should be displayed at the parent dialog in the exe.
The parent dialog knows the rect where the child should be.
PLEASE!!!!
could anyone tell me how it works???
EMail: dawo.office@gmx.net
Thanks and best wishes!!
|
|
|
|
|
Create a regular dll. In dll resource, create your child dialog and specify it's ID. Run class wizard to make a class for your dialog.
Now export your dialog class.
In your exe, import your dialog definition. Use Create member function of your dialog to place it on parent dialog (do not use DoModal member function).
A. Riazi
|
|
|
|
|
Yes, create a Dll, and add in a dialog window and all the necessary stuff as you would for a normal exe. the catch is to add the exported methods (or functions or whatever you call them) to the out side user. here's an example of myddl.h with the exported create call:
//Flags for individual window features
#define SCROLL_VL 0x0001
#define SCROLL_VR 0x0002
#define SCROLL_HT 0x0004
#define SCROLL_HB 0x0008
#define TIC_VL 0x0010
#define TIC_VR 0x0020
#define TIC_HT 0x0040
#define TIC_HB 0x0080
#define STATUS_BAR 0x0100
#define ZOOM_BOX 0x0200
#define ORIGIN 0x0400
#define GRID_LINES 0x0800
//Conglomeration of some standard options
#define STANDARD_SCROLL 0x035A|ORIGIN
#define STANDARD_SCROLL2 SCROLL_VR|SCROLL_HB|TIC_VL|TIC_HB|STATUS_BAR|ZOOM_BOX|ORIGIN
#define STANDARD_VERTSCOPE SCROLL_VR|TIC_VL|TIC_HB|STATUS_BAR|ZOOM_BOX|ORIGIN
#define STANDARD_HORZSCOPE SCROLL_HB|TIC_VL|TIC_HB|STATUS_BAR|ZOOM_BOX|ORIGIN
#define STANDARD_SCROLL3 SCROLL_HB|TIC_VL|TIC_HB|STATUS_BAR|ZOOM_BOX|ORIGIN
//Flags used for cursor styles
#define DASHED_CROSS 0x0001
#define FULL_CROSS 0x0002
#ifdef __cplusplus
#define EXPORT extern "C" __declspec (dllexport)
#else
#define EXPORT __declspec (dllexport)
#endif
EXPORT BOOL CALLBACK CreateDisplay(HWND& hwnd,HINSTANCE hInstance,HWND parent_, int style, bool MDI_child);
Then in mydll.cpp I have this:
//******************************************************//
//Dll Entry point, no initialization needed //
//******************************************************//
int WINAPI DllMain (HINSTANCE hInst, DWORD fdwReason, PVOID pvReserved)
{
return TRUE;
}
EXPORT BOOL CALLBACK CreateDisplay(HWND& hwnd, HINSTANCE hInstance, HWND parent_, int style, bool MDI_child)
{
Display<double,double> *temp =
new Display<double,double>(hInstance,parent_,style,MDI_child);
hwnd = temp->GetHwnd();
the_displays[hwnd] = temp;
temp = NULL;
return TRUE;
}
Now my application uses template classes and my Display template class actually creates the Dialog window and attaches the Winproc, basically everything you normally do to create a normal windows app.
I hope this helps!
Dan Willis
|
|
|
|
|
Okay, suppose I've got a simple AppWizard generated application. I'm relying on the WinApp message pump and I've called SetTimer(1, 1, NULL) .
Since there is just one timer which is not being killed, does the message pump keep reactivating that timer or does it activate the timer, then sleep, then activate the timer again?
|
|
|
|
|
A timer continues until you either call KillTimer() or the thread terminates - take its message queue with it. If you don't need the timer; however, it's best to destroy it to save CPU cycles.
Jeremy Falcon
Imputek
|
|
|
|
|