| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 805 人关注过本帖
标题:求助:VC++菜单编程背景
只看楼主 加入收藏
lixinqing0703
Rank: 2
等 级:论坛游民
威 望:1
帖 子:18
专家分:23
注 册:2008-9-29
结帖率:0
收藏
 问题点数:0 回复次数:1 
求助:VC++菜单编程背景
我写的程序调试运行都没有错,但是窗口背景是花的(应该是白色才对啊),并且用了VC插入一个菜单资源,有打开和关闭功能,在image7.h里定义:
#define IDM_OPEN 1
#define IDM_EXIT 2
但是调试完结果背景
//wcApp.hbrBackground = (HBRUSH) GetStockObjec(WHITE_BRUSH);
却不是白色的,而是从窗口截取的,这是为什么啊,请高手们指点一下。谢谢啊
以下是image.cpp源代码:
// image2.cpp : Defines the entry point for the application.
//
#include <stdio.h>
#include <string.h>
#include <dos.h>
#include <math.h>
#include <windows.h>
#include "image7.h"
 
int WindowInitial(HINSTANCE hInstance,HINSTANCE hPrevInstance,int nCmdShow);
long FAR PASCAL WndProc(HWND,WORD,WORD,LONG);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow);
HWND hwnd;
char *szAppName="NewWindows";
char *szMenuName="新建窗口";

int WINAPI WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
     // TODO: Place code here.
   MSG  msg;

   if (lpCmdLine==0) return 0;
   
   WindowInitial(hInstance,hPrevInstance,nCmdShow);   

   while(GetMessage(&msg,NULL,0,0))
   {
      TranslateMessage(&msg);
      DispatchMessage(&msg);
    
   }
   return msg.wParam;
}
int WindowInitial(HINSTANCE hInstance,
            HINSTANCE hPrevInstance,int nCmdShow)
{
    HWND     hWnd=NULL;
   WNDCLASS wcApp;
    HMENU    hMenu;
    HINSTANCE hIns;
    hIns=hInstance;
   hMenu = LoadMenu (hInstance,szAppName) ;
   if (!hPrevInstance) {
      wcApp.style         = CS_HREDRAW | CS_VREDRAW;
      wcApp.cbClsExtra    = 0;
      wcApp.cbWndExtra    = 0;
      wcApp.hInstance     = hInstance;
      wcApp.lpfnWndProc   = (WNDPROC)WndProc;
      wcApp.hIcon         = LoadIcon(NULL,IDI_APPLICATION);
        wcApp.hCursor       = LoadCursor(NULL,IDC_ARROW);
      wcApp.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
      wcApp.lpszMenuName  = szAppName;
      wcApp.lpszClassName = szAppName;

      RegisterClass(&wcApp);
   }

 hWnd = CreateWindow(szAppName,
                   szMenuName,
                WS_OVERLAPPEDWINDOW,
                0,0,
                600,400,
                NULL,NULL,hInstance,NULL);
 if(NULL==hWnd) return 0;
  ShowWindow(hWnd,nCmdShow);
   UpdateWindow(hWnd);
return 1;}

long FAR PASCAL WndProc(HWND hWnd,WORD message,
            WORD wParam,LONG lParam)
{   PAINTSTRUCT ps;
     HDC hdc;
    
   
   hwnd=hWnd;
  
    switch(message) {
      case WM_CREATE:
        return 0L;
      
      case  WM_CHAR:
          char ch[20];
            // sprintf(ch,"char is %d",wParam);
          MessageBox(hWnd,ch,"windows",MB_OK);
         break;
      case WM_LBUTTONDOWN:
    //      MessageBox(hWnd,"鼠标按下","New Pragram",MB_OK);
          hdc=GetDC(hWnd);
          TextOut(hdc,60,60,"按下鼠标",strlen("按下鼠标"));
          ReleaseDC(hWnd,hdc);
          break;
      case  WM_CLOSE:
          if(IDYES==MessageBox(hWnd,"是否要退出程序?","New Pragram",MB_YESNO))
          {DestroyWindow(hWnd);}
          break;
     case WM_COMMAND:
           switch (wParam) {
           case IDM_OPEN:
               return 0;
          case IDM_EXIT:              
              SendMessage(hWnd,WM_CLOSE,0,0L);
             return 0;
           }
           break;
        case WM_PAINT:
          hdc=BeginPaint(hWnd,&ps);
           TextOut(hdc,55,20,"first wondows",strlen("first wondows"));
           EndPaint(hWnd,&ps);
           break;
    case WM_DESTROY:
PostQuitMessage(0);
        break;
 
    default :
     return DefWindowProc(hWnd,message,wParam,lParam);
}
return 0;
}
搜索更多相关主题的帖子: 菜单 
2008-10-20 15:05
lixinqing0703
Rank: 2
等 级:论坛游民
威 望:1
帖 子:18
专家分:23
注 册:2008-9-29
收藏
得分:0 
把这句改成这样也不对:
hWnd = CreateWindow(szAppName,
              szMenuName,
         WS_OVERLAPPEDWINDOW,
         0,0,
         600,400,
         NULL,hMenu,hInstance,NULL);
究竟是什么原因呢?
2008-10-20 15:08
快速回复:求助:VC++菜单编程背景
数据加载中...
 
   



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

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