| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 613 人关注过本帖
标题:请问各跟大哥,我怎么调不出通用模板窗口??代码如下
只看楼主 加入收藏
whyan
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2008-10-4
收藏
 问题点数:0 回复次数:0 
请问各跟大哥,我怎么调不出通用模板窗口??代码如下
#include "windows.h"
#include "stdio.h"
#include "stdlib.h"
#include "TestHead.h"
#include "commdlg.h"




LRESULT CALLBACK WinProc(HWND hWnd,UINT Message,WPARAM wParam,LPARAM lParam);

BOOL CALLBACK DlgProc(HWND hdlg,UINT Message,WPARAM wParam,LPARAM lParam);

OPENFILENAME ofn;

HINSTANCE hins;

HWND hdialog;

HDC hdc;
PAINTSTRUCT pstr;
HDC hdcmem;

HMENU hmenu;

HBITMAP hbm;
BITMAP bm;

HACCEL hacc;

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
        {
            HWND hWnd;
            MSG Message;
            WNDCLASS WndClass;
            WndClass.hInstance=hInstance;
            WndClass.lpfnWndProc=WinProc;
            WndClass.lpszClassName="whyan";
            WndClass.lpszMenuName="Menu";
            WndClass.style=CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS;
            WndClass.cbClsExtra=0;
            WndClass.cbWndExtra=0;
            WndClass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
            WndClass.hCursor=LoadCursor(NULL,IDC_ARROW);
            WndClass.hIcon=LoadIcon(NULL,"IDI_MAP");
            RegisterClass(&WndClass);
            
            hins=hInstance;
            hmenu=LoadMenu(hInstance,"Menu");
            
            hbm=LoadBitmap(hInstance,"dell");
            GetObject(hbm,sizeof(BITMAP),(LPVOID)&bm);

            hacc=LoadAccelerators(hInstance,"about");

            

            hWnd=CreateWindow("whyan","whyan",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,hmenu,hInstance,NULL);
            ShowWindow(hWnd,SW_SHOWNORMAL);
            UpdateWindow(hWnd);

            while(GetMessage(&Message,NULL,0,0))
            {
                if(!IsDialogMessage(hdialog,&Message))
                {
                    if(!TranslateAccelerator(hWnd,hacc,&Message))
                        {
                            TranslateMessage(&Message);
                            DispatchMessage(&Message);
                        }
                }
            }
            return Message.wParam;
        }

LRESULT CALLBACK WinProc(HWND hWnd,UINT Message,WPARAM wParam,LPARAM lParam)
        {
            //HDC hdc;
            //HBRUSH hbrush;
            //HPEN pen;
            

            int x,y;
            HCURSOR cursor;
            
            static char text[]="TextFiles(*.txt)\0*.txt\0";

            char StrFileName[]="";

            switch (Message)
            {
            case WM_CREATE:
                hdc=GetDC(hWnd);
                hdcmem=CreateCompatibleDC(hdc);
                ReleaseDC(hWnd,hdc);

                hdialog=CreateDialog(hins,"MENU2",hWnd,DlgProc);
                
                ofn.Flags=0;
                ofn.hInstance=NULL;
                ofn.hwndOwner=hWnd;
                ofn.lCustData=0;
                ofn.lpfnHook=NULL;
                ofn.lpstrCustomFilter=NULL;
                ofn.lpstrDefExt=NULL;
                ofn.lpstrFile=NULL;
                ofn.lpstrFileTitle=NULL;
                ofn.lpstrFilter=text;
                ofn.lpstrInitialDir=NULL;
                ofn.lpstrTitle=NULL;
                ofn.lpTemplateName=NULL;
                ofn.lStructSize=sizeof(OPENFILENAME);
                ofn.nFileExtension=0;
                ofn.nFileOffset=0;
                ofn.nFilterIndex=1;
                ofn.nMaxCustFilter=0;
                ofn.nMaxFile=0;
                ofn.nMaxFileTitle=0;
                break;
            case WM_COMMAND:
                switch(LOWORD(wParam))
                {
                case IDM_NEW:
                    MessageBox(hWnd,"你点了新建文档","information",MB_OK);
                    break;
                case IDM_OPEN:
                    //DialogBox(hins,"MENU1",hWnd,(DLGPROC)DlgProc);
                    ofn.lpstrFile=StrFileName;
                    ofn.Flags=OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST|OFN_HIDEREADONLY;
                    ofn.lpstrTitle="打开";
                    GetOpenFileName(&ofn);
                    break;
                case IDM_SAVE:
                    hdialog=CreateDialog(hins,"MENU2",hWnd,DlgProc);
                    break;

                }
            
                break;
            
            case WM_PAINT:
                hdc=BeginPaint(hWnd,&pstr);
                //SetMapMode(hdc,MM_ANISOTROPIC);
                //pen=(HPEN)GetStockObject(BLACK_PEN);
                //hbrush=(HBRUSH)GetStockObject(DKGRAY_BRUSH);
                //SelectObject(hdc,hbrush);
                //SelectObject(hdc,pen);
                //RoundRect(hdc,50,120,100,200,15,15);

                SelectObject(hdcmem,hbm);
                BitBlt(hdc,50,50,bm.bmWidth,bm.bmHeight,hdcmem,0,0,SRCCOPY);

                EndPaint(hWnd,&pstr);
                break;
            case WM_LBUTTONDOWN:
                //MessageBox(hWnd,"你按下了左键","infomation",MB_OK);
                if(wParam&MK_CONTROL)
                {
                    MessageBox(hWnd,"你按下了control键","infomation",MB_OK);
                }
                if(wParam&MK_SHIFT)
                {
                    MessageBox(hWnd,"你按下了shift键","infomation",MB_OK);
                }
                break;
            case WM_MBUTTONDOWN:
                MessageBox(hWnd,"你按下了中健","infomation",MB_OK);
                break;
            case WM_RBUTTONDOWN:
                MessageBox(hWnd,"你按下了右键","infomation",MB_OK);
                break;
            case WM_LBUTTONDBLCLK:
                MessageBox(hWnd,"你双击了左键","infomation",MB_OK);
                break;
            case WM_MOUSEMOVE:
                x=LOWORD(lParam);//取得lParam的低位值
                y=HIWORD(lParam);//取得lParam的高位值

                if(x>50&&x<400&&y>50&&y<400)
                {
                    if(x>=50&&x<=100&&y>=50&&y<=100)
                        {
                            cursor=LoadCursor(NULL,IDC_WAIT);
                            SetCursor(cursor);
                        }
                    if(x>=100&&x<=400&&y>=100&&y<=400)
                        {
                            cursor=LoadCursor(NULL,IDC_CROSS);
                            SetCursor(cursor);                        
                        }
                
                }
                break;
            case WM_DESTROY:
                PostQuitMessage(0);
                break;
            default:
                return(DefWindowProc(hWnd,Message,wParam,lParam));
            }
            return 0;
        }

BOOL CALLBACK DlgProc(HWND hdlg,UINT Message,WPARAM wParam,LPARAM lParam)
{
    switch(Message)
    {
    case WM_INITDIALOG:
        return 1;
    case WM_COMMAND:
        switch(LOWORD(wParam))
            {
                case IDOK:
                    EndDialog(hdlg,0);
                    break;
            }
        break;
    case WM_CLOSE:
        EndDialog(hdlg,0);
        break;
    }
    return 0;

}
搜索更多相关主题的帖子: 模板 窗口 代码 
2008-10-15 10:49
快速回复:请问各跟大哥,我怎么调不出通用模板窗口??代码如下
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.027719 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved