Newsgroup: it.comp.lang.visual-basic
Titolo: Problem Creating a window using Win32 API in VB. Please, help!!!

Hi
I am trying to create a window using CreateWindowEx in Visual Basic.
But before calling that, I need register a class name lpClassName.
For that, I am calling RegisterClassEx API.
This API takes WNDCLASSEX as the parameter. So I have to fill it before I
call the above function.
I am filling the structure as --->
    Dim pcWndClassEx As WNDCLASSEX
    pcWndClassEx.cbSize = Len(pcWndClassEx)
    pcWndClassEx.style = CS_OWNDC Or CS_HREDRAW Or CS_SAVEBITS Or CS_VREDRAW
*   pcWndClassEx.lpfnwndproc =        ???
    pcWndClassEx.hInstance = 0          ???
    pcWndClassEx.hIcon = Form1.Icon
    pcWndClassEx.hbrBackground = COLOR_WINDOWTEXT + 1
    pcWndClassEx.lpszMenuName = vbNullString
    pcWndClassEx.hIconSm = 0
    pcWndClassEx.lpszClassName = "MYWINDOW"
    pcWndClassEx.cbClsextra = 2
    pcWndClassEx.cbWndExtra = 2
I am not able to think a way for supplying the WindowProc i.e. lpfnwndproc
I am also not very sure, how one can handle messages or events on the window
created from visual basic using win32 API
What would be the way to implement the event handling of this window and
what should be
pcWndClassEx.lpfnwndproc =        ???           question mark here.
Please, guide me about what values other properties be filled with.
I am also not able to run GetLastError in Win32. It always returns 0.
My goal doing all this is to create a window from VB which is a popup and
doesn't show any focus shift from parent window even if it is clicked.
(Same like Menu)
Thanks in advance.
Farukh.

In the pcWndClassEx.lpfnwndproc you need to put the memory address of the
function that will handle all messages sent from windows to your window.
Of course, before getting the address you need to create a WndProc into a
BAS module, that function must have the same declaration as a Window
Callback procedure.
here's A C example of WndProc:
LRESULT CALLBACK WndProc(
    HWND hwnd,        // handle to window
    UINT uMsg,        // message identifier
    WPARAM wParam,    // first message parameter
    LPARAM lParam)    // second message parameter
{ 
 
    switch (uMsg) 
    { 
        case WM_CREATE: 
            // Initialize the window. 
            return 0; 
 
        case WM_PAINT: 
            // Paint the window's client area. 
            return 0; 
 
        case WM_SIZE: 
            // Set the size and position of the window. 
            return 0; 
 
        case WM_DESTROY: 
            // Clean up window-specific data objects. 
            return 0; 
 
        // 
        // Process other messages. 
        // 
 
        default: 
            return DefWindowProc(hwnd, uMsg, wParam, lParam); 
    } 
    return 0; 
}
VB Equivalent:
Public Function WindowProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
'// Insert message processing here!
Select Case Msg
   Case WM_???
      Debug.Print ...
End Select
...
...
...
End Function
As you probably know the AddressOf let you retrieve the memory address of a function (only those in .bas modules), the problem is that AddressOf is an operator,not a function so in order to assign the memory address to a structure member you need this helper function.
Function GetProc(proc As Long) As Long
 GetProc = proc
End Function
To use the function...
pcWndClassEx.lpfnwndproc =GetProc(AddressOf WndProc)
Regarding your goal.
Wouldn't be easier to have a timer that polls active object and use that object to set the focus back when user clicks your popup wind
ow? or in alternative subclass your window(instead of building from scratch)
and trap WM_ACTIVATE message.
Be careful, working with addressOf involves a lot of GPFs!
Bye
Corrado

More about your goal...
If your popup window is just a message window (like tooltips) you can use
this simple trick:
Remove Caption Bar and disable the window, this will avoid user activation,
then use ShowWindow using SW_SHOWNOACTIVATE as flag. Don't forget to put
window on top using ZOrder.
Bye,
Corrado


Maybe you can have a standard VB form, and show it using ShowWindow() API,
with the SW_NOACTIVATE parameter (check out this one, I'm not sure to
remember it exactly).
--
Roal Zanazzi
z...@iol.it