|
In addition... To check this[^] won't hurt you.
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
|
please let me know the procedure of creating modelessdilog box dynamically
kir_MFC
|
|
|
|
|
The procedure in your previous post is the correct way.
You should try the suggestions given there and follow up on that instead of posting the question again.
|
|
|
|
|
i use InternetOpenUrl (as async) to receive a file from a url.
this is the code i use :
BOOL CMyCode::RequestFile( LPCTSTR lpszUrl )<br />
{<br />
m_hInternet = InternetOpen(_T("MyCode"), INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, INTERNET_FLAG_ASYNC);<br />
if (!m_hInternet)<br />
{<br />
return FALSE;<br />
}<br />
<br />
InternetSetStatusCallback(m_hInternet, CMyCode::InternetStatusCallback);<br />
<br />
InternetOpenUrl(m_hInternet, <br />
lpszUrl, <br />
NULL,<br />
0, <br />
INTERNET_FLAG_RELOAD | INTERNET_FLAG_PRAGMA_NOCACHE | INTERNET_FLAG_NO_CACHE_WRITE, <br />
(DWORD) this);<br />
return TRUE;<br />
}<br />
<br />
void __stdcall CMyCode::InternetStatusCallback (HINTERNET hSession, DWORD Context, DWORD Status, LPVOID pInformation, DWORD InfoLength)<br />
{<br />
CMyCode* pThis = (CMyCode*) Context;<br />
if (!pThis)<br />
{<br />
return;<br />
}<br />
<br />
switch (Status) <br />
{<br />
case INTERNET_STATUS_RESPONSE_RECEIVED:<br />
m_dwNumytes2Read = (*(DWORD *)pInformation);<br />
break;<br />
case INTERNET_STATUS_HANDLE_CREATED:<br />
m_hHttpSession = * (HINTERNET *) pInformation;
break;<br />
case INTERNET_STATUS_REQUEST_COMPLETE:<br />
CompleteRequest();<br />
break;<br />
case INTERNET_STATUS_HANDLE_CLOSING:<br />
break;<br />
default:<br />
ATLTRACE(_T("Status is %ld\n"), Status);<br />
break;<br />
} <br />
}<br />
<br />
void CMyCode::CompleteRequest()<br />
{<br />
LPBYTE pBuff = new BYTE[m_dwNumytes2Read];<br />
ZeroMemory(pBuff, m_dwNumytes2Read);<br />
<br />
DWORD dwBytesRead(0);<br />
BOOL bOK(TRUE);<br />
while (bOK)<br />
{<br />
bOK = InternetReadFile (m_hHttpSession, pBuff, m_dwNumytes2Read, &dwBytesRead);<br />
if (!dwBytesRead)<br />
bOK = FALSE;<br />
}<br />
<br />
if (pBuff)<br />
delete []pBuff;<br />
<br />
Abort();<br />
<br />
}<br />
<br />
the code works ok only i have 2 major problems:
1. the file is received in a chunks of 267/268 Bytes each time i call InternetReadFile????
2. the CPU reaches 80% until the file is download completely
can any1 help me here?
thanks in advanced
Interface basics click here :
http://www.codeproject.com/com/COMBasics.asp
don't forget to vote
|
|
|
|
|
You can try URLDownloadToFile function.
|
|
|
|
|
thanks for the reply...
i can not use other methods other than what i've posted in my code (for stupid reasons go figure)
so i would still like any help regarding my issues
thanks again
Interface basics click here :
http://www.codeproject.com/com/COMBasics.asp
don't forget to vote
|
|
|
|
|
YaronNir wrote: i can not use other methods other than what i've posted in my code (for stupid reasons go figure)
so i would still like any help regarding my issues
Then You're at a dead end! We cannot help you any further!(for stupid reasons go figure).
Bram van Kampen
|
|
|
|
|
this sort of reply is in appropriate,
if you can see below i got a really good reply who took my question seriously
shame on you....
Interface basics click here :
http://www.codeproject.com/com/COMBasics.asp
don't forget to vote
|
|
|
|
|
Have you checked the value of m_dwNumytes2Read bfore your call to InternetReadFile() ?
|
|
|
|
|
what do you mean? can you give an example
Interface basics click here :
http://www.codeproject.com/com/COMBasics.asp
don't forget to vote
|
|
|
|
|
You have the following code (btw could you edit your original message and put the code between <pre></pre> tags):
case INTERNET_STATUS_RESPONSE_RECEIVED:
m_dwNumytes2Read = (*(DWORD *)pInformation);
break;
void CMyCode::CompleteRequest()
{
LPBYTE pBuff = new BYTE[m_dwNumytes2Read];
ZeroMemory(pBuff, m_dwNumytes2Read);
DWORD dwBytesRead(0);
BOOL bOK(TRUE);
while (bOK)
{
bOK = InternetReadFile (m_hHttpSession, pBuff, m_dwNumytes2Read, &dwBytesRead);
}
The value of m_dwNumytes2Read is set when you process the INTERNET_STATUS_RESPONSE_RECEIVED message and is relevant to the status information, so it is probably less than the amount of data that may be available. Try resetting it to some bigger value before calling InternetReadFile() for example:
dwNumytes2Read = 2048;
LPBYTE pBuff = new BYTE[m_dwNumytes2Read];
DWORD dwBytesRead;
BOOL bOK(TRUE);
while (bOK)
{
bOK = InternetReadFile (m_hHttpSession, pBuff, m_dwNumytes2Read, &dwBytesRead);
|
|
|
|
|
thanks for the reply - it did solve the problem now the chunck are 2048 bytes each time - good!
the second problem still remains - high CPU about 80% - how can i solve this?
thanks again for your kind reply
Interface basics click here :
http://www.codeproject.com/com/COMBasics.asp
don't forget to vote
|
|
|
|
|
First thing is to run some tests with different buffer sizes to see how that affects performance, 2048 was just a number plucked from the air.
Looking at your code I notice that you use ZeroMemory on the input buffer just before reading data into it; this is wasteful and serves no purpose, just allocate it with the new call.
Alternatively you could allocate your buffer at the beginning of the program, either via new or as a static data area. This would save repeated new delete[] pairs, and the consequent garbage collection code.
There may be other issues in the rest of your code, but I leave that for you to investigate.
|
|
|
|
|
once again - thank you!
Interface basics click here :
http://www.codeproject.com/com/COMBasics.asp
don't forget to vote
|
|
|
|
|
Hi,
I want to know how to call an Crystal report using VC++ code in Visual Studio 2008. In Visual Studio 6, we use to have Project->Add to Project->Components and Control. This will enable us to add the Crystal Report component into our application. But I couldn't find a way to add Crystal report control into my VC++ application using VS 2008.
Please help me with this. If you have a sample code for VS 2005/VS 2008 that will help.
Thanks in Advance
|
|
|
|
|
Hi,
I am trying to write a multi-line string into an edit control on a
dialog box. I am using following code however not getting any success.
CWnd *pWnd =GetDlgItem(IDC_STATIC_MSGCNT);
CRect lpRect = CRect(100,100,20,20);
pWnd->GetWindowRect(&lpRect);
CEdit *pEdit = new CEdit();
pEdit->Create(ES_MULTILINE|ES_LEFT|ES_READONLY,lpRect,this,m_iEditCTLID++);
pEdit->ShowWindow(SW_SHOW);
CString str;
str.Format("%d",pWLSErrRpt->GetWLSMessageNo());
pEdit->SetWindowTextA(str);
Appreciate your help.
Thanks
|
|
|
|
|
Multiline editbox requires "\r\n" in the string to split the string into multiple lines.
|
|
|
|
|
itkid wrote: I am trying to write a multi-line string into an edit control...
No, you are writing a number to the control.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hello,
I'm trying to develop a deskband/tray app using MFC. I guess there are more experienced programmers out there that might be able to help me. I wrote a simple spec what I need: http://www.kulone.com/contrib/utilproject/spec.pdf
I have some code already that builds under VS2008: http://www.kulone.com/contrib/utilproject/demos.zip
I'm looking for someone with experience developing C++/MFC apps, possibly experienced with deskband and tray apps. I can also pay a small fee for the solution ($700).
regards
Damjan
--
damjan12@kulone.com
|
|
|
|
|
|
How to write C or C++ program that locks desktop icons placement? I have googled around it and all I found were commercial software or closed source software.
Any hints are welcome.
thanks!
|
|
|
|
|
The following answer makes the assumption that you are using windows XP/vista/7.
The following website should help:
http://www.activewin.com/tips/reg/desktop_3.shtml[^]
If you follow the instructions it locks the desktop icon(s); although it is still possible to rearrange them.
To accomplish this in a windows application you will need to use the registry api's(use the 'RegCreate' function(s)) here http://msdn.microsoft.com/en-us/library/aa383729%28VS.85%29.aspx[^] to create a registry key.
I tested this on xp and realised that I had auto arrange on, after turning this off it is no longer working.
I am now looking for the registry key for auto arrange.
I have code in c/c++ that can change the alignment of desktop icons on the (e.g. left align icons), I will post this if you want it.
modified on Sunday, January 10, 2010 10:05 PM
|
|
|
|
|
The instructions from the website http://www.activewin.com/tips/reg/desktop_3.shtml[^][^] are now working(make sure you restart/logoff or it will not work, as I found).
Here is the code for a working program that accomplishes the following:
1. Left Align icons on the screen(test this by moving desktop icon(s) to a
different part of the screen and then press the 'Arrange Icons' button in the compiled app)
2. Lock icons on the desktop so that they can only be rearranged.
The application accomplishes this be creating the NoSaveSettings key as mentioned in the above given website(this sets the Auto Arrange to on after the system has been shutdown/restart/user logged off).
3. Restart the computer. CAUTION before pressing the Add 'NoSaveSettingsKey' button save all of your work as it will restart the computer. You have been warned, use the code at your own risk.
Here is the code:
#include <windows.h>
#include <Reason.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
void arrange();
void noSaveSettings();
void restart();
HWND hwnd;
HWND hLeftArrangeButton;
HWND hDoNotSaveSettings;
#define WINDOWCLASSNAME "WindowsApp" /* Class Name */
#define WINDOWTITLE "Auto Arrange"
#define WINDOWWIDTH 640
#define WINDOWHEIGHT 480
#define BUTTONONETEXT "Arrange Icons"
#define BUTTONTWOTEXT "Add 'NoSaveSettingsKey'"
#define ERRORTITLE "Error!"
#define REGKEYNAME "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer"
#ifndef SHTDN_REASON_MAJOR_OPERATINGSYSTEM
#define SHTDN_REASON_MAJOR_OPERATINGSYSTEM 0x00020000 //from reason.h
#endif
#ifndef SHTDN_REASON_MINOR_RECONFIG
#define SHTDN_REASON_MINOR_RECONFIG 0x00000004 //from reason.h
#endif
#ifndef SHTDN_REASON_FLAG_PLANNED
#define SHTDN_REASON_FLAG_PLANNED 0x80000000 //from reason.h
#endif
int WINAPI WinMain(HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)
{
MSG messages;
WNDCLASSEX wincl;
wincl.hInstance = hThisInstance;
wincl.lpszClassName = WINDOWCLASSNAME;
wincl.lpfnWndProc = WndProc;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof(WNDCLASSEX);
wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor(NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
if(!RegisterClassEx(&wincl))
{
MessageBox(NULL, "Window Registration Failed!", ERRORTITLE,
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
hwnd = CreateWindowEx(
0,
WINDOWCLASSNAME,
WINDOWTITLE,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
WINDOWWIDTH,
WINDOWHEIGHT,
HWND_DESKTOP,
NULL,
hThisInstance,
NULL
);
hLeftArrangeButton = CreateWindow("BUTTON", BUTTONONETEXT, WS_CHILD | WS_VISIBLE | BS_TEXT,
20, 80, 240, 30, hwnd, NULL, hThisInstance, NULL);
hDoNotSaveSettings = CreateWindow("BUTTON", BUTTONTWOTEXT, WS_CHILD | WS_VISIBLE | BS_TEXT,
20, 120, 240, 30, hwnd, NULL, hThisInstance, NULL);
if(hwnd == NULL)
{
MessageBox(NULL, "Window Creation Failed!", ERRORTITLE,
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
ShowWindow(hwnd, nFunsterStil);
UpdateWindow(hwnd);
while(GetMessage(&messages, NULL, 0, 0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}
void arrange()
{
const int arrange = 4118;
const int leftAlign = 1;
HWND desktopHandle;
HWND childWindow;
HWND childOfChildWindow;
desktopHandle = FindWindow("Progman", NULL);
childWindow = GetWindow(desktopHandle, GW_CHILD);
childOfChildWindow = GetWindow(childWindow, GW_CHILD);
SendMessage(childOfChildWindow, arrange, leftAlign , 0);
}
void noSaveSettings()
{
HKEY hk;
DWORD dwDisp;
DWORD value = 1;
if (RegCreateKeyEx(HKEY_CURRENT_USER, REGKEYNAME,
0, NULL, REG_OPTION_NON_VOLATILE,KEY_WRITE, NULL, &hk, &dwDisp))
{
MessageBox(NULL,"Unable to create Explorer key",ERRORTITLE,MB_OK);
}
if (RegSetValueEx(hk,"NoSaveSettings",0, REG_DWORD, (LPBYTE) &value, sizeof(DWORD)))
{
MessageBox(NULL,"Unable to add NoSaveSettings",ERRORTITLE,MB_OK);
RegCloseKey(hk);
}
RegCloseKey(hk);
}
void restart()
{
HANDLE tokenHandle;
TOKEN_PRIVILEGES theTokenPrivilege;
if(!OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &tokenHandle))
{
MessageBox(NULL,"Could not obtain a token",ERRORTITLE,MB_OK);
}
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &theTokenPrivilege.Privileges[0].Luid);
theTokenPrivilege.PrivilegeCount = 1;
theTokenPrivilege.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(tokenHandle, FALSE, &theTokenPrivilege, 0, (PTOKEN_PRIVILEGES)NULL, 0);
if (GetLastError() != ERROR_SUCCESS)
{
MessageBox(NULL,"Unable to restart the computer",ERRORTITLE,MB_OK);
return;
}
if (!ExitWindowsEx(EWX_REBOOT | EWX_FORCE, SHTDN_REASON_MAJOR_OPERATINGSYSTEM |
SHTDN_REASON_MINOR_RECONFIG | SHTDN_REASON_FLAG_PLANNED))
{
MessageBox(NULL,"Unable to restart the computer",ERRORTITLE,MB_OK);
return;
}
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_COMMAND:
{
HWND hwndCtl = (HWND)lParam;
int code = HIWORD(wParam);
if (hwndCtl == hLeftArrangeButton)
{
arrange();
}
if (hwndCtl == hDoNotSaveSettings)
{
noSaveSettings();
restart();
}
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
Hope this helps.
|
|
|
|
|
Great code, but I have 1 problem (I used Code::Blocks to compile)
C:\Documents and Settings\rain\My Documents\fail.o:fail.cpp text+0x96)||undefined reference to `_GetStockObject@4'|
||=== Build finished: 1 errors, 0 warnings ===|
I tried this manually but it didn't work (I use win xp pro).
Is there any solutions that works like lockig icons works in linux? I have seen linux desktops which are made so if you lock icons then u cant move them, icons just won't come with ur mouse, can I do this kond locking in windows too?
|
|
|
|
|