Q 895000080 怎么报答都行
问题一:下面代码有 WndProc ,但是为何没有作为函数参数
hWnd = CreateWindow(IDS_APP_TITLE, IDS_APP_TITLE, WS_VISIBLE,
0,0, 240, 320, 
NULL, NULL, hInstance, NULL);
问题二:我要在上面创建按钮 点击按钮退出,有没什么好办法,用 CreateDialog 去取代CreateWindow 合理吗?
如果合理 那里面的一堆参数 会牵连到什么吗问题三  可以把 CreateWindow的回调函数 直接复制 粘贴 给  CreateDialog 的回调函数吗重点问题!!!回调函数 如何 和 CreateDialog 关联 问题四:帮我看下 我下面的  CreateDialog  为何失败
#include "stdafx.h"
#include "browse.h"
#include <windows.h>
#include <commctrl.h>
#include <Htmlctrl.h>
#include <aygshell.h>
// forward defines (instead of using string tables)
#define IDS_APP_TITLE TEXT("Browse")
#define IDS_START_PAGE TEXT("file://\\Program Files\\Browse\\start.html")
#define WM_LAUNCHBROWSER (WM_USER + 1)
#include"resource2.h",
// Global Variables:
HINSTANCE g_hInst; // The current instance
LPTSTR  Filename;
// Forward declarations of functions 
ATOM MyRegisterClass(
 HINSTANCE,
 LPTSTR
 );
BOOL InitInstance(
  HINSTANCE, 
  int
  );
LRESULT CALLBACK WndProc(
 HWND,
 UINT,
 WPARAM,
 LPARAM
 );
