帮忙看看这个为什么我在win32中显示不了系统菜单

暗示的味道 2015-08-28 08:48:41
#include<windows.h>
#include<tchar.h>
#include"resource.h"
#define IDR_SYS_MENU2 1
LRESULT CALLBACK WndProc (HWND ,UINT ,WPARAM ,LPARAM );
BOOL CALLBACK DlgProc(HWND ,UINT ,WPARAM ,LPARAM );
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstrance,PSTR szCmdLine,int iCmdShow)
{
WNDCLASS wndclass;
MSG msg;
HMENU hmenu;
HWND hwnd;
static TCHAR szname[]=_T("hello");
wndclass.style=CS_HREDRAW|CS_VREDRAW;
wndclass.lpfnWndProc=WndProc;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hInstance=hInstance;
wndclass.hIcon=LoadIcon(hInstance,MAKEINTRESOURCE(IDI_ARRE));
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground=(HBRUSH)GetStockObject(COLOR_BTNFACE+1);
wndclass.lpszMenuName=NULL; //MAKEINTRESOURCE(IDR_MENU2);
wndclass.lpszClassName=szname;
if(!RegisterClass(&wndclass))
{
MessageBox(NULL,_T("aaa"),szname,MB_ICONERROR);
return 0;
}
hwnd=CreateWindow(szname,
_T("aa"),
WS_OVERLAPPEDWINDOW,//|WS_CAPTION|WS_SYSMENU,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
//hmenu=CreateMenu();
//hmenupop=CreateMenu();
hmenu=GetSystemMenu(hwnd,FALSE);
AppendMenu(hmenu,MF_STRING,IDR_SYS_MENU2,_T("00"));
ShowWindow(hwnd,iCmdShow);
UpdateWindow(hwnd);

while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);}
return 0;}
LRESULT CALLBACK WndProc (HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
HMENU hmenu;
HINSTANCE hInstance;
switch(message)
{
case WM_CREATE:
hInstance=((LPCREATESTRUCT)lParam)->hInstance;
case WM_SYSCOMMAND:
//
switch(LOWORD(wParam))
{
case IDR_SYS_MENU2:

MessageBox(NULL,_T("aaa"),_T("aa)"),MB_ICONERROR);


return 0;
}
return 0;
case WM_COMMAND:
switch(LOWORD(wParam))
{
hmenu=GetMenu(hwnd);
case IDV_1:
case IDV_2:


DialogBox(hInstance,_T("boot"),hwnd,DlgProc);
break;
}return 0;

case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,message,wParam,lParam);
}
BOOL CALLBACK DlgProc(HWND hwnd ,UINT message ,WPARAM wParam,LPARAM lParam)
{
switch(message)
{
case WM_INITDIALOG:
return 0;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
case IDCANCEL:
MessageBox(NULL,_T("dd"),_T("AA"),MB_ICONERROR);
EndDialog(hwnd,0);
}break;
}
return FALSE;
}



...全文
233 14 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
暗示的味道 2015-09-01
  • 打赏
  • 举报
回复
大佬,太感谢啦
www_adintr_com 2015-08-31
  • 打赏
  • 举报
回复
引用 11 楼 u012792138 的回复:
显示系统菜单怎么办?@???
啥子咋办 系统菜单不是显示有的吗 你知道系统菜单是哪个不? 在标题栏点右键弹出的菜单,你去试试,你添加的菜单项已经在里面了的。
暗示的味道 2015-08-31
  • 打赏
  • 举报
回复
呃 大佬对不起我明白了 嗨
暗示的味道 2015-08-31
  • 打赏
  • 举报
回复
显示系统菜单怎么办?@???
www_adintr_com 2015-08-30
  • 打赏
  • 举报
回复
引用 8 楼 u012792138 的回复:
上面这个我想显示一个按钮可显示不出来??? 两个问题是一个错误吗??

HWND	hwndpop=CreateWindow(_T("aa"),_T("KK"),
WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
10,20,30,40,hwnd,(HMENU)1,((LPCREATESTRUCT)lParam)->hInstance,NULL);
改成

			HWND	hwndpop=CreateWindow(_T("button"),_T("KK"),
				WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
				10,20,30,40,hwnd,(HMENU)1,((LPCREATESTRUCT)lParam)->hInstance,NULL);
