| By Bruce Armstrong | Article Rating: |
|
| April 26, 2005 10:00 AM EDT | Reads: |
29,970 |
hThreadID = GetCurrentThreadId() ;
Finally, we call the SetWindowsHookEx method, indicating that we are implementing the WH_CALLWNDPROCRET hook. There are a number of different types of hooks documented for SetWindowsHookEx on Microsoft's MSDN site. The WH_CALLWNDPROCRET hook means that our callback will be fired each time the dialog finishes processing a SendMessage message. The lParam argument that is passed to our callback contains a structure that lets us know more specifically what information was included in the original SendMessage call. I'll discuss a little later why we used this particular hook.
hHook = SetWindowsHookEx
( WH_CALLWNDPROCRET, DialogHook, (HINSTANCE)hInstance, hThreadID ) ;
Before we get there, let's look at the remaining functions. The FilterFileTypes function simply takes the PowerBuilder string array argument with the file types the developer wants to filter out of the dialog and copies the values to the member array we declared earlier:
int pArrayItemCount ;
pblong dim[1] ;
IPB_Value* ipv ;
int i ;
m_filetypes = m_pSession->NewUnbounded SimpleArray( pbvalue_string ) ;
pbarray pbaFileTypes = ci->pArgs->GetAt(0)->GetArray() ;
pArrayItemCount = m_pSession->GetArrayLength(pbaFileTypes) ;
for( i=1; i <= pArrayItemCount; i++)
{
dim[0]= i;
ipv = m_pSession -> AcquireArrayItemValue ( pbaFileTypes, dim ) ;
m_pSession -> SetArrayItemValue ( m_filetypes, dim, ipv ) ;
m_pSession -> ReleaseValue ( ipv ) ;
}
The SetDefaultFileType function is a bit simpler - just copying the value that was passed to the member:
pbDefault = ci->pArgs->GetAt(0)->GetString() ;
m_default = (LPSTR)m_pSession->GetString(pbDefault);
The destructor for our class calls the UnhookWindowsHookEx to tell the Windows API we're no longer interested in receiving messages.
UnhookWindowsHookEx ( hHook ) ;
delete this;
The DialogHook callback function is where the bulk of the processing occurs. The first thing we do is examine the value of the nCode argument that was passed to us. If the value of that argument is less than 0, we are being instructed by the Windows API that we need to exit our own callback without further processing and allow the next callback in line to have the message and then return back the value returned by that callback.
if ( nCode < 0 )
{
DWORD lResult ;
lResult = CallNextHookEx ( hHook, nCode, wParam, lParam ) ;
return lResult ;
}
Otherwise, we declare a structure to receive information about exactly what the dialog was doing when we were called and cast the lParam argument into that structure. Once we have that, we check to see if the message the dialog received was the CB_ADDSTRING message (the message sent by the original creator of the dialog to add an item to a dropdown list box). If it was, we also check to see if the m_filetypes array is populated. That's because the developer may not have called the FilterFileTypes method; they may simply be using the SetDefaultFileType to set the default.
Published April 26, 2005 Reads 29,970
Copyright © 2005 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Bruce Armstrong
Bruce Armstrong is a development lead with Integrated Data Services (www.get-integrated.com). A charter member of TeamSybase, he has been using PowerBuilder since version 1.0.B. He was a contributing author to SYS-CON's PowerBuilder 4.0 Secrets of the Masters and the editor of SAMs' PowerBuilder 9: Advanced Client/Server Development.
- Why SOA Needs Cloud Computing - Part 1
- Cloud Expo and The End of Tech Recession
- The Transition to Cloud Computing: What Does It Mean For You?
- A Rules Engine Built in PowerBuilder
- Sybase Named “Silver Sponsor” of iPhone Developer Summit
- How PowerBuilder Got Its Groove Back
- The Cloud Has Cross-Border Ambitions
- Ulitzer Names The World's 30 Most Influential Virtualization Bloggers
- Ulitzer Named "New Media" Partner of Greatly Anticipated iStrategy Event in Berlin
- Risks and Enterprise Mobility?
- Steps for Success in Enterprise Mobility?
- Are Mobile Luddites Resisting Mobility?
- The Difference Between Web Hosting and Cloud Computing
- Sybase CTO to Speak at 4th International Cloud Computing Expo
- Why SOA Needs Cloud Computing - Part 1
- Cloud Expo and The End of Tech Recession
- The Transition to Cloud Computing: What Does It Mean For You?
- Five Reasons to Choose a Private Cloud
- Seeding The Cloud: The Future of Data Management
- The Threat Behind the Firewall
- Economy Drives Adoption of Virtual Lab Technology
- Tips for Efficient PaaS Application Design
- A Rules Engine Built in PowerBuilder
- Sybase Named “Silver Sponsor” of iPhone Developer Summit
- Where Are RIA Technologies Headed in 2008?
- PowerBuilder History - How Did It Evolve?
- The Top 250 Players in the Cloud Computing Ecosystem
- Custom Common Dialogs Using SetWindowsHookEx
- DDDW Tips and Tricks
- OLE - Extending the Capabilities of PowerBuilder
- DataWindow.NET How To: Data Entry Form
- Book Excerpt: Sybase Adaptive Server Anywhere
- Sybase ASE 12.5 Performance and Tuning
- Working with SOA & Web Services in PowerBuilder
- Office 2003 Toolbar: A New Look For Your Old PowerBuilder App
- Dynamically Creating DataWindow Objects

































