Click here to Skip to main content
15,918,404 members
Home / Discussions / System Admin
   

System Admin

 
GeneralRe: Opening USB Problem Pin
Mekong River28-May-06 23:35
Mekong River28-May-06 23:35 
GeneralRe: Opening USB Problem Pin
albCode28-May-06 23:46
albCode28-May-06 23:46 
GeneralRe: Opening USB Problem Pin
Mekong River28-May-06 23:53
Mekong River28-May-06 23:53 
GeneralRe: Opening USB Problem Pin
albCode29-May-06 0:42
albCode29-May-06 0:42 
GeneralRe: Opening USB Problem Pin
Mekong River29-May-06 5:48
Mekong River29-May-06 5:48 
GeneralRe: Opening USB Problem Pin
albCode29-May-06 20:35
albCode29-May-06 20:35 
GeneralRe: Opening USB Problem Pin
Mekong River29-May-06 21:16
Mekong River29-May-06 21:16 
GeneralRe: Opening USB Problem Pin
albCode29-May-06 21:30
albCode29-May-06 21:30 
GeneralRe: Opening USB Problem Pin
Mekong River29-May-06 21:34
Mekong River29-May-06 21:34 
GeneralRe: Opening USB Problem Pin
albCode29-May-06 22:16
albCode29-May-06 22:16 
GeneralRe: Opening USB Problem Pin
Michael Martin29-May-06 0:07
professionalMichael Martin29-May-06 0:07 
GeneralRe: Opening USB Problem Pin
albCode29-May-06 0:43
albCode29-May-06 0:43 
QuestionFile and setting transfer from windows xp to windows 2000 Pin
Mekong River28-May-06 18:34
Mekong River28-May-06 18:34 
QuestionConvert pst file from outlook 2003 to outlook xp Pin
Mekong River28-May-06 18:31
Mekong River28-May-06 18:31 
QuestionInternet gets disconnected... :( Pin
Eytukan26-May-06 6:21
Eytukan26-May-06 6:21 
AnswerRe: Internet gets disconnected... :( Pin
Eytukan26-May-06 6:22
Eytukan26-May-06 6:22 
AnswerRe: Internet gets disconnected... :( Pin
rituparn11-Jun-06 8:58
rituparn11-Jun-06 8:58 
GeneralRe: Internet gets disconnected... :( Pin
Eytukan11-Jun-06 20:53
Eytukan11-Jun-06 20:53 
QuestionCannot Access shared folder in win service on Win 2003 server Pin
LoveMay25-May-06 10:19
LoveMay25-May-06 10:19 
AnswerRe: Cannot Access shared folder in win service on Win 2003 server Pin
Mekong River25-May-06 15:57
Mekong River25-May-06 15:57 
AnswerRe: Cannot Access shared folder in win service on Win 2003 server Pin
progload25-May-06 19:43
progload25-May-06 19:43 
GeneralRe: Cannot Access shared folder in win service on Win 2003 server Pin
LoveMay26-May-06 3:12
LoveMay26-May-06 3:12 
QuestionMarvell Yukon network controller - Crap? Pin
Ray Cassick25-May-06 6:30
Ray Cassick25-May-06 6:30 
AnswerRe: Marvell Yukon network controller - Crap? Pin
Mekong River25-May-06 15:44
Mekong River25-May-06 15:44 
QuestionInserting a button into another application's window Pin
tuckmeng25-May-06 5:47
tuckmeng25-May-06 5:47 
Hi,

I'm learning how to insert a button into another application's window using c programming. In short, I wrote an EXE file which modified a particular Window of another EXE file to insert a button in that window. Need some advice:

a. I was able to get to the other application's window by first hooking onto the other application's window handle. But the strange thing is that my callback function for WM_LBUTTONDOWN of my introduced button was not called when I click on the inserted button. Instead, I had to do a GetMessage in my main program to get the message for the button and check the message member in there. With this, I was able to insert an extra button into a messagebox in another EXE file while it's running.

b. What I don't quite understand is that when I try to use the same technique on different windows, I get different errors. For instance, if I were to insert a button this way into a .NET window, the button shows up as a white patch. It responds to the click though. For some other programs, my button crashed without inserting itself. Puzzled by the different behaviour. Is it due to the windows message queue and the different nature of windows that I'm getting this?

c. Strangely, although my callback WinProc function is not called when I click on the button, not defining the WinProc actually causes my program to die when attaching itself to any window that's not a messagebox. Not quite sure why.

If someone can guide me to any article on how to insert controls into another app's windows or to understand the windows message loop more, I would be grateful. I'm trying to do a little enhancement to a program whose source code is lost (ie, I only have the binary).

My code looks like this:

#include <windows.h>
#include <stdio.h>

LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);

int WinMain(HINSTANCE hInst,HINSTANCE,LPSTR,int)
{
HWND hWnd, hwndButton;
WNDCLASS wc;
MSG msg;
// Trace Windows Handle based on Name
hWnd = (HWND) 0x1D0458;
printf("Begin Program\n");

wc.style=CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc=WindowProc;
wc.cbClsExtra=0;
wc.cbWndExtra=0;
wc.hInstance=hInst;
wc.hIcon=NULL;
wc.hCursor=NULL;
wc.hbrBackground=(HBRUSH)COLOR_WINDOWFRAME;
wc.lpszMenuName=NULL;
wc.lpszClassName="BUTTON";

if (!RegisterClass(&wc)) return 0;
printf("Finished Creating Button");
hwndButton = CreateWindow(
"BUTTON", // predefined class
"H", // button text
WS_VISIBLE | WS_CHILD , // styles

// Size and position values are given explicitly, because
// the CW_USEDEFAULT constant gives zero values for buttons.
950, // starting x position
0, // starting y position
20, // button width
20, // button height
hWnd, // parent window
NULL, // No menu
(HINSTANCE) GetWindowLongPtr(hWnd, GWLP_HINSTANCE),
NULL); // pointer not needed

if (!hwndButton) return 0;

ShowWindow(hwndButton,SW_SHOW);
UpdateWindow(hwndButton);
while (GetMessage(&msg,NULL,0,0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
printf("In Message Loop");
if (msg.message == WM_LBUTTONDOWN) {
MessageBox(0,"Button Worked in main loop","Button Worked",MB_OK);
printf("Works!");
ShowWindow(hwndButton,SW_SHOW);
} // end if
if (msg.message == WM_DESTROY) {
printf("Quitting\n");
// exit(0);
} // end if
} // end while

}// end all

LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
return DefWindowProc(hwnd, msg, wparam, lparam);
}

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.