Window Explorer can't be found [closed] - c++

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
I'm using VC6 on XP system. I want to find a window whose title matches "C:\", but it can't be found. The return value of hr is -2147023116. Can anybody help?
HWND hwnd = FindWindow(NULL, "C:\\");
IWebBrowserApp *pwba;
HWND hwndindex = NULL;
HRESULT hr = pwba->get_HWND((long*)hwndindex);
if (hwnd == hwndindex)
{
BOOL found = true;
blablabla...
}

below code should work:
INT iIndex = 1;
HWND hwnd = ::GetWindow( ::GetDesktopWindow(), GW_CHILD | GW_HWNDFIRST );
while( hwnd ) {
CString sCaption;
::GetWindowText(hwnd, sCaption.GetBuffer(256), 255);
sCaption.ReleaseBuffer();
//DWORD dwProcessID = 0L;
//::GetWindowThreadProcessId(hwnd, &dwProcessID);
//CString sExePath;
//::GetModuleFileName((HMODULE)dwProcessID, sExePath.GetBuffer(MAX_PATH), MAX_PATH);
//sExePath.ReleaseBuffer();
if ( sCaption.Find(_T("c:\\")) != -1 ) {
// found you!
}
hwnd = ::GetWindow( hwnd, GW_HWNDNEXT );
}

HRESULT hr = pwba->get_HWND((long*)&hwndindex);
Problem solved! I missed one important "&"

Related

