|
Hi
Try ExitWindowsEx(EWX_POWEROFF, 0);
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hi,
Hope someone can help me out here please. I'm trying to create a status bar in my app so I added the function:
<br />
HWND DoCreateStatusBar(HWND hwndParent, int nStatusID, <br />
HINSTANCE hinst, int nParts) <br />
{ <br />
HWND hwndStatus; <br />
RECT rcClient; <br />
HLOCAL hloc; <br />
LPINT lpParts; <br />
int i, nWidth; <br />
<br />
InitCommonControls(); <br />
<br />
hwndStatus = CreateWindowEx( <br />
0,
STATUSCLASSNAME,
(LPCTSTR) NULL,
SBARS_SIZEGRIP |
WS_CHILD,
0, 0, 0, 0,
hwndParent,
(HMENU) nStatusID,
hinst,
NULL);
<br />
GetClientRect(hwndParent, &rcClient); <br />
<br />
hloc = LocalAlloc(LHND, sizeof(int) * nParts); <br />
lpParts = (LPINT)LocalLock(hloc); <br />
<br />
nWidth = rcClient.right / nParts; <br />
for (i = 0; i < nParts; i++) { <br />
lpParts[i] = nWidth; <br />
nWidth += nWidth; <br />
} <br />
<br />
SendMessage(hwndStatus, SB_SETPARTS, (WPARAM) nParts, <br />
(LPARAM) lpParts); <br />
<br />
LocalUnlock(hloc); <br />
LocalFree(hloc); <br />
return hwndStatus; <br />
} <br />
Which I got from MSDN. Then in my wndproc case: WM_CREATE I put in:
<br />
statusbar = DoCreateStatusBar(hwnd, ID_STATUSBAR, hInst, 4);<br />
Everything compiles fine but unfortunately I don't get a status bar, is there some message I have to send it to make it display itself?
Thanks in advance,
Paddy.
|
|
|
|
|
Did you forget to call InitCommonControls() or InitCommonControlsEx(). If so then that is the reason.
|
|
|
|
|
Thanks for the help, I was calling InitCommonControls() but I forgot to include the WS_VISIBLE flag when I was creating the status bar!
|
|
|
|
|
I am attempting to develop an ActiveX control subclassed from the MFC Listbox.
Following the MSDN tutorial, I set everything up through the Control Wizard, including setting LISTBOX as the subclassed windows control. The problem is, the tutorials (I have read several) all say "If you want your subclassed control to keep the same appearance as the corresponding Windows control, the OnDraw member function for the control should contain only a call to the DoSuperclassPaint member function, as in the following example:
void CSampleCtrl::OnDraw( CDC* pdc, const CRect& rcBounds,
const CRect& rcInvalid )
{
DoSuperclassPaint( pdc, rcBounds );
}
"
Which is what the Control Wizard automatically does and which is how I left it. I was thinking that if I just leave it like so, when I add it to a new project, it will draw me a standard-looking listbox. Instead, I get a plain white box. I also tried calling AddString in my project and was informed by the compiler that the method does not exist.
So far I see no evidence of my ActiveX control being subclassed form LISTBOX (I have the following as well provided by class wizard:
BOOL CSampleCtrl::PreCreateWindow( CREATESTRUCT& cs )
{
cs.lpszClass = _T("BUTTON");
return COleControl::PreCreateWindow(cs);
}
BOOL CSampleCtrl::IsSubclassedControl( )
{
return TRUE;
}
)
Why am I just getting a white box?? Are there some message handlers I need to address first?? As for the AddString not working, I'm still a little rusty on subclassing... do I have to add methods for all listbox methods I want to use in my control and just call CListbox::Addstring(blah, blah, blah) in order to use the Listbox Functionality???
I have read a lot of articles and tutorials on subclassing and activex controls and mfc controls and there seems to be something that I don't know that is overlooked or assumed to be obvious. Any ideas??
Tym!
|
|
|
|
|
You might want to check your listbox styles. It should "Have Strings" and not be "Owner Draw".
You can pick your friends, and you can pick your nose, but you can't pick your friend's nose.
|
|
|
|
|
I have a dll that contains a number of resources for dialog boxes. Since I am working on the PPC and it does not support wizards, I am trying to make my dialog boxes act like a wizard.
I can get the first dialog box to open correctly and all is fine. When the user clicks "Next"(defined as IDOK), the systems calls the proper class to setup the next dialog, but it displays the first Dialog box. I have setup AfxMessageBox() at various points in the application to tell what is getting called and it does call the proper class.
I have a single function exported from the dll that the main application calls to start the "wizard" Inside this function I have declared two objects, one for my first dialog box and one for my second dialog box.
void DLLEXPORT StartWizard()<br />
{<br />
CDialogOne dlg1;<br />
CDialogTwo dlg2;<br />
int nResult;<br />
<br />
nResult = dlg1.DoModal();<br />
<br />
if(nResult == IDOK)<br />
{<br />
nResult == dlg2.DoModal();<br />
}<br />
<br />
}
Each time this is run, I get the first dialog box displayed twice. Any ideas?
Thanks,
-Eric
|
|
|
|
|
I've been trying for a while to figure out how to create a shortcut onto the start menu for a program. Anyone know how?
SAVAGE KEN
|
|
|
|
|
Use the IShellLink interface.
Todd Smith
|
|
|
|
|
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);
}
|
|
|
|
|