|
Exactly what I wanted to know. Thanks....
SAVAGE KEN
|
|
|
|
|
Hi all
May i ask u somethin? any one can tell me how i can make the maxmize in the SDI application disable and take the Form view size..any one help
thunx
ZoOka
|
|
|
|
|
this piece of code works fine without the msdn code. He generate an event for "Event Error" registry entry.
[code]
void CEventTestDlg::OnOK()
{
HANDLE hEvent;
CString strInfo;
char *szList[1];
strInfo = "Hellow World";
szList[0] = strInfo.GetBuffer(0);
hEvent = RegisterEventSource(NULL, "Event Error");
ReportEvent(hEvent, EVENTLOG_INFORMATION_TYPE, 2, NULL, NULL, 1, 0, (const char**)szList, NULL);
strInfo.ReleaseBuffer();
DeregisterEventSource(hEvent);
}
[/code]
Now, I went to MSDN to get another piece of code. I believe this code suppose to display the user in the event viewer under the user field. But for any reason, I can't get it to work with my. Here is the whole code. I keep getting some errors. Can somebody fix that for me.
[code]
void CEventTestDlg::OnOK()
{
HANDLE hEvent;
CString strInfo;
char *szList[1];
LPSTR pszUser;
LPDWORD pcbUser;
EVENTLOGRECORD *perl;
strInfo = "Hellow World";
szList[0] = strInfo.GetBuffer(0);
hEvent = RegisterEventSource(NULL, "ErrLogServer");
ReportEvent(hEvent, EVENTLOG_INFORMATION_TYPE, 2, NULL, NULL, 1, 0, (const char**)szList, NULL);
strInfo.ReleaseBuffer();
GetEventUserName(EVENTLOGRECORD *pelr, LPSTR pszUser, LPDWORD pcbUser);
DeregisterEventSource(hEvent);
}
BOOL GetEventUserName(EVENTLOGRECORD *pelr, LPSTR pszUser, LPDWORD pcbUser)
{
PSID lpSid;
char szName[256];
char szDomain[256];
SID_NAME_USE snu;
DWORD dwLen;
DWORD cbName = 256;
DWORD cbDomain = 256;
// Point to the SID.
lpSid = (PSID)((LPBYTE) pelr + pelr->UserSidOffset);
if (LookupAccountSid(NULL, lpSid, szName, &cbName, szDomain,
&cbDomain, &snu))
{
// Determine whether the buffer is large enough.
dwLen = lstrlen(lpszUser) + 1;
if (dwLen > *lpcbUser)
{
SetLastError( ERROR_INSUFFICIENT_BUFFER );
*lpcbUser = dwLen;
return FALSE;
}
// Return the user's name.
lstrcpy( lpszUser, szName );
}
else
{
// Use the error status from LookupAccountSid.
return FALSE;
}
SetLastError(0);
return TRUE;
}
[/code]
All that I want, I want to display the username under the user field. I don't know if this function is supposed to do that or retrieve the username. I have tried another approach by using a message compiller. If somebody knows a method I can use or send me or posted a simple code, that will be fine.
|
|
|
|
|
What is the last message posted by an MFC Dialog application? NC_DESTROY
I ask because I want to know the best place to put my cleanup code.
- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
|
|
|
|
|
The last message any window gets is WM_NCDESTROY . Override CWnd::PostNcDestroy() in your class when you need to do cleanup after the window is destroyed. (Of course, you could always do it in the destructor, except in the case of modeless dialogs where PostNcDestroy() is the preferred choice.)
--Mike--
I'm bored... Episode I bored.
1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
Damn, Michael, that's 2 for 2 today!
- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
|
|
|
|
|
I am reading Petzold's book on Win32 and I am at the chapter concerning printing. He gives an example which is supposed to find out the current version of windows you are running and then call EnumPrinters(). I can't compile this code I get the error: error C2440: '=' : cannot convert from 'void *' to 'struct _PRINTER_INFO_5A *'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast.
By casting it to pInfo5 = (PRINTER_INFO_5*) malloc(dwNeeded); it compiles but then the program crashes when I try to print...it is the 5th parameter of EnumPrinters which is causing the problem. My question is what code changes do I need to make to this into C++ using new and delete and in general what would be a better way of writing this function? (Modifications in the code would by much appreciated)
HDC GetPrinterDC (void)
{
DWORD dwNeeded, dwReturned ;
HDC hdc ;
PRINTER_INFO_4 * pinfo4 ;
PRINTER_INFO_5 * pinfo5 ;
if (GetVersion () & 0x80000000)
{
EnumPrinters (PRINTER_ENUM_DEFAULT, NULL, 5, NULL,
0, &dwNeeded, &dwReturned) ;
pinfo5 = malloc (dwNeeded) ;
EnumPrinters (PRINTER_ENUM_DEFAULT, NULL, 5, (PBYTE) pinfo5,
dwNeeded, &dwNeeded, &dwReturned) ;
hdc = CreateDC (NULL, pinfo5->pPrinterName, NULL, NULL) ;
free (pinfo5) ;
}
else
{
EnumPrinters (PRINTER_ENUM_LOCAL, NULL, 4, NULL,
0, &dwNeeded, &dwReturned) ;
pinfo4 = malloc (dwNeeded) ;
EnumPrinters (PRINTER_ENUM_LOCAL, NULL, 4, (PBYTE) pinfo4,
dwNeeded, &dwNeeded, &dwReturned) ;
hdc = CreateDC (NULL, pinfo4->pPrinterName, NULL, NULL) ;
free (pinfo4) ;
}
return hdc ;
}
|
|
|
|
|
With the casting changes, the code works perfectly on my XP system. The code should work. Also, there is no reason to change the code to use new/delete. It will only complicate the code and gain you nothing.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
The cast is necessary because of stricter type rules in C++. C allows implicit conversion to and from void* , while C++ only allows implicit conversion to void* . Therefore you need to cast the void* returned by malloc .
Not sure about the crash, your code (well, the NT branch at least) works fine for me.
--Mike--
I'm bored... Episode I bored.
1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
Does the crash have anything with me not having a printer actually connected to my computer? In debug mode dwNeeded had a value of zero and I guess this is what causes the crash on the second call to EnumPrinters a value I suppose will increase once I attach a printer. And is this the proper way to cast it?:
pinfo4 = (PRINTER_INFO_4*) malloc (dwNeeded);
Thanks for all the help so far.
|
|
|
|
|
Yeah. His code lacks the test for dwNeeded returning 0. If that is the case, there is really no need to even do a malloc and the second enum call. Just return a NULL HDC and be done with it. Of course, all calling programs should test for NULL HDC.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
I'm looking for a library that I could use to write a small program that only sends e-mails (no reading). Can anyone suggest one?
Thanks!
|
|
|
|
|
|
|
I have an application who splits the window in two, similar to windows explorer. I need to print the contents of the right side, but I can only capture printing messages on the left window.... I was thinking of cathing the messages in one window and sending them to the other. Is this a good idea or is there a better way ?
Thank you
Nelson Gonçalves
|
|
|
|
|
Hi.
I am having problems "painting" a Picture Control on a MODELESS dialog. My dialog (called GraphicsParams) has a picture control that calls CColorDialog and allows the user to select a color. The picture control (color swatch) is then painted with the color selected.
My problem is that my picture control is not updated with the current color in OnInitDialog(). Further more, I experience the weird side in my GraphicsParams dialog:
1) place another window (dialog) object over my Color Swatch client area
keeping it over my Color Swatch
2) Set focus back to my GraphicsParams dialog -- don't move
3) Without moving either dialogs, toggle focus between the two
** the color swatch resorts back to the default (black) color.
Would you know what is going on and what I need to do?
Thanks.
Johnny
Here is what I have now:
//////////////////////////////////////////////////////
// CGraphicsParameters dialog -- .H
class CGraphicsParameters : public CDialog
{
// Other stuff left out for brevety
private:
// use to display colors as a sample swatch on the dialog
COLORREF m_ModelColor;
CRect m_ModelColorSwatch;
// Construction
public:
// use to display colors as a sample swatch on the dialog
void SetModelColorSwatch(COLORREF rgbColor);
}
//////////////////////////////////////////////////////
// CGraphicsParameters dialog -- .CPP
BOOL CGraphicsParameters::OnInitDialog()
{
CDialog::OnInitDialog();
// other dialog initialization goes here
// Initialize the color swatch rectangles - for later painting
// Calculate true location of the color swatch
// Get a pointer to CWnd
CWnd* pModelColor = GetDlgItem(IDC_MODEL_COLOR);
// Find its location on screen
pModelColor->GetWindowRect(&m_ModelColorSwatch);
// Store client coordinates
ScreenToClient(&m_ModelColorSwatch);
m_ModelColorSwatch.DeflateRect(2, 2, 1, 1); // for the sunken control setting
SetModelColorSwatch(m_ModelColor);
return TRUE;
}
void CGraphicsParameters::OnPaint()
{
SetModelColorSwatch(m_ModelColor);
CDialog::OnPaint();
}
// callback function for changing the model color - uses MFC common color dialog
void CGraphicsParameters::OnModelColor()
{
CColorDialog dlg(m_ModelColor, CC_FULLOPEN);
if (dlg.DoModal() == IDOK)
{
m_ModelColor = dlg.GetColor();
SetModelColorSwatch(m_ModelColor);
}
}
// update the color swatch with the RGB color value
void CGraphicsParameters::SetModelColorSwatch(COLORREF rgbColor)
{
CBrush swatch;
swatch.CreateSolidBrush(rgbColor);
CClientDC dc(this);
dc.FillRect(&m_ModelColorSwatch, &swatch);
}
|
|
|
|
|
I have seen the sample code for my use. But I forgot to save it. Now I cannot remember its location.
The code implements a list control, almost as the same as in VC6 under Options -> Paths -> Paths:. The user can create a new item by clicking the rectangle with a star, and delete it with the red cross. He can also move an item up and down with the other Up- and Down arrows.
Who can plz help me to find it? Thanks!
|
|
|
|
|
|
Hey,
does anyone know what message is being sent when the mousepointer is over a tab in a tabcontrol? My problem is that the things I have drawn inside a tab is flickering when I move the mouse over the tabs. Might be some message painting the tabs yellow in WinXP? When I switch the tablayout to buttons the problem disappears...
Cheers
|
|
|
|
|
I writing my menu by LoadMenuIndirect function. I saw my menu with Debug mode but I dont' see it with Release mode ! Why ?
|
|
|
|
|
How are these right hand corner notifications are launched by msn or McAfee or others to name a few?
|
|
|
|
|
|
Hi, this may be a stupid question, but could someone please tell me how to start a help file (which is in html format by the way), from MFC? I've tried both WinExec and CreateProcess, but neither work. Secondly, if the help file gets big enough to where i can make a .chm out of it, could i use the same method?
|
|
|
|
|
For compled help files (.chm) use the function HtmlHelp(
HWND hwndCaller,
LPCSTR pszFile,
UINT uCommand,
DWORD dwData) ;
It's really easy to use. I personally wouldn't use pure .html files - .chm is more user-friendly, providing easy navigation.
Btw: That function is declared in htmlhelp.h, and you need to link to htmlhelp.lib to get it work.
|
|
|
|
|
|