BOOL APIENTRY DllMain( HANDLE hModule, 
  DWORD  ul_reason_for_call, 
  LPVOID lpReserved
  )
{
return TRUE;
}void showhtml(LPTSTR  filename)
{
/*
::MessageBox(NULL,_T("success!"),_T("test"),MB_OK); HWND hRet = CreateDialog(g_hInst, (LPCTSTR)IDD_MAIN_DLG,NULL, NULL);
if(hRet == NULL)
{
::MessageBox(NULL,_T("fail!"),_T("test"),MB_OK); }
if(hRet != NULL)
{
::MessageBox(NULL,_T("not fail!"),_T("test"),MB_OK); } ShowWindow(hRet, SW_SHOW);
*/ Filename= filename; HINSTANCE hInstance;
int       nCmdShow=SW_SHOWMAXIMIZED; MSG msg;
// Perform application initialization:
if (FALSE == InitInstance (hInstance, nCmdShow)) 
{
return ;
} // Main Msg loop:
while (GetMessage(&msg, NULL, 0, 0)) 
{
TranslateMessage(&msg);
DispatchMessage(&msg);
} return ;
}
ATOM MyRegisterClass(
 HINSTANCE hInstance, 
 LPTSTR szWindowClass
 )
{
WNDCLASS wc; wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC) WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_BROWSE));
wc.hCursor = 0;
wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = 0;
wc.lpszClassName = szWindowClass; return RegisterClass(&wc);
}//
//  FUNCTION: InitInstance(HANDLE, int)
//
//  PURPOSE: Saves instance handle and creates main window
//
//  COMMENTS:
//
//    In this function, we save the instance handle in a global variable and
//    create and display the main program window.
//
BOOL InitInstance(
  HINSTANCE hInstance, 
  int nCmdShow
  )
{
HWND hWnd = NULL; g_hInst = hInstance; // Store instance handle in our global variable //If it is already running, then focus on the window
hWnd = FindWindow(IDS_APP_TITLE, IDS_APP_TITLE);
if (NULL != hWnd) 
{
SetForegroundWindow (hWnd);
return FALSE;
}  MyRegisterClass(hInstance, IDS_APP_TITLE); RECT rect;
GetClientRect(hWnd, &rect); // create a full-screen window for the browser control
hWnd = CreateWindow(IDS_APP_TITLE, IDS_APP_TITLE, WS_VISIBLE,
0,0, 240, 320, 
NULL, NULL, hInstance, NULL);
if (NULL == hWnd)
{
return FALSE;
} // Hide all the Shell parts and show the window in full screen mode.
//SHFullScreen(hWnd, SHFS_HIDETASKBAR | SHFS_HIDESTARTICON | SHFS_HIDESIPBUTTON); ShowWindow(hWnd, SW_SHOW);
UpdateWindow(hWnd); return TRUE;
}//
//  FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_NOTIFY  - Handle specific system notifications
//  WM_CREATE      - This code runs when the app starts
// WM_PAINT      - Paint the main window
//  WM_DESTROY      - post a quit Msg and return
//  WM_LAUNCHBROWSER - This code starts the browser control and loads a start page
//
//
LRESULT CALLBACK WndProc(
HWND hWnd, 
UINT Msg, 
WPARAM wParam, 
LPARAM lParam)
{
WCHAR wszURL[1000];
    HWND hWndHtml; switch (Msg) 
{
case WM_NOTIFY:
        {
NM_HTMLVIEW* pnmHTMLView = (NM_HTMLVIEW*)lParam;

            switch (pnmHTMLView->hdr.code)
            {
            // this code is processed when a user clicks on a hyperlink
case NM_HOTSPOT:
                // read the target string
mbstowcs(wszURL, (const char *)pnmHTMLView->szTarget, 1000);

// if the link is just "exit", then exit
if(wcscmp(wszURL, L"exit") == 0)
{
PostMessage(hWnd, WM_CLOSE, NULL, NULL);
                    // Returning TRUE indicates that we have handled the Msg
                    // and the control will not do its default processing.
                    return TRUE;
}
break;
}
}
        // Returning FALSE indicates to the html control that it should do
        // the default processing.
return FALSE;

case WM_CREATE:
// launch the browser control on startup
PostMessage(hWnd, WM_LAUNCHBROWSER, NULL, NULL);
break;

case WM_DESTROY:
PostQuitMessage(0);
break;

case WM_LAUNCHBROWSER:

// the only function call required to create a browser control instance
if (TRUE == InitHTMLControl(g_hInst))
{
// create the window for the control
hWndHtml = CreateWindow(TEXT("DISPLAYCLASS"), NULL, WS_VISIBLE, 0, 30, 
240, 210, 
hWnd, NULL, g_hInst, NULL);
ShowWindow(hWndHtml, SW_SHOW);
UpdateWindow(hWndHtml);

// load the start page into the browser window
SendMessage(hWndHtml, DTM_NAVIGATE, 0, (LPARAM)(LPTSTR)IDS_START_PAGE);
}
else
{
MessageBox(hWnd, TEXT("Unable to Launch Browser"), TEXT("Browser Control Problem:") , NULL);
DestroyWindow(hWnd);
}
break;

default:
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
return 0;
}

解决方案 »

  1.   

    问题一:下面代码有 WndProc ,但是为何没有作为函数参数
    ==============================
    它们是通过窗口类关联在一起的,
    hWnd = CreateWindow(IDS_APP_TITLE, IDS_APP_TITLE, WS_VISIBLE,0,0, 240, 320,  
    NULL, NULL, hInstance, NULL);
    中的应该是一个字符串,其实也就是类名,而在你的程序中应该有
    ATON RegisterClassEx(CONST WNDCLASSEX *Ipwcx); 注册的类名,其中Ipwcx中的
    WNDPROC lpfnWndProc指定处理函数。问题二:我要在上面创建按钮 点击按钮退出,有没什么好办法,用 CreateDialog 去取代CreateWindow 合理吗?
    如果合理 那里面的一堆参数 会牵连到什么吗
    ==========
    直接用CreateWindow也可以创建按钮啊,按钮的窗口类名是"Button",这个窗口类是系统创建好的,你直接可以用。问题三 可以把 CreateWindow的回调函数 直接复制 粘贴 给 CreateDialog 的回调函数吗
    ===============
    不行,它们的函数原型并不相同,处理方式也不完全一样,所以还是要修改的。
      

  2.   

    第四个太长了,不过HWND hRet = CreateDialog(g_hInst, (LPCTSTR)IDD_MAIN_DLG,NULL, NULL);
    你这个没写处理函数啊
      

  3.   

    DialogBoxParam DialogBox 这两个不好吗? 干什么用CreateDialog?