www_adintr_com 2015-08-30
  • 打赏
  • 举报
回复

case WM_SYSCOMMAND:
//
switch(LOWORD(wParam))
{
case IDR_SYS_MENU2:
    MessageBox(NULL,_T("aaa"),_T("aa)"),MB_ICONERROR);
   return 0;
}
return 0;
这里的 return 0 改成 DefWindowProc

case WM_SYSCOMMAND:
//
switch(LOWORD(wParam))
{
case IDR_SYS_MENU2:
    MessageBox(NULL,_T("aaa"),_T("aa)"),MB_ICONERROR);
   return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
你不让系统处理移动,关闭这些消息,自然没有反应了。
暗示的味道 2015-08-30
  • 打赏
  • 举报
回复
上面这个我想显示一个按钮可显示不出来??? 两个问题是一个错误吗??
暗示的味道 2015-08-30
  • 打赏
  • 举报
回复
#include <tchar.h> #include <windows.h> #define ID_TIME1 1 #define ID_TIME2 2 #define ID_TIME3 3 /* Declare Windows procedure */ LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM); /* Make the class name into a global variable */ TCHAR szClassName[ ] = _T("CodeBlocksWindowsApp"); int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nCmdShow) { HWND hwnd; /* This is the handle for our window */ MSG messages; /* Here messages to the application are saved */ WNDCLASSEX wincl; /* Data structure for the windowclass */ /* The Window structure */ wincl.hInstance = hThisInstance; wincl.lpszClassName = szClassName; wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */ wincl.style = CS_DBLCLKS; /* Catch double-clicks */ wincl.cbSize = sizeof (WNDCLASSEX); /* Use default icon and mouse-pointer */ wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION); wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION); wincl.hCursor = LoadCursor (NULL, IDC_ARROW); wincl.lpszMenuName = NULL; /* No menu */ wincl.cbClsExtra = 0; /* No extra bytes after the window class */ wincl.cbWndExtra = 0; /* structure or the window instance */ /* Use Windows's default colour as the background of the window */ wincl.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH) ; /* Register the window class, and if it fails quit the program */ if (!RegisterClassEx (&wincl)) return 0; /* The class is registered, let's create the program*/ hwnd = CreateWindowEx ( 0, /* Extended possibilites for variation */ szClassName, /* Classname */ _T("Code::Blocks Template Windows App"), /* Title Text */ WS_OVERLAPPEDWINDOW, /* default window */ CW_USEDEFAULT, /* Windows decides the position */ CW_USEDEFAULT, /* where the window ends up on the screen */ 544, /* The programs width */ 375, /* and height in pixels */ HWND_DESKTOP, /* The window is a child-window to desktop */ NULL, /* No menu */ hThisInstance, /* Program Instance handler */ NULL /* No Window Creation data */ ); /* Make the window visible on the screen */ ShowWindow (hwnd, nCmdShow); /* Run the message loop. It will run until GetMessage() returns 0 */ while (GetMessage (&messages, NULL, 0, 0)) { /* Translate virtual-key messages into character messages */ TranslateMessage(&messages); /* Send message to WindowProcedure */ DispatchMessage(&messages); } /* The program return-value is 0 - The value that PostQuitMessage() gave */ return messages.wParam; } /* This function is called by the Windows function DispatchMessage() */ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {//Run-Time Check Failure #3 - The variable 'hwndpop' is being used without being initialized. HDC hdc; //hwndpop; PAINTSTRUCT ps; static int M=0,N=0; switch (message) /* handle the messages */ { case WM_CREATE: { //SetTimer(hwnd,ID_TIME1,1000,NULL); //SetTimer(hwnd,ID_TIME2,60000,NULL); //SetTimer(hwnd,ID_TIME3,3600000,NULL); HWND hwndpop=CreateWindow(_T("aa"),_T("KK"), WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON, 10,20,30,40,hwnd,(HMENU)1,((LPCREATESTRUCT)lParam)->hInstance,NULL); return 0;} /*case WM_TIMER: M=!M; InvalidateRect(hwnd,NULL,FALSE); return 0; //case ID_TIME2: //case ID_TIME3: //MessageBox(NULL,_T("hh"),_T("AA"),NULL); */ case WM_PAINT: hdc=BeginPaint(hwnd,&ps); //Rectangle(hdc,200,200,1000,1000); //InvalidateRect(hwnd,NULL,TRUE //UpdateWindow(hwndpop); //MoveToEx(hdc,0,0,NULL); //LineTo(hdc,120,120); //InvalidateRect(hwnd,NULL,TRUE); EndPaint(hwnd,&ps); break; case WM_DESTROY: PostQuitMessage (0); /* send a WM_QUIT to the message queue */ break; default: /* for messages that we don't deal with */ return DefWindowProc (hwnd, message, wParam, lParam); } return 0; }
宋寒松 2015-08-30
  • 打赏
  • 举报
回复
给你一个范例,参照它调试一下自己的代码:

#if defined(UNICODE) && !defined(_UNICODE)
    #define _UNICODE
#elif defined(_UNICODE) && !defined(UNICODE)
    #define UNICODE
#endif

#include <tchar.h>
#include <windows.h>

/*  Declare Windows procedure  */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/*  Make the class name into a global variable  */
TCHAR szClassName[ ] = _T("CodeBlocksWindowsApp");

int WINAPI WinMain (HINSTANCE hThisInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR lpszArgument,
                     int nCmdShow)
{
    HWND hwnd;               /* This is the handle for our window */
    MSG messages;            /* Here messages to the application are saved */
    WNDCLASSEX wincl;        /* Data structure for the windowclass */

    /* The Window structure */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use Windows's default colour as the background of the window */
    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

    /* Register the window class, and if it fails quit the program */
    if (!RegisterClassEx (&wincl))
        return 0;

    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx (
           0,                   /* Extended possibilites for variation */
           szClassName,         /* Classname */
           _T("Code::Blocks Template Windows App"),       /* Title Text */
           WS_OVERLAPPEDWINDOW, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           544,                 /* The programs width */
           375,                 /* and height in pixels */
           HWND_DESKTOP,        /* The window is a child-window to desktop */
           NULL,                /* No menu */
           hThisInstance,       /* Program Instance handler */
           NULL                 /* No Window Creation data */
           );

    /* Make the window visible on the screen */
    ShowWindow (hwnd, nCmdShow);

    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (GetMessage (&messages, NULL, 0, 0))
    {
        /* Translate virtual-key messages into character messages */
        TranslateMessage(&messages);
        /* Send message to WindowProcedure */
        DispatchMessage(&messages);
    }

    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;
}


/*  This function is called by the Windows function DispatchMessage()  */

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)                  /* handle the messages */
    {
        case WM_DESTROY:
            PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
            break;
        default:                      /* for messages that we don't deal with */
            return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
}
暗示的味道 2015-08-30
  • 打赏
  • 举报
回复
我想显示系统菜单 在windows程序设计.第10章里有个例子,可我运行就没有系统菜单还有就是什么都动不了只能靠任务管理器关闭???
暗示的味道 2015-08-29
  • 打赏
  • 举报
回复
没用啊??不是这里问题??
赵4老师 2015-08-28
  • 打赏
  • 举报
回复
关于自己是否适合编程的很简单的测试: 在报纸或杂志上随便找一段约1000字的文章,在Word中输入一遍。输完后再参考下面答案: A里面有10处以上文字或标点错误 B里面没有文字或标点错误并敢为此跟人打赌 C里面没有文字或标点错误并且字体和排版完全与原稿一致 D打印在半透明的纸上和原稿重叠在一起检查一模一样,且自我感觉很有成就感 A不适合编程(理由:打字准确度偏低、粗心大意) B初级程序员(理由:打字准确度很高、认真细致、自信、理解全角半角概念) C高级程序员(理由:在B的基础上理解字体和排版也是电脑打印的重要因素、但相比D还不够偏执、精益求精、结果可验证) D软件项目经理(理由:能针对项目给出令人信服的细致到极点的需求说明和典型测试用例。用户几乎挑不出毛病。专业!) 如果想从A变成B的话,到我的资源http://download.csdn.net/detail/zhao4zhong1/4084259里面下载“适合程序员的键盘练习”
fly_dragon_fly 2015-08-28
  • 打赏
  • 举报
回复
WM_CREATE差break;
暗示的味道 2015-08-28
  • 打赏
  • 举报
回复
而且我运行之后整个都窗口都死掉了,关都关不了只有打开任务管理器才关掉

70,022

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