|
can't you debug it..just try and understand at what point what are the values int the variables and what is it you were expecting...when u will do a thorough debugging I hope you will come up with the solution of your question..try to see what are the user information and what is the exact reason why u r getting it like this..
cheers
Himanshu
|
|
|
|
|
i think u r the only one to ponder over my prob!
i'm sorry for the delay in replying,
u know the murphy's laws, that's the case for me!
i can't even debug my app in win Xp (i don't know why) i get an error in MSDEv.exe as soon as i try to debug!
all i want is to give admin rights to my application which will work in guest login with all the security restrictions!
but no luck!
i've checked the value in variables using error logging, thay are going the way as i want but still i get an error Acccess_denied while executing a process after impersonating administrator!
anyways thanx for ur concern!!!!!!
|
|
|
|
|
I am trying to create some controls during runtime. I resolved all my errors but I think it now has a memory leak. Not sure how to test that, but I don't delete array at the end. I have commented out once place I was trying to delete the array in the WM_CLOSE section. Can anyone help me be able to delete the array and get no errors? here is the code I am using to do this. It also requires a dialog box named IDD_DIALOG1 (generic name) and a push buton IDOK. (just add a dialog into the resource editor and it should work.
---BEGIN CODE---
#include <afx.h>
#include <windows.h>
#include "resource.h"
HWND HWND_DLG_MAIN;
HINSTANCE ghInstance;
//made global to attempt to reduce possible problems
CString szTmp;
HWND *StaticArr;
HWND *temp;
int cnt = 0;
int x = 10;
int y = 10;
int h = 75;
int w = 25;
int loopctr = 0;
BOOL MainWndProc(HWND, UINT, WPARAM, LPARAM);//Main window procedure
BOOL MainOnCommand(HWND, WORD, WORD, HWND);//WM_COMMAND procedure
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR, int)
{
ghInstance = hInstance;
DialogBoxParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DIALOG1),
NULL, (DLGPROC)MainWndProc, 0);//Create the main dialog box
return FALSE;
}
BOOL MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_INITDIALOG:
HWND_DLG_MAIN = hWnd;
break;
case WM_COMMAND:
MainOnCommand(HWND_DLG_MAIN, LOWORD(wParam), HIWORD(wParam), (HWND)lParam);
break;
case WM_CLOSE:
for(loopctr = 0; loopctr < cnt; loopctr++)
DestroyWindow(StaticArr[loopctr]);
//delete [] StaticArr;
EndDialog(HWND_DLG_MAIN, 0);
DestroyWindow(hWnd);
break;
}
return FALSE;
}
BOOL MainOnCommand(HWND hWnd, WORD wCommand, WORD wNotify, HWND hControl)
{
switch(wCommand)
{
case IDOK:
if(cnt > 1)
{
temp = new HWND[cnt];
}
else
{
temp = new HWND[1];
}
temp = StaticArr;
if(cnt > 1)
{
delete [] StaticArr;
}
StaticArr = new HWND[++cnt];
delete [] temp;
szTmp.Format("Label-%d", cnt);
StaticArr[cnt-1] = CreateWindowEx(
NULL, // extended window style
"STATIC", // pointer to registered class name
szTmp, // pointer to window name
WS_CHILD | WS_VISIBLE | WS_BORDER,// window style
x, // horizontal position of window
y, // vertical position of window
h, // window width
w, // window height
HWND_DLG_MAIN, // handle to parent or owner window
NULL, // handle to menu, or child-window identifier
ghInstance, // handle to application instance
NULL // pointer to window-creation data
);
y+=25;//move the next label down some
break;
}
return FALSE;
}
---END CODE---
Thanks for any help you can give me on this. I am not sure where, and now even if, I need to delete the Array at.
Just to note, it is StaticArr that I am trying to figure out where to delete.
EDIT - When making over 443controls, it errors out as well. Not so concerned about this, because if it ever needs that many controls, I'll shoot my database.
Quinn
The wisest of the wise may err. - Aeschylus
|
|
|
|
|
I guess thats the only thing you are doing is deleting it at a wrong time, what i suggest it you initialize the array in constructor of the application and delete it in destructor. or if you wanna go like this then too i can't understand this bit..
DestroyWindow(StaticArr[loopctr]);
//delete [] StaticArr;
EndDialog(HWND_DLG_MAIN, 0);
DestroyWindow(hWnd);
why don't you just delete array and enddialog() then destroywindow.
thats all i can suggest at this time..
cheers
Himanshu
|
|
|
|
|
I found the answer.
I was setting the pointers equal and when I deleted I freed the chunk of memory both were pointing to, and when I created new it created a new chunk. Took a few to get out of sync.
I just had to add in a for loop and it works all better now.
Thanks for anyway working to try and get me an answer.
I changed the IF statement structure section to this
---BEG CODE---
if(cnt < 1)
{
StaticArr = new HWND[++cnt];
}
else if(cnt > 0)
{
temp = new HWND[cnt];
for(loopctr=0; loopctr < cnt; loopctr++)
{
temp[loopctr] = StaticArr[loopctr];
}
delete [] StaticArr;
StaticArr = new HWND[++cnt];
for(loopctr=0; loopctr < cnt; loopctr++)
{
StaticArr[loopctr] = temp[loopctr];
}
delete [] temp;
}
---END CODE---
The wisest of the wise may err. - Aeschylus
|
|
|
|
|
hello @all,
i have a mfc-program and two CStrings.
i would like to connect these, but everyone in its own line, e.g. they should be separated with a Return.
CString one="123";
CString two="456";
CString combination="123
456";
how can i get the CString 'combination'????
thanks
sunny
|
|
|
|
|
"123\n456" will place a return between the new strings when the string is output.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
hello,u can do it as following:
combination=one+two;
|
|
|
|
|
Hello,
u can do it as this:
combination=one+0X0A+0X0D+two;
good luck!
|
|
|
|
|
In my program (VISUAL C++ MFC) I have to open a window to visualize a video captured by a webcam (in real time). So how can I visualize the streaming video when the webcam start capturing? Do you know if there is a web site with some sample source code?? Thank U very much!! And sorry for my question but I've not long experience with C++...
|
|
|
|
|
I think you should use DirectShow for this work.
There are some samples and tutorials about DirectShow on the MSDN.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dx8_c/directx_cpp/htm/directshow.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dx8_c/directx_cpp/htm/directshowsamples.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dx8_c/directx_cpp/htm/directshowtutorials.asp
Daniel
---------------------------
Never change a running system!
|
|
|
|
|
Hi,
I want to turn the pc off from a c++ program
Im using MFC and have a timer that can be used or after an event i want to call a function that would turn your pc off
any ideas?
thanks guys
Li Mu Bai
|
|
|
|
|
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
|
|
|
|
|