|
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?
|
|
|
|
|
For some reason GetStockObject() is not defined. You need to add the following lines to windows.h
void * GetStockObject(int value);
If that does not work then replace this line
wincl.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH) with
wincl.hbrBackground = NULL; and the window should turn transparent.
Here is some code that partially accomplishes what you want.
It does lock the icons on the desktop, although you will not
be able to click on them(A nasty trick you could play on someone ).
Press the 'Arrange Icons' button to lock the desktop icons.
To reenable the desktop icons uncomment this line
EnableWindow(childOfChildWindow,TRUE);
in the 'void arrange()' function and recompile.
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 = NULL;
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);
EnableWindow(childOfChildWindow,FALSE);
}
void noSaveSettings()
{
HKEY hk;
DWORD dwDisposition;
DWORD value = 1;
if (RegCreateKeyEx(HKEY_CURRENT_USER, REGKEYNAME,
0, NULL, REG_OPTION_NON_VOLATILE,KEY_WRITE, NULL, &hk, &dwDisposition))
{
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;
}
|
|
|
|
|
|
Hello
Is possible to catch a system event if mouse is in Drag'N'Drop mode?
I mean an event when PC user is dragging something between two application f.e. from AcrobatReader to Photoshop and I want catch this event from my app.
Or the one possible solution is asynchronously track mouse way and buttons...
Thanx
|
|
|
|
|
You could use SetWindowsHookEx[^] to install a global hook of type WH_CALLWNDPROC or WH_GETMESSAGE to intercept the WM_DROPFILES message that is sent during the drop event of a drag and drop operation.
|
|
|
|
|
thank for answ. catching the event is more important than getting the WM_DROPFILES target. but will, try.
|
|
|
|
|
I've got 2 static libs with 1 function of the same name
1) mylib1.lib (myfunction() prints "my lib one")
2) mylib2.lib (myfunction() prints "MY LIB TWO")
I need the exe to use that single function and be able to call either code from 1) or from 2)
Thus I created mylib wrappers each linked explicitly with 1) and 2) that code from mylib will be compiled into the wrappers.
3) wrapper1.lib <-- mylib1.lib
4) wrapper2.lib <-- mylib2.lib
In 3) there is wrapper1() function calling myfunction() from 1) and in 4) there is wrapper2() function calling myfunction() from 2)
Once I created exe program and linked both 3) and 4) with it and call first wrapper1() and then wrapper2() only code from 1) is called.
But if I keep only wrapper2() call then 2) is called.
How to resolve the problem to be able to call 1) and 2) implementations?
I can not modify 1) and 2) libs.
Dlls are not allowed either.
There should be some linker switches I presume?
Чесноков
|
|
|
|
|
Also in that order of libs myfunction() from 2) is called.
#pragma comment(lib, "wrapper2")
#pragma comment(lib, "wrapper1")
It seems once the myfunction code is found it is no longer added again.
Чесноков
|
|
|
|
|
Chesnokov Yuriy wrote:
There should be some linker switches I presume?
i don't think so, but you can check the linker documentation.
http://msdn.microsoft.com/en-us/library/aa270751%28VS.60%29.aspx[^]
i know you can force the linker to pick the first match that it finds, and to ignore subsequent matches. but i don't think there's a way to tell the linker to pick specific symbols from specific libs.
(also, duplicate postings here are frowned upon.)
modified on Monday, January 11, 2010 10:43 AM
|
|
|
|
|