Jump to content
Tuts 4 You

Enabling A Menu Button


Sigma

Recommended Posts

Posted

Does anyone know how to achieve VEOVEO like behavior? I ideal would like to check to see if a certain window is running, then if that window has focus, and if so, enable the buttons.

In a pseudo-code/C hybrid:

if((Window_Caption == "My window") && ("My Window" has focus)
{
Enables buttons
}

I have no idea what to even look for API wise in MSDN, so I'd take any hints/suggestions/pointers.

Thanks

Posted

I've seen a patch for TMPGenc XPress.

The problem was, you had to reenable some kinda license.

However, the boxes for the 'serial' used to retrieve a trial lic by some server couldnt be changed.

This tool was meant to do exactly this, making them writable...

The most ridiculous about it was, that it crashed when you pulled the app above TMPGenc and hit 'Enable editboxes' LOL

Actually, I can't help you w/ your problem, sorry :D

// Searching MSDN for 'enable label' 'enable menu' did not help ?

Posted (edited)

//EDIT

Thanks yamraaj, i got it.

What is the best way (give you know the HWND of the window in question) to find a specific button?

Edited by Sigma
Posted

I have done this once using the FindWindow and the EnumChildProc API.

void CLauncherDlg::OnBnClickedOk()
{
CWnd* handle1 = NULL; handle1 = FindWindow(NULL, "Some window");
if(handle1)
{
EnumChildWindows(handle1->m_hWnd, EnumChildProc, 0);
}
}BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lParam)
{
char szBuffer[100];
int iResult = GetWindowText( hwnd, szBuffer, 100);
CString sTest = szBuffer;
if(sTest == "caption from button")
{
// Your code here
}
}

Hope it helps.

Good luck.

Posted

Sh**t, I just noticed you are asking about a Menu Button.

The snipet I posted was to find the handle to a regular button, I'm not sure if it will help. :blush:

Posted

Hey man, thanks for the code. I actually sorted it out :P same method tho! I couldn't get the menu button to work, so i'm just enabling the button. Ah well!

Cheers all

  • 1 year later...
proletsearch
Posted

This thread is quite old, but I will post a quite old but working asm solution. It might help someone else ;) It's not mine solution. Author notes below:

; Author: Deuce

; Enables all child windows belonging to the foreground window.

.386
.model flat,stdcallinclude \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.libDlgProc proto :DWORD,:DWORD,:DWORD,:DWORD
EnableAll proto :DWORD, :DWORD.const
ENABLER equ 101
ICON equ 102
IDC_HANDLE equ 1002
IDC_ENABLE equ 1001
TIMERID equ WM_USER.data
template db '%lX',0
posBuffer db 10 dup (0).code
start:
invoke GetModuleHandle,NULL
invoke DialogBoxParam,eax,ENABLER,NULL,offset DlgProc,NULL
invoke ExitProcess,eaxDlgProc proc hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM cmp uMsg,WM_TIMER ;It's been 200 ms, enumerate the windows again!
je getPoint
cmp uMsg,WM_INITDIALOG ;Initialization stuff
je boxStart
cmp uMsg,WM_CLOSE
je boxClose retFalse:
mov eax,FALSE
ret boxStart:
invoke SetTimer,hWnd,TIMERID,200,NULL ;Start up the timer for 200 ms intervals
jmp retTrue boxClose:
invoke KillTimer,hWnd,TIMERID ;Okay we're done so shut everything down
invoke EndDialog,hWnd,NULL
jmp retTrue getPoint:
invoke IsDlgButtonChecked,hWnd,IDC_ENABLE ;Are we activated?
cmp eax,BST_CHECKED
jne retTrue invoke GetForegroundWindow ;Yep, what window is activated? push eax
invoke wsprintf,offset posBuffer,offset template,eax ;Translate handle value to ASCII
invoke SetDlgItemText,hWnd,IDC_HANDLE,offset posBuffer;Set the handle edit box
pop eax invoke EnumChildWindows,eax,offset EnableAll,NULL ;Now we are gonna filter through all child windows
retTrue:
mov eax,TRUE
retDlgProc endp
EnableAll proc hWnd:HWND,lParam:LPARAM ;Windows sends the handle of each child window here
invoke IsWindowEnabled,hWnd ;Is this child window enabled or not?
cmp eax,TRUE
je getNext invoke EnableWindow,hWnd,TRUE ;No, it's not! So we'll enable it :)
getNext:
mov eax,TRUE ;Return TRUE to get handle of next child window
ret
EnableAll endp
end start

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...