Shell Execute has the following signature :
HINSTANCE ShellExecute(
__in_opt HWND hwnd,
__in_opt LPCTSTR lpOperation,
__in LPCTSTR lpFile,
__in_opt LPCTSTR lpParameters,
__in_opt LPCTSTR lpDirectory,
__in INT nShowCmd
);
How can we use lpParameters , Can we handle the parameter in my application. I am executing my app as below:
HINSTANCE hShellExecuteStatus = ShellExecute(NULL, "open", "MyPath/MyApp.EXE", NULL, NULL, SW_SHOWNORMAL);
Can I pass something in the 4th parameter i.e: lpParameters , so that I can handle this with MyApp.Exe , let's say if I am passing "Hi: in the 4th param:
HINSTANCE hShellExecuteStatus = ShellExecute(NULL, "open", "MyPath/MyApp.EXE", "Hi", NULL, SW_SHOWNORMAL);
Can I check in my application whether it is hi and display a message high.
I tried with POSTMESSAGE , but is not helpful with shellexecute
lpParameters will come through in the command line. Use GetCommandLine() to see it.
Related
I need to click on the "I Agree" button in the below code programmatically, could you please help? is this possible to use SendMessage(hButton, BM_CLICK, 0, 0); ?
typedef HRESULT STDAPICALLTYPE AcquireDeveloperLicense(
_In_opt_ HWND hwndParent,
_Out_ FILETIME *pExpiration
);
HINSTANCE hDll = LoadLibrary(TEXT("WSClient.dll"));
AcquireDeveloperLicense *acquire_license = (AcquireDeveloperLicense*)GetProcAddress(hDll, "AcquireDeveloperLicense");
FILETIME pExpiration = {};
HWND hwnd = GetConsoleWindow();
HRESULT result = acquire_license(hwnd, &pExpiration);
I am using visual studio 2015 and I want to write C++ static library that I can use in Unicode projects and in Multi-Byte projects, how I doing it right?
For example I have this code:
namespace Reg
{
LONG WINAPI CreateKey(
_In_ HKEY hKey,
_In_ LPCTSTR lpSubKey,
_In_ REGSAM samDesired,
_Out_ PHKEY phkResult
)
{
return RegCreateKeyEx(hKey,
lpSubKey,
0, NULL,
REG_OPTION_NON_VOLATILE,
samDesired,
NULL,
phkResult,
NULL);
}
}
Like Raymond Chen suggested in a comment, you can use two separate overloaded functions - one for Ansi, one for Unicode:
namespace Reg
{
LONG WINAPI CreateKey(
_In_ HKEY hKey,
_In_ LPCSTR lpSubKey,
_In_ REGSAM samDesired,
_Out_ PHKEY phkResult
)
{
return RegCreateKeyExA(hKey,
lpSubKey,
0, NULL,
REG_OPTION_NON_VOLATILE,
samDesired,
NULL,
phkResult,
NULL);
}
LONG WINAPI CreateKey(
_In_ HKEY hKey,
_In_ LPCWSTR lpSubKey,
_In_ REGSAM samDesired,
_Out_ PHKEY phkResult
)
{
return RegCreateKeyExW(hKey,
lpSubKey,
0, NULL,
REG_OPTION_NON_VOLATILE,
samDesired,
NULL,
phkResult,
NULL);
}
}
Or, like rubenvb suggested, just forget about the Ansi function altogether, focus on just Unicode by itself:
namespace Reg
{
LONG WINAPI CreateKey(
_In_ HKEY hKey,
_In_ LPCWSTR lpSubKey,
_In_ REGSAM samDesired,
_Out_ PHKEY phkResult
)
{
return RegCreateKeyExW(hKey,
lpSubKey,
0, NULL,
REG_OPTION_NON_VOLATILE,
samDesired,
NULL,
phkResult,
NULL);
}
}
you could do it same way as is usually used for Win32 functions:
CreateKeyW(..) { unicode implementation }
CreateKeyA(..) { byte string implementation }
#ifdef UNICODE
#define CreateKey CreateKeyW
#else
#define CreateKey CreateKeyA
#endif
I'm using WinInet and InternetOpenUrl to download a file... which is working. But I want to monitor the progress so I tried to add a Callback function but for some reason it's never called...
The code:
void CALLBACK DownloadProgress(HINTERNET hInternet, DWORD_PTR dwContext, DWORD dwInternetStatus, LPVOID lpvStatusInformation, DWORD dwStatusInformationLength)
{
// this function never gets called
MessageBox(NULL, L"test", L"test", MB_OK);
}
void Download()
{
HINTERNET hOpen = InternetOpen(0, INTERNET_OPEN_TYPE_DIRECT, 0, 0, 0);
InternetSetStatusCallback(hOpen, DownloadProgress);
HINTERNET hOpenUrl = InternetOpenUrl(hOpen, L"http://www.website.com/test.txt", 0, 0, 0, 0);
// small edit
InternetReadFile(hOpenUrl, data, SIZE, &size);
}
What am I doing wrong here?
From the MSDN:
INTERNET_STATUS_CALLBACK InternetSetStatusCallback(
_In_ HINTERNET hInternet,
_In_ INTERNET_STATUS_CALLBACK lpfnInternetCallback
);
Note The callback function specified in the lpfnInternetCallback
parameter will not be called on asynchronous operations for the
request handle when the dwContext parameter of HttpOpenRequest is set
to zero (INTERNET_NO_CALLBACK), or the connection handle when the
dwContext handle of InternetConnect is set to zero
(INTERNET_NO_CALLBACK).
In your case, you are using InternetOpenUrl (after calling InternetOpen) which is an easy alternative to work with URLs when you not need to access the particulars of the protocol. Syntax:
HINTERNET InternetOpenUrl(
_In_ HINTERNET hInternet,
_In_ LPCTSTR lpszUrl,
_In_ LPCTSTR lpszHeaders,
_In_ DWORD dwHeadersLength,
_In_ DWORD dwFlags,
_In_ DWORD_PTR dwContext
);
dwContext is an application-defined value that's passed to the callback function registered with InternetSetStatusCallback. Is used to identify the application context.
Now, note that you are passing dwContext=0 to this function in your code. If you change that, your code will work as you expect.
I'm using Dev C++. After I created a windows application, it generated some code which creates a window. I understand the code broadly. I've found the code to set the size, title, and background color but how do I set up the default position of the new window? I want to start it at the center of the screen.
You should have CreateWindow function, its definition is as follows:
HWND WINAPI CreateWindow(
__in_opt LPCTSTR lpClassName,
__in_opt LPCTSTR lpWindowName,
__in DWORD dwStyle,
__in int x,
__in int y,
__in int nWidth,
__in int nHeight,
__in_opt HWND hWndParent,
__in_opt HMENU hMenu,
__in_opt HINSTANCE hInstance,
__in_opt LPVOID lpParam
);
The x and y parameters specify the location of the newly-created window. These are the ones you need to set.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Windows Taskbar API
Win32: How to hide 3rd party windows in taskbar by hWnd
How can I prevent window from showing in the taskbar after I created it with CreateWindow? (Is there any parameter that allows me to do this, or something?)
set 'dwStyle' to WS_POPUP, the third argument:
HWND WINAPI CreateWindow(
__in_opt LPCTSTR lpClassName,
__in_opt LPCTSTR lpWindowName,
__in DWORD dwStyle,
__in int x,
__in int y,
__in int nWidth,
__in int nHeight,
__in_opt HWND hWndParent,
__in_opt HMENU hMenu,
__in_opt HINSTANCE hInstance,
__in_opt LPVOID lpParam);
If you're doing win32, I suggest, for your own sanity, you give Qt a try.
ITaskbarList::DeleteTab will also remove a window from the taskbar.