how can we Hijack DLL to lock all directories in windows to verify [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I mean when we double click a directory,in requests us to verify.I think it can be done by dll-injection.Hope can give some ideas or tutorial.Thanks
Hijack DLL is not required. It use Window Message Hook.
At the first, create DLL that call SetWindowsHookEx.
hHookMsg = SetWindowsHookEx(WH_GETMESSAGE, (HOOKPROC)MsgProc, hInstance, 0);
For example, called install_hook, And MsgProc here
LRESULT CALLBACK MsgProc(INT nCode, WPARAM wp, LPARAM lp) {
CHAR className[256];
MSG *pmsg;
LVHITTESTINFO htif;
POINT pt;
pmsg = (MSG*)lp;
GetClassName(pmsg->hwnd, className, sizeof(className));
if (!strcmp(className, "SysListView32")) {
if (pmsg->message == WM_LBUTTONDBLCLK) {
GetCursorPos((LPPOINT)&pt);
htif.pt = pt;
ScreenToClient(pmsg->hwnd, &htif.pt);
SendMessage(pmsg->hwnd, LVM_HITTEST, 0, (LPARAM)&htif);
if ((htif.flags & LVHT_ONITEM) != 0) {
// you can write action here
}
}
}
return CallNextHookEx( hHookMesg, nCode, wp, lp );
}
And create EXE that call this install_hook.

C++ Take a Screenshot [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I'm new to C++ and have to take a screenshot. I think I have set up everything besides the print method itself and that's where I'm struggling.
I found a post on so which describes how to take a screenshot, but it somehow doesn't work for me. (How to capture part of the screen and save it to a BMP?)
My Method looks like this:
STDOVERRIDEMETHODIMP VImplPrintable::Print(HDC hdc, CRect* pCr)
{
HDC hdcSource = GetDC(NULL);
HDC hdcMemory = CreateCompatibleDC(hdcSource);
int capX = GetDeviceCaps(hdcSource, HORZRES);
int capY = GetDeviceCaps(hdcSource, VERTRES);
HBITMAP hBitmap = CreateCompatibleBitmap(hdcSource, pCr->Width(), pCr->Height());
HBITMAP hBitmapOld = (HBITMAP)SelectObject(hdcMemory, hBitmap);
BitBlt(hdcMemory, 0, 0, pCr->Width(), pCr->Height(), hdcSource, pCr->top, pCr->left, SRCCOPY);
DeleteDC(hdcSource);
DeleteDC(hdcMemory);
return S_OK;
}
Problem is the screenshot seems to be an empty bitmap.
I don't really know if I it makes sense to create a new HDC when I'm
already getting one as a parameter. Any help is appreciated.
I cannot test because I do not know what is the framework that calls that method, but as you receive the HDC you want to write to, you simply should not use a memory DC and directly BitBlt there. But you should also test the return value of WinAPI calls to return error conditions to the caller:
STDOVERRIDEMETHODIMP VImplPrintable::Print(HDC hdc, CRect* pCr)
{
HDC hdcSource = GetDC(NULL);
if (NULL == hdcSource) return E_FAIL;
HRESUL cr = S_OK;
if (!BitBlt(hdc, 0, 0, pCr->Width(), pCr->Height(), hdcSource, pCr->top, pCr->left,
SRCCOPY)) cr = E_FAIL;
DeleteDC(hdcSource);
return cr;
}

FindWindowA Can't find process [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I tried to check value from a game but it seems FindWindowA can't find this game process I tried with other games and it worked. I checked in Process Hacker how the window is called and it still the same as in code but it still didn't work.
First project.cpp : main project file.
#include <iostream>
#include <Windows.h>
#include <string>
using namespace std;
DWORD pid;
DWORD Ammo = 0x01E7A938;
int MyAmmo;
int main()
{
HWND hWnd = FindWindowA(0, ("War Thunder Client"));
GetWindowThreadProcessId(hWnd, &pid);
HANDLE pHandle = OpenProcess(PROCESS_VM_READ, FALSE, pid);
while (true)
{
cout << MyAmmo << endl;
Sleep(100);
system("CLS");
}
system("Pause");
}
First, you should check if FindWindowA does actually find your window. If it does not than hWnd will have the value of NULL.
Second, the value of MyAmmo is not set everywhere. It is initalised to 0 because it is a global variable, but otherwise it's value is not changed anywhere.

C++: How might one draw an ASCII character at a specific location in command prompt [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Basically, I want to be able to create a function where I can go:
draw('C', x, y);
draw('h', x+1, y);
draw('a', x+2, y);
draw('r', x+3, y);
and command prompt will display Char at the given x and y position
All I could figure out in my research is that I will have to include <windows.h>, which I have very minimal experience with, and use the pre-defined content in that library.
This might help you get started. See https://msdn.microsoft.com/en-us/library/windows/desktop/ms682073(v=vs.85).aspx for more info.
#include <windows.h>
#include <stdio.h>
void main()
{
HANDLE screenBuffer = CreateConsoleScreenBuffer(
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
CONSOLE_TEXTMODE_BUFFER,
NULL);
if (screenBuffer == INVALID_HANDLE_VALUE)
{
printf("CreateConsoleScreenBuffer failed - (%d)\n", GetLastError());
return;
}
if (!SetConsoleActiveScreenBuffer(screenBuffer))
{
printf("SetConsoleActiveScreenBuffer failed - (%d)\n", GetLastError());
CloseHandle(screenBuffer);
return;
}
for (int x = 0; x < 10; ++x)
{
DWORD numCharsWritten;
WriteConsoleOutputCharacter(screenBuffer, "X", 1, COORD{(short)x, 1}, &numCharsWritten);
Sleep(1000);
}
CloseHandle(screenBuffer);
}

Never ending Win32 Message loop [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 13 years ago.
Improve this question
I have the following code:
MSG mssg;
// run till completed
while (true) {
// is there a message to process?
while(PeekMessage( &mssg, NULL, 0, 0, PM_REMOVE)) {
// dispatch the message
TranslateMessage(&mssg);
DispatchMessage(&mssg);
}
if(mssg.message == WM_QUIT){
break;
}
// our stuff will go here!!
Render();
listeners->OnUpdate();
}
Once it enters the inner loop with peekmessage it does not exit until the application is closed. Thus if I place a breakpoint at Render() and OnUpdate(), they will never be called during the lifetime of the application.
This runs contrary to what I'm being told here and here. How do I do this properly?
A typical game loop has this form:
MSG mssg;
bool notdone = true;
// run till completed
while ( notdone ) {
// is there a message to process?
if (PeekMessage( &mssg, NULL, 0, 0, PM_REMOVE)) {
if (mssg.message == WM_QUIT) notdone = false;
// dispatch the message
TranslateMessage(&mssg);
DispatchMessage(&mssg);
} else {
// our stuff will go here!!
Render();
listeners->OnUpdate();
}
}